vue.esm-browser.js 582 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948
  1. /**
  2. * Make a map and return a function for checking if a key
  3. * is in that map.
  4. * IMPORTANT: all calls of this function must be prefixed with
  5. * \/\*#\_\_PURE\_\_\*\/
  6. * So that rollup can tree-shake them if necessary.
  7. */
  8. function makeMap(str, expectsLowerCase) {
  9. const map = Object.create(null);
  10. const list = str.split(',');
  11. for (let i = 0; i < list.length; i++) {
  12. map[list[i]] = true;
  13. }
  14. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  15. }
  16. /**
  17. * dev only flag -> name mapping
  18. */
  19. const PatchFlagNames = {
  20. [1 /* TEXT */]: `TEXT`,
  21. [2 /* CLASS */]: `CLASS`,
  22. [4 /* STYLE */]: `STYLE`,
  23. [8 /* PROPS */]: `PROPS`,
  24. [16 /* FULL_PROPS */]: `FULL_PROPS`,
  25. [32 /* HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  26. [64 /* STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  27. [128 /* KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  28. [256 /* UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  29. [512 /* NEED_PATCH */]: `NEED_PATCH`,
  30. [1024 /* DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  31. [2048 /* DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
  32. [-1 /* HOISTED */]: `HOISTED`,
  33. [-2 /* BAIL */]: `BAIL`
  34. };
  35. /**
  36. * Dev only
  37. */
  38. const slotFlagsText = {
  39. [1 /* STABLE */]: 'STABLE',
  40. [2 /* DYNAMIC */]: 'DYNAMIC',
  41. [3 /* FORWARDED */]: 'FORWARDED'
  42. };
  43. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  44. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  45. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt';
  46. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  47. const range = 2;
  48. function generateCodeFrame(source, start = 0, end = source.length) {
  49. // Split the content into individual lines but capture the newline sequence
  50. // that separated each line. This is important because the actual sequence is
  51. // needed to properly take into account the full line length for offset
  52. // comparison
  53. let lines = source.split(/(\r?\n)/);
  54. // Separate the lines and newline sequences into separate arrays for easier referencing
  55. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  56. lines = lines.filter((_, idx) => idx % 2 === 0);
  57. let count = 0;
  58. const res = [];
  59. for (let i = 0; i < lines.length; i++) {
  60. count +=
  61. lines[i].length +
  62. ((newlineSequences[i] && newlineSequences[i].length) || 0);
  63. if (count >= start) {
  64. for (let j = i - range; j <= i + range || end > count; j++) {
  65. if (j < 0 || j >= lines.length)
  66. continue;
  67. const line = j + 1;
  68. res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
  69. const lineLength = lines[j].length;
  70. const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
  71. if (j === i) {
  72. // push underline
  73. const pad = start - (count - (lineLength + newLineSeqLength));
  74. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  75. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  76. }
  77. else if (j > i) {
  78. if (end > count) {
  79. const length = Math.max(Math.min(end - count, lineLength), 1);
  80. res.push(` | ` + '^'.repeat(length));
  81. }
  82. count += lineLength + newLineSeqLength;
  83. }
  84. }
  85. break;
  86. }
  87. }
  88. return res.join('\n');
  89. }
  90. /**
  91. * On the client we only need to offer special cases for boolean attributes that
  92. * have different names from their corresponding dom properties:
  93. * - itemscope -> N/A
  94. * - allowfullscreen -> allowFullscreen
  95. * - formnovalidate -> formNoValidate
  96. * - ismap -> isMap
  97. * - nomodule -> noModule
  98. * - novalidate -> noValidate
  99. * - readonly -> readOnly
  100. */
  101. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  102. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  103. /**
  104. * Boolean attributes should be included if the value is truthy or ''.
  105. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  106. */
  107. function includeBooleanAttr(value) {
  108. return !!value || value === '';
  109. }
  110. function normalizeStyle(value) {
  111. if (isArray(value)) {
  112. const res = {};
  113. for (let i = 0; i < value.length; i++) {
  114. const item = value[i];
  115. const normalized = isString(item)
  116. ? parseStringStyle(item)
  117. : normalizeStyle(item);
  118. if (normalized) {
  119. for (const key in normalized) {
  120. res[key] = normalized[key];
  121. }
  122. }
  123. }
  124. return res;
  125. }
  126. else if (isString(value)) {
  127. return value;
  128. }
  129. else if (isObject(value)) {
  130. return value;
  131. }
  132. }
  133. const listDelimiterRE = /;(?![^(]*\))/g;
  134. const propertyDelimiterRE = /:(.+)/;
  135. function parseStringStyle(cssText) {
  136. const ret = {};
  137. cssText.split(listDelimiterRE).forEach(item => {
  138. if (item) {
  139. const tmp = item.split(propertyDelimiterRE);
  140. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  141. }
  142. });
  143. return ret;
  144. }
  145. function normalizeClass(value) {
  146. let res = '';
  147. if (isString(value)) {
  148. res = value;
  149. }
  150. else if (isArray(value)) {
  151. for (let i = 0; i < value.length; i++) {
  152. const normalized = normalizeClass(value[i]);
  153. if (normalized) {
  154. res += normalized + ' ';
  155. }
  156. }
  157. }
  158. else if (isObject(value)) {
  159. for (const name in value) {
  160. if (value[name]) {
  161. res += name + ' ';
  162. }
  163. }
  164. }
  165. return res.trim();
  166. }
  167. function normalizeProps(props) {
  168. if (!props)
  169. return null;
  170. let { class: klass, style } = props;
  171. if (klass && !isString(klass)) {
  172. props.class = normalizeClass(klass);
  173. }
  174. if (style) {
  175. props.style = normalizeStyle(style);
  176. }
  177. return props;
  178. }
  179. // These tag configs are shared between compiler-dom and runtime-dom, so they
  180. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  181. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  182. 'header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  183. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  184. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  185. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  186. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  187. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  188. 'option,output,progress,select,textarea,details,dialog,menu,' +
  189. 'summary,template,blockquote,iframe,tfoot';
  190. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  191. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  192. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  193. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  194. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  195. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  196. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  197. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  198. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  199. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  200. 'text,textPath,title,tspan,unknown,use,view';
  201. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  202. /**
  203. * Compiler only.
  204. * Do NOT use in runtime code paths unless behind `true` flag.
  205. */
  206. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  207. /**
  208. * Compiler only.
  209. * Do NOT use in runtime code paths unless behind `true` flag.
  210. */
  211. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  212. /**
  213. * Compiler only.
  214. * Do NOT use in runtime code paths unless behind `true` flag.
  215. */
  216. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  217. function looseCompareArrays(a, b) {
  218. if (a.length !== b.length)
  219. return false;
  220. let equal = true;
  221. for (let i = 0; equal && i < a.length; i++) {
  222. equal = looseEqual(a[i], b[i]);
  223. }
  224. return equal;
  225. }
  226. function looseEqual(a, b) {
  227. if (a === b)
  228. return true;
  229. let aValidType = isDate(a);
  230. let bValidType = isDate(b);
  231. if (aValidType || bValidType) {
  232. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  233. }
  234. aValidType = isSymbol(a);
  235. bValidType = isSymbol(b);
  236. if (aValidType || bValidType) {
  237. return a === b;
  238. }
  239. aValidType = isArray(a);
  240. bValidType = isArray(b);
  241. if (aValidType || bValidType) {
  242. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  243. }
  244. aValidType = isObject(a);
  245. bValidType = isObject(b);
  246. if (aValidType || bValidType) {
  247. /* istanbul ignore if: this if will probably never be called */
  248. if (!aValidType || !bValidType) {
  249. return false;
  250. }
  251. const aKeysCount = Object.keys(a).length;
  252. const bKeysCount = Object.keys(b).length;
  253. if (aKeysCount !== bKeysCount) {
  254. return false;
  255. }
  256. for (const key in a) {
  257. const aHasKey = a.hasOwnProperty(key);
  258. const bHasKey = b.hasOwnProperty(key);
  259. if ((aHasKey && !bHasKey) ||
  260. (!aHasKey && bHasKey) ||
  261. !looseEqual(a[key], b[key])) {
  262. return false;
  263. }
  264. }
  265. }
  266. return String(a) === String(b);
  267. }
  268. function looseIndexOf(arr, val) {
  269. return arr.findIndex(item => looseEqual(item, val));
  270. }
  271. /**
  272. * For converting {{ interpolation }} values to displayed strings.
  273. * @private
  274. */
  275. const toDisplayString = (val) => {
  276. return isString(val)
  277. ? val
  278. : val == null
  279. ? ''
  280. : isArray(val) ||
  281. (isObject(val) &&
  282. (val.toString === objectToString || !isFunction(val.toString)))
  283. ? JSON.stringify(val, replacer, 2)
  284. : String(val);
  285. };
  286. const replacer = (_key, val) => {
  287. // can't use isRef here since @vue/shared has no deps
  288. if (val && val.__v_isRef) {
  289. return replacer(_key, val.value);
  290. }
  291. else if (isMap(val)) {
  292. return {
  293. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  294. entries[`${key} =>`] = val;
  295. return entries;
  296. }, {})
  297. };
  298. }
  299. else if (isSet(val)) {
  300. return {
  301. [`Set(${val.size})`]: [...val.values()]
  302. };
  303. }
  304. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  305. return String(val);
  306. }
  307. return val;
  308. };
  309. const EMPTY_OBJ = Object.freeze({})
  310. ;
  311. const EMPTY_ARR = Object.freeze([]) ;
  312. const NOOP = () => { };
  313. /**
  314. * Always return false.
  315. */
  316. const NO = () => false;
  317. const onRE = /^on[^a-z]/;
  318. const isOn = (key) => onRE.test(key);
  319. const isModelListener = (key) => key.startsWith('onUpdate:');
  320. const extend = Object.assign;
  321. const remove = (arr, el) => {
  322. const i = arr.indexOf(el);
  323. if (i > -1) {
  324. arr.splice(i, 1);
  325. }
  326. };
  327. const hasOwnProperty = Object.prototype.hasOwnProperty;
  328. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  329. const isArray = Array.isArray;
  330. const isMap = (val) => toTypeString(val) === '[object Map]';
  331. const isSet = (val) => toTypeString(val) === '[object Set]';
  332. const isDate = (val) => toTypeString(val) === '[object Date]';
  333. const isFunction = (val) => typeof val === 'function';
  334. const isString = (val) => typeof val === 'string';
  335. const isSymbol = (val) => typeof val === 'symbol';
  336. const isObject = (val) => val !== null && typeof val === 'object';
  337. const isPromise = (val) => {
  338. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  339. };
  340. const objectToString = Object.prototype.toString;
  341. const toTypeString = (value) => objectToString.call(value);
  342. const toRawType = (value) => {
  343. // extract "RawType" from strings like "[object RawType]"
  344. return toTypeString(value).slice(8, -1);
  345. };
  346. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  347. const isIntegerKey = (key) => isString(key) &&
  348. key !== 'NaN' &&
  349. key[0] !== '-' &&
  350. '' + parseInt(key, 10) === key;
  351. const isReservedProp = /*#__PURE__*/ makeMap(
  352. // the leading comma is intentional so empty string "" is also included
  353. ',key,ref,ref_for,ref_key,' +
  354. 'onVnodeBeforeMount,onVnodeMounted,' +
  355. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  356. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  357. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  358. const cacheStringFunction = (fn) => {
  359. const cache = Object.create(null);
  360. return ((str) => {
  361. const hit = cache[str];
  362. return hit || (cache[str] = fn(str));
  363. });
  364. };
  365. const camelizeRE = /-(\w)/g;
  366. /**
  367. * @private
  368. */
  369. const camelize = cacheStringFunction((str) => {
  370. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  371. });
  372. const hyphenateRE = /\B([A-Z])/g;
  373. /**
  374. * @private
  375. */
  376. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  377. /**
  378. * @private
  379. */
  380. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  381. /**
  382. * @private
  383. */
  384. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  385. // compare whether a value has changed, accounting for NaN.
  386. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  387. const invokeArrayFns = (fns, arg) => {
  388. for (let i = 0; i < fns.length; i++) {
  389. fns[i](arg);
  390. }
  391. };
  392. const def = (obj, key, value) => {
  393. Object.defineProperty(obj, key, {
  394. configurable: true,
  395. enumerable: false,
  396. value
  397. });
  398. };
  399. const toNumber = (val) => {
  400. const n = parseFloat(val);
  401. return isNaN(n) ? val : n;
  402. };
  403. let _globalThis;
  404. const getGlobalThis = () => {
  405. return (_globalThis ||
  406. (_globalThis =
  407. typeof globalThis !== 'undefined'
  408. ? globalThis
  409. : typeof self !== 'undefined'
  410. ? self
  411. : typeof window !== 'undefined'
  412. ? window
  413. : typeof global !== 'undefined'
  414. ? global
  415. : {}));
  416. };
  417. function warn(msg, ...args) {
  418. console.warn(`[Vue warn] ${msg}`, ...args);
  419. }
  420. let activeEffectScope;
  421. class EffectScope {
  422. constructor(detached = false) {
  423. /**
  424. * @internal
  425. */
  426. this.active = true;
  427. /**
  428. * @internal
  429. */
  430. this.effects = [];
  431. /**
  432. * @internal
  433. */
  434. this.cleanups = [];
  435. if (!detached && activeEffectScope) {
  436. this.parent = activeEffectScope;
  437. this.index =
  438. (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
  439. }
  440. }
  441. run(fn) {
  442. if (this.active) {
  443. const currentEffectScope = activeEffectScope;
  444. try {
  445. activeEffectScope = this;
  446. return fn();
  447. }
  448. finally {
  449. activeEffectScope = currentEffectScope;
  450. }
  451. }
  452. else {
  453. warn(`cannot run an inactive effect scope.`);
  454. }
  455. }
  456. /**
  457. * This should only be called on non-detached scopes
  458. * @internal
  459. */
  460. on() {
  461. activeEffectScope = this;
  462. }
  463. /**
  464. * This should only be called on non-detached scopes
  465. * @internal
  466. */
  467. off() {
  468. activeEffectScope = this.parent;
  469. }
  470. stop(fromParent) {
  471. if (this.active) {
  472. let i, l;
  473. for (i = 0, l = this.effects.length; i < l; i++) {
  474. this.effects[i].stop();
  475. }
  476. for (i = 0, l = this.cleanups.length; i < l; i++) {
  477. this.cleanups[i]();
  478. }
  479. if (this.scopes) {
  480. for (i = 0, l = this.scopes.length; i < l; i++) {
  481. this.scopes[i].stop(true);
  482. }
  483. }
  484. // nested scope, dereference from parent to avoid memory leaks
  485. if (this.parent && !fromParent) {
  486. // optimized O(1) removal
  487. const last = this.parent.scopes.pop();
  488. if (last && last !== this) {
  489. this.parent.scopes[this.index] = last;
  490. last.index = this.index;
  491. }
  492. }
  493. this.active = false;
  494. }
  495. }
  496. }
  497. function effectScope(detached) {
  498. return new EffectScope(detached);
  499. }
  500. function recordEffectScope(effect, scope = activeEffectScope) {
  501. if (scope && scope.active) {
  502. scope.effects.push(effect);
  503. }
  504. }
  505. function getCurrentScope() {
  506. return activeEffectScope;
  507. }
  508. function onScopeDispose(fn) {
  509. if (activeEffectScope) {
  510. activeEffectScope.cleanups.push(fn);
  511. }
  512. else {
  513. warn(`onScopeDispose() is called when there is no active effect scope` +
  514. ` to be associated with.`);
  515. }
  516. }
  517. const createDep = (effects) => {
  518. const dep = new Set(effects);
  519. dep.w = 0;
  520. dep.n = 0;
  521. return dep;
  522. };
  523. const wasTracked = (dep) => (dep.w & trackOpBit) > 0;
  524. const newTracked = (dep) => (dep.n & trackOpBit) > 0;
  525. const initDepMarkers = ({ deps }) => {
  526. if (deps.length) {
  527. for (let i = 0; i < deps.length; i++) {
  528. deps[i].w |= trackOpBit; // set was tracked
  529. }
  530. }
  531. };
  532. const finalizeDepMarkers = (effect) => {
  533. const { deps } = effect;
  534. if (deps.length) {
  535. let ptr = 0;
  536. for (let i = 0; i < deps.length; i++) {
  537. const dep = deps[i];
  538. if (wasTracked(dep) && !newTracked(dep)) {
  539. dep.delete(effect);
  540. }
  541. else {
  542. deps[ptr++] = dep;
  543. }
  544. // clear bits
  545. dep.w &= ~trackOpBit;
  546. dep.n &= ~trackOpBit;
  547. }
  548. deps.length = ptr;
  549. }
  550. };
  551. const targetMap = new WeakMap();
  552. // The number of effects currently being tracked recursively.
  553. let effectTrackDepth = 0;
  554. let trackOpBit = 1;
  555. /**
  556. * The bitwise track markers support at most 30 levels of recursion.
  557. * This value is chosen to enable modern JS engines to use a SMI on all platforms.
  558. * When recursion depth is greater, fall back to using a full cleanup.
  559. */
  560. const maxMarkerBits = 30;
  561. let activeEffect;
  562. const ITERATE_KEY = Symbol('iterate' );
  563. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  564. class ReactiveEffect {
  565. constructor(fn, scheduler = null, scope) {
  566. this.fn = fn;
  567. this.scheduler = scheduler;
  568. this.active = true;
  569. this.deps = [];
  570. this.parent = undefined;
  571. recordEffectScope(this, scope);
  572. }
  573. run() {
  574. if (!this.active) {
  575. return this.fn();
  576. }
  577. let parent = activeEffect;
  578. let lastShouldTrack = shouldTrack;
  579. while (parent) {
  580. if (parent === this) {
  581. return;
  582. }
  583. parent = parent.parent;
  584. }
  585. try {
  586. this.parent = activeEffect;
  587. activeEffect = this;
  588. shouldTrack = true;
  589. trackOpBit = 1 << ++effectTrackDepth;
  590. if (effectTrackDepth <= maxMarkerBits) {
  591. initDepMarkers(this);
  592. }
  593. else {
  594. cleanupEffect(this);
  595. }
  596. return this.fn();
  597. }
  598. finally {
  599. if (effectTrackDepth <= maxMarkerBits) {
  600. finalizeDepMarkers(this);
  601. }
  602. trackOpBit = 1 << --effectTrackDepth;
  603. activeEffect = this.parent;
  604. shouldTrack = lastShouldTrack;
  605. this.parent = undefined;
  606. if (this.deferStop) {
  607. this.stop();
  608. }
  609. }
  610. }
  611. stop() {
  612. // stopped while running itself - defer the cleanup
  613. if (activeEffect === this) {
  614. this.deferStop = true;
  615. }
  616. else if (this.active) {
  617. cleanupEffect(this);
  618. if (this.onStop) {
  619. this.onStop();
  620. }
  621. this.active = false;
  622. }
  623. }
  624. }
  625. function cleanupEffect(effect) {
  626. const { deps } = effect;
  627. if (deps.length) {
  628. for (let i = 0; i < deps.length; i++) {
  629. deps[i].delete(effect);
  630. }
  631. deps.length = 0;
  632. }
  633. }
  634. function effect(fn, options) {
  635. if (fn.effect) {
  636. fn = fn.effect.fn;
  637. }
  638. const _effect = new ReactiveEffect(fn);
  639. if (options) {
  640. extend(_effect, options);
  641. if (options.scope)
  642. recordEffectScope(_effect, options.scope);
  643. }
  644. if (!options || !options.lazy) {
  645. _effect.run();
  646. }
  647. const runner = _effect.run.bind(_effect);
  648. runner.effect = _effect;
  649. return runner;
  650. }
  651. function stop(runner) {
  652. runner.effect.stop();
  653. }
  654. let shouldTrack = true;
  655. const trackStack = [];
  656. function pauseTracking() {
  657. trackStack.push(shouldTrack);
  658. shouldTrack = false;
  659. }
  660. function resetTracking() {
  661. const last = trackStack.pop();
  662. shouldTrack = last === undefined ? true : last;
  663. }
  664. function track(target, type, key) {
  665. if (shouldTrack && activeEffect) {
  666. let depsMap = targetMap.get(target);
  667. if (!depsMap) {
  668. targetMap.set(target, (depsMap = new Map()));
  669. }
  670. let dep = depsMap.get(key);
  671. if (!dep) {
  672. depsMap.set(key, (dep = createDep()));
  673. }
  674. const eventInfo = { effect: activeEffect, target, type, key }
  675. ;
  676. trackEffects(dep, eventInfo);
  677. }
  678. }
  679. function trackEffects(dep, debuggerEventExtraInfo) {
  680. let shouldTrack = false;
  681. if (effectTrackDepth <= maxMarkerBits) {
  682. if (!newTracked(dep)) {
  683. dep.n |= trackOpBit; // set newly tracked
  684. shouldTrack = !wasTracked(dep);
  685. }
  686. }
  687. else {
  688. // Full cleanup mode.
  689. shouldTrack = !dep.has(activeEffect);
  690. }
  691. if (shouldTrack) {
  692. dep.add(activeEffect);
  693. activeEffect.deps.push(dep);
  694. if (activeEffect.onTrack) {
  695. activeEffect.onTrack(Object.assign({ effect: activeEffect }, debuggerEventExtraInfo));
  696. }
  697. }
  698. }
  699. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  700. const depsMap = targetMap.get(target);
  701. if (!depsMap) {
  702. // never been tracked
  703. return;
  704. }
  705. let deps = [];
  706. if (type === "clear" /* CLEAR */) {
  707. // collection being cleared
  708. // trigger all effects for target
  709. deps = [...depsMap.values()];
  710. }
  711. else if (key === 'length' && isArray(target)) {
  712. depsMap.forEach((dep, key) => {
  713. if (key === 'length' || key >= newValue) {
  714. deps.push(dep);
  715. }
  716. });
  717. }
  718. else {
  719. // schedule runs for SET | ADD | DELETE
  720. if (key !== void 0) {
  721. deps.push(depsMap.get(key));
  722. }
  723. // also run for iteration key on ADD | DELETE | Map.SET
  724. switch (type) {
  725. case "add" /* ADD */:
  726. if (!isArray(target)) {
  727. deps.push(depsMap.get(ITERATE_KEY));
  728. if (isMap(target)) {
  729. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  730. }
  731. }
  732. else if (isIntegerKey(key)) {
  733. // new index added to array -> length changes
  734. deps.push(depsMap.get('length'));
  735. }
  736. break;
  737. case "delete" /* DELETE */:
  738. if (!isArray(target)) {
  739. deps.push(depsMap.get(ITERATE_KEY));
  740. if (isMap(target)) {
  741. deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
  742. }
  743. }
  744. break;
  745. case "set" /* SET */:
  746. if (isMap(target)) {
  747. deps.push(depsMap.get(ITERATE_KEY));
  748. }
  749. break;
  750. }
  751. }
  752. const eventInfo = { target, type, key, newValue, oldValue, oldTarget }
  753. ;
  754. if (deps.length === 1) {
  755. if (deps[0]) {
  756. {
  757. triggerEffects(deps[0], eventInfo);
  758. }
  759. }
  760. }
  761. else {
  762. const effects = [];
  763. for (const dep of deps) {
  764. if (dep) {
  765. effects.push(...dep);
  766. }
  767. }
  768. {
  769. triggerEffects(createDep(effects), eventInfo);
  770. }
  771. }
  772. }
  773. function triggerEffects(dep, debuggerEventExtraInfo) {
  774. // spread into array for stabilization
  775. const effects = isArray(dep) ? dep : [...dep];
  776. for (const effect of effects) {
  777. if (effect.computed) {
  778. triggerEffect(effect, debuggerEventExtraInfo);
  779. }
  780. }
  781. for (const effect of effects) {
  782. if (!effect.computed) {
  783. triggerEffect(effect, debuggerEventExtraInfo);
  784. }
  785. }
  786. }
  787. function triggerEffect(effect, debuggerEventExtraInfo) {
  788. if (effect !== activeEffect || effect.allowRecurse) {
  789. if (effect.onTrigger) {
  790. effect.onTrigger(extend({ effect }, debuggerEventExtraInfo));
  791. }
  792. if (effect.scheduler) {
  793. effect.scheduler();
  794. }
  795. else {
  796. effect.run();
  797. }
  798. }
  799. }
  800. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  801. const builtInSymbols = new Set(
  802. /*#__PURE__*/
  803. Object.getOwnPropertyNames(Symbol)
  804. // ios10.x Object.getOwnPropertyNames(Symbol) can enumerate 'arguments' and 'caller'
  805. // but accessing them on Symbol leads to TypeError because Symbol is a strict mode
  806. // function
  807. .filter(key => key !== 'arguments' && key !== 'caller')
  808. .map(key => Symbol[key])
  809. .filter(isSymbol));
  810. const get = /*#__PURE__*/ createGetter();
  811. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  812. const readonlyGet = /*#__PURE__*/ createGetter(true);
  813. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  814. const arrayInstrumentations = /*#__PURE__*/ createArrayInstrumentations();
  815. function createArrayInstrumentations() {
  816. const instrumentations = {};
  817. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  818. instrumentations[key] = function (...args) {
  819. const arr = toRaw(this);
  820. for (let i = 0, l = this.length; i < l; i++) {
  821. track(arr, "get" /* GET */, i + '');
  822. }
  823. // we run the method using the original args first (which may be reactive)
  824. const res = arr[key](...args);
  825. if (res === -1 || res === false) {
  826. // if that didn't work, run it again using raw values.
  827. return arr[key](...args.map(toRaw));
  828. }
  829. else {
  830. return res;
  831. }
  832. };
  833. });
  834. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  835. instrumentations[key] = function (...args) {
  836. pauseTracking();
  837. const res = toRaw(this)[key].apply(this, args);
  838. resetTracking();
  839. return res;
  840. };
  841. });
  842. return instrumentations;
  843. }
  844. function createGetter(isReadonly = false, shallow = false) {
  845. return function get(target, key, receiver) {
  846. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  847. return !isReadonly;
  848. }
  849. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  850. return isReadonly;
  851. }
  852. else if (key === "__v_isShallow" /* IS_SHALLOW */) {
  853. return shallow;
  854. }
  855. else if (key === "__v_raw" /* RAW */ &&
  856. receiver ===
  857. (isReadonly
  858. ? shallow
  859. ? shallowReadonlyMap
  860. : readonlyMap
  861. : shallow
  862. ? shallowReactiveMap
  863. : reactiveMap).get(target)) {
  864. return target;
  865. }
  866. const targetIsArray = isArray(target);
  867. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  868. return Reflect.get(arrayInstrumentations, key, receiver);
  869. }
  870. const res = Reflect.get(target, key, receiver);
  871. if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
  872. return res;
  873. }
  874. if (!isReadonly) {
  875. track(target, "get" /* GET */, key);
  876. }
  877. if (shallow) {
  878. return res;
  879. }
  880. if (isRef(res)) {
  881. // ref unwrapping - skip unwrap for Array + integer key.
  882. return targetIsArray && isIntegerKey(key) ? res : res.value;
  883. }
  884. if (isObject(res)) {
  885. // Convert returned value into a proxy as well. we do the isObject check
  886. // here to avoid invalid value warning. Also need to lazy access readonly
  887. // and reactive here to avoid circular dependency.
  888. return isReadonly ? readonly(res) : reactive(res);
  889. }
  890. return res;
  891. };
  892. }
  893. const set = /*#__PURE__*/ createSetter();
  894. const shallowSet = /*#__PURE__*/ createSetter(true);
  895. function createSetter(shallow = false) {
  896. return function set(target, key, value, receiver) {
  897. let oldValue = target[key];
  898. if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
  899. return false;
  900. }
  901. if (!shallow && !isReadonly(value)) {
  902. if (!isShallow(value)) {
  903. value = toRaw(value);
  904. oldValue = toRaw(oldValue);
  905. }
  906. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  907. oldValue.value = value;
  908. return true;
  909. }
  910. }
  911. const hadKey = isArray(target) && isIntegerKey(key)
  912. ? Number(key) < target.length
  913. : hasOwn(target, key);
  914. const result = Reflect.set(target, key, value, receiver);
  915. // don't trigger if target is something up in the prototype chain of original
  916. if (target === toRaw(receiver)) {
  917. if (!hadKey) {
  918. trigger(target, "add" /* ADD */, key, value);
  919. }
  920. else if (hasChanged(value, oldValue)) {
  921. trigger(target, "set" /* SET */, key, value, oldValue);
  922. }
  923. }
  924. return result;
  925. };
  926. }
  927. function deleteProperty(target, key) {
  928. const hadKey = hasOwn(target, key);
  929. const oldValue = target[key];
  930. const result = Reflect.deleteProperty(target, key);
  931. if (result && hadKey) {
  932. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  933. }
  934. return result;
  935. }
  936. function has(target, key) {
  937. const result = Reflect.has(target, key);
  938. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  939. track(target, "has" /* HAS */, key);
  940. }
  941. return result;
  942. }
  943. function ownKeys(target) {
  944. track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  945. return Reflect.ownKeys(target);
  946. }
  947. const mutableHandlers = {
  948. get,
  949. set,
  950. deleteProperty,
  951. has,
  952. ownKeys
  953. };
  954. const readonlyHandlers = {
  955. get: readonlyGet,
  956. set(target, key) {
  957. {
  958. warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  959. }
  960. return true;
  961. },
  962. deleteProperty(target, key) {
  963. {
  964. warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  965. }
  966. return true;
  967. }
  968. };
  969. const shallowReactiveHandlers = /*#__PURE__*/ extend({}, mutableHandlers, {
  970. get: shallowGet,
  971. set: shallowSet
  972. });
  973. // Props handlers are special in the sense that it should not unwrap top-level
  974. // refs (in order to allow refs to be explicitly passed down), but should
  975. // retain the reactivity of the normal readonly object.
  976. const shallowReadonlyHandlers = /*#__PURE__*/ extend({}, readonlyHandlers, {
  977. get: shallowReadonlyGet
  978. });
  979. const toShallow = (value) => value;
  980. const getProto = (v) => Reflect.getPrototypeOf(v);
  981. function get$1(target, key, isReadonly = false, isShallow = false) {
  982. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  983. // of the value
  984. target = target["__v_raw" /* RAW */];
  985. const rawTarget = toRaw(target);
  986. const rawKey = toRaw(key);
  987. if (!isReadonly) {
  988. if (key !== rawKey) {
  989. track(rawTarget, "get" /* GET */, key);
  990. }
  991. track(rawTarget, "get" /* GET */, rawKey);
  992. }
  993. const { has } = getProto(rawTarget);
  994. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  995. if (has.call(rawTarget, key)) {
  996. return wrap(target.get(key));
  997. }
  998. else if (has.call(rawTarget, rawKey)) {
  999. return wrap(target.get(rawKey));
  1000. }
  1001. else if (target !== rawTarget) {
  1002. // #3602 readonly(reactive(Map))
  1003. // ensure that the nested reactive `Map` can do tracking for itself
  1004. target.get(key);
  1005. }
  1006. }
  1007. function has$1(key, isReadonly = false) {
  1008. const target = this["__v_raw" /* RAW */];
  1009. const rawTarget = toRaw(target);
  1010. const rawKey = toRaw(key);
  1011. if (!isReadonly) {
  1012. if (key !== rawKey) {
  1013. track(rawTarget, "has" /* HAS */, key);
  1014. }
  1015. track(rawTarget, "has" /* HAS */, rawKey);
  1016. }
  1017. return key === rawKey
  1018. ? target.has(key)
  1019. : target.has(key) || target.has(rawKey);
  1020. }
  1021. function size(target, isReadonly = false) {
  1022. target = target["__v_raw" /* RAW */];
  1023. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  1024. return Reflect.get(target, 'size', target);
  1025. }
  1026. function add(value) {
  1027. value = toRaw(value);
  1028. const target = toRaw(this);
  1029. const proto = getProto(target);
  1030. const hadKey = proto.has.call(target, value);
  1031. if (!hadKey) {
  1032. target.add(value);
  1033. trigger(target, "add" /* ADD */, value, value);
  1034. }
  1035. return this;
  1036. }
  1037. function set$1(key, value) {
  1038. value = toRaw(value);
  1039. const target = toRaw(this);
  1040. const { has, get } = getProto(target);
  1041. let hadKey = has.call(target, key);
  1042. if (!hadKey) {
  1043. key = toRaw(key);
  1044. hadKey = has.call(target, key);
  1045. }
  1046. else {
  1047. checkIdentityKeys(target, has, key);
  1048. }
  1049. const oldValue = get.call(target, key);
  1050. target.set(key, value);
  1051. if (!hadKey) {
  1052. trigger(target, "add" /* ADD */, key, value);
  1053. }
  1054. else if (hasChanged(value, oldValue)) {
  1055. trigger(target, "set" /* SET */, key, value, oldValue);
  1056. }
  1057. return this;
  1058. }
  1059. function deleteEntry(key) {
  1060. const target = toRaw(this);
  1061. const { has, get } = getProto(target);
  1062. let hadKey = has.call(target, key);
  1063. if (!hadKey) {
  1064. key = toRaw(key);
  1065. hadKey = has.call(target, key);
  1066. }
  1067. else {
  1068. checkIdentityKeys(target, has, key);
  1069. }
  1070. const oldValue = get ? get.call(target, key) : undefined;
  1071. // forward the operation before queueing reactions
  1072. const result = target.delete(key);
  1073. if (hadKey) {
  1074. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  1075. }
  1076. return result;
  1077. }
  1078. function clear() {
  1079. const target = toRaw(this);
  1080. const hadItems = target.size !== 0;
  1081. const oldTarget = isMap(target)
  1082. ? new Map(target)
  1083. : new Set(target)
  1084. ;
  1085. // forward the operation before queueing reactions
  1086. const result = target.clear();
  1087. if (hadItems) {
  1088. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  1089. }
  1090. return result;
  1091. }
  1092. function createForEach(isReadonly, isShallow) {
  1093. return function forEach(callback, thisArg) {
  1094. const observed = this;
  1095. const target = observed["__v_raw" /* RAW */];
  1096. const rawTarget = toRaw(target);
  1097. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1098. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  1099. return target.forEach((value, key) => {
  1100. // important: make sure the callback is
  1101. // 1. invoked with the reactive map as `this` and 3rd arg
  1102. // 2. the value received should be a corresponding reactive/readonly.
  1103. return callback.call(thisArg, wrap(value), wrap(key), observed);
  1104. });
  1105. };
  1106. }
  1107. function createIterableMethod(method, isReadonly, isShallow) {
  1108. return function (...args) {
  1109. const target = this["__v_raw" /* RAW */];
  1110. const rawTarget = toRaw(target);
  1111. const targetIsMap = isMap(rawTarget);
  1112. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  1113. const isKeyOnly = method === 'keys' && targetIsMap;
  1114. const innerIterator = target[method](...args);
  1115. const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
  1116. !isReadonly &&
  1117. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  1118. // return a wrapped iterator which returns observed versions of the
  1119. // values emitted from the real iterator
  1120. return {
  1121. // iterator protocol
  1122. next() {
  1123. const { value, done } = innerIterator.next();
  1124. return done
  1125. ? { value, done }
  1126. : {
  1127. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  1128. done
  1129. };
  1130. },
  1131. // iterable protocol
  1132. [Symbol.iterator]() {
  1133. return this;
  1134. }
  1135. };
  1136. };
  1137. }
  1138. function createReadonlyMethod(type) {
  1139. return function (...args) {
  1140. {
  1141. const key = args[0] ? `on key "${args[0]}" ` : ``;
  1142. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  1143. }
  1144. return type === "delete" /* DELETE */ ? false : this;
  1145. };
  1146. }
  1147. function createInstrumentations() {
  1148. const mutableInstrumentations = {
  1149. get(key) {
  1150. return get$1(this, key);
  1151. },
  1152. get size() {
  1153. return size(this);
  1154. },
  1155. has: has$1,
  1156. add,
  1157. set: set$1,
  1158. delete: deleteEntry,
  1159. clear,
  1160. forEach: createForEach(false, false)
  1161. };
  1162. const shallowInstrumentations = {
  1163. get(key) {
  1164. return get$1(this, key, false, true);
  1165. },
  1166. get size() {
  1167. return size(this);
  1168. },
  1169. has: has$1,
  1170. add,
  1171. set: set$1,
  1172. delete: deleteEntry,
  1173. clear,
  1174. forEach: createForEach(false, true)
  1175. };
  1176. const readonlyInstrumentations = {
  1177. get(key) {
  1178. return get$1(this, key, true);
  1179. },
  1180. get size() {
  1181. return size(this, true);
  1182. },
  1183. has(key) {
  1184. return has$1.call(this, key, true);
  1185. },
  1186. add: createReadonlyMethod("add" /* ADD */),
  1187. set: createReadonlyMethod("set" /* SET */),
  1188. delete: createReadonlyMethod("delete" /* DELETE */),
  1189. clear: createReadonlyMethod("clear" /* CLEAR */),
  1190. forEach: createForEach(true, false)
  1191. };
  1192. const shallowReadonlyInstrumentations = {
  1193. get(key) {
  1194. return get$1(this, key, true, true);
  1195. },
  1196. get size() {
  1197. return size(this, true);
  1198. },
  1199. has(key) {
  1200. return has$1.call(this, key, true);
  1201. },
  1202. add: createReadonlyMethod("add" /* ADD */),
  1203. set: createReadonlyMethod("set" /* SET */),
  1204. delete: createReadonlyMethod("delete" /* DELETE */),
  1205. clear: createReadonlyMethod("clear" /* CLEAR */),
  1206. forEach: createForEach(true, true)
  1207. };
  1208. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  1209. iteratorMethods.forEach(method => {
  1210. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  1211. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  1212. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  1213. shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true);
  1214. });
  1215. return [
  1216. mutableInstrumentations,
  1217. readonlyInstrumentations,
  1218. shallowInstrumentations,
  1219. shallowReadonlyInstrumentations
  1220. ];
  1221. }
  1222. const [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations] = /* #__PURE__*/ createInstrumentations();
  1223. function createInstrumentationGetter(isReadonly, shallow) {
  1224. const instrumentations = shallow
  1225. ? isReadonly
  1226. ? shallowReadonlyInstrumentations
  1227. : shallowInstrumentations
  1228. : isReadonly
  1229. ? readonlyInstrumentations
  1230. : mutableInstrumentations;
  1231. return (target, key, receiver) => {
  1232. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  1233. return !isReadonly;
  1234. }
  1235. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  1236. return isReadonly;
  1237. }
  1238. else if (key === "__v_raw" /* RAW */) {
  1239. return target;
  1240. }
  1241. return Reflect.get(hasOwn(instrumentations, key) && key in target
  1242. ? instrumentations
  1243. : target, key, receiver);
  1244. };
  1245. }
  1246. const mutableCollectionHandlers = {
  1247. get: /*#__PURE__*/ createInstrumentationGetter(false, false)
  1248. };
  1249. const shallowCollectionHandlers = {
  1250. get: /*#__PURE__*/ createInstrumentationGetter(false, true)
  1251. };
  1252. const readonlyCollectionHandlers = {
  1253. get: /*#__PURE__*/ createInstrumentationGetter(true, false)
  1254. };
  1255. const shallowReadonlyCollectionHandlers = {
  1256. get: /*#__PURE__*/ createInstrumentationGetter(true, true)
  1257. };
  1258. function checkIdentityKeys(target, has, key) {
  1259. const rawKey = toRaw(key);
  1260. if (rawKey !== key && has.call(target, rawKey)) {
  1261. const type = toRawType(target);
  1262. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  1263. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  1264. `which can lead to inconsistencies. ` +
  1265. `Avoid differentiating between the raw and reactive versions ` +
  1266. `of an object and only use the reactive version if possible.`);
  1267. }
  1268. }
  1269. const reactiveMap = new WeakMap();
  1270. const shallowReactiveMap = new WeakMap();
  1271. const readonlyMap = new WeakMap();
  1272. const shallowReadonlyMap = new WeakMap();
  1273. function targetTypeMap(rawType) {
  1274. switch (rawType) {
  1275. case 'Object':
  1276. case 'Array':
  1277. return 1 /* COMMON */;
  1278. case 'Map':
  1279. case 'Set':
  1280. case 'WeakMap':
  1281. case 'WeakSet':
  1282. return 2 /* COLLECTION */;
  1283. default:
  1284. return 0 /* INVALID */;
  1285. }
  1286. }
  1287. function getTargetType(value) {
  1288. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  1289. ? 0 /* INVALID */
  1290. : targetTypeMap(toRawType(value));
  1291. }
  1292. function reactive(target) {
  1293. // if trying to observe a readonly proxy, return the readonly version.
  1294. if (isReadonly(target)) {
  1295. return target;
  1296. }
  1297. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
  1298. }
  1299. /**
  1300. * Return a shallowly-reactive copy of the original object, where only the root
  1301. * level properties are reactive. It also does not auto-unwrap refs (even at the
  1302. * root level).
  1303. */
  1304. function shallowReactive(target) {
  1305. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers, shallowReactiveMap);
  1306. }
  1307. /**
  1308. * Creates a readonly copy of the original object. Note the returned copy is not
  1309. * made reactive, but `readonly` can be called on an already reactive object.
  1310. */
  1311. function readonly(target) {
  1312. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
  1313. }
  1314. /**
  1315. * Returns a reactive-copy of the original object, where only the root level
  1316. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1317. * returned properties.
  1318. * This is used for creating the props proxy object for stateful components.
  1319. */
  1320. function shallowReadonly(target) {
  1321. return createReactiveObject(target, true, shallowReadonlyHandlers, shallowReadonlyCollectionHandlers, shallowReadonlyMap);
  1322. }
  1323. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
  1324. if (!isObject(target)) {
  1325. {
  1326. console.warn(`value cannot be made reactive: ${String(target)}`);
  1327. }
  1328. return target;
  1329. }
  1330. // target is already a Proxy, return it.
  1331. // exception: calling readonly() on a reactive object
  1332. if (target["__v_raw" /* RAW */] &&
  1333. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1334. return target;
  1335. }
  1336. // target already has corresponding Proxy
  1337. const existingProxy = proxyMap.get(target);
  1338. if (existingProxy) {
  1339. return existingProxy;
  1340. }
  1341. // only specific value types can be observed.
  1342. const targetType = getTargetType(target);
  1343. if (targetType === 0 /* INVALID */) {
  1344. return target;
  1345. }
  1346. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1347. proxyMap.set(target, proxy);
  1348. return proxy;
  1349. }
  1350. function isReactive(value) {
  1351. if (isReadonly(value)) {
  1352. return isReactive(value["__v_raw" /* RAW */]);
  1353. }
  1354. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1355. }
  1356. function isReadonly(value) {
  1357. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1358. }
  1359. function isShallow(value) {
  1360. return !!(value && value["__v_isShallow" /* IS_SHALLOW */]);
  1361. }
  1362. function isProxy(value) {
  1363. return isReactive(value) || isReadonly(value);
  1364. }
  1365. function toRaw(observed) {
  1366. const raw = observed && observed["__v_raw" /* RAW */];
  1367. return raw ? toRaw(raw) : observed;
  1368. }
  1369. function markRaw(value) {
  1370. def(value, "__v_skip" /* SKIP */, true);
  1371. return value;
  1372. }
  1373. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  1374. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  1375. function trackRefValue(ref) {
  1376. if (shouldTrack && activeEffect) {
  1377. ref = toRaw(ref);
  1378. {
  1379. trackEffects(ref.dep || (ref.dep = createDep()), {
  1380. target: ref,
  1381. type: "get" /* GET */,
  1382. key: 'value'
  1383. });
  1384. }
  1385. }
  1386. }
  1387. function triggerRefValue(ref, newVal) {
  1388. ref = toRaw(ref);
  1389. if (ref.dep) {
  1390. {
  1391. triggerEffects(ref.dep, {
  1392. target: ref,
  1393. type: "set" /* SET */,
  1394. key: 'value',
  1395. newValue: newVal
  1396. });
  1397. }
  1398. }
  1399. }
  1400. function isRef(r) {
  1401. return !!(r && r.__v_isRef === true);
  1402. }
  1403. function ref(value) {
  1404. return createRef(value, false);
  1405. }
  1406. function shallowRef(value) {
  1407. return createRef(value, true);
  1408. }
  1409. function createRef(rawValue, shallow) {
  1410. if (isRef(rawValue)) {
  1411. return rawValue;
  1412. }
  1413. return new RefImpl(rawValue, shallow);
  1414. }
  1415. class RefImpl {
  1416. constructor(value, __v_isShallow) {
  1417. this.__v_isShallow = __v_isShallow;
  1418. this.dep = undefined;
  1419. this.__v_isRef = true;
  1420. this._rawValue = __v_isShallow ? value : toRaw(value);
  1421. this._value = __v_isShallow ? value : toReactive(value);
  1422. }
  1423. get value() {
  1424. trackRefValue(this);
  1425. return this._value;
  1426. }
  1427. set value(newVal) {
  1428. newVal = this.__v_isShallow ? newVal : toRaw(newVal);
  1429. if (hasChanged(newVal, this._rawValue)) {
  1430. this._rawValue = newVal;
  1431. this._value = this.__v_isShallow ? newVal : toReactive(newVal);
  1432. triggerRefValue(this, newVal);
  1433. }
  1434. }
  1435. }
  1436. function triggerRef(ref) {
  1437. triggerRefValue(ref, ref.value );
  1438. }
  1439. function unref(ref) {
  1440. return isRef(ref) ? ref.value : ref;
  1441. }
  1442. const shallowUnwrapHandlers = {
  1443. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1444. set: (target, key, value, receiver) => {
  1445. const oldValue = target[key];
  1446. if (isRef(oldValue) && !isRef(value)) {
  1447. oldValue.value = value;
  1448. return true;
  1449. }
  1450. else {
  1451. return Reflect.set(target, key, value, receiver);
  1452. }
  1453. }
  1454. };
  1455. function proxyRefs(objectWithRefs) {
  1456. return isReactive(objectWithRefs)
  1457. ? objectWithRefs
  1458. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1459. }
  1460. class CustomRefImpl {
  1461. constructor(factory) {
  1462. this.dep = undefined;
  1463. this.__v_isRef = true;
  1464. const { get, set } = factory(() => trackRefValue(this), () => triggerRefValue(this));
  1465. this._get = get;
  1466. this._set = set;
  1467. }
  1468. get value() {
  1469. return this._get();
  1470. }
  1471. set value(newVal) {
  1472. this._set(newVal);
  1473. }
  1474. }
  1475. function customRef(factory) {
  1476. return new CustomRefImpl(factory);
  1477. }
  1478. function toRefs(object) {
  1479. if (!isProxy(object)) {
  1480. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1481. }
  1482. const ret = isArray(object) ? new Array(object.length) : {};
  1483. for (const key in object) {
  1484. ret[key] = toRef(object, key);
  1485. }
  1486. return ret;
  1487. }
  1488. class ObjectRefImpl {
  1489. constructor(_object, _key, _defaultValue) {
  1490. this._object = _object;
  1491. this._key = _key;
  1492. this._defaultValue = _defaultValue;
  1493. this.__v_isRef = true;
  1494. }
  1495. get value() {
  1496. const val = this._object[this._key];
  1497. return val === undefined ? this._defaultValue : val;
  1498. }
  1499. set value(newVal) {
  1500. this._object[this._key] = newVal;
  1501. }
  1502. }
  1503. function toRef(object, key, defaultValue) {
  1504. const val = object[key];
  1505. return isRef(val)
  1506. ? val
  1507. : new ObjectRefImpl(object, key, defaultValue);
  1508. }
  1509. class ComputedRefImpl {
  1510. constructor(getter, _setter, isReadonly, isSSR) {
  1511. this._setter = _setter;
  1512. this.dep = undefined;
  1513. this.__v_isRef = true;
  1514. this._dirty = true;
  1515. this.effect = new ReactiveEffect(getter, () => {
  1516. if (!this._dirty) {
  1517. this._dirty = true;
  1518. triggerRefValue(this);
  1519. }
  1520. });
  1521. this.effect.computed = this;
  1522. this.effect.active = this._cacheable = !isSSR;
  1523. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1524. }
  1525. get value() {
  1526. // the computed ref may get wrapped by other proxies e.g. readonly() #3376
  1527. const self = toRaw(this);
  1528. trackRefValue(self);
  1529. if (self._dirty || !self._cacheable) {
  1530. self._dirty = false;
  1531. self._value = self.effect.run();
  1532. }
  1533. return self._value;
  1534. }
  1535. set value(newValue) {
  1536. this._setter(newValue);
  1537. }
  1538. }
  1539. function computed(getterOrOptions, debugOptions, isSSR = false) {
  1540. let getter;
  1541. let setter;
  1542. const onlyGetter = isFunction(getterOrOptions);
  1543. if (onlyGetter) {
  1544. getter = getterOrOptions;
  1545. setter = () => {
  1546. console.warn('Write operation failed: computed value is readonly');
  1547. }
  1548. ;
  1549. }
  1550. else {
  1551. getter = getterOrOptions.get;
  1552. setter = getterOrOptions.set;
  1553. }
  1554. const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
  1555. if (debugOptions && !isSSR) {
  1556. cRef.effect.onTrack = debugOptions.onTrack;
  1557. cRef.effect.onTrigger = debugOptions.onTrigger;
  1558. }
  1559. return cRef;
  1560. }
  1561. const stack = [];
  1562. function pushWarningContext(vnode) {
  1563. stack.push(vnode);
  1564. }
  1565. function popWarningContext() {
  1566. stack.pop();
  1567. }
  1568. function warn$1(msg, ...args) {
  1569. // avoid props formatting or warn handler tracking deps that might be mutated
  1570. // during patch, leading to infinite recursion.
  1571. pauseTracking();
  1572. const instance = stack.length ? stack[stack.length - 1].component : null;
  1573. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1574. const trace = getComponentTrace();
  1575. if (appWarnHandler) {
  1576. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  1577. msg + args.join(''),
  1578. instance && instance.proxy,
  1579. trace
  1580. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1581. .join('\n'),
  1582. trace
  1583. ]);
  1584. }
  1585. else {
  1586. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1587. /* istanbul ignore if */
  1588. if (trace.length &&
  1589. // avoid spamming console during tests
  1590. !false) {
  1591. warnArgs.push(`\n`, ...formatTrace(trace));
  1592. }
  1593. console.warn(...warnArgs);
  1594. }
  1595. resetTracking();
  1596. }
  1597. function getComponentTrace() {
  1598. let currentVNode = stack[stack.length - 1];
  1599. if (!currentVNode) {
  1600. return [];
  1601. }
  1602. // we can't just use the stack because it will be incomplete during updates
  1603. // that did not start from the root. Re-construct the parent chain using
  1604. // instance parent pointers.
  1605. const normalizedStack = [];
  1606. while (currentVNode) {
  1607. const last = normalizedStack[0];
  1608. if (last && last.vnode === currentVNode) {
  1609. last.recurseCount++;
  1610. }
  1611. else {
  1612. normalizedStack.push({
  1613. vnode: currentVNode,
  1614. recurseCount: 0
  1615. });
  1616. }
  1617. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1618. currentVNode = parentInstance && parentInstance.vnode;
  1619. }
  1620. return normalizedStack;
  1621. }
  1622. /* istanbul ignore next */
  1623. function formatTrace(trace) {
  1624. const logs = [];
  1625. trace.forEach((entry, i) => {
  1626. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1627. });
  1628. return logs;
  1629. }
  1630. function formatTraceEntry({ vnode, recurseCount }) {
  1631. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1632. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1633. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1634. const close = `>` + postfix;
  1635. return vnode.props
  1636. ? [open, ...formatProps(vnode.props), close]
  1637. : [open + close];
  1638. }
  1639. /* istanbul ignore next */
  1640. function formatProps(props) {
  1641. const res = [];
  1642. const keys = Object.keys(props);
  1643. keys.slice(0, 3).forEach(key => {
  1644. res.push(...formatProp(key, props[key]));
  1645. });
  1646. if (keys.length > 3) {
  1647. res.push(` ...`);
  1648. }
  1649. return res;
  1650. }
  1651. /* istanbul ignore next */
  1652. function formatProp(key, value, raw) {
  1653. if (isString(value)) {
  1654. value = JSON.stringify(value);
  1655. return raw ? value : [`${key}=${value}`];
  1656. }
  1657. else if (typeof value === 'number' ||
  1658. typeof value === 'boolean' ||
  1659. value == null) {
  1660. return raw ? value : [`${key}=${value}`];
  1661. }
  1662. else if (isRef(value)) {
  1663. value = formatProp(key, toRaw(value.value), true);
  1664. return raw ? value : [`${key}=Ref<`, value, `>`];
  1665. }
  1666. else if (isFunction(value)) {
  1667. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1668. }
  1669. else {
  1670. value = toRaw(value);
  1671. return raw ? value : [`${key}=`, value];
  1672. }
  1673. }
  1674. const ErrorTypeStrings = {
  1675. ["sp" /* SERVER_PREFETCH */]: 'serverPrefetch hook',
  1676. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  1677. ["c" /* CREATED */]: 'created hook',
  1678. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  1679. ["m" /* MOUNTED */]: 'mounted hook',
  1680. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  1681. ["u" /* UPDATED */]: 'updated',
  1682. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1683. ["um" /* UNMOUNTED */]: 'unmounted hook',
  1684. ["a" /* ACTIVATED */]: 'activated hook',
  1685. ["da" /* DEACTIVATED */]: 'deactivated hook',
  1686. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  1687. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  1688. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  1689. [0 /* SETUP_FUNCTION */]: 'setup function',
  1690. [1 /* RENDER_FUNCTION */]: 'render function',
  1691. [2 /* WATCH_GETTER */]: 'watcher getter',
  1692. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  1693. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  1694. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  1695. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1696. [7 /* VNODE_HOOK */]: 'vnode hook',
  1697. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  1698. [9 /* TRANSITION_HOOK */]: 'transition hook',
  1699. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  1700. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  1701. [12 /* FUNCTION_REF */]: 'ref function',
  1702. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1703. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1704. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core'
  1705. };
  1706. function callWithErrorHandling(fn, instance, type, args) {
  1707. let res;
  1708. try {
  1709. res = args ? fn(...args) : fn();
  1710. }
  1711. catch (err) {
  1712. handleError(err, instance, type);
  1713. }
  1714. return res;
  1715. }
  1716. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1717. if (isFunction(fn)) {
  1718. const res = callWithErrorHandling(fn, instance, type, args);
  1719. if (res && isPromise(res)) {
  1720. res.catch(err => {
  1721. handleError(err, instance, type);
  1722. });
  1723. }
  1724. return res;
  1725. }
  1726. const values = [];
  1727. for (let i = 0; i < fn.length; i++) {
  1728. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1729. }
  1730. return values;
  1731. }
  1732. function handleError(err, instance, type, throwInDev = true) {
  1733. const contextVNode = instance ? instance.vnode : null;
  1734. if (instance) {
  1735. let cur = instance.parent;
  1736. // the exposed instance is the render proxy to keep it consistent with 2.x
  1737. const exposedInstance = instance.proxy;
  1738. // in production the hook receives only the error code
  1739. const errorInfo = ErrorTypeStrings[type] ;
  1740. while (cur) {
  1741. const errorCapturedHooks = cur.ec;
  1742. if (errorCapturedHooks) {
  1743. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1744. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1745. return;
  1746. }
  1747. }
  1748. }
  1749. cur = cur.parent;
  1750. }
  1751. // app-level handling
  1752. const appErrorHandler = instance.appContext.config.errorHandler;
  1753. if (appErrorHandler) {
  1754. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1755. return;
  1756. }
  1757. }
  1758. logError(err, type, contextVNode, throwInDev);
  1759. }
  1760. function logError(err, type, contextVNode, throwInDev = true) {
  1761. {
  1762. const info = ErrorTypeStrings[type];
  1763. if (contextVNode) {
  1764. pushWarningContext(contextVNode);
  1765. }
  1766. warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1767. if (contextVNode) {
  1768. popWarningContext();
  1769. }
  1770. // crash in dev by default so it's more noticeable
  1771. if (throwInDev) {
  1772. throw err;
  1773. }
  1774. else {
  1775. console.error(err);
  1776. }
  1777. }
  1778. }
  1779. let isFlushing = false;
  1780. let isFlushPending = false;
  1781. const queue = [];
  1782. let flushIndex = 0;
  1783. const pendingPreFlushCbs = [];
  1784. let activePreFlushCbs = null;
  1785. let preFlushIndex = 0;
  1786. const pendingPostFlushCbs = [];
  1787. let activePostFlushCbs = null;
  1788. let postFlushIndex = 0;
  1789. const resolvedPromise = /*#__PURE__*/ Promise.resolve();
  1790. let currentFlushPromise = null;
  1791. let currentPreFlushParentJob = null;
  1792. const RECURSION_LIMIT = 100;
  1793. function nextTick(fn) {
  1794. const p = currentFlushPromise || resolvedPromise;
  1795. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1796. }
  1797. // #2768
  1798. // Use binary-search to find a suitable position in the queue,
  1799. // so that the queue maintains the increasing order of job's id,
  1800. // which can prevent the job from being skipped and also can avoid repeated patching.
  1801. function findInsertionIndex(id) {
  1802. // the start index should be `flushIndex + 1`
  1803. let start = flushIndex + 1;
  1804. let end = queue.length;
  1805. while (start < end) {
  1806. const middle = (start + end) >>> 1;
  1807. const middleJobId = getId(queue[middle]);
  1808. middleJobId < id ? (start = middle + 1) : (end = middle);
  1809. }
  1810. return start;
  1811. }
  1812. function queueJob(job) {
  1813. // the dedupe search uses the startIndex argument of Array.includes()
  1814. // by default the search index includes the current job that is being run
  1815. // so it cannot recursively trigger itself again.
  1816. // if the job is a watch() callback, the search will start with a +1 index to
  1817. // allow it recursively trigger itself - it is the user's responsibility to
  1818. // ensure it doesn't end up in an infinite loop.
  1819. if ((!queue.length ||
  1820. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  1821. job !== currentPreFlushParentJob) {
  1822. if (job.id == null) {
  1823. queue.push(job);
  1824. }
  1825. else {
  1826. queue.splice(findInsertionIndex(job.id), 0, job);
  1827. }
  1828. queueFlush();
  1829. }
  1830. }
  1831. function queueFlush() {
  1832. if (!isFlushing && !isFlushPending) {
  1833. isFlushPending = true;
  1834. currentFlushPromise = resolvedPromise.then(flushJobs);
  1835. }
  1836. }
  1837. function invalidateJob(job) {
  1838. const i = queue.indexOf(job);
  1839. if (i > flushIndex) {
  1840. queue.splice(i, 1);
  1841. }
  1842. }
  1843. function queueCb(cb, activeQueue, pendingQueue, index) {
  1844. if (!isArray(cb)) {
  1845. if (!activeQueue ||
  1846. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  1847. pendingQueue.push(cb);
  1848. }
  1849. }
  1850. else {
  1851. // if cb is an array, it is a component lifecycle hook which can only be
  1852. // triggered by a job, which is already deduped in the main queue, so
  1853. // we can skip duplicate check here to improve perf
  1854. pendingQueue.push(...cb);
  1855. }
  1856. queueFlush();
  1857. }
  1858. function queuePreFlushCb(cb) {
  1859. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  1860. }
  1861. function queuePostFlushCb(cb) {
  1862. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  1863. }
  1864. function flushPreFlushCbs(seen, parentJob = null) {
  1865. if (pendingPreFlushCbs.length) {
  1866. currentPreFlushParentJob = parentJob;
  1867. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  1868. pendingPreFlushCbs.length = 0;
  1869. {
  1870. seen = seen || new Map();
  1871. }
  1872. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  1873. if (checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex])) {
  1874. continue;
  1875. }
  1876. activePreFlushCbs[preFlushIndex]();
  1877. }
  1878. activePreFlushCbs = null;
  1879. preFlushIndex = 0;
  1880. currentPreFlushParentJob = null;
  1881. // recursively flush until it drains
  1882. flushPreFlushCbs(seen, parentJob);
  1883. }
  1884. }
  1885. function flushPostFlushCbs(seen) {
  1886. // flush any pre cbs queued during the flush (e.g. pre watchers)
  1887. flushPreFlushCbs();
  1888. if (pendingPostFlushCbs.length) {
  1889. const deduped = [...new Set(pendingPostFlushCbs)];
  1890. pendingPostFlushCbs.length = 0;
  1891. // #1947 already has active queue, nested flushPostFlushCbs call
  1892. if (activePostFlushCbs) {
  1893. activePostFlushCbs.push(...deduped);
  1894. return;
  1895. }
  1896. activePostFlushCbs = deduped;
  1897. {
  1898. seen = seen || new Map();
  1899. }
  1900. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1901. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1902. if (checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex])) {
  1903. continue;
  1904. }
  1905. activePostFlushCbs[postFlushIndex]();
  1906. }
  1907. activePostFlushCbs = null;
  1908. postFlushIndex = 0;
  1909. }
  1910. }
  1911. const getId = (job) => job.id == null ? Infinity : job.id;
  1912. function flushJobs(seen) {
  1913. isFlushPending = false;
  1914. isFlushing = true;
  1915. {
  1916. seen = seen || new Map();
  1917. }
  1918. flushPreFlushCbs(seen);
  1919. // Sort queue before flush.
  1920. // This ensures that:
  1921. // 1. Components are updated from parent to child. (because parent is always
  1922. // created before the child so its render effect will have smaller
  1923. // priority number)
  1924. // 2. If a component is unmounted during a parent component's update,
  1925. // its update can be skipped.
  1926. queue.sort((a, b) => getId(a) - getId(b));
  1927. // conditional usage of checkRecursiveUpdate must be determined out of
  1928. // try ... catch block since Rollup by default de-optimizes treeshaking
  1929. // inside try-catch. This can leave all warning code unshaked. Although
  1930. // they would get eventually shaken by a minifier like terser, some minifiers
  1931. // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
  1932. const check = (job) => checkRecursiveUpdates(seen, job)
  1933. ;
  1934. try {
  1935. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1936. const job = queue[flushIndex];
  1937. if (job && job.active !== false) {
  1938. if (true && check(job)) {
  1939. continue;
  1940. }
  1941. // console.log(`running:`, job.id)
  1942. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  1943. }
  1944. }
  1945. }
  1946. finally {
  1947. flushIndex = 0;
  1948. queue.length = 0;
  1949. flushPostFlushCbs(seen);
  1950. isFlushing = false;
  1951. currentFlushPromise = null;
  1952. // some postFlushCb queued jobs!
  1953. // keep flushing until it drains.
  1954. if (queue.length ||
  1955. pendingPreFlushCbs.length ||
  1956. pendingPostFlushCbs.length) {
  1957. flushJobs(seen);
  1958. }
  1959. }
  1960. }
  1961. function checkRecursiveUpdates(seen, fn) {
  1962. if (!seen.has(fn)) {
  1963. seen.set(fn, 1);
  1964. }
  1965. else {
  1966. const count = seen.get(fn);
  1967. if (count > RECURSION_LIMIT) {
  1968. const instance = fn.ownerInstance;
  1969. const componentName = instance && getComponentName(instance.type);
  1970. warn$1(`Maximum recursive updates exceeded${componentName ? ` in component <${componentName}>` : ``}. ` +
  1971. `This means you have a reactive effect that is mutating its own ` +
  1972. `dependencies and thus recursively triggering itself. Possible sources ` +
  1973. `include component template, render function, updated hook or ` +
  1974. `watcher source function.`);
  1975. return true;
  1976. }
  1977. else {
  1978. seen.set(fn, count + 1);
  1979. }
  1980. }
  1981. }
  1982. /* eslint-disable no-restricted-globals */
  1983. let isHmrUpdating = false;
  1984. const hmrDirtyComponents = new Set();
  1985. // Expose the HMR runtime on the global object
  1986. // This makes it entirely tree-shakable without polluting the exports and makes
  1987. // it easier to be used in toolings like vue-loader
  1988. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1989. // to be set so that its instances can be registered / removed.
  1990. {
  1991. getGlobalThis().__VUE_HMR_RUNTIME__ = {
  1992. createRecord: tryWrap(createRecord),
  1993. rerender: tryWrap(rerender),
  1994. reload: tryWrap(reload)
  1995. };
  1996. }
  1997. const map = new Map();
  1998. function registerHMR(instance) {
  1999. const id = instance.type.__hmrId;
  2000. let record = map.get(id);
  2001. if (!record) {
  2002. createRecord(id, instance.type);
  2003. record = map.get(id);
  2004. }
  2005. record.instances.add(instance);
  2006. }
  2007. function unregisterHMR(instance) {
  2008. map.get(instance.type.__hmrId).instances.delete(instance);
  2009. }
  2010. function createRecord(id, initialDef) {
  2011. if (map.has(id)) {
  2012. return false;
  2013. }
  2014. map.set(id, {
  2015. initialDef: normalizeClassComponent(initialDef),
  2016. instances: new Set()
  2017. });
  2018. return true;
  2019. }
  2020. function normalizeClassComponent(component) {
  2021. return isClassComponent(component) ? component.__vccOpts : component;
  2022. }
  2023. function rerender(id, newRender) {
  2024. const record = map.get(id);
  2025. if (!record) {
  2026. return;
  2027. }
  2028. // update initial record (for not-yet-rendered component)
  2029. record.initialDef.render = newRender;
  2030. [...record.instances].forEach(instance => {
  2031. if (newRender) {
  2032. instance.render = newRender;
  2033. normalizeClassComponent(instance.type).render = newRender;
  2034. }
  2035. instance.renderCache = [];
  2036. // this flag forces child components with slot content to update
  2037. isHmrUpdating = true;
  2038. instance.update();
  2039. isHmrUpdating = false;
  2040. });
  2041. }
  2042. function reload(id, newComp) {
  2043. const record = map.get(id);
  2044. if (!record)
  2045. return;
  2046. newComp = normalizeClassComponent(newComp);
  2047. // update initial def (for not-yet-rendered components)
  2048. updateComponentDef(record.initialDef, newComp);
  2049. // create a snapshot which avoids the set being mutated during updates
  2050. const instances = [...record.instances];
  2051. for (const instance of instances) {
  2052. const oldComp = normalizeClassComponent(instance.type);
  2053. if (!hmrDirtyComponents.has(oldComp)) {
  2054. // 1. Update existing comp definition to match new one
  2055. if (oldComp !== record.initialDef) {
  2056. updateComponentDef(oldComp, newComp);
  2057. }
  2058. // 2. mark definition dirty. This forces the renderer to replace the
  2059. // component on patch.
  2060. hmrDirtyComponents.add(oldComp);
  2061. }
  2062. // 3. invalidate options resolution cache
  2063. instance.appContext.optionsCache.delete(instance.type);
  2064. // 4. actually update
  2065. if (instance.ceReload) {
  2066. // custom element
  2067. hmrDirtyComponents.add(oldComp);
  2068. instance.ceReload(newComp.styles);
  2069. hmrDirtyComponents.delete(oldComp);
  2070. }
  2071. else if (instance.parent) {
  2072. // 4. Force the parent instance to re-render. This will cause all updated
  2073. // components to be unmounted and re-mounted. Queue the update so that we
  2074. // don't end up forcing the same parent to re-render multiple times.
  2075. queueJob(instance.parent.update);
  2076. // instance is the inner component of an async custom element
  2077. // invoke to reset styles
  2078. if (instance.parent.type.__asyncLoader &&
  2079. instance.parent.ceReload) {
  2080. instance.parent.ceReload(newComp.styles);
  2081. }
  2082. }
  2083. else if (instance.appContext.reload) {
  2084. // root instance mounted via createApp() has a reload method
  2085. instance.appContext.reload();
  2086. }
  2087. else if (typeof window !== 'undefined') {
  2088. // root instance inside tree created via raw render(). Force reload.
  2089. window.location.reload();
  2090. }
  2091. else {
  2092. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  2093. }
  2094. }
  2095. // 5. make sure to cleanup dirty hmr components after update
  2096. queuePostFlushCb(() => {
  2097. for (const instance of instances) {
  2098. hmrDirtyComponents.delete(normalizeClassComponent(instance.type));
  2099. }
  2100. });
  2101. }
  2102. function updateComponentDef(oldComp, newComp) {
  2103. extend(oldComp, newComp);
  2104. for (const key in oldComp) {
  2105. if (key !== '__file' && !(key in newComp)) {
  2106. delete oldComp[key];
  2107. }
  2108. }
  2109. }
  2110. function tryWrap(fn) {
  2111. return (id, arg) => {
  2112. try {
  2113. return fn(id, arg);
  2114. }
  2115. catch (e) {
  2116. console.error(e);
  2117. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  2118. `Full reload required.`);
  2119. }
  2120. };
  2121. }
  2122. let devtools;
  2123. let buffer = [];
  2124. let devtoolsNotInstalled = false;
  2125. function emit(event, ...args) {
  2126. if (devtools) {
  2127. devtools.emit(event, ...args);
  2128. }
  2129. else if (!devtoolsNotInstalled) {
  2130. buffer.push({ event, args });
  2131. }
  2132. }
  2133. function setDevtoolsHook(hook, target) {
  2134. var _a, _b;
  2135. devtools = hook;
  2136. if (devtools) {
  2137. devtools.enabled = true;
  2138. buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
  2139. buffer = [];
  2140. }
  2141. else if (
  2142. // handle late devtools injection - only do this if we are in an actual
  2143. // browser environment to avoid the timer handle stalling test runner exit
  2144. // (#4815)
  2145. typeof window !== 'undefined' &&
  2146. // some envs mock window but not fully
  2147. window.HTMLElement &&
  2148. // also exclude jsdom
  2149. !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
  2150. const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
  2151. target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
  2152. replay.push((newHook) => {
  2153. setDevtoolsHook(newHook, target);
  2154. });
  2155. // clear buffer after 3s - the user probably doesn't have devtools installed
  2156. // at all, and keeping the buffer will cause memory leaks (#4738)
  2157. setTimeout(() => {
  2158. if (!devtools) {
  2159. target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
  2160. devtoolsNotInstalled = true;
  2161. buffer = [];
  2162. }
  2163. }, 3000);
  2164. }
  2165. else {
  2166. // non-browser env, assume not installed
  2167. devtoolsNotInstalled = true;
  2168. buffer = [];
  2169. }
  2170. }
  2171. function devtoolsInitApp(app, version) {
  2172. emit("app:init" /* APP_INIT */, app, version, {
  2173. Fragment,
  2174. Text,
  2175. Comment,
  2176. Static
  2177. });
  2178. }
  2179. function devtoolsUnmountApp(app) {
  2180. emit("app:unmount" /* APP_UNMOUNT */, app);
  2181. }
  2182. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  2183. const devtoolsComponentUpdated =
  2184. /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  2185. const devtoolsComponentRemoved =
  2186. /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  2187. function createDevtoolsComponentHook(hook) {
  2188. return (component) => {
  2189. emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  2190. };
  2191. }
  2192. const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:start" /* PERFORMANCE_START */);
  2193. const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook("perf:end" /* PERFORMANCE_END */);
  2194. function createDevtoolsPerformanceHook(hook) {
  2195. return (component, type, time) => {
  2196. emit(hook, component.appContext.app, component.uid, component, type, time);
  2197. };
  2198. }
  2199. function devtoolsComponentEmit(component, event, params) {
  2200. emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  2201. }
  2202. function emit$1(instance, event, ...rawArgs) {
  2203. if (instance.isUnmounted)
  2204. return;
  2205. const props = instance.vnode.props || EMPTY_OBJ;
  2206. {
  2207. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  2208. if (emitsOptions) {
  2209. if (!(event in emitsOptions) &&
  2210. !(false )) {
  2211. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  2212. warn$1(`Component emitted event "${event}" but it is neither declared in ` +
  2213. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  2214. }
  2215. }
  2216. else {
  2217. const validator = emitsOptions[event];
  2218. if (isFunction(validator)) {
  2219. const isValid = validator(...rawArgs);
  2220. if (!isValid) {
  2221. warn$1(`Invalid event arguments: event validation failed for event "${event}".`);
  2222. }
  2223. }
  2224. }
  2225. }
  2226. }
  2227. let args = rawArgs;
  2228. const isModelListener = event.startsWith('update:');
  2229. // for v-model update:xxx events, apply modifiers on args
  2230. const modelArg = isModelListener && event.slice(7);
  2231. if (modelArg && modelArg in props) {
  2232. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  2233. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  2234. if (trim) {
  2235. args = rawArgs.map(a => a.trim());
  2236. }
  2237. if (number) {
  2238. args = rawArgs.map(toNumber);
  2239. }
  2240. }
  2241. {
  2242. devtoolsComponentEmit(instance, event, args);
  2243. }
  2244. {
  2245. const lowerCaseEvent = event.toLowerCase();
  2246. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  2247. warn$1(`Event "${lowerCaseEvent}" is emitted in component ` +
  2248. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  2249. `Note that HTML attributes are case-insensitive and you cannot use ` +
  2250. `v-on to listen to camelCase events when using in-DOM templates. ` +
  2251. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  2252. }
  2253. }
  2254. let handlerName;
  2255. let handler = props[(handlerName = toHandlerKey(event))] ||
  2256. // also try camelCase event handler (#2249)
  2257. props[(handlerName = toHandlerKey(camelize(event)))];
  2258. // for v-model update:xxx events, also trigger kebab-case equivalent
  2259. // for props passed via kebab-case
  2260. if (!handler && isModelListener) {
  2261. handler = props[(handlerName = toHandlerKey(hyphenate(event)))];
  2262. }
  2263. if (handler) {
  2264. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2265. }
  2266. const onceHandler = props[handlerName + `Once`];
  2267. if (onceHandler) {
  2268. if (!instance.emitted) {
  2269. instance.emitted = {};
  2270. }
  2271. else if (instance.emitted[handlerName]) {
  2272. return;
  2273. }
  2274. instance.emitted[handlerName] = true;
  2275. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  2276. }
  2277. }
  2278. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  2279. const cache = appContext.emitsCache;
  2280. const cached = cache.get(comp);
  2281. if (cached !== undefined) {
  2282. return cached;
  2283. }
  2284. const raw = comp.emits;
  2285. let normalized = {};
  2286. // apply mixin/extends props
  2287. let hasExtends = false;
  2288. if (!isFunction(comp)) {
  2289. const extendEmits = (raw) => {
  2290. const normalizedFromExtend = normalizeEmitsOptions(raw, appContext, true);
  2291. if (normalizedFromExtend) {
  2292. hasExtends = true;
  2293. extend(normalized, normalizedFromExtend);
  2294. }
  2295. };
  2296. if (!asMixin && appContext.mixins.length) {
  2297. appContext.mixins.forEach(extendEmits);
  2298. }
  2299. if (comp.extends) {
  2300. extendEmits(comp.extends);
  2301. }
  2302. if (comp.mixins) {
  2303. comp.mixins.forEach(extendEmits);
  2304. }
  2305. }
  2306. if (!raw && !hasExtends) {
  2307. cache.set(comp, null);
  2308. return null;
  2309. }
  2310. if (isArray(raw)) {
  2311. raw.forEach(key => (normalized[key] = null));
  2312. }
  2313. else {
  2314. extend(normalized, raw);
  2315. }
  2316. cache.set(comp, normalized);
  2317. return normalized;
  2318. }
  2319. // Check if an incoming prop key is a declared emit event listener.
  2320. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  2321. // both considered matched listeners.
  2322. function isEmitListener(options, key) {
  2323. if (!options || !isOn(key)) {
  2324. return false;
  2325. }
  2326. key = key.slice(2).replace(/Once$/, '');
  2327. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  2328. hasOwn(options, hyphenate(key)) ||
  2329. hasOwn(options, key));
  2330. }
  2331. /**
  2332. * mark the current rendering instance for asset resolution (e.g.
  2333. * resolveComponent, resolveDirective) during render
  2334. */
  2335. let currentRenderingInstance = null;
  2336. let currentScopeId = null;
  2337. /**
  2338. * Note: rendering calls maybe nested. The function returns the parent rendering
  2339. * instance if present, which should be restored after the render is done:
  2340. *
  2341. * ```js
  2342. * const prev = setCurrentRenderingInstance(i)
  2343. * // ...render
  2344. * setCurrentRenderingInstance(prev)
  2345. * ```
  2346. */
  2347. function setCurrentRenderingInstance(instance) {
  2348. const prev = currentRenderingInstance;
  2349. currentRenderingInstance = instance;
  2350. currentScopeId = (instance && instance.type.__scopeId) || null;
  2351. return prev;
  2352. }
  2353. /**
  2354. * Set scope id when creating hoisted vnodes.
  2355. * @private compiler helper
  2356. */
  2357. function pushScopeId(id) {
  2358. currentScopeId = id;
  2359. }
  2360. /**
  2361. * Technically we no longer need this after 3.0.8 but we need to keep the same
  2362. * API for backwards compat w/ code generated by compilers.
  2363. * @private
  2364. */
  2365. function popScopeId() {
  2366. currentScopeId = null;
  2367. }
  2368. /**
  2369. * Only for backwards compat
  2370. * @private
  2371. */
  2372. const withScopeId = (_id) => withCtx;
  2373. /**
  2374. * Wrap a slot function to memoize current rendering instance
  2375. * @private compiler helper
  2376. */
  2377. function withCtx(fn, ctx = currentRenderingInstance, isNonScopedSlot // false only
  2378. ) {
  2379. if (!ctx)
  2380. return fn;
  2381. // already normalized
  2382. if (fn._n) {
  2383. return fn;
  2384. }
  2385. const renderFnWithContext = (...args) => {
  2386. // If a user calls a compiled slot inside a template expression (#1745), it
  2387. // can mess up block tracking, so by default we disable block tracking and
  2388. // force bail out when invoking a compiled slot (indicated by the ._d flag).
  2389. // This isn't necessary if rendering a compiled `<slot>`, so we flip the
  2390. // ._d flag off when invoking the wrapped fn inside `renderSlot`.
  2391. if (renderFnWithContext._d) {
  2392. setBlockTracking(-1);
  2393. }
  2394. const prevInstance = setCurrentRenderingInstance(ctx);
  2395. const res = fn(...args);
  2396. setCurrentRenderingInstance(prevInstance);
  2397. if (renderFnWithContext._d) {
  2398. setBlockTracking(1);
  2399. }
  2400. {
  2401. devtoolsComponentUpdated(ctx);
  2402. }
  2403. return res;
  2404. };
  2405. // mark normalized to avoid duplicated wrapping
  2406. renderFnWithContext._n = true;
  2407. // mark this as compiled by default
  2408. // this is used in vnode.ts -> normalizeChildren() to set the slot
  2409. // rendering flag.
  2410. renderFnWithContext._c = true;
  2411. // disable block tracking by default
  2412. renderFnWithContext._d = true;
  2413. return renderFnWithContext;
  2414. }
  2415. /**
  2416. * dev only flag to track whether $attrs was used during render.
  2417. * If $attrs was used during render then the warning for failed attrs
  2418. * fallthrough can be suppressed.
  2419. */
  2420. let accessedAttrs = false;
  2421. function markAttrsAccessed() {
  2422. accessedAttrs = true;
  2423. }
  2424. function renderComponentRoot(instance) {
  2425. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx, inheritAttrs } = instance;
  2426. let result;
  2427. let fallthroughAttrs;
  2428. const prev = setCurrentRenderingInstance(instance);
  2429. {
  2430. accessedAttrs = false;
  2431. }
  2432. try {
  2433. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  2434. // withProxy is a proxy with a different `has` trap only for
  2435. // runtime-compiled render functions using `with` block.
  2436. const proxyToUse = withProxy || proxy;
  2437. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  2438. fallthroughAttrs = attrs;
  2439. }
  2440. else {
  2441. // functional
  2442. const render = Component;
  2443. // in dev, mark attrs accessed if optional props (attrs === props)
  2444. if (true && attrs === props) {
  2445. markAttrsAccessed();
  2446. }
  2447. result = normalizeVNode(render.length > 1
  2448. ? render(props, true
  2449. ? {
  2450. get attrs() {
  2451. markAttrsAccessed();
  2452. return attrs;
  2453. },
  2454. slots,
  2455. emit
  2456. }
  2457. : { attrs, slots, emit })
  2458. : render(props, null /* we know it doesn't need it */));
  2459. fallthroughAttrs = Component.props
  2460. ? attrs
  2461. : getFunctionalFallthrough(attrs);
  2462. }
  2463. }
  2464. catch (err) {
  2465. blockStack.length = 0;
  2466. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  2467. result = createVNode(Comment);
  2468. }
  2469. // attr merging
  2470. // in dev mode, comments are preserved, and it's possible for a template
  2471. // to have comments along side the root element which makes it a fragment
  2472. let root = result;
  2473. let setRoot = undefined;
  2474. if (result.patchFlag > 0 &&
  2475. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  2476. [root, setRoot] = getChildRoot(result);
  2477. }
  2478. if (fallthroughAttrs && inheritAttrs !== false) {
  2479. const keys = Object.keys(fallthroughAttrs);
  2480. const { shapeFlag } = root;
  2481. if (keys.length) {
  2482. if (shapeFlag & (1 /* ELEMENT */ | 6 /* COMPONENT */)) {
  2483. if (propsOptions && keys.some(isModelListener)) {
  2484. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  2485. // prop, it indicates this component expects to handle v-model and
  2486. // it should not fallthrough.
  2487. // related: #1543, #1643, #1989
  2488. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  2489. }
  2490. root = cloneVNode(root, fallthroughAttrs);
  2491. }
  2492. else if (!accessedAttrs && root.type !== Comment) {
  2493. const allAttrs = Object.keys(attrs);
  2494. const eventAttrs = [];
  2495. const extraAttrs = [];
  2496. for (let i = 0, l = allAttrs.length; i < l; i++) {
  2497. const key = allAttrs[i];
  2498. if (isOn(key)) {
  2499. // ignore v-model handlers when they fail to fallthrough
  2500. if (!isModelListener(key)) {
  2501. // remove `on`, lowercase first letter to reflect event casing
  2502. // accurately
  2503. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  2504. }
  2505. }
  2506. else {
  2507. extraAttrs.push(key);
  2508. }
  2509. }
  2510. if (extraAttrs.length) {
  2511. warn$1(`Extraneous non-props attributes (` +
  2512. `${extraAttrs.join(', ')}) ` +
  2513. `were passed to component but could not be automatically inherited ` +
  2514. `because component renders fragment or text root nodes.`);
  2515. }
  2516. if (eventAttrs.length) {
  2517. warn$1(`Extraneous non-emits event listeners (` +
  2518. `${eventAttrs.join(', ')}) ` +
  2519. `were passed to component but could not be automatically inherited ` +
  2520. `because component renders fragment or text root nodes. ` +
  2521. `If the listener is intended to be a component custom event listener only, ` +
  2522. `declare it using the "emits" option.`);
  2523. }
  2524. }
  2525. }
  2526. }
  2527. // inherit directives
  2528. if (vnode.dirs) {
  2529. if (!isElementRoot(root)) {
  2530. warn$1(`Runtime directive used on component with non-element root node. ` +
  2531. `The directives will not function as intended.`);
  2532. }
  2533. // clone before mutating since the root may be a hoisted vnode
  2534. root = cloneVNode(root);
  2535. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2536. }
  2537. // inherit transition data
  2538. if (vnode.transition) {
  2539. if (!isElementRoot(root)) {
  2540. warn$1(`Component inside <Transition> renders non-element root node ` +
  2541. `that cannot be animated.`);
  2542. }
  2543. root.transition = vnode.transition;
  2544. }
  2545. if (setRoot) {
  2546. setRoot(root);
  2547. }
  2548. else {
  2549. result = root;
  2550. }
  2551. setCurrentRenderingInstance(prev);
  2552. return result;
  2553. }
  2554. /**
  2555. * dev only
  2556. * In dev mode, template root level comments are rendered, which turns the
  2557. * template into a fragment root, but we need to locate the single element
  2558. * root for attrs and scope id processing.
  2559. */
  2560. const getChildRoot = (vnode) => {
  2561. const rawChildren = vnode.children;
  2562. const dynamicChildren = vnode.dynamicChildren;
  2563. const childRoot = filterSingleRoot(rawChildren);
  2564. if (!childRoot) {
  2565. return [vnode, undefined];
  2566. }
  2567. const index = rawChildren.indexOf(childRoot);
  2568. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2569. const setRoot = (updatedRoot) => {
  2570. rawChildren[index] = updatedRoot;
  2571. if (dynamicChildren) {
  2572. if (dynamicIndex > -1) {
  2573. dynamicChildren[dynamicIndex] = updatedRoot;
  2574. }
  2575. else if (updatedRoot.patchFlag > 0) {
  2576. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2577. }
  2578. }
  2579. };
  2580. return [normalizeVNode(childRoot), setRoot];
  2581. };
  2582. function filterSingleRoot(children) {
  2583. let singleRoot;
  2584. for (let i = 0; i < children.length; i++) {
  2585. const child = children[i];
  2586. if (isVNode(child)) {
  2587. // ignore user comment
  2588. if (child.type !== Comment || child.children === 'v-if') {
  2589. if (singleRoot) {
  2590. // has more than 1 non-comment child, return now
  2591. return;
  2592. }
  2593. else {
  2594. singleRoot = child;
  2595. }
  2596. }
  2597. }
  2598. else {
  2599. return;
  2600. }
  2601. }
  2602. return singleRoot;
  2603. }
  2604. const getFunctionalFallthrough = (attrs) => {
  2605. let res;
  2606. for (const key in attrs) {
  2607. if (key === 'class' || key === 'style' || isOn(key)) {
  2608. (res || (res = {}))[key] = attrs[key];
  2609. }
  2610. }
  2611. return res;
  2612. };
  2613. const filterModelListeners = (attrs, props) => {
  2614. const res = {};
  2615. for (const key in attrs) {
  2616. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2617. res[key] = attrs[key];
  2618. }
  2619. }
  2620. return res;
  2621. };
  2622. const isElementRoot = (vnode) => {
  2623. return (vnode.shapeFlag & (6 /* COMPONENT */ | 1 /* ELEMENT */) ||
  2624. vnode.type === Comment // potential v-if branch switch
  2625. );
  2626. };
  2627. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2628. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2629. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2630. const emits = component.emitsOptions;
  2631. // Parent component's render function was hot-updated. Since this may have
  2632. // caused the child component's slots content to have changed, we need to
  2633. // force the child to update as well.
  2634. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2635. return true;
  2636. }
  2637. // force child update for runtime directive or transition on component vnode.
  2638. if (nextVNode.dirs || nextVNode.transition) {
  2639. return true;
  2640. }
  2641. if (optimized && patchFlag >= 0) {
  2642. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2643. // slot content that references values that might have changed,
  2644. // e.g. in a v-for
  2645. return true;
  2646. }
  2647. if (patchFlag & 16 /* FULL_PROPS */) {
  2648. if (!prevProps) {
  2649. return !!nextProps;
  2650. }
  2651. // presence of this flag indicates props are always non-null
  2652. return hasPropsChanged(prevProps, nextProps, emits);
  2653. }
  2654. else if (patchFlag & 8 /* PROPS */) {
  2655. const dynamicProps = nextVNode.dynamicProps;
  2656. for (let i = 0; i < dynamicProps.length; i++) {
  2657. const key = dynamicProps[i];
  2658. if (nextProps[key] !== prevProps[key] &&
  2659. !isEmitListener(emits, key)) {
  2660. return true;
  2661. }
  2662. }
  2663. }
  2664. }
  2665. else {
  2666. // this path is only taken by manually written render functions
  2667. // so presence of any children leads to a forced update
  2668. if (prevChildren || nextChildren) {
  2669. if (!nextChildren || !nextChildren.$stable) {
  2670. return true;
  2671. }
  2672. }
  2673. if (prevProps === nextProps) {
  2674. return false;
  2675. }
  2676. if (!prevProps) {
  2677. return !!nextProps;
  2678. }
  2679. if (!nextProps) {
  2680. return true;
  2681. }
  2682. return hasPropsChanged(prevProps, nextProps, emits);
  2683. }
  2684. return false;
  2685. }
  2686. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2687. const nextKeys = Object.keys(nextProps);
  2688. if (nextKeys.length !== Object.keys(prevProps).length) {
  2689. return true;
  2690. }
  2691. for (let i = 0; i < nextKeys.length; i++) {
  2692. const key = nextKeys[i];
  2693. if (nextProps[key] !== prevProps[key] &&
  2694. !isEmitListener(emitsOptions, key)) {
  2695. return true;
  2696. }
  2697. }
  2698. return false;
  2699. }
  2700. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2701. ) {
  2702. while (parent && parent.subTree === vnode) {
  2703. (vnode = parent.vnode).el = el;
  2704. parent = parent.parent;
  2705. }
  2706. }
  2707. const isSuspense = (type) => type.__isSuspense;
  2708. // Suspense exposes a component-like API, and is treated like a component
  2709. // in the compiler, but internally it's a special built-in type that hooks
  2710. // directly into the renderer.
  2711. const SuspenseImpl = {
  2712. name: 'Suspense',
  2713. // In order to make Suspense tree-shakable, we need to avoid importing it
  2714. // directly in the renderer. The renderer checks for the __isSuspense flag
  2715. // on a vnode's type and calls the `process` method, passing in renderer
  2716. // internals.
  2717. __isSuspense: true,
  2718. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized,
  2719. // platform-specific impl passed from renderer
  2720. rendererInternals) {
  2721. if (n1 == null) {
  2722. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals);
  2723. }
  2724. else {
  2725. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, rendererInternals);
  2726. }
  2727. },
  2728. hydrate: hydrateSuspense,
  2729. create: createSuspenseBoundary,
  2730. normalize: normalizeSuspenseChildren
  2731. };
  2732. // Force-casted public typing for h and TSX props inference
  2733. const Suspense = (SuspenseImpl );
  2734. function triggerEvent(vnode, name) {
  2735. const eventListener = vnode.props && vnode.props[name];
  2736. if (isFunction(eventListener)) {
  2737. eventListener();
  2738. }
  2739. }
  2740. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals) {
  2741. const { p: patch, o: { createElement } } = rendererInternals;
  2742. const hiddenContainer = createElement('div');
  2743. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals));
  2744. // start mounting the content subtree in an off-dom container
  2745. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds);
  2746. // now check if we have encountered any async deps
  2747. if (suspense.deps > 0) {
  2748. // has async
  2749. // invoke @fallback event
  2750. triggerEvent(vnode, 'onPending');
  2751. triggerEvent(vnode, 'onFallback');
  2752. // mount the fallback tree
  2753. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2754. isSVG, slotScopeIds);
  2755. setActiveBranch(suspense, vnode.ssFallback);
  2756. }
  2757. else {
  2758. // Suspense has no async deps. Just resolve.
  2759. suspense.resolve();
  2760. }
  2761. }
  2762. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotScopeIds, optimized, { p: patch, um: unmount, o: { createElement } }) {
  2763. const suspense = (n2.suspense = n1.suspense);
  2764. suspense.vnode = n2;
  2765. n2.el = n1.el;
  2766. const newBranch = n2.ssContent;
  2767. const newFallback = n2.ssFallback;
  2768. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2769. if (pendingBranch) {
  2770. suspense.pendingBranch = newBranch;
  2771. if (isSameVNodeType(newBranch, pendingBranch)) {
  2772. // same root type but content may have changed.
  2773. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2774. if (suspense.deps <= 0) {
  2775. suspense.resolve();
  2776. }
  2777. else if (isInFallback) {
  2778. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2779. isSVG, slotScopeIds, optimized);
  2780. setActiveBranch(suspense, newFallback);
  2781. }
  2782. }
  2783. else {
  2784. // toggled before pending tree is resolved
  2785. suspense.pendingId++;
  2786. if (isHydrating) {
  2787. // if toggled before hydration is finished, the current DOM tree is
  2788. // no longer valid. set it as the active branch so it will be unmounted
  2789. // when resolved
  2790. suspense.isHydrating = false;
  2791. suspense.activeBranch = pendingBranch;
  2792. }
  2793. else {
  2794. unmount(pendingBranch, parentComponent, suspense);
  2795. }
  2796. // increment pending ID. this is used to invalidate async callbacks
  2797. // reset suspense state
  2798. suspense.deps = 0;
  2799. // discard effects from pending branch
  2800. suspense.effects.length = 0;
  2801. // discard previous container
  2802. suspense.hiddenContainer = createElement('div');
  2803. if (isInFallback) {
  2804. // already in fallback state
  2805. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2806. if (suspense.deps <= 0) {
  2807. suspense.resolve();
  2808. }
  2809. else {
  2810. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2811. isSVG, slotScopeIds, optimized);
  2812. setActiveBranch(suspense, newFallback);
  2813. }
  2814. }
  2815. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2816. // toggled "back" to current active branch
  2817. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2818. // force resolve
  2819. suspense.resolve(true);
  2820. }
  2821. else {
  2822. // switched to a 3rd branch
  2823. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2824. if (suspense.deps <= 0) {
  2825. suspense.resolve();
  2826. }
  2827. }
  2828. }
  2829. }
  2830. else {
  2831. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2832. // root did not change, just normal patch
  2833. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2834. setActiveBranch(suspense, newBranch);
  2835. }
  2836. else {
  2837. // root node toggled
  2838. // invoke @pending event
  2839. triggerEvent(n2, 'onPending');
  2840. // mount pending branch in off-dom container
  2841. suspense.pendingBranch = newBranch;
  2842. suspense.pendingId++;
  2843. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, slotScopeIds, optimized);
  2844. if (suspense.deps <= 0) {
  2845. // incoming branch has no async deps, resolve now.
  2846. suspense.resolve();
  2847. }
  2848. else {
  2849. const { timeout, pendingId } = suspense;
  2850. if (timeout > 0) {
  2851. setTimeout(() => {
  2852. if (suspense.pendingId === pendingId) {
  2853. suspense.fallback(newFallback);
  2854. }
  2855. }, timeout);
  2856. }
  2857. else if (timeout === 0) {
  2858. suspense.fallback(newFallback);
  2859. }
  2860. }
  2861. }
  2862. }
  2863. }
  2864. let hasWarned = false;
  2865. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
  2866. /* istanbul ignore if */
  2867. if (!hasWarned) {
  2868. hasWarned = true;
  2869. // @ts-ignore `console.info` cannot be null error
  2870. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2871. }
  2872. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2873. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2874. const suspense = {
  2875. vnode,
  2876. parent,
  2877. parentComponent,
  2878. isSVG,
  2879. container,
  2880. hiddenContainer,
  2881. anchor,
  2882. deps: 0,
  2883. pendingId: 0,
  2884. timeout: typeof timeout === 'number' ? timeout : -1,
  2885. activeBranch: null,
  2886. pendingBranch: null,
  2887. isInFallback: true,
  2888. isHydrating,
  2889. isUnmounted: false,
  2890. effects: [],
  2891. resolve(resume = false) {
  2892. {
  2893. if (!resume && !suspense.pendingBranch) {
  2894. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2895. }
  2896. if (suspense.isUnmounted) {
  2897. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2898. }
  2899. }
  2900. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2901. if (suspense.isHydrating) {
  2902. suspense.isHydrating = false;
  2903. }
  2904. else if (!resume) {
  2905. const delayEnter = activeBranch &&
  2906. pendingBranch.transition &&
  2907. pendingBranch.transition.mode === 'out-in';
  2908. if (delayEnter) {
  2909. activeBranch.transition.afterLeave = () => {
  2910. if (pendingId === suspense.pendingId) {
  2911. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2912. }
  2913. };
  2914. }
  2915. // this is initial anchor on mount
  2916. let { anchor } = suspense;
  2917. // unmount current active tree
  2918. if (activeBranch) {
  2919. // if the fallback tree was mounted, it may have been moved
  2920. // as part of a parent suspense. get the latest anchor for insertion
  2921. anchor = next(activeBranch);
  2922. unmount(activeBranch, parentComponent, suspense, true);
  2923. }
  2924. if (!delayEnter) {
  2925. // move content from off-dom container to actual container
  2926. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2927. }
  2928. }
  2929. setActiveBranch(suspense, pendingBranch);
  2930. suspense.pendingBranch = null;
  2931. suspense.isInFallback = false;
  2932. // flush buffered effects
  2933. // check if there is a pending parent suspense
  2934. let parent = suspense.parent;
  2935. let hasUnresolvedAncestor = false;
  2936. while (parent) {
  2937. if (parent.pendingBranch) {
  2938. // found a pending parent suspense, merge buffered post jobs
  2939. // into that parent
  2940. parent.effects.push(...effects);
  2941. hasUnresolvedAncestor = true;
  2942. break;
  2943. }
  2944. parent = parent.parent;
  2945. }
  2946. // no pending parent suspense, flush all jobs
  2947. if (!hasUnresolvedAncestor) {
  2948. queuePostFlushCb(effects);
  2949. }
  2950. suspense.effects = [];
  2951. // invoke @resolve event
  2952. triggerEvent(vnode, 'onResolve');
  2953. },
  2954. fallback(fallbackVNode) {
  2955. if (!suspense.pendingBranch) {
  2956. return;
  2957. }
  2958. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2959. // invoke @fallback event
  2960. triggerEvent(vnode, 'onFallback');
  2961. const anchor = next(activeBranch);
  2962. const mountFallback = () => {
  2963. if (!suspense.isInFallback) {
  2964. return;
  2965. }
  2966. // mount the fallback tree
  2967. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2968. isSVG, slotScopeIds, optimized);
  2969. setActiveBranch(suspense, fallbackVNode);
  2970. };
  2971. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2972. if (delayEnter) {
  2973. activeBranch.transition.afterLeave = mountFallback;
  2974. }
  2975. suspense.isInFallback = true;
  2976. // unmount current active branch
  2977. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2978. true // shouldRemove
  2979. );
  2980. if (!delayEnter) {
  2981. mountFallback();
  2982. }
  2983. },
  2984. move(container, anchor, type) {
  2985. suspense.activeBranch &&
  2986. move(suspense.activeBranch, container, anchor, type);
  2987. suspense.container = container;
  2988. },
  2989. next() {
  2990. return suspense.activeBranch && next(suspense.activeBranch);
  2991. },
  2992. registerDep(instance, setupRenderEffect) {
  2993. const isInPendingSuspense = !!suspense.pendingBranch;
  2994. if (isInPendingSuspense) {
  2995. suspense.deps++;
  2996. }
  2997. const hydratedEl = instance.vnode.el;
  2998. instance
  2999. .asyncDep.catch(err => {
  3000. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  3001. })
  3002. .then(asyncSetupResult => {
  3003. // retry when the setup() promise resolves.
  3004. // component may have been unmounted before resolve.
  3005. if (instance.isUnmounted ||
  3006. suspense.isUnmounted ||
  3007. suspense.pendingId !== instance.suspenseId) {
  3008. return;
  3009. }
  3010. // retry from this component
  3011. instance.asyncResolved = true;
  3012. const { vnode } = instance;
  3013. {
  3014. pushWarningContext(vnode);
  3015. }
  3016. handleSetupResult(instance, asyncSetupResult, false);
  3017. if (hydratedEl) {
  3018. // vnode may have been replaced if an update happened before the
  3019. // async dep is resolved.
  3020. vnode.el = hydratedEl;
  3021. }
  3022. const placeholder = !hydratedEl && instance.subTree.el;
  3023. setupRenderEffect(instance, vnode,
  3024. // component may have been moved before resolve.
  3025. // if this is not a hydration, instance.subTree will be the comment
  3026. // placeholder.
  3027. parentNode(hydratedEl || instance.subTree.el),
  3028. // anchor will not be used if this is hydration, so only need to
  3029. // consider the comment placeholder case.
  3030. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  3031. if (placeholder) {
  3032. remove(placeholder);
  3033. }
  3034. updateHOCHostEl(instance, vnode.el);
  3035. {
  3036. popWarningContext();
  3037. }
  3038. // only decrease deps count if suspense is not already resolved
  3039. if (isInPendingSuspense && --suspense.deps === 0) {
  3040. suspense.resolve();
  3041. }
  3042. });
  3043. },
  3044. unmount(parentSuspense, doRemove) {
  3045. suspense.isUnmounted = true;
  3046. if (suspense.activeBranch) {
  3047. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  3048. }
  3049. if (suspense.pendingBranch) {
  3050. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  3051. }
  3052. }
  3053. };
  3054. return suspense;
  3055. }
  3056. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, rendererInternals, hydrateNode) {
  3057. /* eslint-disable no-restricted-globals */
  3058. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, slotScopeIds, optimized, rendererInternals, true /* hydrating */));
  3059. // there are two possible scenarios for server-rendered suspense:
  3060. // - success: ssr content should be fully resolved
  3061. // - failure: ssr content should be the fallback branch.
  3062. // however, on the client we don't really know if it has failed or not
  3063. // attempt to hydrate the DOM assuming it has succeeded, but we still
  3064. // need to construct a suspense boundary first
  3065. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, slotScopeIds, optimized);
  3066. if (suspense.deps === 0) {
  3067. suspense.resolve();
  3068. }
  3069. return result;
  3070. /* eslint-enable no-restricted-globals */
  3071. }
  3072. function normalizeSuspenseChildren(vnode) {
  3073. const { shapeFlag, children } = vnode;
  3074. const isSlotChildren = shapeFlag & 32 /* SLOTS_CHILDREN */;
  3075. vnode.ssContent = normalizeSuspenseSlot(isSlotChildren ? children.default : children);
  3076. vnode.ssFallback = isSlotChildren
  3077. ? normalizeSuspenseSlot(children.fallback)
  3078. : createVNode(Comment);
  3079. }
  3080. function normalizeSuspenseSlot(s) {
  3081. let block;
  3082. if (isFunction(s)) {
  3083. const trackBlock = isBlockTreeEnabled && s._c;
  3084. if (trackBlock) {
  3085. // disableTracking: false
  3086. // allow block tracking for compiled slots
  3087. // (see ./componentRenderContext.ts)
  3088. s._d = false;
  3089. openBlock();
  3090. }
  3091. s = s();
  3092. if (trackBlock) {
  3093. s._d = true;
  3094. block = currentBlock;
  3095. closeBlock();
  3096. }
  3097. }
  3098. if (isArray(s)) {
  3099. const singleChild = filterSingleRoot(s);
  3100. if (!singleChild) {
  3101. warn$1(`<Suspense> slots expect a single root node.`);
  3102. }
  3103. s = singleChild;
  3104. }
  3105. s = normalizeVNode(s);
  3106. if (block && !s.dynamicChildren) {
  3107. s.dynamicChildren = block.filter(c => c !== s);
  3108. }
  3109. return s;
  3110. }
  3111. function queueEffectWithSuspense(fn, suspense) {
  3112. if (suspense && suspense.pendingBranch) {
  3113. if (isArray(fn)) {
  3114. suspense.effects.push(...fn);
  3115. }
  3116. else {
  3117. suspense.effects.push(fn);
  3118. }
  3119. }
  3120. else {
  3121. queuePostFlushCb(fn);
  3122. }
  3123. }
  3124. function setActiveBranch(suspense, branch) {
  3125. suspense.activeBranch = branch;
  3126. const { vnode, parentComponent } = suspense;
  3127. const el = (vnode.el = branch.el);
  3128. // in case suspense is the root node of a component,
  3129. // recursively update the HOC el
  3130. if (parentComponent && parentComponent.subTree === vnode) {
  3131. parentComponent.vnode.el = el;
  3132. updateHOCHostEl(parentComponent, el);
  3133. }
  3134. }
  3135. function provide(key, value) {
  3136. if (!currentInstance) {
  3137. {
  3138. warn$1(`provide() can only be used inside setup().`);
  3139. }
  3140. }
  3141. else {
  3142. let provides = currentInstance.provides;
  3143. // by default an instance inherits its parent's provides object
  3144. // but when it needs to provide values of its own, it creates its
  3145. // own provides object using parent provides object as prototype.
  3146. // this way in `inject` we can simply look up injections from direct
  3147. // parent and let the prototype chain do the work.
  3148. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  3149. if (parentProvides === provides) {
  3150. provides = currentInstance.provides = Object.create(parentProvides);
  3151. }
  3152. // TS doesn't allow symbol as index type
  3153. provides[key] = value;
  3154. }
  3155. }
  3156. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  3157. // fallback to `currentRenderingInstance` so that this can be called in
  3158. // a functional component
  3159. const instance = currentInstance || currentRenderingInstance;
  3160. if (instance) {
  3161. // #2400
  3162. // to support `app.use` plugins,
  3163. // fallback to appContext's `provides` if the instance is at root
  3164. const provides = instance.parent == null
  3165. ? instance.vnode.appContext && instance.vnode.appContext.provides
  3166. : instance.parent.provides;
  3167. if (provides && key in provides) {
  3168. // TS doesn't allow symbol as index type
  3169. return provides[key];
  3170. }
  3171. else if (arguments.length > 1) {
  3172. return treatDefaultAsFactory && isFunction(defaultValue)
  3173. ? defaultValue.call(instance.proxy)
  3174. : defaultValue;
  3175. }
  3176. else {
  3177. warn$1(`injection "${String(key)}" not found.`);
  3178. }
  3179. }
  3180. else {
  3181. warn$1(`inject() can only be used inside setup() or functional components.`);
  3182. }
  3183. }
  3184. // Simple effect.
  3185. function watchEffect(effect, options) {
  3186. return doWatch(effect, null, options);
  3187. }
  3188. function watchPostEffect(effect, options) {
  3189. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'post' }) ));
  3190. }
  3191. function watchSyncEffect(effect, options) {
  3192. return doWatch(effect, null, (Object.assign(Object.assign({}, options), { flush: 'sync' }) ));
  3193. }
  3194. // initial value for watchers to trigger on undefined initial values
  3195. const INITIAL_WATCHER_VALUE = {};
  3196. // implementation
  3197. function watch(source, cb, options) {
  3198. if (!isFunction(cb)) {
  3199. warn$1(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3200. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3201. `supports \`watch(source, cb, options?) signature.`);
  3202. }
  3203. return doWatch(source, cb, options);
  3204. }
  3205. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ) {
  3206. if (!cb) {
  3207. if (immediate !== undefined) {
  3208. warn$1(`watch() "immediate" option is only respected when using the ` +
  3209. `watch(source, callback, options?) signature.`);
  3210. }
  3211. if (deep !== undefined) {
  3212. warn$1(`watch() "deep" option is only respected when using the ` +
  3213. `watch(source, callback, options?) signature.`);
  3214. }
  3215. }
  3216. const warnInvalidSource = (s) => {
  3217. warn$1(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3218. `a reactive object, or an array of these types.`);
  3219. };
  3220. const instance = currentInstance;
  3221. let getter;
  3222. let forceTrigger = false;
  3223. let isMultiSource = false;
  3224. if (isRef(source)) {
  3225. getter = () => source.value;
  3226. forceTrigger = isShallow(source);
  3227. }
  3228. else if (isReactive(source)) {
  3229. getter = () => source;
  3230. deep = true;
  3231. }
  3232. else if (isArray(source)) {
  3233. isMultiSource = true;
  3234. forceTrigger = source.some(s => isReactive(s) || isShallow(s));
  3235. getter = () => source.map(s => {
  3236. if (isRef(s)) {
  3237. return s.value;
  3238. }
  3239. else if (isReactive(s)) {
  3240. return traverse(s);
  3241. }
  3242. else if (isFunction(s)) {
  3243. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */);
  3244. }
  3245. else {
  3246. warnInvalidSource(s);
  3247. }
  3248. });
  3249. }
  3250. else if (isFunction(source)) {
  3251. if (cb) {
  3252. // getter with cb
  3253. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */);
  3254. }
  3255. else {
  3256. // no cb -> simple effect
  3257. getter = () => {
  3258. if (instance && instance.isUnmounted) {
  3259. return;
  3260. }
  3261. if (cleanup) {
  3262. cleanup();
  3263. }
  3264. return callWithAsyncErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onCleanup]);
  3265. };
  3266. }
  3267. }
  3268. else {
  3269. getter = NOOP;
  3270. warnInvalidSource(source);
  3271. }
  3272. if (cb && deep) {
  3273. const baseGetter = getter;
  3274. getter = () => traverse(baseGetter());
  3275. }
  3276. let cleanup;
  3277. let onCleanup = (fn) => {
  3278. cleanup = effect.onStop = () => {
  3279. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  3280. };
  3281. };
  3282. let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE;
  3283. const job = () => {
  3284. if (!effect.active) {
  3285. return;
  3286. }
  3287. if (cb) {
  3288. // watch(source, cb)
  3289. const newValue = effect.run();
  3290. if (deep ||
  3291. forceTrigger ||
  3292. (isMultiSource
  3293. ? newValue.some((v, i) => hasChanged(v, oldValue[i]))
  3294. : hasChanged(newValue, oldValue)) ||
  3295. (false )) {
  3296. // cleanup before running cb again
  3297. if (cleanup) {
  3298. cleanup();
  3299. }
  3300. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  3301. newValue,
  3302. // pass undefined as the old value when it's changed for the first time
  3303. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  3304. onCleanup
  3305. ]);
  3306. oldValue = newValue;
  3307. }
  3308. }
  3309. else {
  3310. // watchEffect
  3311. effect.run();
  3312. }
  3313. };
  3314. // important: mark the job as a watcher callback so that scheduler knows
  3315. // it is allowed to self-trigger (#1727)
  3316. job.allowRecurse = !!cb;
  3317. let scheduler;
  3318. if (flush === 'sync') {
  3319. scheduler = job; // the scheduler function gets called directly
  3320. }
  3321. else if (flush === 'post') {
  3322. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3323. }
  3324. else {
  3325. // default: 'pre'
  3326. scheduler = () => queuePreFlushCb(job);
  3327. }
  3328. const effect = new ReactiveEffect(getter, scheduler);
  3329. {
  3330. effect.onTrack = onTrack;
  3331. effect.onTrigger = onTrigger;
  3332. }
  3333. // initial run
  3334. if (cb) {
  3335. if (immediate) {
  3336. job();
  3337. }
  3338. else {
  3339. oldValue = effect.run();
  3340. }
  3341. }
  3342. else if (flush === 'post') {
  3343. queuePostRenderEffect(effect.run.bind(effect), instance && instance.suspense);
  3344. }
  3345. else {
  3346. effect.run();
  3347. }
  3348. return () => {
  3349. effect.stop();
  3350. if (instance && instance.scope) {
  3351. remove(instance.scope.effects, effect);
  3352. }
  3353. };
  3354. }
  3355. // this.$watch
  3356. function instanceWatch(source, value, options) {
  3357. const publicThis = this.proxy;
  3358. const getter = isString(source)
  3359. ? source.includes('.')
  3360. ? createPathGetter(publicThis, source)
  3361. : () => publicThis[source]
  3362. : source.bind(publicThis, publicThis);
  3363. let cb;
  3364. if (isFunction(value)) {
  3365. cb = value;
  3366. }
  3367. else {
  3368. cb = value.handler;
  3369. options = value;
  3370. }
  3371. const cur = currentInstance;
  3372. setCurrentInstance(this);
  3373. const res = doWatch(getter, cb.bind(publicThis), options);
  3374. if (cur) {
  3375. setCurrentInstance(cur);
  3376. }
  3377. else {
  3378. unsetCurrentInstance();
  3379. }
  3380. return res;
  3381. }
  3382. function createPathGetter(ctx, path) {
  3383. const segments = path.split('.');
  3384. return () => {
  3385. let cur = ctx;
  3386. for (let i = 0; i < segments.length && cur; i++) {
  3387. cur = cur[segments[i]];
  3388. }
  3389. return cur;
  3390. };
  3391. }
  3392. function traverse(value, seen) {
  3393. if (!isObject(value) || value["__v_skip" /* SKIP */]) {
  3394. return value;
  3395. }
  3396. seen = seen || new Set();
  3397. if (seen.has(value)) {
  3398. return value;
  3399. }
  3400. seen.add(value);
  3401. if (isRef(value)) {
  3402. traverse(value.value, seen);
  3403. }
  3404. else if (isArray(value)) {
  3405. for (let i = 0; i < value.length; i++) {
  3406. traverse(value[i], seen);
  3407. }
  3408. }
  3409. else if (isSet(value) || isMap(value)) {
  3410. value.forEach((v) => {
  3411. traverse(v, seen);
  3412. });
  3413. }
  3414. else if (isPlainObject(value)) {
  3415. for (const key in value) {
  3416. traverse(value[key], seen);
  3417. }
  3418. }
  3419. return value;
  3420. }
  3421. function useTransitionState() {
  3422. const state = {
  3423. isMounted: false,
  3424. isLeaving: false,
  3425. isUnmounting: false,
  3426. leavingVNodes: new Map()
  3427. };
  3428. onMounted(() => {
  3429. state.isMounted = true;
  3430. });
  3431. onBeforeUnmount(() => {
  3432. state.isUnmounting = true;
  3433. });
  3434. return state;
  3435. }
  3436. const TransitionHookValidator = [Function, Array];
  3437. const BaseTransitionImpl = {
  3438. name: `BaseTransition`,
  3439. props: {
  3440. mode: String,
  3441. appear: Boolean,
  3442. persisted: Boolean,
  3443. // enter
  3444. onBeforeEnter: TransitionHookValidator,
  3445. onEnter: TransitionHookValidator,
  3446. onAfterEnter: TransitionHookValidator,
  3447. onEnterCancelled: TransitionHookValidator,
  3448. // leave
  3449. onBeforeLeave: TransitionHookValidator,
  3450. onLeave: TransitionHookValidator,
  3451. onAfterLeave: TransitionHookValidator,
  3452. onLeaveCancelled: TransitionHookValidator,
  3453. // appear
  3454. onBeforeAppear: TransitionHookValidator,
  3455. onAppear: TransitionHookValidator,
  3456. onAfterAppear: TransitionHookValidator,
  3457. onAppearCancelled: TransitionHookValidator
  3458. },
  3459. setup(props, { slots }) {
  3460. const instance = getCurrentInstance();
  3461. const state = useTransitionState();
  3462. let prevTransitionKey;
  3463. return () => {
  3464. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3465. if (!children || !children.length) {
  3466. return;
  3467. }
  3468. let child = children[0];
  3469. if (children.length > 1) {
  3470. let hasFound = false;
  3471. // locate first non-comment child
  3472. for (const c of children) {
  3473. if (c.type !== Comment) {
  3474. if (hasFound) {
  3475. // warn more than one non-comment child
  3476. warn$1('<transition> can only be used on a single element or component. ' +
  3477. 'Use <transition-group> for lists.');
  3478. break;
  3479. }
  3480. child = c;
  3481. hasFound = true;
  3482. }
  3483. }
  3484. }
  3485. // there's no need to track reactivity for these props so use the raw
  3486. // props for a bit better perf
  3487. const rawProps = toRaw(props);
  3488. const { mode } = rawProps;
  3489. // check mode
  3490. if (mode &&
  3491. mode !== 'in-out' &&
  3492. mode !== 'out-in' &&
  3493. mode !== 'default') {
  3494. warn$1(`invalid <transition> mode: ${mode}`);
  3495. }
  3496. if (state.isLeaving) {
  3497. return emptyPlaceholder(child);
  3498. }
  3499. // in the case of <transition><keep-alive/></transition>, we need to
  3500. // compare the type of the kept-alive children.
  3501. const innerChild = getKeepAliveChild(child);
  3502. if (!innerChild) {
  3503. return emptyPlaceholder(child);
  3504. }
  3505. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3506. setTransitionHooks(innerChild, enterHooks);
  3507. const oldChild = instance.subTree;
  3508. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3509. let transitionKeyChanged = false;
  3510. const { getTransitionKey } = innerChild.type;
  3511. if (getTransitionKey) {
  3512. const key = getTransitionKey();
  3513. if (prevTransitionKey === undefined) {
  3514. prevTransitionKey = key;
  3515. }
  3516. else if (key !== prevTransitionKey) {
  3517. prevTransitionKey = key;
  3518. transitionKeyChanged = true;
  3519. }
  3520. }
  3521. // handle mode
  3522. if (oldInnerChild &&
  3523. oldInnerChild.type !== Comment &&
  3524. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3525. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3526. // update old tree's hooks in case of dynamic transition
  3527. setTransitionHooks(oldInnerChild, leavingHooks);
  3528. // switching between different views
  3529. if (mode === 'out-in') {
  3530. state.isLeaving = true;
  3531. // return placeholder node and queue update when leave finishes
  3532. leavingHooks.afterLeave = () => {
  3533. state.isLeaving = false;
  3534. instance.update();
  3535. };
  3536. return emptyPlaceholder(child);
  3537. }
  3538. else if (mode === 'in-out' && innerChild.type !== Comment) {
  3539. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3540. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3541. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3542. // early removal callback
  3543. el._leaveCb = () => {
  3544. earlyRemove();
  3545. el._leaveCb = undefined;
  3546. delete enterHooks.delayedLeave;
  3547. };
  3548. enterHooks.delayedLeave = delayedLeave;
  3549. };
  3550. }
  3551. }
  3552. return child;
  3553. };
  3554. }
  3555. };
  3556. // export the public type for h/tsx inference
  3557. // also to avoid inline import() in generated d.ts files
  3558. const BaseTransition = BaseTransitionImpl;
  3559. function getLeavingNodesForType(state, vnode) {
  3560. const { leavingVNodes } = state;
  3561. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3562. if (!leavingVNodesCache) {
  3563. leavingVNodesCache = Object.create(null);
  3564. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3565. }
  3566. return leavingVNodesCache;
  3567. }
  3568. // The transition hooks are attached to the vnode as vnode.transition
  3569. // and will be called at appropriate timing in the renderer.
  3570. function resolveTransitionHooks(vnode, props, state, instance) {
  3571. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3572. const key = String(vnode.key);
  3573. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3574. const callHook = (hook, args) => {
  3575. hook &&
  3576. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  3577. };
  3578. const callAsyncHook = (hook, args) => {
  3579. const done = args[1];
  3580. callHook(hook, args);
  3581. if (isArray(hook)) {
  3582. if (hook.every(hook => hook.length <= 1))
  3583. done();
  3584. }
  3585. else if (hook.length <= 1) {
  3586. done();
  3587. }
  3588. };
  3589. const hooks = {
  3590. mode,
  3591. persisted,
  3592. beforeEnter(el) {
  3593. let hook = onBeforeEnter;
  3594. if (!state.isMounted) {
  3595. if (appear) {
  3596. hook = onBeforeAppear || onBeforeEnter;
  3597. }
  3598. else {
  3599. return;
  3600. }
  3601. }
  3602. // for same element (v-show)
  3603. if (el._leaveCb) {
  3604. el._leaveCb(true /* cancelled */);
  3605. }
  3606. // for toggled element with same key (v-if)
  3607. const leavingVNode = leavingVNodesCache[key];
  3608. if (leavingVNode &&
  3609. isSameVNodeType(vnode, leavingVNode) &&
  3610. leavingVNode.el._leaveCb) {
  3611. // force early removal (not cancelled)
  3612. leavingVNode.el._leaveCb();
  3613. }
  3614. callHook(hook, [el]);
  3615. },
  3616. enter(el) {
  3617. let hook = onEnter;
  3618. let afterHook = onAfterEnter;
  3619. let cancelHook = onEnterCancelled;
  3620. if (!state.isMounted) {
  3621. if (appear) {
  3622. hook = onAppear || onEnter;
  3623. afterHook = onAfterAppear || onAfterEnter;
  3624. cancelHook = onAppearCancelled || onEnterCancelled;
  3625. }
  3626. else {
  3627. return;
  3628. }
  3629. }
  3630. let called = false;
  3631. const done = (el._enterCb = (cancelled) => {
  3632. if (called)
  3633. return;
  3634. called = true;
  3635. if (cancelled) {
  3636. callHook(cancelHook, [el]);
  3637. }
  3638. else {
  3639. callHook(afterHook, [el]);
  3640. }
  3641. if (hooks.delayedLeave) {
  3642. hooks.delayedLeave();
  3643. }
  3644. el._enterCb = undefined;
  3645. });
  3646. if (hook) {
  3647. callAsyncHook(hook, [el, done]);
  3648. }
  3649. else {
  3650. done();
  3651. }
  3652. },
  3653. leave(el, remove) {
  3654. const key = String(vnode.key);
  3655. if (el._enterCb) {
  3656. el._enterCb(true /* cancelled */);
  3657. }
  3658. if (state.isUnmounting) {
  3659. return remove();
  3660. }
  3661. callHook(onBeforeLeave, [el]);
  3662. let called = false;
  3663. const done = (el._leaveCb = (cancelled) => {
  3664. if (called)
  3665. return;
  3666. called = true;
  3667. remove();
  3668. if (cancelled) {
  3669. callHook(onLeaveCancelled, [el]);
  3670. }
  3671. else {
  3672. callHook(onAfterLeave, [el]);
  3673. }
  3674. el._leaveCb = undefined;
  3675. if (leavingVNodesCache[key] === vnode) {
  3676. delete leavingVNodesCache[key];
  3677. }
  3678. });
  3679. leavingVNodesCache[key] = vnode;
  3680. if (onLeave) {
  3681. callAsyncHook(onLeave, [el, done]);
  3682. }
  3683. else {
  3684. done();
  3685. }
  3686. },
  3687. clone(vnode) {
  3688. return resolveTransitionHooks(vnode, props, state, instance);
  3689. }
  3690. };
  3691. return hooks;
  3692. }
  3693. // the placeholder really only handles one special case: KeepAlive
  3694. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3695. // placeholder with empty content to avoid the KeepAlive instance from being
  3696. // unmounted.
  3697. function emptyPlaceholder(vnode) {
  3698. if (isKeepAlive(vnode)) {
  3699. vnode = cloneVNode(vnode);
  3700. vnode.children = null;
  3701. return vnode;
  3702. }
  3703. }
  3704. function getKeepAliveChild(vnode) {
  3705. return isKeepAlive(vnode)
  3706. ? vnode.children
  3707. ? vnode.children[0]
  3708. : undefined
  3709. : vnode;
  3710. }
  3711. function setTransitionHooks(vnode, hooks) {
  3712. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  3713. setTransitionHooks(vnode.component.subTree, hooks);
  3714. }
  3715. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  3716. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3717. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3718. }
  3719. else {
  3720. vnode.transition = hooks;
  3721. }
  3722. }
  3723. function getTransitionRawChildren(children, keepComment = false, parentKey) {
  3724. let ret = [];
  3725. let keyedFragmentCount = 0;
  3726. for (let i = 0; i < children.length; i++) {
  3727. let child = children[i];
  3728. // #5360 inherit parent key in case of <template v-for>
  3729. const key = parentKey == null
  3730. ? child.key
  3731. : String(parentKey) + String(child.key != null ? child.key : i);
  3732. // handle fragment children case, e.g. v-for
  3733. if (child.type === Fragment) {
  3734. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  3735. keyedFragmentCount++;
  3736. ret = ret.concat(getTransitionRawChildren(child.children, keepComment, key));
  3737. }
  3738. // comment placeholders should be skipped, e.g. v-if
  3739. else if (keepComment || child.type !== Comment) {
  3740. ret.push(key != null ? cloneVNode(child, { key }) : child);
  3741. }
  3742. }
  3743. // #1126 if a transition children list contains multiple sub fragments, these
  3744. // fragments will be merged into a flat children array. Since each v-for
  3745. // fragment may contain different static bindings inside, we need to de-op
  3746. // these children to force full diffs to ensure correct behavior.
  3747. if (keyedFragmentCount > 1) {
  3748. for (let i = 0; i < ret.length; i++) {
  3749. ret[i].patchFlag = -2 /* BAIL */;
  3750. }
  3751. }
  3752. return ret;
  3753. }
  3754. // implementation, close to no-op
  3755. function defineComponent(options) {
  3756. return isFunction(options) ? { setup: options, name: options.name } : options;
  3757. }
  3758. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  3759. function defineAsyncComponent(source) {
  3760. if (isFunction(source)) {
  3761. source = { loader: source };
  3762. }
  3763. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  3764. suspensible = true, onError: userOnError } = source;
  3765. let pendingRequest = null;
  3766. let resolvedComp;
  3767. let retries = 0;
  3768. const retry = () => {
  3769. retries++;
  3770. pendingRequest = null;
  3771. return load();
  3772. };
  3773. const load = () => {
  3774. let thisRequest;
  3775. return (pendingRequest ||
  3776. (thisRequest = pendingRequest =
  3777. loader()
  3778. .catch(err => {
  3779. err = err instanceof Error ? err : new Error(String(err));
  3780. if (userOnError) {
  3781. return new Promise((resolve, reject) => {
  3782. const userRetry = () => resolve(retry());
  3783. const userFail = () => reject(err);
  3784. userOnError(err, userRetry, userFail, retries + 1);
  3785. });
  3786. }
  3787. else {
  3788. throw err;
  3789. }
  3790. })
  3791. .then((comp) => {
  3792. if (thisRequest !== pendingRequest && pendingRequest) {
  3793. return pendingRequest;
  3794. }
  3795. if (!comp) {
  3796. warn$1(`Async component loader resolved to undefined. ` +
  3797. `If you are using retry(), make sure to return its return value.`);
  3798. }
  3799. // interop module default
  3800. if (comp &&
  3801. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  3802. comp = comp.default;
  3803. }
  3804. if (comp && !isObject(comp) && !isFunction(comp)) {
  3805. throw new Error(`Invalid async component load result: ${comp}`);
  3806. }
  3807. resolvedComp = comp;
  3808. return comp;
  3809. })));
  3810. };
  3811. return defineComponent({
  3812. name: 'AsyncComponentWrapper',
  3813. __asyncLoader: load,
  3814. get __asyncResolved() {
  3815. return resolvedComp;
  3816. },
  3817. setup() {
  3818. const instance = currentInstance;
  3819. // already resolved
  3820. if (resolvedComp) {
  3821. return () => createInnerComp(resolvedComp, instance);
  3822. }
  3823. const onError = (err) => {
  3824. pendingRequest = null;
  3825. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  3826. };
  3827. // suspense-controlled or SSR.
  3828. if ((suspensible && instance.suspense) ||
  3829. (false )) {
  3830. return load()
  3831. .then(comp => {
  3832. return () => createInnerComp(comp, instance);
  3833. })
  3834. .catch(err => {
  3835. onError(err);
  3836. return () => errorComponent
  3837. ? createVNode(errorComponent, {
  3838. error: err
  3839. })
  3840. : null;
  3841. });
  3842. }
  3843. const loaded = ref(false);
  3844. const error = ref();
  3845. const delayed = ref(!!delay);
  3846. if (delay) {
  3847. setTimeout(() => {
  3848. delayed.value = false;
  3849. }, delay);
  3850. }
  3851. if (timeout != null) {
  3852. setTimeout(() => {
  3853. if (!loaded.value && !error.value) {
  3854. const err = new Error(`Async component timed out after ${timeout}ms.`);
  3855. onError(err);
  3856. error.value = err;
  3857. }
  3858. }, timeout);
  3859. }
  3860. load()
  3861. .then(() => {
  3862. loaded.value = true;
  3863. if (instance.parent && isKeepAlive(instance.parent.vnode)) {
  3864. // parent is keep-alive, force update so the loaded component's
  3865. // name is taken into account
  3866. queueJob(instance.parent.update);
  3867. }
  3868. })
  3869. .catch(err => {
  3870. onError(err);
  3871. error.value = err;
  3872. });
  3873. return () => {
  3874. if (loaded.value && resolvedComp) {
  3875. return createInnerComp(resolvedComp, instance);
  3876. }
  3877. else if (error.value && errorComponent) {
  3878. return createVNode(errorComponent, {
  3879. error: error.value
  3880. });
  3881. }
  3882. else if (loadingComponent && !delayed.value) {
  3883. return createVNode(loadingComponent);
  3884. }
  3885. };
  3886. }
  3887. });
  3888. }
  3889. function createInnerComp(comp, { vnode: { ref, props, children, shapeFlag }, parent }) {
  3890. const vnode = createVNode(comp, props, children);
  3891. // ensure inner component inherits the async wrapper's ref owner
  3892. vnode.ref = ref;
  3893. return vnode;
  3894. }
  3895. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3896. const KeepAliveImpl = {
  3897. name: `KeepAlive`,
  3898. // Marker for special handling inside the renderer. We are not using a ===
  3899. // check directly on KeepAlive in the renderer, because importing it directly
  3900. // would prevent it from being tree-shaken.
  3901. __isKeepAlive: true,
  3902. props: {
  3903. include: [String, RegExp, Array],
  3904. exclude: [String, RegExp, Array],
  3905. max: [String, Number]
  3906. },
  3907. setup(props, { slots }) {
  3908. const instance = getCurrentInstance();
  3909. // KeepAlive communicates with the instantiated renderer via the
  3910. // ctx where the renderer passes in its internals,
  3911. // and the KeepAlive instance exposes activate/deactivate implementations.
  3912. // The whole point of this is to avoid importing KeepAlive directly in the
  3913. // renderer to facilitate tree-shaking.
  3914. const sharedContext = instance.ctx;
  3915. const cache = new Map();
  3916. const keys = new Set();
  3917. let current = null;
  3918. {
  3919. instance.__v_cache = cache;
  3920. }
  3921. const parentSuspense = instance.suspense;
  3922. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3923. const storageContainer = createElement('div');
  3924. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3925. const instance = vnode.component;
  3926. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  3927. // in case props have changed
  3928. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, vnode.slotScopeIds, optimized);
  3929. queuePostRenderEffect(() => {
  3930. instance.isDeactivated = false;
  3931. if (instance.a) {
  3932. invokeArrayFns(instance.a);
  3933. }
  3934. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3935. if (vnodeHook) {
  3936. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3937. }
  3938. }, parentSuspense);
  3939. {
  3940. // Update components tree
  3941. devtoolsComponentAdded(instance);
  3942. }
  3943. };
  3944. sharedContext.deactivate = (vnode) => {
  3945. const instance = vnode.component;
  3946. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  3947. queuePostRenderEffect(() => {
  3948. if (instance.da) {
  3949. invokeArrayFns(instance.da);
  3950. }
  3951. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3952. if (vnodeHook) {
  3953. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3954. }
  3955. instance.isDeactivated = true;
  3956. }, parentSuspense);
  3957. {
  3958. // Update components tree
  3959. devtoolsComponentAdded(instance);
  3960. }
  3961. };
  3962. function unmount(vnode) {
  3963. // reset the shapeFlag so it can be properly unmounted
  3964. resetShapeFlag(vnode);
  3965. _unmount(vnode, instance, parentSuspense, true);
  3966. }
  3967. function pruneCache(filter) {
  3968. cache.forEach((vnode, key) => {
  3969. const name = getComponentName(vnode.type);
  3970. if (name && (!filter || !filter(name))) {
  3971. pruneCacheEntry(key);
  3972. }
  3973. });
  3974. }
  3975. function pruneCacheEntry(key) {
  3976. const cached = cache.get(key);
  3977. if (!current || cached.type !== current.type) {
  3978. unmount(cached);
  3979. }
  3980. else if (current) {
  3981. // current active instance should no longer be kept-alive.
  3982. // we can't unmount it now but it might be later, so reset its flag now.
  3983. resetShapeFlag(current);
  3984. }
  3985. cache.delete(key);
  3986. keys.delete(key);
  3987. }
  3988. // prune cache on include/exclude prop change
  3989. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3990. include && pruneCache(name => matches(include, name));
  3991. exclude && pruneCache(name => !matches(exclude, name));
  3992. },
  3993. // prune post-render after `current` has been updated
  3994. { flush: 'post', deep: true });
  3995. // cache sub tree after render
  3996. let pendingCacheKey = null;
  3997. const cacheSubtree = () => {
  3998. // fix #1621, the pendingCacheKey could be 0
  3999. if (pendingCacheKey != null) {
  4000. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  4001. }
  4002. };
  4003. onMounted(cacheSubtree);
  4004. onUpdated(cacheSubtree);
  4005. onBeforeUnmount(() => {
  4006. cache.forEach(cached => {
  4007. const { subTree, suspense } = instance;
  4008. const vnode = getInnerChild(subTree);
  4009. if (cached.type === vnode.type) {
  4010. // current instance will be unmounted as part of keep-alive's unmount
  4011. resetShapeFlag(vnode);
  4012. // but invoke its deactivated hook here
  4013. const da = vnode.component.da;
  4014. da && queuePostRenderEffect(da, suspense);
  4015. return;
  4016. }
  4017. unmount(cached);
  4018. });
  4019. });
  4020. return () => {
  4021. pendingCacheKey = null;
  4022. if (!slots.default) {
  4023. return null;
  4024. }
  4025. const children = slots.default();
  4026. const rawVNode = children[0];
  4027. if (children.length > 1) {
  4028. {
  4029. warn$1(`KeepAlive should contain exactly one component child.`);
  4030. }
  4031. current = null;
  4032. return children;
  4033. }
  4034. else if (!isVNode(rawVNode) ||
  4035. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  4036. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  4037. current = null;
  4038. return rawVNode;
  4039. }
  4040. let vnode = getInnerChild(rawVNode);
  4041. const comp = vnode.type;
  4042. // for async components, name check should be based in its loaded
  4043. // inner component if available
  4044. const name = getComponentName(isAsyncWrapper(vnode)
  4045. ? vnode.type.__asyncResolved || {}
  4046. : comp);
  4047. const { include, exclude, max } = props;
  4048. if ((include && (!name || !matches(include, name))) ||
  4049. (exclude && name && matches(exclude, name))) {
  4050. current = vnode;
  4051. return rawVNode;
  4052. }
  4053. const key = vnode.key == null ? comp : vnode.key;
  4054. const cachedVNode = cache.get(key);
  4055. // clone vnode if it's reused because we are going to mutate it
  4056. if (vnode.el) {
  4057. vnode = cloneVNode(vnode);
  4058. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  4059. rawVNode.ssContent = vnode;
  4060. }
  4061. }
  4062. // #1513 it's possible for the returned vnode to be cloned due to attr
  4063. // fallthrough or scopeId, so the vnode here may not be the final vnode
  4064. // that is mounted. Instead of caching it directly, we store the pending
  4065. // key and cache `instance.subTree` (the normalized vnode) in
  4066. // beforeMount/beforeUpdate hooks.
  4067. pendingCacheKey = key;
  4068. if (cachedVNode) {
  4069. // copy over mounted state
  4070. vnode.el = cachedVNode.el;
  4071. vnode.component = cachedVNode.component;
  4072. if (vnode.transition) {
  4073. // recursively update transition hooks on subTree
  4074. setTransitionHooks(vnode, vnode.transition);
  4075. }
  4076. // avoid vnode being mounted as fresh
  4077. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  4078. // make this key the freshest
  4079. keys.delete(key);
  4080. keys.add(key);
  4081. }
  4082. else {
  4083. keys.add(key);
  4084. // prune oldest entry
  4085. if (max && keys.size > parseInt(max, 10)) {
  4086. pruneCacheEntry(keys.values().next().value);
  4087. }
  4088. }
  4089. // avoid vnode being unmounted
  4090. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4091. current = vnode;
  4092. return isSuspense(rawVNode.type) ? rawVNode : vnode;
  4093. };
  4094. }
  4095. };
  4096. // export the public type for h/tsx inference
  4097. // also to avoid inline import() in generated d.ts files
  4098. const KeepAlive = KeepAliveImpl;
  4099. function matches(pattern, name) {
  4100. if (isArray(pattern)) {
  4101. return pattern.some((p) => matches(p, name));
  4102. }
  4103. else if (isString(pattern)) {
  4104. return pattern.split(',').includes(name);
  4105. }
  4106. else if (pattern.test) {
  4107. return pattern.test(name);
  4108. }
  4109. /* istanbul ignore next */
  4110. return false;
  4111. }
  4112. function onActivated(hook, target) {
  4113. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  4114. }
  4115. function onDeactivated(hook, target) {
  4116. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  4117. }
  4118. function registerKeepAliveHook(hook, type, target = currentInstance) {
  4119. // cache the deactivate branch check wrapper for injected hooks so the same
  4120. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  4121. // deactivation check".
  4122. const wrappedHook = hook.__wdc ||
  4123. (hook.__wdc = () => {
  4124. // only fire the hook if the target instance is NOT in a deactivated branch.
  4125. let current = target;
  4126. while (current) {
  4127. if (current.isDeactivated) {
  4128. return;
  4129. }
  4130. current = current.parent;
  4131. }
  4132. return hook();
  4133. });
  4134. injectHook(type, wrappedHook, target);
  4135. // In addition to registering it on the target instance, we walk up the parent
  4136. // chain and register it on all ancestor instances that are keep-alive roots.
  4137. // This avoids the need to walk the entire component tree when invoking these
  4138. // hooks, and more importantly, avoids the need to track child components in
  4139. // arrays.
  4140. if (target) {
  4141. let current = target.parent;
  4142. while (current && current.parent) {
  4143. if (isKeepAlive(current.parent.vnode)) {
  4144. injectToKeepAliveRoot(wrappedHook, type, target, current);
  4145. }
  4146. current = current.parent;
  4147. }
  4148. }
  4149. }
  4150. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  4151. // injectHook wraps the original for error handling, so make sure to remove
  4152. // the wrapped version.
  4153. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  4154. onUnmounted(() => {
  4155. remove(keepAliveRoot[type], injected);
  4156. }, target);
  4157. }
  4158. function resetShapeFlag(vnode) {
  4159. let shapeFlag = vnode.shapeFlag;
  4160. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  4161. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  4162. }
  4163. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  4164. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  4165. }
  4166. vnode.shapeFlag = shapeFlag;
  4167. }
  4168. function getInnerChild(vnode) {
  4169. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  4170. }
  4171. function injectHook(type, hook, target = currentInstance, prepend = false) {
  4172. if (target) {
  4173. const hooks = target[type] || (target[type] = []);
  4174. // cache the error handling wrapper for injected hooks so the same hook
  4175. // can be properly deduped by the scheduler. "__weh" stands for "with error
  4176. // handling".
  4177. const wrappedHook = hook.__weh ||
  4178. (hook.__weh = (...args) => {
  4179. if (target.isUnmounted) {
  4180. return;
  4181. }
  4182. // disable tracking inside all lifecycle hooks
  4183. // since they can potentially be called inside effects.
  4184. pauseTracking();
  4185. // Set currentInstance during hook invocation.
  4186. // This assumes the hook does not synchronously trigger other hooks, which
  4187. // can only be false when the user does something really funky.
  4188. setCurrentInstance(target);
  4189. const res = callWithAsyncErrorHandling(hook, target, type, args);
  4190. unsetCurrentInstance();
  4191. resetTracking();
  4192. return res;
  4193. });
  4194. if (prepend) {
  4195. hooks.unshift(wrappedHook);
  4196. }
  4197. else {
  4198. hooks.push(wrappedHook);
  4199. }
  4200. return wrappedHook;
  4201. }
  4202. else {
  4203. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  4204. warn$1(`${apiName} is called when there is no active component instance to be ` +
  4205. `associated with. ` +
  4206. `Lifecycle injection APIs can only be used during execution of setup().` +
  4207. (` If you are using async setup(), make sure to register lifecycle ` +
  4208. `hooks before the first await statement.`
  4209. ));
  4210. }
  4211. }
  4212. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  4213. // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
  4214. (!isInSSRComponentSetup || lifecycle === "sp" /* SERVER_PREFETCH */) &&
  4215. injectHook(lifecycle, hook, target);
  4216. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  4217. const onMounted = createHook("m" /* MOUNTED */);
  4218. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  4219. const onUpdated = createHook("u" /* UPDATED */);
  4220. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  4221. const onUnmounted = createHook("um" /* UNMOUNTED */);
  4222. const onServerPrefetch = createHook("sp" /* SERVER_PREFETCH */);
  4223. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  4224. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  4225. function onErrorCaptured(hook, target = currentInstance) {
  4226. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  4227. }
  4228. /**
  4229. Runtime helper for applying directives to a vnode. Example usage:
  4230. const comp = resolveComponent('comp')
  4231. const foo = resolveDirective('foo')
  4232. const bar = resolveDirective('bar')
  4233. return withDirectives(h(comp), [
  4234. [foo, this.x],
  4235. [bar, this.y]
  4236. ])
  4237. */
  4238. function validateDirectiveName(name) {
  4239. if (isBuiltInDirective(name)) {
  4240. warn$1('Do not use built-in directive ids as custom directive id: ' + name);
  4241. }
  4242. }
  4243. /**
  4244. * Adds directives to a VNode.
  4245. */
  4246. function withDirectives(vnode, directives) {
  4247. const internalInstance = currentRenderingInstance;
  4248. if (internalInstance === null) {
  4249. warn$1(`withDirectives can only be used inside render functions.`);
  4250. return vnode;
  4251. }
  4252. const instance = getExposeProxy(internalInstance) ||
  4253. internalInstance.proxy;
  4254. const bindings = vnode.dirs || (vnode.dirs = []);
  4255. for (let i = 0; i < directives.length; i++) {
  4256. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4257. if (isFunction(dir)) {
  4258. dir = {
  4259. mounted: dir,
  4260. updated: dir
  4261. };
  4262. }
  4263. if (dir.deep) {
  4264. traverse(value);
  4265. }
  4266. bindings.push({
  4267. dir,
  4268. instance,
  4269. value,
  4270. oldValue: void 0,
  4271. arg,
  4272. modifiers
  4273. });
  4274. }
  4275. return vnode;
  4276. }
  4277. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4278. const bindings = vnode.dirs;
  4279. const oldBindings = prevVNode && prevVNode.dirs;
  4280. for (let i = 0; i < bindings.length; i++) {
  4281. const binding = bindings[i];
  4282. if (oldBindings) {
  4283. binding.oldValue = oldBindings[i].value;
  4284. }
  4285. let hook = binding.dir[name];
  4286. if (hook) {
  4287. // disable tracking inside all lifecycle hooks
  4288. // since they can potentially be called inside effects.
  4289. pauseTracking();
  4290. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  4291. vnode.el,
  4292. binding,
  4293. vnode,
  4294. prevVNode
  4295. ]);
  4296. resetTracking();
  4297. }
  4298. }
  4299. }
  4300. const COMPONENTS = 'components';
  4301. const DIRECTIVES = 'directives';
  4302. /**
  4303. * @private
  4304. */
  4305. function resolveComponent(name, maybeSelfReference) {
  4306. return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name;
  4307. }
  4308. const NULL_DYNAMIC_COMPONENT = Symbol();
  4309. /**
  4310. * @private
  4311. */
  4312. function resolveDynamicComponent(component) {
  4313. if (isString(component)) {
  4314. return resolveAsset(COMPONENTS, component, false) || component;
  4315. }
  4316. else {
  4317. // invalid types will fallthrough to createVNode and raise warning
  4318. return (component || NULL_DYNAMIC_COMPONENT);
  4319. }
  4320. }
  4321. /**
  4322. * @private
  4323. */
  4324. function resolveDirective(name) {
  4325. return resolveAsset(DIRECTIVES, name);
  4326. }
  4327. // implementation
  4328. function resolveAsset(type, name, warnMissing = true, maybeSelfReference = false) {
  4329. const instance = currentRenderingInstance || currentInstance;
  4330. if (instance) {
  4331. const Component = instance.type;
  4332. // explicit self name has highest priority
  4333. if (type === COMPONENTS) {
  4334. const selfName = getComponentName(Component, false /* do not include inferred name to avoid breaking existing code */);
  4335. if (selfName &&
  4336. (selfName === name ||
  4337. selfName === camelize(name) ||
  4338. selfName === capitalize(camelize(name)))) {
  4339. return Component;
  4340. }
  4341. }
  4342. const res =
  4343. // local registration
  4344. // check instance[type] first which is resolved for options API
  4345. resolve(instance[type] || Component[type], name) ||
  4346. // global registration
  4347. resolve(instance.appContext[type], name);
  4348. if (!res && maybeSelfReference) {
  4349. // fallback to implicit self-reference
  4350. return Component;
  4351. }
  4352. if (warnMissing && !res) {
  4353. const extra = type === COMPONENTS
  4354. ? `\nIf this is a native custom element, make sure to exclude it from ` +
  4355. `component resolution via compilerOptions.isCustomElement.`
  4356. : ``;
  4357. warn$1(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`);
  4358. }
  4359. return res;
  4360. }
  4361. else {
  4362. warn$1(`resolve${capitalize(type.slice(0, -1))} ` +
  4363. `can only be used in render() or setup().`);
  4364. }
  4365. }
  4366. function resolve(registry, name) {
  4367. return (registry &&
  4368. (registry[name] ||
  4369. registry[camelize(name)] ||
  4370. registry[capitalize(camelize(name))]));
  4371. }
  4372. /**
  4373. * Actual implementation
  4374. */
  4375. function renderList(source, renderItem, cache, index) {
  4376. let ret;
  4377. const cached = (cache && cache[index]);
  4378. if (isArray(source) || isString(source)) {
  4379. ret = new Array(source.length);
  4380. for (let i = 0, l = source.length; i < l; i++) {
  4381. ret[i] = renderItem(source[i], i, undefined, cached && cached[i]);
  4382. }
  4383. }
  4384. else if (typeof source === 'number') {
  4385. if (!Number.isInteger(source)) {
  4386. warn$1(`The v-for range expect an integer value but got ${source}.`);
  4387. }
  4388. ret = new Array(source);
  4389. for (let i = 0; i < source; i++) {
  4390. ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]);
  4391. }
  4392. }
  4393. else if (isObject(source)) {
  4394. if (source[Symbol.iterator]) {
  4395. ret = Array.from(source, (item, i) => renderItem(item, i, undefined, cached && cached[i]));
  4396. }
  4397. else {
  4398. const keys = Object.keys(source);
  4399. ret = new Array(keys.length);
  4400. for (let i = 0, l = keys.length; i < l; i++) {
  4401. const key = keys[i];
  4402. ret[i] = renderItem(source[key], key, i, cached && cached[i]);
  4403. }
  4404. }
  4405. }
  4406. else {
  4407. ret = [];
  4408. }
  4409. if (cache) {
  4410. cache[index] = ret;
  4411. }
  4412. return ret;
  4413. }
  4414. /**
  4415. * Compiler runtime helper for creating dynamic slots object
  4416. * @private
  4417. */
  4418. function createSlots(slots, dynamicSlots) {
  4419. for (let i = 0; i < dynamicSlots.length; i++) {
  4420. const slot = dynamicSlots[i];
  4421. // array of dynamic slot generated by <template v-for="..." #[...]>
  4422. if (isArray(slot)) {
  4423. for (let j = 0; j < slot.length; j++) {
  4424. slots[slot[j].name] = slot[j].fn;
  4425. }
  4426. }
  4427. else if (slot) {
  4428. // conditional single slot generated by <template v-if="..." #foo>
  4429. slots[slot.name] = slot.fn;
  4430. }
  4431. }
  4432. return slots;
  4433. }
  4434. /**
  4435. * Compiler runtime helper for rendering `<slot/>`
  4436. * @private
  4437. */
  4438. function renderSlot(slots, name, props = {},
  4439. // this is not a user-facing function, so the fallback is always generated by
  4440. // the compiler and guaranteed to be a function returning an array
  4441. fallback, noSlotted) {
  4442. if (currentRenderingInstance.isCE ||
  4443. (currentRenderingInstance.parent &&
  4444. isAsyncWrapper(currentRenderingInstance.parent) &&
  4445. currentRenderingInstance.parent.isCE)) {
  4446. return createVNode('slot', name === 'default' ? null : { name }, fallback && fallback());
  4447. }
  4448. let slot = slots[name];
  4449. if (slot && slot.length > 1) {
  4450. warn$1(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  4451. `function. You need to mark this component with $dynamic-slots in the ` +
  4452. `parent template.`);
  4453. slot = () => [];
  4454. }
  4455. // a compiled slot disables block tracking by default to avoid manual
  4456. // invocation interfering with template-based block tracking, but in
  4457. // `renderSlot` we can be sure that it's template-based so we can force
  4458. // enable it.
  4459. if (slot && slot._c) {
  4460. slot._d = false;
  4461. }
  4462. openBlock();
  4463. const validSlotContent = slot && ensureValidVNode(slot(props));
  4464. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  4465. ? 64 /* STABLE_FRAGMENT */
  4466. : -2 /* BAIL */);
  4467. if (!noSlotted && rendered.scopeId) {
  4468. rendered.slotScopeIds = [rendered.scopeId + '-s'];
  4469. }
  4470. if (slot && slot._c) {
  4471. slot._d = true;
  4472. }
  4473. return rendered;
  4474. }
  4475. function ensureValidVNode(vnodes) {
  4476. return vnodes.some(child => {
  4477. if (!isVNode(child))
  4478. return true;
  4479. if (child.type === Comment)
  4480. return false;
  4481. if (child.type === Fragment &&
  4482. !ensureValidVNode(child.children))
  4483. return false;
  4484. return true;
  4485. })
  4486. ? vnodes
  4487. : null;
  4488. }
  4489. /**
  4490. * For prefixing keys in v-on="obj" with "on"
  4491. * @private
  4492. */
  4493. function toHandlers(obj) {
  4494. const ret = {};
  4495. if (!isObject(obj)) {
  4496. warn$1(`v-on with no argument expects an object value.`);
  4497. return ret;
  4498. }
  4499. for (const key in obj) {
  4500. ret[toHandlerKey(key)] = obj[key];
  4501. }
  4502. return ret;
  4503. }
  4504. /**
  4505. * #2437 In Vue 3, functional components do not have a public instance proxy but
  4506. * they exist in the internal parent chain. For code that relies on traversing
  4507. * public $parent chains, skip functional ones and go to the parent instead.
  4508. */
  4509. const getPublicInstance = (i) => {
  4510. if (!i)
  4511. return null;
  4512. if (isStatefulComponent(i))
  4513. return getExposeProxy(i) || i.proxy;
  4514. return getPublicInstance(i.parent);
  4515. };
  4516. const publicPropertiesMap =
  4517. // Move PURE marker to new line to workaround compiler discarding it
  4518. // due to type annotation
  4519. /*#__PURE__*/ extend(Object.create(null), {
  4520. $: i => i,
  4521. $el: i => i.vnode.el,
  4522. $data: i => i.data,
  4523. $props: i => (shallowReadonly(i.props) ),
  4524. $attrs: i => (shallowReadonly(i.attrs) ),
  4525. $slots: i => (shallowReadonly(i.slots) ),
  4526. $refs: i => (shallowReadonly(i.refs) ),
  4527. $parent: i => getPublicInstance(i.parent),
  4528. $root: i => getPublicInstance(i.root),
  4529. $emit: i => i.emit,
  4530. $options: i => (resolveMergedOptions(i) ),
  4531. $forceUpdate: i => i.f || (i.f = () => queueJob(i.update)),
  4532. $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy)),
  4533. $watch: i => (instanceWatch.bind(i) )
  4534. });
  4535. const isReservedPrefix = (key) => key === '_' || key === '$';
  4536. const PublicInstanceProxyHandlers = {
  4537. get({ _: instance }, key) {
  4538. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  4539. // for internal formatters to know that this is a Vue instance
  4540. if (key === '__isVue') {
  4541. return true;
  4542. }
  4543. // prioritize <script setup> bindings during dev.
  4544. // this allows even properties that start with _ or $ to be used - so that
  4545. // it aligns with the production behavior where the render fn is inlined and
  4546. // indeed has access to all declared variables.
  4547. if (setupState !== EMPTY_OBJ &&
  4548. setupState.__isScriptSetup &&
  4549. hasOwn(setupState, key)) {
  4550. return setupState[key];
  4551. }
  4552. // data / props / ctx
  4553. // This getter gets called for every property access on the render context
  4554. // during render and is a major hotspot. The most expensive part of this
  4555. // is the multiple hasOwn() calls. It's much faster to do a simple property
  4556. // access on a plain object, so we use an accessCache object (with null
  4557. // prototype) to memoize what access type a key corresponds to.
  4558. let normalizedProps;
  4559. if (key[0] !== '$') {
  4560. const n = accessCache[key];
  4561. if (n !== undefined) {
  4562. switch (n) {
  4563. case 1 /* SETUP */:
  4564. return setupState[key];
  4565. case 2 /* DATA */:
  4566. return data[key];
  4567. case 4 /* CONTEXT */:
  4568. return ctx[key];
  4569. case 3 /* PROPS */:
  4570. return props[key];
  4571. // default: just fallthrough
  4572. }
  4573. }
  4574. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  4575. accessCache[key] = 1 /* SETUP */;
  4576. return setupState[key];
  4577. }
  4578. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4579. accessCache[key] = 2 /* DATA */;
  4580. return data[key];
  4581. }
  4582. else if (
  4583. // only cache other properties when instance has declared (thus stable)
  4584. // props
  4585. (normalizedProps = instance.propsOptions[0]) &&
  4586. hasOwn(normalizedProps, key)) {
  4587. accessCache[key] = 3 /* PROPS */;
  4588. return props[key];
  4589. }
  4590. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4591. accessCache[key] = 4 /* CONTEXT */;
  4592. return ctx[key];
  4593. }
  4594. else if (shouldCacheAccess) {
  4595. accessCache[key] = 0 /* OTHER */;
  4596. }
  4597. }
  4598. const publicGetter = publicPropertiesMap[key];
  4599. let cssModule, globalProperties;
  4600. // public $xxx properties
  4601. if (publicGetter) {
  4602. if (key === '$attrs') {
  4603. track(instance, "get" /* GET */, key);
  4604. markAttrsAccessed();
  4605. }
  4606. return publicGetter(instance);
  4607. }
  4608. else if (
  4609. // css module (injected by vue-loader)
  4610. (cssModule = type.__cssModules) &&
  4611. (cssModule = cssModule[key])) {
  4612. return cssModule;
  4613. }
  4614. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  4615. // user may set custom properties to `this` that start with `$`
  4616. accessCache[key] = 4 /* CONTEXT */;
  4617. return ctx[key];
  4618. }
  4619. else if (
  4620. // global properties
  4621. ((globalProperties = appContext.config.globalProperties),
  4622. hasOwn(globalProperties, key))) {
  4623. {
  4624. return globalProperties[key];
  4625. }
  4626. }
  4627. else if (currentRenderingInstance &&
  4628. (!isString(key) ||
  4629. // #1091 avoid internal isRef/isVNode checks on component instance leading
  4630. // to infinite warning loop
  4631. key.indexOf('__v') !== 0)) {
  4632. if (data !== EMPTY_OBJ && isReservedPrefix(key[0]) && hasOwn(data, key)) {
  4633. warn$1(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  4634. `character ("$" or "_") and is not proxied on the render context.`);
  4635. }
  4636. else if (instance === currentRenderingInstance) {
  4637. warn$1(`Property ${JSON.stringify(key)} was accessed during render ` +
  4638. `but is not defined on instance.`);
  4639. }
  4640. }
  4641. },
  4642. set({ _: instance }, key, value) {
  4643. const { data, setupState, ctx } = instance;
  4644. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  4645. setupState[key] = value;
  4646. return true;
  4647. }
  4648. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  4649. data[key] = value;
  4650. return true;
  4651. }
  4652. else if (hasOwn(instance.props, key)) {
  4653. warn$1(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  4654. return false;
  4655. }
  4656. if (key[0] === '$' && key.slice(1) in instance) {
  4657. warn$1(`Attempting to mutate public property "${key}". ` +
  4658. `Properties starting with $ are reserved and readonly.`, instance);
  4659. return false;
  4660. }
  4661. else {
  4662. if (key in instance.appContext.config.globalProperties) {
  4663. Object.defineProperty(ctx, key, {
  4664. enumerable: true,
  4665. configurable: true,
  4666. value
  4667. });
  4668. }
  4669. else {
  4670. ctx[key] = value;
  4671. }
  4672. }
  4673. return true;
  4674. },
  4675. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  4676. let normalizedProps;
  4677. return (!!accessCache[key] ||
  4678. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  4679. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  4680. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  4681. hasOwn(ctx, key) ||
  4682. hasOwn(publicPropertiesMap, key) ||
  4683. hasOwn(appContext.config.globalProperties, key));
  4684. },
  4685. defineProperty(target, key, descriptor) {
  4686. if (descriptor.get != null) {
  4687. // invalidate key cache of a getter based property #5417
  4688. target._.accessCache[key] = 0;
  4689. }
  4690. else if (hasOwn(descriptor, 'value')) {
  4691. this.set(target, key, descriptor.value, null);
  4692. }
  4693. return Reflect.defineProperty(target, key, descriptor);
  4694. }
  4695. };
  4696. {
  4697. PublicInstanceProxyHandlers.ownKeys = (target) => {
  4698. warn$1(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  4699. `The keys will be empty in production mode to avoid performance overhead.`);
  4700. return Reflect.ownKeys(target);
  4701. };
  4702. }
  4703. const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend({}, PublicInstanceProxyHandlers, {
  4704. get(target, key) {
  4705. // fast path for unscopables when using `with` block
  4706. if (key === Symbol.unscopables) {
  4707. return;
  4708. }
  4709. return PublicInstanceProxyHandlers.get(target, key, target);
  4710. },
  4711. has(_, key) {
  4712. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  4713. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  4714. warn$1(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  4715. }
  4716. return has;
  4717. }
  4718. });
  4719. // dev only
  4720. // In dev mode, the proxy target exposes the same properties as seen on `this`
  4721. // for easier console inspection. In prod mode it will be an empty object so
  4722. // these properties definitions can be skipped.
  4723. function createDevRenderContext(instance) {
  4724. const target = {};
  4725. // expose internal instance for proxy handlers
  4726. Object.defineProperty(target, `_`, {
  4727. configurable: true,
  4728. enumerable: false,
  4729. get: () => instance
  4730. });
  4731. // expose public properties
  4732. Object.keys(publicPropertiesMap).forEach(key => {
  4733. Object.defineProperty(target, key, {
  4734. configurable: true,
  4735. enumerable: false,
  4736. get: () => publicPropertiesMap[key](instance),
  4737. // intercepted by the proxy so no need for implementation,
  4738. // but needed to prevent set errors
  4739. set: NOOP
  4740. });
  4741. });
  4742. return target;
  4743. }
  4744. // dev only
  4745. function exposePropsOnRenderContext(instance) {
  4746. const { ctx, propsOptions: [propsOptions] } = instance;
  4747. if (propsOptions) {
  4748. Object.keys(propsOptions).forEach(key => {
  4749. Object.defineProperty(ctx, key, {
  4750. enumerable: true,
  4751. configurable: true,
  4752. get: () => instance.props[key],
  4753. set: NOOP
  4754. });
  4755. });
  4756. }
  4757. }
  4758. // dev only
  4759. function exposeSetupStateOnRenderContext(instance) {
  4760. const { ctx, setupState } = instance;
  4761. Object.keys(toRaw(setupState)).forEach(key => {
  4762. if (!setupState.__isScriptSetup) {
  4763. if (isReservedPrefix(key[0])) {
  4764. warn$1(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  4765. `which are reserved prefixes for Vue internals.`);
  4766. return;
  4767. }
  4768. Object.defineProperty(ctx, key, {
  4769. enumerable: true,
  4770. configurable: true,
  4771. get: () => setupState[key],
  4772. set: NOOP
  4773. });
  4774. }
  4775. });
  4776. }
  4777. function createDuplicateChecker() {
  4778. const cache = Object.create(null);
  4779. return (type, key) => {
  4780. if (cache[key]) {
  4781. warn$1(`${type} property "${key}" is already defined in ${cache[key]}.`);
  4782. }
  4783. else {
  4784. cache[key] = type;
  4785. }
  4786. };
  4787. }
  4788. let shouldCacheAccess = true;
  4789. function applyOptions(instance) {
  4790. const options = resolveMergedOptions(instance);
  4791. const publicThis = instance.proxy;
  4792. const ctx = instance.ctx;
  4793. // do not cache property access on public proxy during state initialization
  4794. shouldCacheAccess = false;
  4795. // call beforeCreate first before accessing other options since
  4796. // the hook may mutate resolved options (#2791)
  4797. if (options.beforeCreate) {
  4798. callHook(options.beforeCreate, instance, "bc" /* BEFORE_CREATE */);
  4799. }
  4800. const {
  4801. // state
  4802. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  4803. // lifecycle
  4804. created, beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured, serverPrefetch,
  4805. // public API
  4806. expose, inheritAttrs,
  4807. // assets
  4808. components, directives, filters } = options;
  4809. const checkDuplicateProperties = createDuplicateChecker() ;
  4810. {
  4811. const [propsOptions] = instance.propsOptions;
  4812. if (propsOptions) {
  4813. for (const key in propsOptions) {
  4814. checkDuplicateProperties("Props" /* PROPS */, key);
  4815. }
  4816. }
  4817. }
  4818. // options initialization order (to be consistent with Vue 2):
  4819. // - props (already done outside of this function)
  4820. // - inject
  4821. // - methods
  4822. // - data (deferred since it relies on `this` access)
  4823. // - computed
  4824. // - watch (deferred since it relies on `this` access)
  4825. if (injectOptions) {
  4826. resolveInjections(injectOptions, ctx, checkDuplicateProperties, instance.appContext.config.unwrapInjectedRef);
  4827. }
  4828. if (methods) {
  4829. for (const key in methods) {
  4830. const methodHandler = methods[key];
  4831. if (isFunction(methodHandler)) {
  4832. // In dev mode, we use the `createRenderContext` function to define
  4833. // methods to the proxy target, and those are read-only but
  4834. // reconfigurable, so it needs to be redefined here
  4835. {
  4836. Object.defineProperty(ctx, key, {
  4837. value: methodHandler.bind(publicThis),
  4838. configurable: true,
  4839. enumerable: true,
  4840. writable: true
  4841. });
  4842. }
  4843. {
  4844. checkDuplicateProperties("Methods" /* METHODS */, key);
  4845. }
  4846. }
  4847. else {
  4848. warn$1(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  4849. `Did you reference the function correctly?`);
  4850. }
  4851. }
  4852. }
  4853. if (dataOptions) {
  4854. if (!isFunction(dataOptions)) {
  4855. warn$1(`The data option must be a function. ` +
  4856. `Plain object usage is no longer supported.`);
  4857. }
  4858. const data = dataOptions.call(publicThis, publicThis);
  4859. if (isPromise(data)) {
  4860. warn$1(`data() returned a Promise - note data() cannot be async; If you ` +
  4861. `intend to perform data fetching before component renders, use ` +
  4862. `async setup() + <Suspense>.`);
  4863. }
  4864. if (!isObject(data)) {
  4865. warn$1(`data() should return an object.`);
  4866. }
  4867. else {
  4868. instance.data = reactive(data);
  4869. {
  4870. for (const key in data) {
  4871. checkDuplicateProperties("Data" /* DATA */, key);
  4872. // expose data on ctx during dev
  4873. if (!isReservedPrefix(key[0])) {
  4874. Object.defineProperty(ctx, key, {
  4875. configurable: true,
  4876. enumerable: true,
  4877. get: () => data[key],
  4878. set: NOOP
  4879. });
  4880. }
  4881. }
  4882. }
  4883. }
  4884. }
  4885. // state initialization complete at this point - start caching access
  4886. shouldCacheAccess = true;
  4887. if (computedOptions) {
  4888. for (const key in computedOptions) {
  4889. const opt = computedOptions[key];
  4890. const get = isFunction(opt)
  4891. ? opt.bind(publicThis, publicThis)
  4892. : isFunction(opt.get)
  4893. ? opt.get.bind(publicThis, publicThis)
  4894. : NOOP;
  4895. if (get === NOOP) {
  4896. warn$1(`Computed property "${key}" has no getter.`);
  4897. }
  4898. const set = !isFunction(opt) && isFunction(opt.set)
  4899. ? opt.set.bind(publicThis)
  4900. : () => {
  4901. warn$1(`Write operation failed: computed property "${key}" is readonly.`);
  4902. }
  4903. ;
  4904. const c = computed$1({
  4905. get,
  4906. set
  4907. });
  4908. Object.defineProperty(ctx, key, {
  4909. enumerable: true,
  4910. configurable: true,
  4911. get: () => c.value,
  4912. set: v => (c.value = v)
  4913. });
  4914. {
  4915. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  4916. }
  4917. }
  4918. }
  4919. if (watchOptions) {
  4920. for (const key in watchOptions) {
  4921. createWatcher(watchOptions[key], ctx, publicThis, key);
  4922. }
  4923. }
  4924. if (provideOptions) {
  4925. const provides = isFunction(provideOptions)
  4926. ? provideOptions.call(publicThis)
  4927. : provideOptions;
  4928. Reflect.ownKeys(provides).forEach(key => {
  4929. provide(key, provides[key]);
  4930. });
  4931. }
  4932. if (created) {
  4933. callHook(created, instance, "c" /* CREATED */);
  4934. }
  4935. function registerLifecycleHook(register, hook) {
  4936. if (isArray(hook)) {
  4937. hook.forEach(_hook => register(_hook.bind(publicThis)));
  4938. }
  4939. else if (hook) {
  4940. register(hook.bind(publicThis));
  4941. }
  4942. }
  4943. registerLifecycleHook(onBeforeMount, beforeMount);
  4944. registerLifecycleHook(onMounted, mounted);
  4945. registerLifecycleHook(onBeforeUpdate, beforeUpdate);
  4946. registerLifecycleHook(onUpdated, updated);
  4947. registerLifecycleHook(onActivated, activated);
  4948. registerLifecycleHook(onDeactivated, deactivated);
  4949. registerLifecycleHook(onErrorCaptured, errorCaptured);
  4950. registerLifecycleHook(onRenderTracked, renderTracked);
  4951. registerLifecycleHook(onRenderTriggered, renderTriggered);
  4952. registerLifecycleHook(onBeforeUnmount, beforeUnmount);
  4953. registerLifecycleHook(onUnmounted, unmounted);
  4954. registerLifecycleHook(onServerPrefetch, serverPrefetch);
  4955. if (isArray(expose)) {
  4956. if (expose.length) {
  4957. const exposed = instance.exposed || (instance.exposed = {});
  4958. expose.forEach(key => {
  4959. Object.defineProperty(exposed, key, {
  4960. get: () => publicThis[key],
  4961. set: val => (publicThis[key] = val)
  4962. });
  4963. });
  4964. }
  4965. else if (!instance.exposed) {
  4966. instance.exposed = {};
  4967. }
  4968. }
  4969. // options that are handled when creating the instance but also need to be
  4970. // applied from mixins
  4971. if (render && instance.render === NOOP) {
  4972. instance.render = render;
  4973. }
  4974. if (inheritAttrs != null) {
  4975. instance.inheritAttrs = inheritAttrs;
  4976. }
  4977. // asset options.
  4978. if (components)
  4979. instance.components = components;
  4980. if (directives)
  4981. instance.directives = directives;
  4982. }
  4983. function resolveInjections(injectOptions, ctx, checkDuplicateProperties = NOOP, unwrapRef = false) {
  4984. if (isArray(injectOptions)) {
  4985. injectOptions = normalizeInject(injectOptions);
  4986. }
  4987. for (const key in injectOptions) {
  4988. const opt = injectOptions[key];
  4989. let injected;
  4990. if (isObject(opt)) {
  4991. if ('default' in opt) {
  4992. injected = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  4993. }
  4994. else {
  4995. injected = inject(opt.from || key);
  4996. }
  4997. }
  4998. else {
  4999. injected = inject(opt);
  5000. }
  5001. if (isRef(injected)) {
  5002. // TODO remove the check in 3.3
  5003. if (unwrapRef) {
  5004. Object.defineProperty(ctx, key, {
  5005. enumerable: true,
  5006. configurable: true,
  5007. get: () => injected.value,
  5008. set: v => (injected.value = v)
  5009. });
  5010. }
  5011. else {
  5012. {
  5013. warn$1(`injected property "${key}" is a ref and will be auto-unwrapped ` +
  5014. `and no longer needs \`.value\` in the next minor release. ` +
  5015. `To opt-in to the new behavior now, ` +
  5016. `set \`app.config.unwrapInjectedRef = true\` (this config is ` +
  5017. `temporary and will not be needed in the future.)`);
  5018. }
  5019. ctx[key] = injected;
  5020. }
  5021. }
  5022. else {
  5023. ctx[key] = injected;
  5024. }
  5025. {
  5026. checkDuplicateProperties("Inject" /* INJECT */, key);
  5027. }
  5028. }
  5029. }
  5030. function callHook(hook, instance, type) {
  5031. callWithAsyncErrorHandling(isArray(hook)
  5032. ? hook.map(h => h.bind(instance.proxy))
  5033. : hook.bind(instance.proxy), instance, type);
  5034. }
  5035. function createWatcher(raw, ctx, publicThis, key) {
  5036. const getter = key.includes('.')
  5037. ? createPathGetter(publicThis, key)
  5038. : () => publicThis[key];
  5039. if (isString(raw)) {
  5040. const handler = ctx[raw];
  5041. if (isFunction(handler)) {
  5042. watch(getter, handler);
  5043. }
  5044. else {
  5045. warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
  5046. }
  5047. }
  5048. else if (isFunction(raw)) {
  5049. watch(getter, raw.bind(publicThis));
  5050. }
  5051. else if (isObject(raw)) {
  5052. if (isArray(raw)) {
  5053. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  5054. }
  5055. else {
  5056. const handler = isFunction(raw.handler)
  5057. ? raw.handler.bind(publicThis)
  5058. : ctx[raw.handler];
  5059. if (isFunction(handler)) {
  5060. watch(getter, handler, raw);
  5061. }
  5062. else {
  5063. warn$1(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  5064. }
  5065. }
  5066. }
  5067. else {
  5068. warn$1(`Invalid watch option: "${key}"`, raw);
  5069. }
  5070. }
  5071. /**
  5072. * Resolve merged options and cache it on the component.
  5073. * This is done only once per-component since the merging does not involve
  5074. * instances.
  5075. */
  5076. function resolveMergedOptions(instance) {
  5077. const base = instance.type;
  5078. const { mixins, extends: extendsOptions } = base;
  5079. const { mixins: globalMixins, optionsCache: cache, config: { optionMergeStrategies } } = instance.appContext;
  5080. const cached = cache.get(base);
  5081. let resolved;
  5082. if (cached) {
  5083. resolved = cached;
  5084. }
  5085. else if (!globalMixins.length && !mixins && !extendsOptions) {
  5086. {
  5087. resolved = base;
  5088. }
  5089. }
  5090. else {
  5091. resolved = {};
  5092. if (globalMixins.length) {
  5093. globalMixins.forEach(m => mergeOptions(resolved, m, optionMergeStrategies, true));
  5094. }
  5095. mergeOptions(resolved, base, optionMergeStrategies);
  5096. }
  5097. cache.set(base, resolved);
  5098. return resolved;
  5099. }
  5100. function mergeOptions(to, from, strats, asMixin = false) {
  5101. const { mixins, extends: extendsOptions } = from;
  5102. if (extendsOptions) {
  5103. mergeOptions(to, extendsOptions, strats, true);
  5104. }
  5105. if (mixins) {
  5106. mixins.forEach((m) => mergeOptions(to, m, strats, true));
  5107. }
  5108. for (const key in from) {
  5109. if (asMixin && key === 'expose') {
  5110. warn$1(`"expose" option is ignored when declared in mixins or extends. ` +
  5111. `It should only be declared in the base component itself.`);
  5112. }
  5113. else {
  5114. const strat = internalOptionMergeStrats[key] || (strats && strats[key]);
  5115. to[key] = strat ? strat(to[key], from[key]) : from[key];
  5116. }
  5117. }
  5118. return to;
  5119. }
  5120. const internalOptionMergeStrats = {
  5121. data: mergeDataFn,
  5122. props: mergeObjectOptions,
  5123. emits: mergeObjectOptions,
  5124. // objects
  5125. methods: mergeObjectOptions,
  5126. computed: mergeObjectOptions,
  5127. // lifecycle
  5128. beforeCreate: mergeAsArray,
  5129. created: mergeAsArray,
  5130. beforeMount: mergeAsArray,
  5131. mounted: mergeAsArray,
  5132. beforeUpdate: mergeAsArray,
  5133. updated: mergeAsArray,
  5134. beforeDestroy: mergeAsArray,
  5135. beforeUnmount: mergeAsArray,
  5136. destroyed: mergeAsArray,
  5137. unmounted: mergeAsArray,
  5138. activated: mergeAsArray,
  5139. deactivated: mergeAsArray,
  5140. errorCaptured: mergeAsArray,
  5141. serverPrefetch: mergeAsArray,
  5142. // assets
  5143. components: mergeObjectOptions,
  5144. directives: mergeObjectOptions,
  5145. // watch
  5146. watch: mergeWatchOptions,
  5147. // provide / inject
  5148. provide: mergeDataFn,
  5149. inject: mergeInject
  5150. };
  5151. function mergeDataFn(to, from) {
  5152. if (!from) {
  5153. return to;
  5154. }
  5155. if (!to) {
  5156. return from;
  5157. }
  5158. return function mergedDataFn() {
  5159. return (extend)(isFunction(to) ? to.call(this, this) : to, isFunction(from) ? from.call(this, this) : from);
  5160. };
  5161. }
  5162. function mergeInject(to, from) {
  5163. return mergeObjectOptions(normalizeInject(to), normalizeInject(from));
  5164. }
  5165. function normalizeInject(raw) {
  5166. if (isArray(raw)) {
  5167. const res = {};
  5168. for (let i = 0; i < raw.length; i++) {
  5169. res[raw[i]] = raw[i];
  5170. }
  5171. return res;
  5172. }
  5173. return raw;
  5174. }
  5175. function mergeAsArray(to, from) {
  5176. return to ? [...new Set([].concat(to, from))] : from;
  5177. }
  5178. function mergeObjectOptions(to, from) {
  5179. return to ? extend(extend(Object.create(null), to), from) : from;
  5180. }
  5181. function mergeWatchOptions(to, from) {
  5182. if (!to)
  5183. return from;
  5184. if (!from)
  5185. return to;
  5186. const merged = extend(Object.create(null), to);
  5187. for (const key in from) {
  5188. merged[key] = mergeAsArray(to[key], from[key]);
  5189. }
  5190. return merged;
  5191. }
  5192. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  5193. isSSR = false) {
  5194. const props = {};
  5195. const attrs = {};
  5196. def(attrs, InternalObjectKey, 1);
  5197. instance.propsDefaults = Object.create(null);
  5198. setFullProps(instance, rawProps, props, attrs);
  5199. // ensure all declared prop keys are present
  5200. for (const key in instance.propsOptions[0]) {
  5201. if (!(key in props)) {
  5202. props[key] = undefined;
  5203. }
  5204. }
  5205. // validation
  5206. {
  5207. validateProps(rawProps || {}, props, instance);
  5208. }
  5209. if (isStateful) {
  5210. // stateful
  5211. instance.props = isSSR ? props : shallowReactive(props);
  5212. }
  5213. else {
  5214. if (!instance.type.props) {
  5215. // functional w/ optional props, props === attrs
  5216. instance.props = attrs;
  5217. }
  5218. else {
  5219. // functional w/ declared props
  5220. instance.props = props;
  5221. }
  5222. }
  5223. instance.attrs = attrs;
  5224. }
  5225. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  5226. const { props, attrs, vnode: { patchFlag } } = instance;
  5227. const rawCurrentProps = toRaw(props);
  5228. const [options] = instance.propsOptions;
  5229. let hasAttrsChanged = false;
  5230. if (
  5231. // always force full diff in dev
  5232. // - #1942 if hmr is enabled with sfc component
  5233. // - vite#872 non-sfc component used by sfc component
  5234. !((instance.type.__hmrId ||
  5235. (instance.parent && instance.parent.type.__hmrId))) &&
  5236. (optimized || patchFlag > 0) &&
  5237. !(patchFlag & 16 /* FULL_PROPS */)) {
  5238. if (patchFlag & 8 /* PROPS */) {
  5239. // Compiler-generated props & no keys change, just set the updated
  5240. // the props.
  5241. const propsToUpdate = instance.vnode.dynamicProps;
  5242. for (let i = 0; i < propsToUpdate.length; i++) {
  5243. let key = propsToUpdate[i];
  5244. // skip if the prop key is a declared emit event listener
  5245. if (isEmitListener(instance.emitsOptions, key)) {
  5246. continue;
  5247. }
  5248. // PROPS flag guarantees rawProps to be non-null
  5249. const value = rawProps[key];
  5250. if (options) {
  5251. // attr / props separation was done on init and will be consistent
  5252. // in this code path, so just check if attrs have it.
  5253. if (hasOwn(attrs, key)) {
  5254. if (value !== attrs[key]) {
  5255. attrs[key] = value;
  5256. hasAttrsChanged = true;
  5257. }
  5258. }
  5259. else {
  5260. const camelizedKey = camelize(key);
  5261. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance, false /* isAbsent */);
  5262. }
  5263. }
  5264. else {
  5265. if (value !== attrs[key]) {
  5266. attrs[key] = value;
  5267. hasAttrsChanged = true;
  5268. }
  5269. }
  5270. }
  5271. }
  5272. }
  5273. else {
  5274. // full props update.
  5275. if (setFullProps(instance, rawProps, props, attrs)) {
  5276. hasAttrsChanged = true;
  5277. }
  5278. // in case of dynamic props, check if we need to delete keys from
  5279. // the props object
  5280. let kebabKey;
  5281. for (const key in rawCurrentProps) {
  5282. if (!rawProps ||
  5283. // for camelCase
  5284. (!hasOwn(rawProps, key) &&
  5285. // it's possible the original props was passed in as kebab-case
  5286. // and converted to camelCase (#955)
  5287. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  5288. if (options) {
  5289. if (rawPrevProps &&
  5290. // for camelCase
  5291. (rawPrevProps[key] !== undefined ||
  5292. // for kebab-case
  5293. rawPrevProps[kebabKey] !== undefined)) {
  5294. props[key] = resolvePropValue(options, rawCurrentProps, key, undefined, instance, true /* isAbsent */);
  5295. }
  5296. }
  5297. else {
  5298. delete props[key];
  5299. }
  5300. }
  5301. }
  5302. // in the case of functional component w/o props declaration, props and
  5303. // attrs point to the same object so it should already have been updated.
  5304. if (attrs !== rawCurrentProps) {
  5305. for (const key in attrs) {
  5306. if (!rawProps ||
  5307. (!hasOwn(rawProps, key) &&
  5308. (!false ))) {
  5309. delete attrs[key];
  5310. hasAttrsChanged = true;
  5311. }
  5312. }
  5313. }
  5314. }
  5315. // trigger updates for $attrs in case it's used in component slots
  5316. if (hasAttrsChanged) {
  5317. trigger(instance, "set" /* SET */, '$attrs');
  5318. }
  5319. {
  5320. validateProps(rawProps || {}, props, instance);
  5321. }
  5322. }
  5323. function setFullProps(instance, rawProps, props, attrs) {
  5324. const [options, needCastKeys] = instance.propsOptions;
  5325. let hasAttrsChanged = false;
  5326. let rawCastValues;
  5327. if (rawProps) {
  5328. for (let key in rawProps) {
  5329. // key, ref are reserved and never passed down
  5330. if (isReservedProp(key)) {
  5331. continue;
  5332. }
  5333. const value = rawProps[key];
  5334. // prop option names are camelized during normalization, so to support
  5335. // kebab -> camel conversion here we need to camelize the key.
  5336. let camelKey;
  5337. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  5338. if (!needCastKeys || !needCastKeys.includes(camelKey)) {
  5339. props[camelKey] = value;
  5340. }
  5341. else {
  5342. (rawCastValues || (rawCastValues = {}))[camelKey] = value;
  5343. }
  5344. }
  5345. else if (!isEmitListener(instance.emitsOptions, key)) {
  5346. if (!(key in attrs) || value !== attrs[key]) {
  5347. attrs[key] = value;
  5348. hasAttrsChanged = true;
  5349. }
  5350. }
  5351. }
  5352. }
  5353. if (needCastKeys) {
  5354. const rawCurrentProps = toRaw(props);
  5355. const castValues = rawCastValues || EMPTY_OBJ;
  5356. for (let i = 0; i < needCastKeys.length; i++) {
  5357. const key = needCastKeys[i];
  5358. props[key] = resolvePropValue(options, rawCurrentProps, key, castValues[key], instance, !hasOwn(castValues, key));
  5359. }
  5360. }
  5361. return hasAttrsChanged;
  5362. }
  5363. function resolvePropValue(options, props, key, value, instance, isAbsent) {
  5364. const opt = options[key];
  5365. if (opt != null) {
  5366. const hasDefault = hasOwn(opt, 'default');
  5367. // default values
  5368. if (hasDefault && value === undefined) {
  5369. const defaultValue = opt.default;
  5370. if (opt.type !== Function && isFunction(defaultValue)) {
  5371. const { propsDefaults } = instance;
  5372. if (key in propsDefaults) {
  5373. value = propsDefaults[key];
  5374. }
  5375. else {
  5376. setCurrentInstance(instance);
  5377. value = propsDefaults[key] = defaultValue.call(null, props);
  5378. unsetCurrentInstance();
  5379. }
  5380. }
  5381. else {
  5382. value = defaultValue;
  5383. }
  5384. }
  5385. // boolean casting
  5386. if (opt[0 /* shouldCast */]) {
  5387. if (isAbsent && !hasDefault) {
  5388. value = false;
  5389. }
  5390. else if (opt[1 /* shouldCastTrue */] &&
  5391. (value === '' || value === hyphenate(key))) {
  5392. value = true;
  5393. }
  5394. }
  5395. }
  5396. return value;
  5397. }
  5398. function normalizePropsOptions(comp, appContext, asMixin = false) {
  5399. const cache = appContext.propsCache;
  5400. const cached = cache.get(comp);
  5401. if (cached) {
  5402. return cached;
  5403. }
  5404. const raw = comp.props;
  5405. const normalized = {};
  5406. const needCastKeys = [];
  5407. // apply mixin/extends props
  5408. let hasExtends = false;
  5409. if (!isFunction(comp)) {
  5410. const extendProps = (raw) => {
  5411. hasExtends = true;
  5412. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  5413. extend(normalized, props);
  5414. if (keys)
  5415. needCastKeys.push(...keys);
  5416. };
  5417. if (!asMixin && appContext.mixins.length) {
  5418. appContext.mixins.forEach(extendProps);
  5419. }
  5420. if (comp.extends) {
  5421. extendProps(comp.extends);
  5422. }
  5423. if (comp.mixins) {
  5424. comp.mixins.forEach(extendProps);
  5425. }
  5426. }
  5427. if (!raw && !hasExtends) {
  5428. cache.set(comp, EMPTY_ARR);
  5429. return EMPTY_ARR;
  5430. }
  5431. if (isArray(raw)) {
  5432. for (let i = 0; i < raw.length; i++) {
  5433. if (!isString(raw[i])) {
  5434. warn$1(`props must be strings when using array syntax.`, raw[i]);
  5435. }
  5436. const normalizedKey = camelize(raw[i]);
  5437. if (validatePropName(normalizedKey)) {
  5438. normalized[normalizedKey] = EMPTY_OBJ;
  5439. }
  5440. }
  5441. }
  5442. else if (raw) {
  5443. if (!isObject(raw)) {
  5444. warn$1(`invalid props options`, raw);
  5445. }
  5446. for (const key in raw) {
  5447. const normalizedKey = camelize(key);
  5448. if (validatePropName(normalizedKey)) {
  5449. const opt = raw[key];
  5450. const prop = (normalized[normalizedKey] =
  5451. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  5452. if (prop) {
  5453. const booleanIndex = getTypeIndex(Boolean, prop.type);
  5454. const stringIndex = getTypeIndex(String, prop.type);
  5455. prop[0 /* shouldCast */] = booleanIndex > -1;
  5456. prop[1 /* shouldCastTrue */] =
  5457. stringIndex < 0 || booleanIndex < stringIndex;
  5458. // if the prop needs boolean casting or default value
  5459. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  5460. needCastKeys.push(normalizedKey);
  5461. }
  5462. }
  5463. }
  5464. }
  5465. }
  5466. const res = [normalized, needCastKeys];
  5467. cache.set(comp, res);
  5468. return res;
  5469. }
  5470. function validatePropName(key) {
  5471. if (key[0] !== '$') {
  5472. return true;
  5473. }
  5474. else {
  5475. warn$1(`Invalid prop name: "${key}" is a reserved property.`);
  5476. }
  5477. return false;
  5478. }
  5479. // use function string name to check type constructors
  5480. // so that it works across vms / iframes.
  5481. function getType(ctor) {
  5482. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  5483. return match ? match[1] : ctor === null ? 'null' : '';
  5484. }
  5485. function isSameType(a, b) {
  5486. return getType(a) === getType(b);
  5487. }
  5488. function getTypeIndex(type, expectedTypes) {
  5489. if (isArray(expectedTypes)) {
  5490. return expectedTypes.findIndex(t => isSameType(t, type));
  5491. }
  5492. else if (isFunction(expectedTypes)) {
  5493. return isSameType(expectedTypes, type) ? 0 : -1;
  5494. }
  5495. return -1;
  5496. }
  5497. /**
  5498. * dev only
  5499. */
  5500. function validateProps(rawProps, props, instance) {
  5501. const resolvedValues = toRaw(props);
  5502. const options = instance.propsOptions[0];
  5503. for (const key in options) {
  5504. let opt = options[key];
  5505. if (opt == null)
  5506. continue;
  5507. validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key)));
  5508. }
  5509. }
  5510. /**
  5511. * dev only
  5512. */
  5513. function validateProp(name, value, prop, isAbsent) {
  5514. const { type, required, validator } = prop;
  5515. // required!
  5516. if (required && isAbsent) {
  5517. warn$1('Missing required prop: "' + name + '"');
  5518. return;
  5519. }
  5520. // missing but optional
  5521. if (value == null && !prop.required) {
  5522. return;
  5523. }
  5524. // type check
  5525. if (type != null && type !== true) {
  5526. let isValid = false;
  5527. const types = isArray(type) ? type : [type];
  5528. const expectedTypes = [];
  5529. // value is valid as long as one of the specified types match
  5530. for (let i = 0; i < types.length && !isValid; i++) {
  5531. const { valid, expectedType } = assertType(value, types[i]);
  5532. expectedTypes.push(expectedType || '');
  5533. isValid = valid;
  5534. }
  5535. if (!isValid) {
  5536. warn$1(getInvalidTypeMessage(name, value, expectedTypes));
  5537. return;
  5538. }
  5539. }
  5540. // custom validator
  5541. if (validator && !validator(value)) {
  5542. warn$1('Invalid prop: custom validator check failed for prop "' + name + '".');
  5543. }
  5544. }
  5545. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  5546. /**
  5547. * dev only
  5548. */
  5549. function assertType(value, type) {
  5550. let valid;
  5551. const expectedType = getType(type);
  5552. if (isSimpleType(expectedType)) {
  5553. const t = typeof value;
  5554. valid = t === expectedType.toLowerCase();
  5555. // for primitive wrapper objects
  5556. if (!valid && t === 'object') {
  5557. valid = value instanceof type;
  5558. }
  5559. }
  5560. else if (expectedType === 'Object') {
  5561. valid = isObject(value);
  5562. }
  5563. else if (expectedType === 'Array') {
  5564. valid = isArray(value);
  5565. }
  5566. else if (expectedType === 'null') {
  5567. valid = value === null;
  5568. }
  5569. else {
  5570. valid = value instanceof type;
  5571. }
  5572. return {
  5573. valid,
  5574. expectedType
  5575. };
  5576. }
  5577. /**
  5578. * dev only
  5579. */
  5580. function getInvalidTypeMessage(name, value, expectedTypes) {
  5581. let message = `Invalid prop: type check failed for prop "${name}".` +
  5582. ` Expected ${expectedTypes.map(capitalize).join(' | ')}`;
  5583. const expectedType = expectedTypes[0];
  5584. const receivedType = toRawType(value);
  5585. const expectedValue = styleValue(value, expectedType);
  5586. const receivedValue = styleValue(value, receivedType);
  5587. // check if we need to specify expected value
  5588. if (expectedTypes.length === 1 &&
  5589. isExplicable(expectedType) &&
  5590. !isBoolean(expectedType, receivedType)) {
  5591. message += ` with value ${expectedValue}`;
  5592. }
  5593. message += `, got ${receivedType} `;
  5594. // check if we need to specify received value
  5595. if (isExplicable(receivedType)) {
  5596. message += `with value ${receivedValue}.`;
  5597. }
  5598. return message;
  5599. }
  5600. /**
  5601. * dev only
  5602. */
  5603. function styleValue(value, type) {
  5604. if (type === 'String') {
  5605. return `"${value}"`;
  5606. }
  5607. else if (type === 'Number') {
  5608. return `${Number(value)}`;
  5609. }
  5610. else {
  5611. return `${value}`;
  5612. }
  5613. }
  5614. /**
  5615. * dev only
  5616. */
  5617. function isExplicable(type) {
  5618. const explicitTypes = ['string', 'number', 'boolean'];
  5619. return explicitTypes.some(elem => type.toLowerCase() === elem);
  5620. }
  5621. /**
  5622. * dev only
  5623. */
  5624. function isBoolean(...args) {
  5625. return args.some(elem => elem.toLowerCase() === 'boolean');
  5626. }
  5627. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  5628. const normalizeSlotValue = (value) => isArray(value)
  5629. ? value.map(normalizeVNode)
  5630. : [normalizeVNode(value)];
  5631. const normalizeSlot = (key, rawSlot, ctx) => {
  5632. if (rawSlot._n) {
  5633. // already normalized - #5353
  5634. return rawSlot;
  5635. }
  5636. const normalized = withCtx((...args) => {
  5637. if (currentInstance) {
  5638. warn$1(`Slot "${key}" invoked outside of the render function: ` +
  5639. `this will not track dependencies used in the slot. ` +
  5640. `Invoke the slot function inside the render function instead.`);
  5641. }
  5642. return normalizeSlotValue(rawSlot(...args));
  5643. }, ctx);
  5644. normalized._c = false;
  5645. return normalized;
  5646. };
  5647. const normalizeObjectSlots = (rawSlots, slots, instance) => {
  5648. const ctx = rawSlots._ctx;
  5649. for (const key in rawSlots) {
  5650. if (isInternalKey(key))
  5651. continue;
  5652. const value = rawSlots[key];
  5653. if (isFunction(value)) {
  5654. slots[key] = normalizeSlot(key, value, ctx);
  5655. }
  5656. else if (value != null) {
  5657. {
  5658. warn$1(`Non-function value encountered for slot "${key}". ` +
  5659. `Prefer function slots for better performance.`);
  5660. }
  5661. const normalized = normalizeSlotValue(value);
  5662. slots[key] = () => normalized;
  5663. }
  5664. }
  5665. };
  5666. const normalizeVNodeSlots = (instance, children) => {
  5667. if (!isKeepAlive(instance.vnode) &&
  5668. !(false )) {
  5669. warn$1(`Non-function value encountered for default slot. ` +
  5670. `Prefer function slots for better performance.`);
  5671. }
  5672. const normalized = normalizeSlotValue(children);
  5673. instance.slots.default = () => normalized;
  5674. };
  5675. const initSlots = (instance, children) => {
  5676. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5677. const type = children._;
  5678. if (type) {
  5679. // users can get the shallow readonly version of the slots object through `this.$slots`,
  5680. // we should avoid the proxy object polluting the slots of the internal instance
  5681. instance.slots = toRaw(children);
  5682. // make compiler marker non-enumerable
  5683. def(children, '_', type);
  5684. }
  5685. else {
  5686. normalizeObjectSlots(children, (instance.slots = {}));
  5687. }
  5688. }
  5689. else {
  5690. instance.slots = {};
  5691. if (children) {
  5692. normalizeVNodeSlots(instance, children);
  5693. }
  5694. }
  5695. def(instance.slots, InternalObjectKey, 1);
  5696. };
  5697. const updateSlots = (instance, children, optimized) => {
  5698. const { vnode, slots } = instance;
  5699. let needDeletionCheck = true;
  5700. let deletionComparisonTarget = EMPTY_OBJ;
  5701. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  5702. const type = children._;
  5703. if (type) {
  5704. // compiled slots.
  5705. if (isHmrUpdating) {
  5706. // Parent was HMR updated so slot content may have changed.
  5707. // force update slots and mark instance for hmr as well
  5708. extend(slots, children);
  5709. }
  5710. else if (optimized && type === 1 /* STABLE */) {
  5711. // compiled AND stable.
  5712. // no need to update, and skip stale slots removal.
  5713. needDeletionCheck = false;
  5714. }
  5715. else {
  5716. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  5717. // normalization.
  5718. extend(slots, children);
  5719. // #2893
  5720. // when rendering the optimized slots by manually written render function,
  5721. // we need to delete the `slots._` flag if necessary to make subsequent updates reliable,
  5722. // i.e. let the `renderSlot` create the bailed Fragment
  5723. if (!optimized && type === 1 /* STABLE */) {
  5724. delete slots._;
  5725. }
  5726. }
  5727. }
  5728. else {
  5729. needDeletionCheck = !children.$stable;
  5730. normalizeObjectSlots(children, slots);
  5731. }
  5732. deletionComparisonTarget = children;
  5733. }
  5734. else if (children) {
  5735. // non slot object children (direct value) passed to a component
  5736. normalizeVNodeSlots(instance, children);
  5737. deletionComparisonTarget = { default: 1 };
  5738. }
  5739. // delete stale slots
  5740. if (needDeletionCheck) {
  5741. for (const key in slots) {
  5742. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  5743. delete slots[key];
  5744. }
  5745. }
  5746. }
  5747. };
  5748. function createAppContext() {
  5749. return {
  5750. app: null,
  5751. config: {
  5752. isNativeTag: NO,
  5753. performance: false,
  5754. globalProperties: {},
  5755. optionMergeStrategies: {},
  5756. errorHandler: undefined,
  5757. warnHandler: undefined,
  5758. compilerOptions: {}
  5759. },
  5760. mixins: [],
  5761. components: {},
  5762. directives: {},
  5763. provides: Object.create(null),
  5764. optionsCache: new WeakMap(),
  5765. propsCache: new WeakMap(),
  5766. emitsCache: new WeakMap()
  5767. };
  5768. }
  5769. let uid = 0;
  5770. function createAppAPI(render, hydrate) {
  5771. return function createApp(rootComponent, rootProps = null) {
  5772. if (!isFunction(rootComponent)) {
  5773. rootComponent = Object.assign({}, rootComponent);
  5774. }
  5775. if (rootProps != null && !isObject(rootProps)) {
  5776. warn$1(`root props passed to app.mount() must be an object.`);
  5777. rootProps = null;
  5778. }
  5779. const context = createAppContext();
  5780. const installedPlugins = new Set();
  5781. let isMounted = false;
  5782. const app = (context.app = {
  5783. _uid: uid++,
  5784. _component: rootComponent,
  5785. _props: rootProps,
  5786. _container: null,
  5787. _context: context,
  5788. _instance: null,
  5789. version,
  5790. get config() {
  5791. return context.config;
  5792. },
  5793. set config(v) {
  5794. {
  5795. warn$1(`app.config cannot be replaced. Modify individual options instead.`);
  5796. }
  5797. },
  5798. use(plugin, ...options) {
  5799. if (installedPlugins.has(plugin)) {
  5800. warn$1(`Plugin has already been applied to target app.`);
  5801. }
  5802. else if (plugin && isFunction(plugin.install)) {
  5803. installedPlugins.add(plugin);
  5804. plugin.install(app, ...options);
  5805. }
  5806. else if (isFunction(plugin)) {
  5807. installedPlugins.add(plugin);
  5808. plugin(app, ...options);
  5809. }
  5810. else {
  5811. warn$1(`A plugin must either be a function or an object with an "install" ` +
  5812. `function.`);
  5813. }
  5814. return app;
  5815. },
  5816. mixin(mixin) {
  5817. {
  5818. if (!context.mixins.includes(mixin)) {
  5819. context.mixins.push(mixin);
  5820. }
  5821. else {
  5822. warn$1('Mixin has already been applied to target app' +
  5823. (mixin.name ? `: ${mixin.name}` : ''));
  5824. }
  5825. }
  5826. return app;
  5827. },
  5828. component(name, component) {
  5829. {
  5830. validateComponentName(name, context.config);
  5831. }
  5832. if (!component) {
  5833. return context.components[name];
  5834. }
  5835. if (context.components[name]) {
  5836. warn$1(`Component "${name}" has already been registered in target app.`);
  5837. }
  5838. context.components[name] = component;
  5839. return app;
  5840. },
  5841. directive(name, directive) {
  5842. {
  5843. validateDirectiveName(name);
  5844. }
  5845. if (!directive) {
  5846. return context.directives[name];
  5847. }
  5848. if (context.directives[name]) {
  5849. warn$1(`Directive "${name}" has already been registered in target app.`);
  5850. }
  5851. context.directives[name] = directive;
  5852. return app;
  5853. },
  5854. mount(rootContainer, isHydrate, isSVG) {
  5855. if (!isMounted) {
  5856. // #5571
  5857. if (rootContainer.__vue_app__) {
  5858. warn$1(`There is already an app instance mounted on the host container.\n` +
  5859. ` If you want to mount another app on the same host container,` +
  5860. ` you need to unmount the previous app by calling \`app.unmount()\` first.`);
  5861. }
  5862. const vnode = createVNode(rootComponent, rootProps);
  5863. // store app context on the root VNode.
  5864. // this will be set on the root instance on initial mount.
  5865. vnode.appContext = context;
  5866. // HMR root reload
  5867. {
  5868. context.reload = () => {
  5869. render(cloneVNode(vnode), rootContainer, isSVG);
  5870. };
  5871. }
  5872. if (isHydrate && hydrate) {
  5873. hydrate(vnode, rootContainer);
  5874. }
  5875. else {
  5876. render(vnode, rootContainer, isSVG);
  5877. }
  5878. isMounted = true;
  5879. app._container = rootContainer;
  5880. rootContainer.__vue_app__ = app;
  5881. {
  5882. app._instance = vnode.component;
  5883. devtoolsInitApp(app, version);
  5884. }
  5885. return getExposeProxy(vnode.component) || vnode.component.proxy;
  5886. }
  5887. else {
  5888. warn$1(`App has already been mounted.\n` +
  5889. `If you want to remount the same app, move your app creation logic ` +
  5890. `into a factory function and create fresh app instances for each ` +
  5891. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  5892. }
  5893. },
  5894. unmount() {
  5895. if (isMounted) {
  5896. render(null, app._container);
  5897. {
  5898. app._instance = null;
  5899. devtoolsUnmountApp(app);
  5900. }
  5901. delete app._container.__vue_app__;
  5902. }
  5903. else {
  5904. warn$1(`Cannot unmount an app that is not mounted.`);
  5905. }
  5906. },
  5907. provide(key, value) {
  5908. if (key in context.provides) {
  5909. warn$1(`App already provides property with key "${String(key)}". ` +
  5910. `It will be overwritten with the new value.`);
  5911. }
  5912. context.provides[key] = value;
  5913. return app;
  5914. }
  5915. });
  5916. return app;
  5917. };
  5918. }
  5919. /**
  5920. * Function for handling a template ref
  5921. */
  5922. function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
  5923. if (isArray(rawRef)) {
  5924. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
  5925. return;
  5926. }
  5927. if (isAsyncWrapper(vnode) && !isUnmount) {
  5928. // when mounting async components, nothing needs to be done,
  5929. // because the template ref is forwarded to inner component
  5930. return;
  5931. }
  5932. const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
  5933. ? getExposeProxy(vnode.component) || vnode.component.proxy
  5934. : vnode.el;
  5935. const value = isUnmount ? null : refValue;
  5936. const { i: owner, r: ref } = rawRef;
  5937. if (!owner) {
  5938. warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  5939. `A vnode with ref must be created inside the render function.`);
  5940. return;
  5941. }
  5942. const oldRef = oldRawRef && oldRawRef.r;
  5943. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  5944. const setupState = owner.setupState;
  5945. // dynamic ref changed. unset old ref
  5946. if (oldRef != null && oldRef !== ref) {
  5947. if (isString(oldRef)) {
  5948. refs[oldRef] = null;
  5949. if (hasOwn(setupState, oldRef)) {
  5950. setupState[oldRef] = null;
  5951. }
  5952. }
  5953. else if (isRef(oldRef)) {
  5954. oldRef.value = null;
  5955. }
  5956. }
  5957. if (isFunction(ref)) {
  5958. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  5959. }
  5960. else {
  5961. const _isString = isString(ref);
  5962. const _isRef = isRef(ref);
  5963. if (_isString || _isRef) {
  5964. const doSet = () => {
  5965. if (rawRef.f) {
  5966. const existing = _isString ? refs[ref] : ref.value;
  5967. if (isUnmount) {
  5968. isArray(existing) && remove(existing, refValue);
  5969. }
  5970. else {
  5971. if (!isArray(existing)) {
  5972. if (_isString) {
  5973. refs[ref] = [refValue];
  5974. if (hasOwn(setupState, ref)) {
  5975. setupState[ref] = refs[ref];
  5976. }
  5977. }
  5978. else {
  5979. ref.value = [refValue];
  5980. if (rawRef.k)
  5981. refs[rawRef.k] = ref.value;
  5982. }
  5983. }
  5984. else if (!existing.includes(refValue)) {
  5985. existing.push(refValue);
  5986. }
  5987. }
  5988. }
  5989. else if (_isString) {
  5990. refs[ref] = value;
  5991. if (hasOwn(setupState, ref)) {
  5992. setupState[ref] = value;
  5993. }
  5994. }
  5995. else if (_isRef) {
  5996. ref.value = value;
  5997. if (rawRef.k)
  5998. refs[rawRef.k] = value;
  5999. }
  6000. else {
  6001. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  6002. }
  6003. };
  6004. if (value) {
  6005. doSet.id = -1;
  6006. queuePostRenderEffect(doSet, parentSuspense);
  6007. }
  6008. else {
  6009. doSet();
  6010. }
  6011. }
  6012. else {
  6013. warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
  6014. }
  6015. }
  6016. }
  6017. let hasMismatch = false;
  6018. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  6019. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  6020. // Note: hydration is DOM-specific
  6021. // But we have to place it in core due to tight coupling with core - splitting
  6022. // it out creates a ton of unnecessary complexity.
  6023. // Hydration also depends on some renderer internal logic which needs to be
  6024. // passed in via arguments.
  6025. function createHydrationFunctions(rendererInternals) {
  6026. const { mt: mountComponent, p: patch, o: { patchProp, createText, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  6027. const hydrate = (vnode, container) => {
  6028. if (!container.hasChildNodes()) {
  6029. warn$1(`Attempting to hydrate existing markup but container is empty. ` +
  6030. `Performing full mount instead.`);
  6031. patch(null, vnode, container);
  6032. flushPostFlushCbs();
  6033. container._vnode = vnode;
  6034. return;
  6035. }
  6036. hasMismatch = false;
  6037. hydrateNode(container.firstChild, vnode, null, null, null);
  6038. flushPostFlushCbs();
  6039. container._vnode = vnode;
  6040. if (hasMismatch && !false) {
  6041. // this error should show up in production
  6042. console.error(`Hydration completed but contains mismatches.`);
  6043. }
  6044. };
  6045. const hydrateNode = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized = false) => {
  6046. const isFragmentStart = isComment(node) && node.data === '[';
  6047. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
  6048. const { type, ref, shapeFlag, patchFlag } = vnode;
  6049. const domType = node.nodeType;
  6050. vnode.el = node;
  6051. if (patchFlag === -2 /* BAIL */) {
  6052. optimized = false;
  6053. vnode.dynamicChildren = null;
  6054. }
  6055. let nextNode = null;
  6056. switch (type) {
  6057. case Text:
  6058. if (domType !== 3 /* TEXT */) {
  6059. // #5728 empty text node inside a slot can cause hydration failure
  6060. // because the server rendered HTML won't contain a text node
  6061. if (vnode.children === '') {
  6062. insert((vnode.el = createText('')), parentNode(node), node);
  6063. nextNode = node;
  6064. }
  6065. else {
  6066. nextNode = onMismatch();
  6067. }
  6068. }
  6069. else {
  6070. if (node.data !== vnode.children) {
  6071. hasMismatch = true;
  6072. warn$1(`Hydration text mismatch:` +
  6073. `\n- Client: ${JSON.stringify(node.data)}` +
  6074. `\n- Server: ${JSON.stringify(vnode.children)}`);
  6075. node.data = vnode.children;
  6076. }
  6077. nextNode = nextSibling(node);
  6078. }
  6079. break;
  6080. case Comment:
  6081. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  6082. nextNode = onMismatch();
  6083. }
  6084. else {
  6085. nextNode = nextSibling(node);
  6086. }
  6087. break;
  6088. case Static:
  6089. if (domType !== 1 /* ELEMENT */ && domType !== 3 /* TEXT */) {
  6090. nextNode = onMismatch();
  6091. }
  6092. else {
  6093. // determine anchor, adopt content
  6094. nextNode = node;
  6095. // if the static vnode has its content stripped during build,
  6096. // adopt it from the server-rendered HTML.
  6097. const needToAdoptContent = !vnode.children.length;
  6098. for (let i = 0; i < vnode.staticCount; i++) {
  6099. if (needToAdoptContent)
  6100. vnode.children +=
  6101. nextNode.nodeType === 1 /* ELEMENT */
  6102. ? nextNode.outerHTML
  6103. : nextNode.data;
  6104. if (i === vnode.staticCount - 1) {
  6105. vnode.anchor = nextNode;
  6106. }
  6107. nextNode = nextSibling(nextNode);
  6108. }
  6109. return nextNode;
  6110. }
  6111. break;
  6112. case Fragment:
  6113. if (!isFragmentStart) {
  6114. nextNode = onMismatch();
  6115. }
  6116. else {
  6117. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6118. }
  6119. break;
  6120. default:
  6121. if (shapeFlag & 1 /* ELEMENT */) {
  6122. if (domType !== 1 /* ELEMENT */ ||
  6123. vnode.type.toLowerCase() !==
  6124. node.tagName.toLowerCase()) {
  6125. nextNode = onMismatch();
  6126. }
  6127. else {
  6128. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6129. }
  6130. }
  6131. else if (shapeFlag & 6 /* COMPONENT */) {
  6132. // when setting up the render effect, if the initial vnode already
  6133. // has .el set, the component will perform hydration instead of mount
  6134. // on its sub-tree.
  6135. vnode.slotScopeIds = slotScopeIds;
  6136. const container = parentNode(node);
  6137. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  6138. // component may be async, so in the case of fragments we cannot rely
  6139. // on component's rendered output to determine the end of the fragment
  6140. // instead, we do a lookahead to find the end anchor node.
  6141. nextNode = isFragmentStart
  6142. ? locateClosingAsyncAnchor(node)
  6143. : nextSibling(node);
  6144. // #4293 teleport as component root
  6145. if (nextNode &&
  6146. isComment(nextNode) &&
  6147. nextNode.data === 'teleport end') {
  6148. nextNode = nextSibling(nextNode);
  6149. }
  6150. // #3787
  6151. // if component is async, it may get moved / unmounted before its
  6152. // inner component is loaded, so we need to give it a placeholder
  6153. // vnode that matches its adopted DOM.
  6154. if (isAsyncWrapper(vnode)) {
  6155. let subTree;
  6156. if (isFragmentStart) {
  6157. subTree = createVNode(Fragment);
  6158. subTree.anchor = nextNode
  6159. ? nextNode.previousSibling
  6160. : container.lastChild;
  6161. }
  6162. else {
  6163. subTree =
  6164. node.nodeType === 3 ? createTextVNode('') : createVNode('div');
  6165. }
  6166. subTree.el = node;
  6167. vnode.component.subTree = subTree;
  6168. }
  6169. }
  6170. else if (shapeFlag & 64 /* TELEPORT */) {
  6171. if (domType !== 8 /* COMMENT */) {
  6172. nextNode = onMismatch();
  6173. }
  6174. else {
  6175. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, rendererInternals, hydrateChildren);
  6176. }
  6177. }
  6178. else if (shapeFlag & 128 /* SUSPENSE */) {
  6179. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), slotScopeIds, optimized, rendererInternals, hydrateNode);
  6180. }
  6181. else {
  6182. warn$1('Invalid HostVNode type:', type, `(${typeof type})`);
  6183. }
  6184. }
  6185. if (ref != null) {
  6186. setRef(ref, null, parentSuspense, vnode);
  6187. }
  6188. return nextNode;
  6189. };
  6190. const hydrateElement = (el, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6191. optimized = optimized || !!vnode.dynamicChildren;
  6192. const { type, props, patchFlag, shapeFlag, dirs } = vnode;
  6193. // #4006 for form elements with non-string v-model value bindings
  6194. // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
  6195. const forcePatchValue = (type === 'input' && dirs) || type === 'option';
  6196. // skip props & children if this is hoisted static nodes
  6197. // #5405 in dev, always hydrate children for HMR
  6198. {
  6199. if (dirs) {
  6200. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6201. }
  6202. // props
  6203. if (props) {
  6204. if (forcePatchValue ||
  6205. !optimized ||
  6206. patchFlag & (16 /* FULL_PROPS */ | 32 /* HYDRATE_EVENTS */)) {
  6207. for (const key in props) {
  6208. if ((forcePatchValue && key.endsWith('value')) ||
  6209. (isOn(key) && !isReservedProp(key))) {
  6210. patchProp(el, key, null, props[key], false, undefined, parentComponent);
  6211. }
  6212. }
  6213. }
  6214. else if (props.onClick) {
  6215. // Fast path for click listeners (which is most often) to avoid
  6216. // iterating through props.
  6217. patchProp(el, 'onClick', null, props.onClick, false, undefined, parentComponent);
  6218. }
  6219. }
  6220. // vnode / directive hooks
  6221. let vnodeHooks;
  6222. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  6223. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6224. }
  6225. if (dirs) {
  6226. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6227. }
  6228. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  6229. queueEffectWithSuspense(() => {
  6230. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  6231. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6232. }, parentSuspense);
  6233. }
  6234. // children
  6235. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  6236. // skip if element has innerHTML / textContent
  6237. !(props && (props.innerHTML || props.textContent))) {
  6238. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, slotScopeIds, optimized);
  6239. let hasWarned = false;
  6240. while (next) {
  6241. hasMismatch = true;
  6242. if (!hasWarned) {
  6243. warn$1(`Hydration children mismatch in <${vnode.type}>: ` +
  6244. `server rendered element contains more child nodes than client vdom.`);
  6245. hasWarned = true;
  6246. }
  6247. // The SSRed DOM contains more nodes than it should. Remove them.
  6248. const cur = next;
  6249. next = next.nextSibling;
  6250. remove(cur);
  6251. }
  6252. }
  6253. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  6254. if (el.textContent !== vnode.children) {
  6255. hasMismatch = true;
  6256. warn$1(`Hydration text content mismatch in <${vnode.type}>:\n` +
  6257. `- Client: ${el.textContent}\n` +
  6258. `- Server: ${vnode.children}`);
  6259. el.textContent = vnode.children;
  6260. }
  6261. }
  6262. }
  6263. return el.nextSibling;
  6264. };
  6265. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6266. optimized = optimized || !!parentVNode.dynamicChildren;
  6267. const children = parentVNode.children;
  6268. const l = children.length;
  6269. let hasWarned = false;
  6270. for (let i = 0; i < l; i++) {
  6271. const vnode = optimized
  6272. ? children[i]
  6273. : (children[i] = normalizeVNode(children[i]));
  6274. if (node) {
  6275. node = hydrateNode(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized);
  6276. }
  6277. else if (vnode.type === Text && !vnode.children) {
  6278. continue;
  6279. }
  6280. else {
  6281. hasMismatch = true;
  6282. if (!hasWarned) {
  6283. warn$1(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  6284. `server rendered element contains fewer child nodes than client vdom.`);
  6285. hasWarned = true;
  6286. }
  6287. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  6288. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6289. }
  6290. }
  6291. return node;
  6292. };
  6293. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized) => {
  6294. const { slotScopeIds: fragmentSlotScopeIds } = vnode;
  6295. if (fragmentSlotScopeIds) {
  6296. slotScopeIds = slotScopeIds
  6297. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6298. : fragmentSlotScopeIds;
  6299. }
  6300. const container = parentNode(node);
  6301. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, slotScopeIds, optimized);
  6302. if (next && isComment(next) && next.data === ']') {
  6303. return nextSibling((vnode.anchor = next));
  6304. }
  6305. else {
  6306. // fragment didn't hydrate successfully, since we didn't get a end anchor
  6307. // back. This should have led to node/children mismatch warnings.
  6308. hasMismatch = true;
  6309. // since the anchor is missing, we need to create one and insert it
  6310. insert((vnode.anchor = createComment(`]`)), container, next);
  6311. return next;
  6312. }
  6313. };
  6314. const handleMismatch = (node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragment) => {
  6315. hasMismatch = true;
  6316. warn$1(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  6317. ? `(text)`
  6318. : isComment(node) && node.data === '['
  6319. ? `(start of fragment)`
  6320. : ``);
  6321. vnode.el = null;
  6322. if (isFragment) {
  6323. // remove excessive fragment nodes
  6324. const end = locateClosingAsyncAnchor(node);
  6325. while (true) {
  6326. const next = nextSibling(node);
  6327. if (next && next !== end) {
  6328. remove(next);
  6329. }
  6330. else {
  6331. break;
  6332. }
  6333. }
  6334. }
  6335. const next = nextSibling(node);
  6336. const container = parentNode(node);
  6337. remove(node);
  6338. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container), slotScopeIds);
  6339. return next;
  6340. };
  6341. const locateClosingAsyncAnchor = (node) => {
  6342. let match = 0;
  6343. while (node) {
  6344. node = nextSibling(node);
  6345. if (node && isComment(node)) {
  6346. if (node.data === '[')
  6347. match++;
  6348. if (node.data === ']') {
  6349. if (match === 0) {
  6350. return nextSibling(node);
  6351. }
  6352. else {
  6353. match--;
  6354. }
  6355. }
  6356. }
  6357. }
  6358. return node;
  6359. };
  6360. return [hydrate, hydrateNode];
  6361. }
  6362. /* eslint-disable no-restricted-globals */
  6363. let supported;
  6364. let perf;
  6365. function startMeasure(instance, type) {
  6366. if (instance.appContext.config.performance && isSupported()) {
  6367. perf.mark(`vue-${type}-${instance.uid}`);
  6368. }
  6369. {
  6370. devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now());
  6371. }
  6372. }
  6373. function endMeasure(instance, type) {
  6374. if (instance.appContext.config.performance && isSupported()) {
  6375. const startTag = `vue-${type}-${instance.uid}`;
  6376. const endTag = startTag + `:end`;
  6377. perf.mark(endTag);
  6378. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  6379. perf.clearMarks(startTag);
  6380. perf.clearMarks(endTag);
  6381. }
  6382. {
  6383. devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now());
  6384. }
  6385. }
  6386. function isSupported() {
  6387. if (supported !== undefined) {
  6388. return supported;
  6389. }
  6390. if (typeof window !== 'undefined' && window.performance) {
  6391. supported = true;
  6392. perf = window.performance;
  6393. }
  6394. else {
  6395. supported = false;
  6396. }
  6397. return supported;
  6398. }
  6399. const queuePostRenderEffect = queueEffectWithSuspense
  6400. ;
  6401. /**
  6402. * The createRenderer function accepts two generic arguments:
  6403. * HostNode and HostElement, corresponding to Node and Element types in the
  6404. * host environment. For example, for runtime-dom, HostNode would be the DOM
  6405. * `Node` interface and HostElement would be the DOM `Element` interface.
  6406. *
  6407. * Custom renderers can pass in the platform specific types like this:
  6408. *
  6409. * ``` js
  6410. * const { render, createApp } = createRenderer<Node, Element>({
  6411. * patchProp,
  6412. * ...nodeOps
  6413. * })
  6414. * ```
  6415. */
  6416. function createRenderer(options) {
  6417. return baseCreateRenderer(options);
  6418. }
  6419. // Separate API for creating hydration-enabled renderer.
  6420. // Hydration logic is only used when calling this function, making it
  6421. // tree-shakable.
  6422. function createHydrationRenderer(options) {
  6423. return baseCreateRenderer(options, createHydrationFunctions);
  6424. }
  6425. // implementation
  6426. function baseCreateRenderer(options, createHydrationFns) {
  6427. const target = getGlobalThis();
  6428. target.__VUE__ = true;
  6429. {
  6430. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
  6431. }
  6432. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
  6433. // Note: functions inside this closure should use `const xxx = () => {}`
  6434. // style in order to prevent being inlined by minifiers.
  6435. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
  6436. if (n1 === n2) {
  6437. return;
  6438. }
  6439. // patching & not same type, unmount old tree
  6440. if (n1 && !isSameVNodeType(n1, n2)) {
  6441. anchor = getNextHostNode(n1);
  6442. unmount(n1, parentComponent, parentSuspense, true);
  6443. n1 = null;
  6444. }
  6445. if (n2.patchFlag === -2 /* BAIL */) {
  6446. optimized = false;
  6447. n2.dynamicChildren = null;
  6448. }
  6449. const { type, ref, shapeFlag } = n2;
  6450. switch (type) {
  6451. case Text:
  6452. processText(n1, n2, container, anchor);
  6453. break;
  6454. case Comment:
  6455. processCommentNode(n1, n2, container, anchor);
  6456. break;
  6457. case Static:
  6458. if (n1 == null) {
  6459. mountStaticNode(n2, container, anchor, isSVG);
  6460. }
  6461. else {
  6462. patchStaticNode(n1, n2, container, isSVG);
  6463. }
  6464. break;
  6465. case Fragment:
  6466. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6467. break;
  6468. default:
  6469. if (shapeFlag & 1 /* ELEMENT */) {
  6470. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6471. }
  6472. else if (shapeFlag & 6 /* COMPONENT */) {
  6473. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6474. }
  6475. else if (shapeFlag & 64 /* TELEPORT */) {
  6476. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6477. }
  6478. else if (shapeFlag & 128 /* SUSPENSE */) {
  6479. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals);
  6480. }
  6481. else {
  6482. warn$1('Invalid VNode type:', type, `(${typeof type})`);
  6483. }
  6484. }
  6485. // set ref
  6486. if (ref != null && parentComponent) {
  6487. setRef(ref, n1 && n1.ref, parentSuspense, n2 || n1, !n2);
  6488. }
  6489. };
  6490. const processText = (n1, n2, container, anchor) => {
  6491. if (n1 == null) {
  6492. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  6493. }
  6494. else {
  6495. const el = (n2.el = n1.el);
  6496. if (n2.children !== n1.children) {
  6497. hostSetText(el, n2.children);
  6498. }
  6499. }
  6500. };
  6501. const processCommentNode = (n1, n2, container, anchor) => {
  6502. if (n1 == null) {
  6503. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  6504. }
  6505. else {
  6506. // there's no support for dynamic comments
  6507. n2.el = n1.el;
  6508. }
  6509. };
  6510. const mountStaticNode = (n2, container, anchor, isSVG) => {
  6511. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG, n2.el, n2.anchor);
  6512. };
  6513. /**
  6514. * Dev / HMR only
  6515. */
  6516. const patchStaticNode = (n1, n2, container, isSVG) => {
  6517. // static nodes are only patched during dev for HMR
  6518. if (n2.children !== n1.children) {
  6519. const anchor = hostNextSibling(n1.anchor);
  6520. // remove existing
  6521. removeStaticNode(n1);
  6522. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  6523. }
  6524. else {
  6525. n2.el = n1.el;
  6526. n2.anchor = n1.anchor;
  6527. }
  6528. };
  6529. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  6530. let next;
  6531. while (el && el !== anchor) {
  6532. next = hostNextSibling(el);
  6533. hostInsert(el, container, nextSibling);
  6534. el = next;
  6535. }
  6536. hostInsert(anchor, container, nextSibling);
  6537. };
  6538. const removeStaticNode = ({ el, anchor }) => {
  6539. let next;
  6540. while (el && el !== anchor) {
  6541. next = hostNextSibling(el);
  6542. hostRemove(el);
  6543. el = next;
  6544. }
  6545. hostRemove(anchor);
  6546. };
  6547. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6548. isSVG = isSVG || n2.type === 'svg';
  6549. if (n1 == null) {
  6550. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6551. }
  6552. else {
  6553. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6554. }
  6555. };
  6556. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6557. let el;
  6558. let vnodeHook;
  6559. const { type, props, shapeFlag, transition, patchFlag, dirs } = vnode;
  6560. {
  6561. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
  6562. // mount children first, since some props may rely on child content
  6563. // being already rendered, e.g. `<select value>`
  6564. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  6565. hostSetElementText(el, vnode.children);
  6566. }
  6567. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6568. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
  6569. }
  6570. if (dirs) {
  6571. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  6572. }
  6573. // props
  6574. if (props) {
  6575. for (const key in props) {
  6576. if (key !== 'value' && !isReservedProp(key)) {
  6577. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6578. }
  6579. }
  6580. /**
  6581. * Special case for setting value on DOM elements:
  6582. * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
  6583. * - it needs to be forced (#1471)
  6584. * #2353 proposes adding another renderer option to configure this, but
  6585. * the properties affects are so finite it is worth special casing it
  6586. * here to reduce the complexity. (Special casing it also should not
  6587. * affect non-DOM renderers)
  6588. */
  6589. if ('value' in props) {
  6590. hostPatchProp(el, 'value', null, props.value);
  6591. }
  6592. if ((vnodeHook = props.onVnodeBeforeMount)) {
  6593. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6594. }
  6595. }
  6596. // scopeId
  6597. setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
  6598. }
  6599. {
  6600. Object.defineProperty(el, '__vnode', {
  6601. value: vnode,
  6602. enumerable: false
  6603. });
  6604. Object.defineProperty(el, '__vueParentComponent', {
  6605. value: parentComponent,
  6606. enumerable: false
  6607. });
  6608. }
  6609. if (dirs) {
  6610. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  6611. }
  6612. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  6613. // #1689 For inside suspense + suspense resolved case, just call it
  6614. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  6615. transition &&
  6616. !transition.persisted;
  6617. if (needCallTransitionHooks) {
  6618. transition.beforeEnter(el);
  6619. }
  6620. hostInsert(el, container, anchor);
  6621. if ((vnodeHook = props && props.onVnodeMounted) ||
  6622. needCallTransitionHooks ||
  6623. dirs) {
  6624. queuePostRenderEffect(() => {
  6625. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  6626. needCallTransitionHooks && transition.enter(el);
  6627. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  6628. }, parentSuspense);
  6629. }
  6630. };
  6631. const setScopeId = (el, vnode, scopeId, slotScopeIds, parentComponent) => {
  6632. if (scopeId) {
  6633. hostSetScopeId(el, scopeId);
  6634. }
  6635. if (slotScopeIds) {
  6636. for (let i = 0; i < slotScopeIds.length; i++) {
  6637. hostSetScopeId(el, slotScopeIds[i]);
  6638. }
  6639. }
  6640. if (parentComponent) {
  6641. let subTree = parentComponent.subTree;
  6642. if (subTree.patchFlag > 0 &&
  6643. subTree.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  6644. subTree =
  6645. filterSingleRoot(subTree.children) || subTree;
  6646. }
  6647. if (vnode === subTree) {
  6648. const parentVNode = parentComponent.vnode;
  6649. setScopeId(el, parentVNode, parentVNode.scopeId, parentVNode.slotScopeIds, parentComponent.parent);
  6650. }
  6651. }
  6652. };
  6653. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, start = 0) => {
  6654. for (let i = start; i < children.length; i++) {
  6655. const child = (children[i] = optimized
  6656. ? cloneIfMounted(children[i])
  6657. : normalizeVNode(children[i]));
  6658. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6659. }
  6660. };
  6661. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6662. const el = (n2.el = n1.el);
  6663. let { patchFlag, dynamicChildren, dirs } = n2;
  6664. // #1426 take the old vnode's patch flag into account since user may clone a
  6665. // compiler-generated vnode, which de-opts to FULL_PROPS
  6666. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  6667. const oldProps = n1.props || EMPTY_OBJ;
  6668. const newProps = n2.props || EMPTY_OBJ;
  6669. let vnodeHook;
  6670. // disable recurse in beforeUpdate hooks
  6671. parentComponent && toggleRecurse(parentComponent, false);
  6672. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  6673. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6674. }
  6675. if (dirs) {
  6676. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  6677. }
  6678. parentComponent && toggleRecurse(parentComponent, true);
  6679. if (isHmrUpdating) {
  6680. // HMR updated, force full diff
  6681. patchFlag = 0;
  6682. optimized = false;
  6683. dynamicChildren = null;
  6684. }
  6685. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  6686. if (dynamicChildren) {
  6687. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds);
  6688. if (parentComponent && parentComponent.type.__hmrId) {
  6689. traverseStaticChildren(n1, n2);
  6690. }
  6691. }
  6692. else if (!optimized) {
  6693. // full diff
  6694. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG, slotScopeIds, false);
  6695. }
  6696. if (patchFlag > 0) {
  6697. // the presence of a patchFlag means this element's render code was
  6698. // generated by the compiler and can take the fast path.
  6699. // in this path old node and new node are guaranteed to have the same shape
  6700. // (i.e. at the exact same position in the source template)
  6701. if (patchFlag & 16 /* FULL_PROPS */) {
  6702. // element props contain dynamic keys, full diff needed
  6703. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6704. }
  6705. else {
  6706. // class
  6707. // this flag is matched when the element has dynamic class bindings.
  6708. if (patchFlag & 2 /* CLASS */) {
  6709. if (oldProps.class !== newProps.class) {
  6710. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  6711. }
  6712. }
  6713. // style
  6714. // this flag is matched when the element has dynamic style bindings
  6715. if (patchFlag & 4 /* STYLE */) {
  6716. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  6717. }
  6718. // props
  6719. // This flag is matched when the element has dynamic prop/attr bindings
  6720. // other than class and style. The keys of dynamic prop/attrs are saved for
  6721. // faster iteration.
  6722. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  6723. // bail out and go through a full diff because we need to unset the old key
  6724. if (patchFlag & 8 /* PROPS */) {
  6725. // if the flag is present then dynamicProps must be non-null
  6726. const propsToUpdate = n2.dynamicProps;
  6727. for (let i = 0; i < propsToUpdate.length; i++) {
  6728. const key = propsToUpdate[i];
  6729. const prev = oldProps[key];
  6730. const next = newProps[key];
  6731. // #1471 force patch value
  6732. if (next !== prev || key === 'value') {
  6733. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  6734. }
  6735. }
  6736. }
  6737. }
  6738. // text
  6739. // This flag is matched when the element has only dynamic text children.
  6740. if (patchFlag & 1 /* TEXT */) {
  6741. if (n1.children !== n2.children) {
  6742. hostSetElementText(el, n2.children);
  6743. }
  6744. }
  6745. }
  6746. else if (!optimized && dynamicChildren == null) {
  6747. // unoptimized, full diff
  6748. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  6749. }
  6750. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  6751. queuePostRenderEffect(() => {
  6752. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  6753. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  6754. }, parentSuspense);
  6755. }
  6756. };
  6757. // The fast path for blocks.
  6758. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG, slotScopeIds) => {
  6759. for (let i = 0; i < newChildren.length; i++) {
  6760. const oldVNode = oldChildren[i];
  6761. const newVNode = newChildren[i];
  6762. // Determine the container (parent element) for the patch.
  6763. const container =
  6764. // oldVNode may be an errored async setup() component inside Suspense
  6765. // which will not have a mounted element
  6766. oldVNode.el &&
  6767. // - In the case of a Fragment, we need to provide the actual parent
  6768. // of the Fragment itself so it can move its children.
  6769. (oldVNode.type === Fragment ||
  6770. // - In the case of different nodes, there is going to be a replacement
  6771. // which also requires the correct parent container
  6772. !isSameVNodeType(oldVNode, newVNode) ||
  6773. // - In the case of a component, it could contain anything.
  6774. oldVNode.shapeFlag & (6 /* COMPONENT */ | 64 /* TELEPORT */))
  6775. ? hostParentNode(oldVNode.el)
  6776. : // In other cases, the parent container is not actually used so we
  6777. // just pass the block element here to avoid a DOM parentNode call.
  6778. fallbackContainer;
  6779. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, true);
  6780. }
  6781. };
  6782. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  6783. if (oldProps !== newProps) {
  6784. for (const key in newProps) {
  6785. // empty string is not valid prop
  6786. if (isReservedProp(key))
  6787. continue;
  6788. const next = newProps[key];
  6789. const prev = oldProps[key];
  6790. // defer patching value
  6791. if (next !== prev && key !== 'value') {
  6792. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6793. }
  6794. }
  6795. if (oldProps !== EMPTY_OBJ) {
  6796. for (const key in oldProps) {
  6797. if (!isReservedProp(key) && !(key in newProps)) {
  6798. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  6799. }
  6800. }
  6801. }
  6802. if ('value' in newProps) {
  6803. hostPatchProp(el, 'value', oldProps.value, newProps.value);
  6804. }
  6805. }
  6806. };
  6807. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6808. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  6809. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  6810. let { patchFlag, dynamicChildren, slotScopeIds: fragmentSlotScopeIds } = n2;
  6811. if (// #5523 dev root fragment may inherit directives
  6812. (isHmrUpdating || patchFlag & 2048 /* DEV_ROOT_FRAGMENT */)) {
  6813. // HMR updated / Dev root fragment (w/ comments), force full diff
  6814. patchFlag = 0;
  6815. optimized = false;
  6816. dynamicChildren = null;
  6817. }
  6818. // check if this is a slot fragment with :slotted scope ids
  6819. if (fragmentSlotScopeIds) {
  6820. slotScopeIds = slotScopeIds
  6821. ? slotScopeIds.concat(fragmentSlotScopeIds)
  6822. : fragmentSlotScopeIds;
  6823. }
  6824. if (n1 == null) {
  6825. hostInsert(fragmentStartAnchor, container, anchor);
  6826. hostInsert(fragmentEndAnchor, container, anchor);
  6827. // a fragment can only have array children
  6828. // since they are either generated by the compiler, or implicitly created
  6829. // from arrays.
  6830. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6831. }
  6832. else {
  6833. if (patchFlag > 0 &&
  6834. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  6835. dynamicChildren &&
  6836. // #2715 the previous fragment could've been a BAILed one as a result
  6837. // of renderSlot() with no valid children
  6838. n1.dynamicChildren) {
  6839. // a stable fragment (template root or <template v-for>) doesn't need to
  6840. // patch children order, but it may contain dynamicChildren.
  6841. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG, slotScopeIds);
  6842. if (parentComponent && parentComponent.type.__hmrId) {
  6843. traverseStaticChildren(n1, n2);
  6844. }
  6845. else if (
  6846. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  6847. // get moved around. Make sure all root level vnodes inherit el.
  6848. // #2134 or if it's a component root, it may also get moved around
  6849. // as the component is being moved.
  6850. n2.key != null ||
  6851. (parentComponent && n2 === parentComponent.subTree)) {
  6852. traverseStaticChildren(n1, n2, true /* shallow */);
  6853. }
  6854. }
  6855. else {
  6856. // keyed / unkeyed, or manual fragments.
  6857. // for keyed & unkeyed, since they are compiler generated from v-for,
  6858. // each child is guaranteed to be a block so the fragment will never
  6859. // have dynamicChildren.
  6860. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  6861. }
  6862. }
  6863. };
  6864. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  6865. n2.slotScopeIds = slotScopeIds;
  6866. if (n1 == null) {
  6867. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  6868. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  6869. }
  6870. else {
  6871. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6872. }
  6873. }
  6874. else {
  6875. updateComponent(n1, n2, optimized);
  6876. }
  6877. };
  6878. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  6879. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  6880. if (instance.type.__hmrId) {
  6881. registerHMR(instance);
  6882. }
  6883. {
  6884. pushWarningContext(initialVNode);
  6885. startMeasure(instance, `mount`);
  6886. }
  6887. // inject renderer internals for keepAlive
  6888. if (isKeepAlive(initialVNode)) {
  6889. instance.ctx.renderer = internals;
  6890. }
  6891. // resolve props and slots for setup context
  6892. {
  6893. {
  6894. startMeasure(instance, `init`);
  6895. }
  6896. setupComponent(instance);
  6897. {
  6898. endMeasure(instance, `init`);
  6899. }
  6900. }
  6901. // setup() is async. This component relies on async logic to be resolved
  6902. // before proceeding
  6903. if (instance.asyncDep) {
  6904. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  6905. // Give it a placeholder if this is not hydration
  6906. // TODO handle self-defined fallback
  6907. if (!initialVNode.el) {
  6908. const placeholder = (instance.subTree = createVNode(Comment));
  6909. processCommentNode(null, placeholder, container, anchor);
  6910. }
  6911. return;
  6912. }
  6913. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  6914. {
  6915. popWarningContext();
  6916. endMeasure(instance, `mount`);
  6917. }
  6918. };
  6919. const updateComponent = (n1, n2, optimized) => {
  6920. const instance = (n2.component = n1.component);
  6921. if (shouldUpdateComponent(n1, n2, optimized)) {
  6922. if (instance.asyncDep &&
  6923. !instance.asyncResolved) {
  6924. // async & still pending - just update props and slots
  6925. // since the component's reactive effect for render isn't set-up yet
  6926. {
  6927. pushWarningContext(n2);
  6928. }
  6929. updateComponentPreRender(instance, n2, optimized);
  6930. {
  6931. popWarningContext();
  6932. }
  6933. return;
  6934. }
  6935. else {
  6936. // normal update
  6937. instance.next = n2;
  6938. // in case the child component is also queued, remove it to avoid
  6939. // double updating the same child component in the same flush.
  6940. invalidateJob(instance.update);
  6941. // instance.update is the reactive effect.
  6942. instance.update();
  6943. }
  6944. }
  6945. else {
  6946. // no update needed. just copy over properties
  6947. n2.el = n1.el;
  6948. instance.vnode = n2;
  6949. }
  6950. };
  6951. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  6952. const componentUpdateFn = () => {
  6953. if (!instance.isMounted) {
  6954. let vnodeHook;
  6955. const { el, props } = initialVNode;
  6956. const { bm, m, parent } = instance;
  6957. const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
  6958. toggleRecurse(instance, false);
  6959. // beforeMount hook
  6960. if (bm) {
  6961. invokeArrayFns(bm);
  6962. }
  6963. // onVnodeBeforeMount
  6964. if (!isAsyncWrapperVNode &&
  6965. (vnodeHook = props && props.onVnodeBeforeMount)) {
  6966. invokeVNodeHook(vnodeHook, parent, initialVNode);
  6967. }
  6968. toggleRecurse(instance, true);
  6969. if (el && hydrateNode) {
  6970. // vnode has adopted host node - perform hydration instead of mount.
  6971. const hydrateSubTree = () => {
  6972. {
  6973. startMeasure(instance, `render`);
  6974. }
  6975. instance.subTree = renderComponentRoot(instance);
  6976. {
  6977. endMeasure(instance, `render`);
  6978. }
  6979. {
  6980. startMeasure(instance, `hydrate`);
  6981. }
  6982. hydrateNode(el, instance.subTree, instance, parentSuspense, null);
  6983. {
  6984. endMeasure(instance, `hydrate`);
  6985. }
  6986. };
  6987. if (isAsyncWrapperVNode) {
  6988. initialVNode.type.__asyncLoader().then(
  6989. // note: we are moving the render call into an async callback,
  6990. // which means it won't track dependencies - but it's ok because
  6991. // a server-rendered async wrapper is already in resolved state
  6992. // and it will never need to change.
  6993. () => !instance.isUnmounted && hydrateSubTree());
  6994. }
  6995. else {
  6996. hydrateSubTree();
  6997. }
  6998. }
  6999. else {
  7000. {
  7001. startMeasure(instance, `render`);
  7002. }
  7003. const subTree = (instance.subTree = renderComponentRoot(instance));
  7004. {
  7005. endMeasure(instance, `render`);
  7006. }
  7007. {
  7008. startMeasure(instance, `patch`);
  7009. }
  7010. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  7011. {
  7012. endMeasure(instance, `patch`);
  7013. }
  7014. initialVNode.el = subTree.el;
  7015. }
  7016. // mounted hook
  7017. if (m) {
  7018. queuePostRenderEffect(m, parentSuspense);
  7019. }
  7020. // onVnodeMounted
  7021. if (!isAsyncWrapperVNode &&
  7022. (vnodeHook = props && props.onVnodeMounted)) {
  7023. const scopedInitialVNode = initialVNode;
  7024. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, scopedInitialVNode), parentSuspense);
  7025. }
  7026. // activated hook for keep-alive roots.
  7027. // #1742 activated hook must be accessed after first render
  7028. // since the hook may be injected by a child keep-alive
  7029. if (initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */ ||
  7030. (parent &&
  7031. isAsyncWrapper(parent.vnode) &&
  7032. parent.vnode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */)) {
  7033. instance.a && queuePostRenderEffect(instance.a, parentSuspense);
  7034. }
  7035. instance.isMounted = true;
  7036. {
  7037. devtoolsComponentAdded(instance);
  7038. }
  7039. // #2458: deference mount-only object parameters to prevent memleaks
  7040. initialVNode = container = anchor = null;
  7041. }
  7042. else {
  7043. // updateComponent
  7044. // This is triggered by mutation of component's own state (next: null)
  7045. // OR parent calling processComponent (next: VNode)
  7046. let { next, bu, u, parent, vnode } = instance;
  7047. let originNext = next;
  7048. let vnodeHook;
  7049. {
  7050. pushWarningContext(next || instance.vnode);
  7051. }
  7052. // Disallow component effect recursion during pre-lifecycle hooks.
  7053. toggleRecurse(instance, false);
  7054. if (next) {
  7055. next.el = vnode.el;
  7056. updateComponentPreRender(instance, next, optimized);
  7057. }
  7058. else {
  7059. next = vnode;
  7060. }
  7061. // beforeUpdate hook
  7062. if (bu) {
  7063. invokeArrayFns(bu);
  7064. }
  7065. // onVnodeBeforeUpdate
  7066. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  7067. invokeVNodeHook(vnodeHook, parent, next, vnode);
  7068. }
  7069. toggleRecurse(instance, true);
  7070. // render
  7071. {
  7072. startMeasure(instance, `render`);
  7073. }
  7074. const nextTree = renderComponentRoot(instance);
  7075. {
  7076. endMeasure(instance, `render`);
  7077. }
  7078. const prevTree = instance.subTree;
  7079. instance.subTree = nextTree;
  7080. {
  7081. startMeasure(instance, `patch`);
  7082. }
  7083. patch(prevTree, nextTree,
  7084. // parent may have changed if it's in a teleport
  7085. hostParentNode(prevTree.el),
  7086. // anchor may have changed if it's in a fragment
  7087. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  7088. {
  7089. endMeasure(instance, `patch`);
  7090. }
  7091. next.el = nextTree.el;
  7092. if (originNext === null) {
  7093. // self-triggered update. In case of HOC, update parent component
  7094. // vnode el. HOC is indicated by parent instance's subTree pointing
  7095. // to child component's vnode
  7096. updateHOCHostEl(instance, nextTree.el);
  7097. }
  7098. // updated hook
  7099. if (u) {
  7100. queuePostRenderEffect(u, parentSuspense);
  7101. }
  7102. // onVnodeUpdated
  7103. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  7104. queuePostRenderEffect(() => invokeVNodeHook(vnodeHook, parent, next, vnode), parentSuspense);
  7105. }
  7106. {
  7107. devtoolsComponentUpdated(instance);
  7108. }
  7109. {
  7110. popWarningContext();
  7111. }
  7112. }
  7113. };
  7114. // create reactive effect for rendering
  7115. const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(update), instance.scope // track it in component's effect scope
  7116. ));
  7117. const update = (instance.update = () => effect.run());
  7118. update.id = instance.uid;
  7119. // allowRecurse
  7120. // #1801, #2043 component render effects should allow recursive updates
  7121. toggleRecurse(instance, true);
  7122. {
  7123. effect.onTrack = instance.rtc
  7124. ? e => invokeArrayFns(instance.rtc, e)
  7125. : void 0;
  7126. effect.onTrigger = instance.rtg
  7127. ? e => invokeArrayFns(instance.rtg, e)
  7128. : void 0;
  7129. update.ownerInstance = instance;
  7130. }
  7131. update();
  7132. };
  7133. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  7134. nextVNode.component = instance;
  7135. const prevProps = instance.vnode.props;
  7136. instance.vnode = nextVNode;
  7137. instance.next = null;
  7138. updateProps(instance, nextVNode.props, prevProps, optimized);
  7139. updateSlots(instance, nextVNode.children, optimized);
  7140. pauseTracking();
  7141. // props update may have triggered pre-flush watchers.
  7142. // flush them before the render update.
  7143. flushPreFlushCbs(undefined, instance.update);
  7144. resetTracking();
  7145. };
  7146. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized = false) => {
  7147. const c1 = n1 && n1.children;
  7148. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  7149. const c2 = n2.children;
  7150. const { patchFlag, shapeFlag } = n2;
  7151. // fast path
  7152. if (patchFlag > 0) {
  7153. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  7154. // this could be either fully-keyed or mixed (some keyed some not)
  7155. // presence of patchFlag means children are guaranteed to be arrays
  7156. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7157. return;
  7158. }
  7159. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  7160. // unkeyed
  7161. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7162. return;
  7163. }
  7164. }
  7165. // children has 3 possibilities: text, array or no children.
  7166. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  7167. // text children fast path
  7168. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  7169. unmountChildren(c1, parentComponent, parentSuspense);
  7170. }
  7171. if (c2 !== c1) {
  7172. hostSetElementText(container, c2);
  7173. }
  7174. }
  7175. else {
  7176. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  7177. // prev children was array
  7178. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7179. // two arrays, cannot assume anything, do full diff
  7180. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7181. }
  7182. else {
  7183. // no new children, just unmount old
  7184. unmountChildren(c1, parentComponent, parentSuspense, true);
  7185. }
  7186. }
  7187. else {
  7188. // prev children was text OR null
  7189. // new children is array OR null
  7190. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  7191. hostSetElementText(container, '');
  7192. }
  7193. // mount new if array
  7194. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7195. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7196. }
  7197. }
  7198. }
  7199. };
  7200. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7201. c1 = c1 || EMPTY_ARR;
  7202. c2 = c2 || EMPTY_ARR;
  7203. const oldLength = c1.length;
  7204. const newLength = c2.length;
  7205. const commonLength = Math.min(oldLength, newLength);
  7206. let i;
  7207. for (i = 0; i < commonLength; i++) {
  7208. const nextChild = (c2[i] = optimized
  7209. ? cloneIfMounted(c2[i])
  7210. : normalizeVNode(c2[i]));
  7211. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7212. }
  7213. if (oldLength > newLength) {
  7214. // remove old
  7215. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  7216. }
  7217. else {
  7218. // mount new
  7219. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, commonLength);
  7220. }
  7221. };
  7222. // can be all-keyed or mixed
  7223. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
  7224. let i = 0;
  7225. const l2 = c2.length;
  7226. let e1 = c1.length - 1; // prev ending index
  7227. let e2 = l2 - 1; // next ending index
  7228. // 1. sync from start
  7229. // (a b) c
  7230. // (a b) d e
  7231. while (i <= e1 && i <= e2) {
  7232. const n1 = c1[i];
  7233. const n2 = (c2[i] = optimized
  7234. ? cloneIfMounted(c2[i])
  7235. : normalizeVNode(c2[i]));
  7236. if (isSameVNodeType(n1, n2)) {
  7237. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7238. }
  7239. else {
  7240. break;
  7241. }
  7242. i++;
  7243. }
  7244. // 2. sync from end
  7245. // a (b c)
  7246. // d e (b c)
  7247. while (i <= e1 && i <= e2) {
  7248. const n1 = c1[e1];
  7249. const n2 = (c2[e2] = optimized
  7250. ? cloneIfMounted(c2[e2])
  7251. : normalizeVNode(c2[e2]));
  7252. if (isSameVNodeType(n1, n2)) {
  7253. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7254. }
  7255. else {
  7256. break;
  7257. }
  7258. e1--;
  7259. e2--;
  7260. }
  7261. // 3. common sequence + mount
  7262. // (a b)
  7263. // (a b) c
  7264. // i = 2, e1 = 1, e2 = 2
  7265. // (a b)
  7266. // c (a b)
  7267. // i = 0, e1 = -1, e2 = 0
  7268. if (i > e1) {
  7269. if (i <= e2) {
  7270. const nextPos = e2 + 1;
  7271. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  7272. while (i <= e2) {
  7273. patch(null, (c2[i] = optimized
  7274. ? cloneIfMounted(c2[i])
  7275. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7276. i++;
  7277. }
  7278. }
  7279. }
  7280. // 4. common sequence + unmount
  7281. // (a b) c
  7282. // (a b)
  7283. // i = 2, e1 = 2, e2 = 1
  7284. // a (b c)
  7285. // (b c)
  7286. // i = 0, e1 = 0, e2 = -1
  7287. else if (i > e2) {
  7288. while (i <= e1) {
  7289. unmount(c1[i], parentComponent, parentSuspense, true);
  7290. i++;
  7291. }
  7292. }
  7293. // 5. unknown sequence
  7294. // [i ... e1 + 1]: a b [c d e] f g
  7295. // [i ... e2 + 1]: a b [e d c h] f g
  7296. // i = 2, e1 = 4, e2 = 5
  7297. else {
  7298. const s1 = i; // prev starting index
  7299. const s2 = i; // next starting index
  7300. // 5.1 build key:index map for newChildren
  7301. const keyToNewIndexMap = new Map();
  7302. for (i = s2; i <= e2; i++) {
  7303. const nextChild = (c2[i] = optimized
  7304. ? cloneIfMounted(c2[i])
  7305. : normalizeVNode(c2[i]));
  7306. if (nextChild.key != null) {
  7307. if (keyToNewIndexMap.has(nextChild.key)) {
  7308. warn$1(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  7309. }
  7310. keyToNewIndexMap.set(nextChild.key, i);
  7311. }
  7312. }
  7313. // 5.2 loop through old children left to be patched and try to patch
  7314. // matching nodes & remove nodes that are no longer present
  7315. let j;
  7316. let patched = 0;
  7317. const toBePatched = e2 - s2 + 1;
  7318. let moved = false;
  7319. // used to track whether any node has moved
  7320. let maxNewIndexSoFar = 0;
  7321. // works as Map<newIndex, oldIndex>
  7322. // Note that oldIndex is offset by +1
  7323. // and oldIndex = 0 is a special value indicating the new node has
  7324. // no corresponding old node.
  7325. // used for determining longest stable subsequence
  7326. const newIndexToOldIndexMap = new Array(toBePatched);
  7327. for (i = 0; i < toBePatched; i++)
  7328. newIndexToOldIndexMap[i] = 0;
  7329. for (i = s1; i <= e1; i++) {
  7330. const prevChild = c1[i];
  7331. if (patched >= toBePatched) {
  7332. // all new children have been patched so this can only be a removal
  7333. unmount(prevChild, parentComponent, parentSuspense, true);
  7334. continue;
  7335. }
  7336. let newIndex;
  7337. if (prevChild.key != null) {
  7338. newIndex = keyToNewIndexMap.get(prevChild.key);
  7339. }
  7340. else {
  7341. // key-less node, try to locate a key-less node of the same type
  7342. for (j = s2; j <= e2; j++) {
  7343. if (newIndexToOldIndexMap[j - s2] === 0 &&
  7344. isSameVNodeType(prevChild, c2[j])) {
  7345. newIndex = j;
  7346. break;
  7347. }
  7348. }
  7349. }
  7350. if (newIndex === undefined) {
  7351. unmount(prevChild, parentComponent, parentSuspense, true);
  7352. }
  7353. else {
  7354. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  7355. if (newIndex >= maxNewIndexSoFar) {
  7356. maxNewIndexSoFar = newIndex;
  7357. }
  7358. else {
  7359. moved = true;
  7360. }
  7361. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7362. patched++;
  7363. }
  7364. }
  7365. // 5.3 move and mount
  7366. // generate longest stable subsequence only when nodes have moved
  7367. const increasingNewIndexSequence = moved
  7368. ? getSequence(newIndexToOldIndexMap)
  7369. : EMPTY_ARR;
  7370. j = increasingNewIndexSequence.length - 1;
  7371. // looping backwards so that we can use last patched node as anchor
  7372. for (i = toBePatched - 1; i >= 0; i--) {
  7373. const nextIndex = s2 + i;
  7374. const nextChild = c2[nextIndex];
  7375. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  7376. if (newIndexToOldIndexMap[i] === 0) {
  7377. // mount new
  7378. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7379. }
  7380. else if (moved) {
  7381. // move if:
  7382. // There is no stable subsequence (e.g. a reverse)
  7383. // OR current node is not among the stable sequence
  7384. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  7385. move(nextChild, container, anchor, 2 /* REORDER */);
  7386. }
  7387. else {
  7388. j--;
  7389. }
  7390. }
  7391. }
  7392. }
  7393. };
  7394. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  7395. const { el, type, transition, children, shapeFlag } = vnode;
  7396. if (shapeFlag & 6 /* COMPONENT */) {
  7397. move(vnode.component.subTree, container, anchor, moveType);
  7398. return;
  7399. }
  7400. if (shapeFlag & 128 /* SUSPENSE */) {
  7401. vnode.suspense.move(container, anchor, moveType);
  7402. return;
  7403. }
  7404. if (shapeFlag & 64 /* TELEPORT */) {
  7405. type.move(vnode, container, anchor, internals);
  7406. return;
  7407. }
  7408. if (type === Fragment) {
  7409. hostInsert(el, container, anchor);
  7410. for (let i = 0; i < children.length; i++) {
  7411. move(children[i], container, anchor, moveType);
  7412. }
  7413. hostInsert(vnode.anchor, container, anchor);
  7414. return;
  7415. }
  7416. if (type === Static) {
  7417. moveStaticNode(vnode, container, anchor);
  7418. return;
  7419. }
  7420. // single nodes
  7421. const needTransition = moveType !== 2 /* REORDER */ &&
  7422. shapeFlag & 1 /* ELEMENT */ &&
  7423. transition;
  7424. if (needTransition) {
  7425. if (moveType === 0 /* ENTER */) {
  7426. transition.beforeEnter(el);
  7427. hostInsert(el, container, anchor);
  7428. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  7429. }
  7430. else {
  7431. const { leave, delayLeave, afterLeave } = transition;
  7432. const remove = () => hostInsert(el, container, anchor);
  7433. const performLeave = () => {
  7434. leave(el, () => {
  7435. remove();
  7436. afterLeave && afterLeave();
  7437. });
  7438. };
  7439. if (delayLeave) {
  7440. delayLeave(el, remove, performLeave);
  7441. }
  7442. else {
  7443. performLeave();
  7444. }
  7445. }
  7446. }
  7447. else {
  7448. hostInsert(el, container, anchor);
  7449. }
  7450. };
  7451. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  7452. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  7453. // unset ref
  7454. if (ref != null) {
  7455. setRef(ref, null, parentSuspense, vnode, true);
  7456. }
  7457. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  7458. parentComponent.ctx.deactivate(vnode);
  7459. return;
  7460. }
  7461. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  7462. const shouldInvokeVnodeHook = !isAsyncWrapper(vnode);
  7463. let vnodeHook;
  7464. if (shouldInvokeVnodeHook &&
  7465. (vnodeHook = props && props.onVnodeBeforeUnmount)) {
  7466. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7467. }
  7468. if (shapeFlag & 6 /* COMPONENT */) {
  7469. unmountComponent(vnode.component, parentSuspense, doRemove);
  7470. }
  7471. else {
  7472. if (shapeFlag & 128 /* SUSPENSE */) {
  7473. vnode.suspense.unmount(parentSuspense, doRemove);
  7474. return;
  7475. }
  7476. if (shouldInvokeDirs) {
  7477. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  7478. }
  7479. if (shapeFlag & 64 /* TELEPORT */) {
  7480. vnode.type.remove(vnode, parentComponent, parentSuspense, optimized, internals, doRemove);
  7481. }
  7482. else if (dynamicChildren &&
  7483. // #1153: fast path should not be taken for non-stable (v-for) fragments
  7484. (type !== Fragment ||
  7485. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  7486. // fast path for block nodes: only need to unmount dynamic children.
  7487. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  7488. }
  7489. else if ((type === Fragment &&
  7490. patchFlag &
  7491. (128 /* KEYED_FRAGMENT */ | 256 /* UNKEYED_FRAGMENT */)) ||
  7492. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  7493. unmountChildren(children, parentComponent, parentSuspense);
  7494. }
  7495. if (doRemove) {
  7496. remove(vnode);
  7497. }
  7498. }
  7499. if ((shouldInvokeVnodeHook &&
  7500. (vnodeHook = props && props.onVnodeUnmounted)) ||
  7501. shouldInvokeDirs) {
  7502. queuePostRenderEffect(() => {
  7503. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  7504. shouldInvokeDirs &&
  7505. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  7506. }, parentSuspense);
  7507. }
  7508. };
  7509. const remove = vnode => {
  7510. const { type, el, anchor, transition } = vnode;
  7511. if (type === Fragment) {
  7512. if (vnode.patchFlag > 0 &&
  7513. vnode.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */ &&
  7514. transition &&
  7515. !transition.persisted) {
  7516. vnode.children.forEach(child => {
  7517. if (child.type === Comment) {
  7518. hostRemove(child.el);
  7519. }
  7520. else {
  7521. remove(child);
  7522. }
  7523. });
  7524. }
  7525. else {
  7526. removeFragment(el, anchor);
  7527. }
  7528. return;
  7529. }
  7530. if (type === Static) {
  7531. removeStaticNode(vnode);
  7532. return;
  7533. }
  7534. const performRemove = () => {
  7535. hostRemove(el);
  7536. if (transition && !transition.persisted && transition.afterLeave) {
  7537. transition.afterLeave();
  7538. }
  7539. };
  7540. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  7541. transition &&
  7542. !transition.persisted) {
  7543. const { leave, delayLeave } = transition;
  7544. const performLeave = () => leave(el, performRemove);
  7545. if (delayLeave) {
  7546. delayLeave(vnode.el, performRemove, performLeave);
  7547. }
  7548. else {
  7549. performLeave();
  7550. }
  7551. }
  7552. else {
  7553. performRemove();
  7554. }
  7555. };
  7556. const removeFragment = (cur, end) => {
  7557. // For fragments, directly remove all contained DOM nodes.
  7558. // (fragment child nodes cannot have transition)
  7559. let next;
  7560. while (cur !== end) {
  7561. next = hostNextSibling(cur);
  7562. hostRemove(cur);
  7563. cur = next;
  7564. }
  7565. hostRemove(end);
  7566. };
  7567. const unmountComponent = (instance, parentSuspense, doRemove) => {
  7568. if (instance.type.__hmrId) {
  7569. unregisterHMR(instance);
  7570. }
  7571. const { bum, scope, update, subTree, um } = instance;
  7572. // beforeUnmount hook
  7573. if (bum) {
  7574. invokeArrayFns(bum);
  7575. }
  7576. // stop effects in component scope
  7577. scope.stop();
  7578. // update may be null if a component is unmounted before its async
  7579. // setup has resolved.
  7580. if (update) {
  7581. // so that scheduler will no longer invoke it
  7582. update.active = false;
  7583. unmount(subTree, instance, parentSuspense, doRemove);
  7584. }
  7585. // unmounted hook
  7586. if (um) {
  7587. queuePostRenderEffect(um, parentSuspense);
  7588. }
  7589. queuePostRenderEffect(() => {
  7590. instance.isUnmounted = true;
  7591. }, parentSuspense);
  7592. // A component with async dep inside a pending suspense is unmounted before
  7593. // its async dep resolves. This should remove the dep from the suspense, and
  7594. // cause the suspense to resolve immediately if that was the last dep.
  7595. if (parentSuspense &&
  7596. parentSuspense.pendingBranch &&
  7597. !parentSuspense.isUnmounted &&
  7598. instance.asyncDep &&
  7599. !instance.asyncResolved &&
  7600. instance.suspenseId === parentSuspense.pendingId) {
  7601. parentSuspense.deps--;
  7602. if (parentSuspense.deps === 0) {
  7603. parentSuspense.resolve();
  7604. }
  7605. }
  7606. {
  7607. devtoolsComponentRemoved(instance);
  7608. }
  7609. };
  7610. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  7611. for (let i = start; i < children.length; i++) {
  7612. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  7613. }
  7614. };
  7615. const getNextHostNode = vnode => {
  7616. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  7617. return getNextHostNode(vnode.component.subTree);
  7618. }
  7619. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  7620. return vnode.suspense.next();
  7621. }
  7622. return hostNextSibling((vnode.anchor || vnode.el));
  7623. };
  7624. const render = (vnode, container, isSVG) => {
  7625. if (vnode == null) {
  7626. if (container._vnode) {
  7627. unmount(container._vnode, null, null, true);
  7628. }
  7629. }
  7630. else {
  7631. patch(container._vnode || null, vnode, container, null, null, null, isSVG);
  7632. }
  7633. flushPostFlushCbs();
  7634. container._vnode = vnode;
  7635. };
  7636. const internals = {
  7637. p: patch,
  7638. um: unmount,
  7639. m: move,
  7640. r: remove,
  7641. mt: mountComponent,
  7642. mc: mountChildren,
  7643. pc: patchChildren,
  7644. pbc: patchBlockChildren,
  7645. n: getNextHostNode,
  7646. o: options
  7647. };
  7648. let hydrate;
  7649. let hydrateNode;
  7650. if (createHydrationFns) {
  7651. [hydrate, hydrateNode] = createHydrationFns(internals);
  7652. }
  7653. return {
  7654. render,
  7655. hydrate,
  7656. createApp: createAppAPI(render, hydrate)
  7657. };
  7658. }
  7659. function toggleRecurse({ effect, update }, allowed) {
  7660. effect.allowRecurse = update.allowRecurse = allowed;
  7661. }
  7662. /**
  7663. * #1156
  7664. * When a component is HMR-enabled, we need to make sure that all static nodes
  7665. * inside a block also inherit the DOM element from the previous tree so that
  7666. * HMR updates (which are full updates) can retrieve the element for patching.
  7667. *
  7668. * #2080
  7669. * Inside keyed `template` fragment static children, if a fragment is moved,
  7670. * the children will always be moved. Therefore, in order to ensure correct move
  7671. * position, el should be inherited from previous nodes.
  7672. */
  7673. function traverseStaticChildren(n1, n2, shallow = false) {
  7674. const ch1 = n1.children;
  7675. const ch2 = n2.children;
  7676. if (isArray(ch1) && isArray(ch2)) {
  7677. for (let i = 0; i < ch1.length; i++) {
  7678. // this is only called in the optimized path so array children are
  7679. // guaranteed to be vnodes
  7680. const c1 = ch1[i];
  7681. let c2 = ch2[i];
  7682. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  7683. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  7684. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  7685. c2.el = c1.el;
  7686. }
  7687. if (!shallow)
  7688. traverseStaticChildren(c1, c2);
  7689. }
  7690. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  7691. // would have received .el during block patch)
  7692. if (c2.type === Comment && !c2.el) {
  7693. c2.el = c1.el;
  7694. }
  7695. }
  7696. }
  7697. }
  7698. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  7699. function getSequence(arr) {
  7700. const p = arr.slice();
  7701. const result = [0];
  7702. let i, j, u, v, c;
  7703. const len = arr.length;
  7704. for (i = 0; i < len; i++) {
  7705. const arrI = arr[i];
  7706. if (arrI !== 0) {
  7707. j = result[result.length - 1];
  7708. if (arr[j] < arrI) {
  7709. p[i] = j;
  7710. result.push(i);
  7711. continue;
  7712. }
  7713. u = 0;
  7714. v = result.length - 1;
  7715. while (u < v) {
  7716. c = (u + v) >> 1;
  7717. if (arr[result[c]] < arrI) {
  7718. u = c + 1;
  7719. }
  7720. else {
  7721. v = c;
  7722. }
  7723. }
  7724. if (arrI < arr[result[u]]) {
  7725. if (u > 0) {
  7726. p[i] = result[u - 1];
  7727. }
  7728. result[u] = i;
  7729. }
  7730. }
  7731. }
  7732. u = result.length;
  7733. v = result[u - 1];
  7734. while (u-- > 0) {
  7735. result[u] = v;
  7736. v = p[v];
  7737. }
  7738. return result;
  7739. }
  7740. const isTeleport = (type) => type.__isTeleport;
  7741. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  7742. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  7743. const resolveTarget = (props, select) => {
  7744. const targetSelector = props && props.to;
  7745. if (isString(targetSelector)) {
  7746. if (!select) {
  7747. warn$1(`Current renderer does not support string target for Teleports. ` +
  7748. `(missing querySelector renderer option)`);
  7749. return null;
  7750. }
  7751. else {
  7752. const target = select(targetSelector);
  7753. if (!target) {
  7754. warn$1(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  7755. `Note the target element must exist before the component is mounted - ` +
  7756. `i.e. the target cannot be rendered by the component itself, and ` +
  7757. `ideally should be outside of the entire Vue component tree.`);
  7758. }
  7759. return target;
  7760. }
  7761. }
  7762. else {
  7763. if (!targetSelector && !isTeleportDisabled(props)) {
  7764. warn$1(`Invalid Teleport target: ${targetSelector}`);
  7765. }
  7766. return targetSelector;
  7767. }
  7768. };
  7769. const TeleportImpl = {
  7770. __isTeleport: true,
  7771. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized, internals) {
  7772. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  7773. const disabled = isTeleportDisabled(n2.props);
  7774. let { shapeFlag, children, dynamicChildren } = n2;
  7775. // #3302
  7776. // HMR updated, force full diff
  7777. if (isHmrUpdating) {
  7778. optimized = false;
  7779. dynamicChildren = null;
  7780. }
  7781. if (n1 == null) {
  7782. // insert anchors in the main view
  7783. const placeholder = (n2.el = createComment('teleport start')
  7784. );
  7785. const mainAnchor = (n2.anchor = createComment('teleport end')
  7786. );
  7787. insert(placeholder, container, anchor);
  7788. insert(mainAnchor, container, anchor);
  7789. const target = (n2.target = resolveTarget(n2.props, querySelector));
  7790. const targetAnchor = (n2.targetAnchor = createText(''));
  7791. if (target) {
  7792. insert(targetAnchor, target);
  7793. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  7794. isSVG = isSVG || isTargetSVG(target);
  7795. }
  7796. else if (!disabled) {
  7797. warn$1('Invalid Teleport target on mount:', target, `(${typeof target})`);
  7798. }
  7799. const mount = (container, anchor) => {
  7800. // Teleport *always* has Array children. This is enforced in both the
  7801. // compiler and vnode children normalization.
  7802. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7803. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized);
  7804. }
  7805. };
  7806. if (disabled) {
  7807. mount(container, mainAnchor);
  7808. }
  7809. else if (target) {
  7810. mount(target, targetAnchor);
  7811. }
  7812. }
  7813. else {
  7814. // update content
  7815. n2.el = n1.el;
  7816. const mainAnchor = (n2.anchor = n1.anchor);
  7817. const target = (n2.target = n1.target);
  7818. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  7819. const wasDisabled = isTeleportDisabled(n1.props);
  7820. const currentContainer = wasDisabled ? container : target;
  7821. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  7822. isSVG = isSVG || isTargetSVG(target);
  7823. if (dynamicChildren) {
  7824. // fast path when the teleport happens to be a block root
  7825. patchBlockChildren(n1.dynamicChildren, dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG, slotScopeIds);
  7826. // even in block tree mode we need to make sure all root-level nodes
  7827. // in the teleport inherit previous DOM references so that they can
  7828. // be moved in future patches.
  7829. traverseStaticChildren(n1, n2, true);
  7830. }
  7831. else if (!optimized) {
  7832. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG, slotScopeIds, false);
  7833. }
  7834. if (disabled) {
  7835. if (!wasDisabled) {
  7836. // enabled -> disabled
  7837. // move into main container
  7838. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  7839. }
  7840. }
  7841. else {
  7842. // target changed
  7843. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  7844. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  7845. if (nextTarget) {
  7846. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  7847. }
  7848. else {
  7849. warn$1('Invalid Teleport target on update:', target, `(${typeof target})`);
  7850. }
  7851. }
  7852. else if (wasDisabled) {
  7853. // disabled -> enabled
  7854. // move into teleport target
  7855. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  7856. }
  7857. }
  7858. }
  7859. },
  7860. remove(vnode, parentComponent, parentSuspense, optimized, { um: unmount, o: { remove: hostRemove } }, doRemove) {
  7861. const { shapeFlag, children, anchor, targetAnchor, target, props } = vnode;
  7862. if (target) {
  7863. hostRemove(targetAnchor);
  7864. }
  7865. // an unmounted teleport should always remove its children if not disabled
  7866. if (doRemove || !isTeleportDisabled(props)) {
  7867. hostRemove(anchor);
  7868. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7869. for (let i = 0; i < children.length; i++) {
  7870. const child = children[i];
  7871. unmount(child, parentComponent, parentSuspense, true, !!child.dynamicChildren);
  7872. }
  7873. }
  7874. }
  7875. },
  7876. move: moveTeleport,
  7877. hydrate: hydrateTeleport
  7878. };
  7879. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  7880. // move target anchor if this is a target change.
  7881. if (moveType === 0 /* TARGET_CHANGE */) {
  7882. insert(vnode.targetAnchor, container, parentAnchor);
  7883. }
  7884. const { el, anchor, shapeFlag, children, props } = vnode;
  7885. const isReorder = moveType === 2 /* REORDER */;
  7886. // move main view anchor if this is a re-order.
  7887. if (isReorder) {
  7888. insert(el, container, parentAnchor);
  7889. }
  7890. // if this is a re-order and teleport is enabled (content is in target)
  7891. // do not move children. So the opposite is: only move children if this
  7892. // is not a reorder, or the teleport is disabled
  7893. if (!isReorder || isTeleportDisabled(props)) {
  7894. // Teleport has either Array children or no children.
  7895. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7896. for (let i = 0; i < children.length; i++) {
  7897. move(children[i], container, parentAnchor, 2 /* REORDER */);
  7898. }
  7899. }
  7900. }
  7901. // move main view anchor if this is a re-order.
  7902. if (isReorder) {
  7903. insert(anchor, container, parentAnchor);
  7904. }
  7905. }
  7906. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, slotScopeIds, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  7907. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  7908. if (target) {
  7909. // if multiple teleports rendered to the same target element, we need to
  7910. // pick up from where the last teleport finished instead of the first node
  7911. const targetNode = target._lpa || target.firstChild;
  7912. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  7913. if (isTeleportDisabled(vnode.props)) {
  7914. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, slotScopeIds, optimized);
  7915. vnode.targetAnchor = targetNode;
  7916. }
  7917. else {
  7918. vnode.anchor = nextSibling(node);
  7919. // lookahead until we find the target anchor
  7920. // we cannot rely on return value of hydrateChildren() because there
  7921. // could be nested teleports
  7922. let targetAnchor = targetNode;
  7923. while (targetAnchor) {
  7924. targetAnchor = nextSibling(targetAnchor);
  7925. if (targetAnchor &&
  7926. targetAnchor.nodeType === 8 &&
  7927. targetAnchor.data === 'teleport anchor') {
  7928. vnode.targetAnchor = targetAnchor;
  7929. target._lpa =
  7930. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  7931. break;
  7932. }
  7933. }
  7934. hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, slotScopeIds, optimized);
  7935. }
  7936. }
  7937. }
  7938. return vnode.anchor && nextSibling(vnode.anchor);
  7939. }
  7940. // Force-casted public typing for h and TSX props inference
  7941. const Teleport = TeleportImpl;
  7942. const Fragment = Symbol('Fragment' );
  7943. const Text = Symbol('Text' );
  7944. const Comment = Symbol('Comment' );
  7945. const Static = Symbol('Static' );
  7946. // Since v-if and v-for are the two possible ways node structure can dynamically
  7947. // change, once we consider v-if branches and each v-for fragment a block, we
  7948. // can divide a template into nested blocks, and within each block the node
  7949. // structure would be stable. This allows us to skip most children diffing
  7950. // and only worry about the dynamic nodes (indicated by patch flags).
  7951. const blockStack = [];
  7952. let currentBlock = null;
  7953. /**
  7954. * Open a block.
  7955. * This must be called before `createBlock`. It cannot be part of `createBlock`
  7956. * because the children of the block are evaluated before `createBlock` itself
  7957. * is called. The generated code typically looks like this:
  7958. *
  7959. * ```js
  7960. * function render() {
  7961. * return (openBlock(),createBlock('div', null, [...]))
  7962. * }
  7963. * ```
  7964. * disableTracking is true when creating a v-for fragment block, since a v-for
  7965. * fragment always diffs its children.
  7966. *
  7967. * @private
  7968. */
  7969. function openBlock(disableTracking = false) {
  7970. blockStack.push((currentBlock = disableTracking ? null : []));
  7971. }
  7972. function closeBlock() {
  7973. blockStack.pop();
  7974. currentBlock = blockStack[blockStack.length - 1] || null;
  7975. }
  7976. // Whether we should be tracking dynamic child nodes inside a block.
  7977. // Only tracks when this value is > 0
  7978. // We are not using a simple boolean because this value may need to be
  7979. // incremented/decremented by nested usage of v-once (see below)
  7980. let isBlockTreeEnabled = 1;
  7981. /**
  7982. * Block tracking sometimes needs to be disabled, for example during the
  7983. * creation of a tree that needs to be cached by v-once. The compiler generates
  7984. * code like this:
  7985. *
  7986. * ``` js
  7987. * _cache[1] || (
  7988. * setBlockTracking(-1),
  7989. * _cache[1] = createVNode(...),
  7990. * setBlockTracking(1),
  7991. * _cache[1]
  7992. * )
  7993. * ```
  7994. *
  7995. * @private
  7996. */
  7997. function setBlockTracking(value) {
  7998. isBlockTreeEnabled += value;
  7999. }
  8000. function setupBlock(vnode) {
  8001. // save current block children on the block vnode
  8002. vnode.dynamicChildren =
  8003. isBlockTreeEnabled > 0 ? currentBlock || EMPTY_ARR : null;
  8004. // close block
  8005. closeBlock();
  8006. // a block is always going to be patched, so track it as a child of its
  8007. // parent block
  8008. if (isBlockTreeEnabled > 0 && currentBlock) {
  8009. currentBlock.push(vnode);
  8010. }
  8011. return vnode;
  8012. }
  8013. /**
  8014. * @private
  8015. */
  8016. function createElementBlock(type, props, children, patchFlag, dynamicProps, shapeFlag) {
  8017. return setupBlock(createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, true /* isBlock */));
  8018. }
  8019. /**
  8020. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  8021. * A block root keeps track of dynamic nodes within the block in the
  8022. * `dynamicChildren` array.
  8023. *
  8024. * @private
  8025. */
  8026. function createBlock(type, props, children, patchFlag, dynamicProps) {
  8027. return setupBlock(createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */));
  8028. }
  8029. function isVNode(value) {
  8030. return value ? value.__v_isVNode === true : false;
  8031. }
  8032. function isSameVNodeType(n1, n2) {
  8033. if (n2.shapeFlag & 6 /* COMPONENT */ &&
  8034. hmrDirtyComponents.has(n2.type)) {
  8035. // HMR only: if the component has been hot-updated, force a reload.
  8036. return false;
  8037. }
  8038. return n1.type === n2.type && n1.key === n2.key;
  8039. }
  8040. let vnodeArgsTransformer;
  8041. /**
  8042. * Internal API for registering an arguments transform for createVNode
  8043. * used for creating stubs in the test-utils
  8044. * It is *internal* but needs to be exposed for test-utils to pick up proper
  8045. * typings
  8046. */
  8047. function transformVNodeArgs(transformer) {
  8048. vnodeArgsTransformer = transformer;
  8049. }
  8050. const createVNodeWithArgsTransform = (...args) => {
  8051. return _createVNode(...(vnodeArgsTransformer
  8052. ? vnodeArgsTransformer(args, currentRenderingInstance)
  8053. : args));
  8054. };
  8055. const InternalObjectKey = `__vInternal`;
  8056. const normalizeKey = ({ key }) => key != null ? key : null;
  8057. const normalizeRef = ({ ref, ref_key, ref_for }) => {
  8058. return (ref != null
  8059. ? isString(ref) || isRef(ref) || isFunction(ref)
  8060. ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
  8061. : ref
  8062. : null);
  8063. };
  8064. function createBaseVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, shapeFlag = type === Fragment ? 0 : 1 /* ELEMENT */, isBlockNode = false, needFullChildrenNormalization = false) {
  8065. const vnode = {
  8066. __v_isVNode: true,
  8067. __v_skip: true,
  8068. type,
  8069. props,
  8070. key: props && normalizeKey(props),
  8071. ref: props && normalizeRef(props),
  8072. scopeId: currentScopeId,
  8073. slotScopeIds: null,
  8074. children,
  8075. component: null,
  8076. suspense: null,
  8077. ssContent: null,
  8078. ssFallback: null,
  8079. dirs: null,
  8080. transition: null,
  8081. el: null,
  8082. anchor: null,
  8083. target: null,
  8084. targetAnchor: null,
  8085. staticCount: 0,
  8086. shapeFlag,
  8087. patchFlag,
  8088. dynamicProps,
  8089. dynamicChildren: null,
  8090. appContext: null
  8091. };
  8092. if (needFullChildrenNormalization) {
  8093. normalizeChildren(vnode, children);
  8094. // normalize suspense children
  8095. if (shapeFlag & 128 /* SUSPENSE */) {
  8096. type.normalize(vnode);
  8097. }
  8098. }
  8099. else if (children) {
  8100. // compiled element vnode - if children is passed, only possible types are
  8101. // string or Array.
  8102. vnode.shapeFlag |= isString(children)
  8103. ? 8 /* TEXT_CHILDREN */
  8104. : 16 /* ARRAY_CHILDREN */;
  8105. }
  8106. // validate key
  8107. if (vnode.key !== vnode.key) {
  8108. warn$1(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  8109. }
  8110. // track vnode for block tree
  8111. if (isBlockTreeEnabled > 0 &&
  8112. // avoid a block node from tracking itself
  8113. !isBlockNode &&
  8114. // has current parent block
  8115. currentBlock &&
  8116. // presence of a patch flag indicates this node needs patching on updates.
  8117. // component nodes also should always be patched, because even if the
  8118. // component doesn't need to update, it needs to persist the instance on to
  8119. // the next vnode so that it can be properly unmounted later.
  8120. (vnode.patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  8121. // the EVENTS flag is only for hydration and if it is the only flag, the
  8122. // vnode should not be considered dynamic due to handler caching.
  8123. vnode.patchFlag !== 32 /* HYDRATE_EVENTS */) {
  8124. currentBlock.push(vnode);
  8125. }
  8126. return vnode;
  8127. }
  8128. const createVNode = (createVNodeWithArgsTransform );
  8129. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  8130. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  8131. if (!type) {
  8132. warn$1(`Invalid vnode type when creating vnode: ${type}.`);
  8133. }
  8134. type = Comment;
  8135. }
  8136. if (isVNode(type)) {
  8137. // createVNode receiving an existing vnode. This happens in cases like
  8138. // <component :is="vnode"/>
  8139. // #2078 make sure to merge refs during the clone instead of overwriting it
  8140. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  8141. if (children) {
  8142. normalizeChildren(cloned, children);
  8143. }
  8144. if (isBlockTreeEnabled > 0 && !isBlockNode && currentBlock) {
  8145. if (cloned.shapeFlag & 6 /* COMPONENT */) {
  8146. currentBlock[currentBlock.indexOf(type)] = cloned;
  8147. }
  8148. else {
  8149. currentBlock.push(cloned);
  8150. }
  8151. }
  8152. cloned.patchFlag |= -2 /* BAIL */;
  8153. return cloned;
  8154. }
  8155. // class component normalization.
  8156. if (isClassComponent(type)) {
  8157. type = type.__vccOpts;
  8158. }
  8159. // class & style normalization.
  8160. if (props) {
  8161. // for reactive or proxy objects, we need to clone it to enable mutation.
  8162. props = guardReactiveProps(props);
  8163. let { class: klass, style } = props;
  8164. if (klass && !isString(klass)) {
  8165. props.class = normalizeClass(klass);
  8166. }
  8167. if (isObject(style)) {
  8168. // reactive state objects need to be cloned since they are likely to be
  8169. // mutated
  8170. if (isProxy(style) && !isArray(style)) {
  8171. style = extend({}, style);
  8172. }
  8173. props.style = normalizeStyle(style);
  8174. }
  8175. }
  8176. // encode the vnode type information into a bitmap
  8177. const shapeFlag = isString(type)
  8178. ? 1 /* ELEMENT */
  8179. : isSuspense(type)
  8180. ? 128 /* SUSPENSE */
  8181. : isTeleport(type)
  8182. ? 64 /* TELEPORT */
  8183. : isObject(type)
  8184. ? 4 /* STATEFUL_COMPONENT */
  8185. : isFunction(type)
  8186. ? 2 /* FUNCTIONAL_COMPONENT */
  8187. : 0;
  8188. if (shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  8189. type = toRaw(type);
  8190. warn$1(`Vue received a Component which was made a reactive object. This can ` +
  8191. `lead to unnecessary performance overhead, and should be avoided by ` +
  8192. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  8193. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  8194. }
  8195. return createBaseVNode(type, props, children, patchFlag, dynamicProps, shapeFlag, isBlockNode, true);
  8196. }
  8197. function guardReactiveProps(props) {
  8198. if (!props)
  8199. return null;
  8200. return isProxy(props) || InternalObjectKey in props
  8201. ? extend({}, props)
  8202. : props;
  8203. }
  8204. function cloneVNode(vnode, extraProps, mergeRef = false) {
  8205. // This is intentionally NOT using spread or extend to avoid the runtime
  8206. // key enumeration cost.
  8207. const { props, ref, patchFlag, children } = vnode;
  8208. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  8209. const cloned = {
  8210. __v_isVNode: true,
  8211. __v_skip: true,
  8212. type: vnode.type,
  8213. props: mergedProps,
  8214. key: mergedProps && normalizeKey(mergedProps),
  8215. ref: extraProps && extraProps.ref
  8216. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  8217. // if the vnode itself already has a ref, cloneVNode will need to merge
  8218. // the refs so the single vnode can be set on multiple refs
  8219. mergeRef && ref
  8220. ? isArray(ref)
  8221. ? ref.concat(normalizeRef(extraProps))
  8222. : [ref, normalizeRef(extraProps)]
  8223. : normalizeRef(extraProps)
  8224. : ref,
  8225. scopeId: vnode.scopeId,
  8226. slotScopeIds: vnode.slotScopeIds,
  8227. children: patchFlag === -1 /* HOISTED */ && isArray(children)
  8228. ? children.map(deepCloneVNode)
  8229. : children,
  8230. target: vnode.target,
  8231. targetAnchor: vnode.targetAnchor,
  8232. staticCount: vnode.staticCount,
  8233. shapeFlag: vnode.shapeFlag,
  8234. // if the vnode is cloned with extra props, we can no longer assume its
  8235. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  8236. // note: preserve flag for fragments since they use the flag for children
  8237. // fast paths only.
  8238. patchFlag: extraProps && vnode.type !== Fragment
  8239. ? patchFlag === -1 // hoisted node
  8240. ? 16 /* FULL_PROPS */
  8241. : patchFlag | 16 /* FULL_PROPS */
  8242. : patchFlag,
  8243. dynamicProps: vnode.dynamicProps,
  8244. dynamicChildren: vnode.dynamicChildren,
  8245. appContext: vnode.appContext,
  8246. dirs: vnode.dirs,
  8247. transition: vnode.transition,
  8248. // These should technically only be non-null on mounted VNodes. However,
  8249. // they *should* be copied for kept-alive vnodes. So we just always copy
  8250. // them since them being non-null during a mount doesn't affect the logic as
  8251. // they will simply be overwritten.
  8252. component: vnode.component,
  8253. suspense: vnode.suspense,
  8254. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  8255. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  8256. el: vnode.el,
  8257. anchor: vnode.anchor
  8258. };
  8259. return cloned;
  8260. }
  8261. /**
  8262. * Dev only, for HMR of hoisted vnodes reused in v-for
  8263. * https://github.com/vitejs/vite/issues/2022
  8264. */
  8265. function deepCloneVNode(vnode) {
  8266. const cloned = cloneVNode(vnode);
  8267. if (isArray(vnode.children)) {
  8268. cloned.children = vnode.children.map(deepCloneVNode);
  8269. }
  8270. return cloned;
  8271. }
  8272. /**
  8273. * @private
  8274. */
  8275. function createTextVNode(text = ' ', flag = 0) {
  8276. return createVNode(Text, null, text, flag);
  8277. }
  8278. /**
  8279. * @private
  8280. */
  8281. function createStaticVNode(content, numberOfNodes) {
  8282. // A static vnode can contain multiple stringified elements, and the number
  8283. // of elements is necessary for hydration.
  8284. const vnode = createVNode(Static, null, content);
  8285. vnode.staticCount = numberOfNodes;
  8286. return vnode;
  8287. }
  8288. /**
  8289. * @private
  8290. */
  8291. function createCommentVNode(text = '',
  8292. // when used as the v-else branch, the comment node must be created as a
  8293. // block to ensure correct updates.
  8294. asBlock = false) {
  8295. return asBlock
  8296. ? (openBlock(), createBlock(Comment, null, text))
  8297. : createVNode(Comment, null, text);
  8298. }
  8299. function normalizeVNode(child) {
  8300. if (child == null || typeof child === 'boolean') {
  8301. // empty placeholder
  8302. return createVNode(Comment);
  8303. }
  8304. else if (isArray(child)) {
  8305. // fragment
  8306. return createVNode(Fragment, null,
  8307. // #3666, avoid reference pollution when reusing vnode
  8308. child.slice());
  8309. }
  8310. else if (typeof child === 'object') {
  8311. // already vnode, this should be the most common since compiled templates
  8312. // always produce all-vnode children arrays
  8313. return cloneIfMounted(child);
  8314. }
  8315. else {
  8316. // strings and numbers
  8317. return createVNode(Text, null, String(child));
  8318. }
  8319. }
  8320. // optimized normalization for template-compiled render fns
  8321. function cloneIfMounted(child) {
  8322. return child.el === null || child.memo ? child : cloneVNode(child);
  8323. }
  8324. function normalizeChildren(vnode, children) {
  8325. let type = 0;
  8326. const { shapeFlag } = vnode;
  8327. if (children == null) {
  8328. children = null;
  8329. }
  8330. else if (isArray(children)) {
  8331. type = 16 /* ARRAY_CHILDREN */;
  8332. }
  8333. else if (typeof children === 'object') {
  8334. if (shapeFlag & (1 /* ELEMENT */ | 64 /* TELEPORT */)) {
  8335. // Normalize slot to plain children for plain element and Teleport
  8336. const slot = children.default;
  8337. if (slot) {
  8338. // _c marker is added by withCtx() indicating this is a compiled slot
  8339. slot._c && (slot._d = false);
  8340. normalizeChildren(vnode, slot());
  8341. slot._c && (slot._d = true);
  8342. }
  8343. return;
  8344. }
  8345. else {
  8346. type = 32 /* SLOTS_CHILDREN */;
  8347. const slotFlag = children._;
  8348. if (!slotFlag && !(InternalObjectKey in children)) {
  8349. children._ctx = currentRenderingInstance;
  8350. }
  8351. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  8352. // a child component receives forwarded slots from the parent.
  8353. // its slot type is determined by its parent's slot type.
  8354. if (currentRenderingInstance.slots._ === 1 /* STABLE */) {
  8355. children._ = 1 /* STABLE */;
  8356. }
  8357. else {
  8358. children._ = 2 /* DYNAMIC */;
  8359. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  8360. }
  8361. }
  8362. }
  8363. }
  8364. else if (isFunction(children)) {
  8365. children = { default: children, _ctx: currentRenderingInstance };
  8366. type = 32 /* SLOTS_CHILDREN */;
  8367. }
  8368. else {
  8369. children = String(children);
  8370. // force teleport children to array so it can be moved around
  8371. if (shapeFlag & 64 /* TELEPORT */) {
  8372. type = 16 /* ARRAY_CHILDREN */;
  8373. children = [createTextVNode(children)];
  8374. }
  8375. else {
  8376. type = 8 /* TEXT_CHILDREN */;
  8377. }
  8378. }
  8379. vnode.children = children;
  8380. vnode.shapeFlag |= type;
  8381. }
  8382. function mergeProps(...args) {
  8383. const ret = {};
  8384. for (let i = 0; i < args.length; i++) {
  8385. const toMerge = args[i];
  8386. for (const key in toMerge) {
  8387. if (key === 'class') {
  8388. if (ret.class !== toMerge.class) {
  8389. ret.class = normalizeClass([ret.class, toMerge.class]);
  8390. }
  8391. }
  8392. else if (key === 'style') {
  8393. ret.style = normalizeStyle([ret.style, toMerge.style]);
  8394. }
  8395. else if (isOn(key)) {
  8396. const existing = ret[key];
  8397. const incoming = toMerge[key];
  8398. if (incoming &&
  8399. existing !== incoming &&
  8400. !(isArray(existing) && existing.includes(incoming))) {
  8401. ret[key] = existing
  8402. ? [].concat(existing, incoming)
  8403. : incoming;
  8404. }
  8405. }
  8406. else if (key !== '') {
  8407. ret[key] = toMerge[key];
  8408. }
  8409. }
  8410. }
  8411. return ret;
  8412. }
  8413. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  8414. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  8415. vnode,
  8416. prevVNode
  8417. ]);
  8418. }
  8419. const emptyAppContext = createAppContext();
  8420. let uid$1 = 0;
  8421. function createComponentInstance(vnode, parent, suspense) {
  8422. const type = vnode.type;
  8423. // inherit parent app context - or - if root, adopt from root vnode
  8424. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  8425. const instance = {
  8426. uid: uid$1++,
  8427. vnode,
  8428. type,
  8429. parent,
  8430. appContext,
  8431. root: null,
  8432. next: null,
  8433. subTree: null,
  8434. effect: null,
  8435. update: null,
  8436. scope: new EffectScope(true /* detached */),
  8437. render: null,
  8438. proxy: null,
  8439. exposed: null,
  8440. exposeProxy: null,
  8441. withProxy: null,
  8442. provides: parent ? parent.provides : Object.create(appContext.provides),
  8443. accessCache: null,
  8444. renderCache: [],
  8445. // local resolved assets
  8446. components: null,
  8447. directives: null,
  8448. // resolved props and emits options
  8449. propsOptions: normalizePropsOptions(type, appContext),
  8450. emitsOptions: normalizeEmitsOptions(type, appContext),
  8451. // emit
  8452. emit: null,
  8453. emitted: null,
  8454. // props default value
  8455. propsDefaults: EMPTY_OBJ,
  8456. // inheritAttrs
  8457. inheritAttrs: type.inheritAttrs,
  8458. // state
  8459. ctx: EMPTY_OBJ,
  8460. data: EMPTY_OBJ,
  8461. props: EMPTY_OBJ,
  8462. attrs: EMPTY_OBJ,
  8463. slots: EMPTY_OBJ,
  8464. refs: EMPTY_OBJ,
  8465. setupState: EMPTY_OBJ,
  8466. setupContext: null,
  8467. // suspense related
  8468. suspense,
  8469. suspenseId: suspense ? suspense.pendingId : 0,
  8470. asyncDep: null,
  8471. asyncResolved: false,
  8472. // lifecycle hooks
  8473. // not using enums here because it results in computed properties
  8474. isMounted: false,
  8475. isUnmounted: false,
  8476. isDeactivated: false,
  8477. bc: null,
  8478. c: null,
  8479. bm: null,
  8480. m: null,
  8481. bu: null,
  8482. u: null,
  8483. um: null,
  8484. bum: null,
  8485. da: null,
  8486. a: null,
  8487. rtg: null,
  8488. rtc: null,
  8489. ec: null,
  8490. sp: null
  8491. };
  8492. {
  8493. instance.ctx = createDevRenderContext(instance);
  8494. }
  8495. instance.root = parent ? parent.root : instance;
  8496. instance.emit = emit$1.bind(null, instance);
  8497. // apply custom element special handling
  8498. if (vnode.ce) {
  8499. vnode.ce(instance);
  8500. }
  8501. return instance;
  8502. }
  8503. let currentInstance = null;
  8504. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  8505. const setCurrentInstance = (instance) => {
  8506. currentInstance = instance;
  8507. instance.scope.on();
  8508. };
  8509. const unsetCurrentInstance = () => {
  8510. currentInstance && currentInstance.scope.off();
  8511. currentInstance = null;
  8512. };
  8513. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  8514. function validateComponentName(name, config) {
  8515. const appIsNativeTag = config.isNativeTag || NO;
  8516. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  8517. warn$1('Do not use built-in or reserved HTML elements as component id: ' + name);
  8518. }
  8519. }
  8520. function isStatefulComponent(instance) {
  8521. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  8522. }
  8523. let isInSSRComponentSetup = false;
  8524. function setupComponent(instance, isSSR = false) {
  8525. isInSSRComponentSetup = isSSR;
  8526. const { props, children } = instance.vnode;
  8527. const isStateful = isStatefulComponent(instance);
  8528. initProps(instance, props, isStateful, isSSR);
  8529. initSlots(instance, children);
  8530. const setupResult = isStateful
  8531. ? setupStatefulComponent(instance, isSSR)
  8532. : undefined;
  8533. isInSSRComponentSetup = false;
  8534. return setupResult;
  8535. }
  8536. function setupStatefulComponent(instance, isSSR) {
  8537. var _a;
  8538. const Component = instance.type;
  8539. {
  8540. if (Component.name) {
  8541. validateComponentName(Component.name, instance.appContext.config);
  8542. }
  8543. if (Component.components) {
  8544. const names = Object.keys(Component.components);
  8545. for (let i = 0; i < names.length; i++) {
  8546. validateComponentName(names[i], instance.appContext.config);
  8547. }
  8548. }
  8549. if (Component.directives) {
  8550. const names = Object.keys(Component.directives);
  8551. for (let i = 0; i < names.length; i++) {
  8552. validateDirectiveName(names[i]);
  8553. }
  8554. }
  8555. if (Component.compilerOptions && isRuntimeOnly()) {
  8556. warn$1(`"compilerOptions" is only supported when using a build of Vue that ` +
  8557. `includes the runtime compiler. Since you are using a runtime-only ` +
  8558. `build, the options should be passed via your build tool config instead.`);
  8559. }
  8560. }
  8561. // 0. create render proxy property access cache
  8562. instance.accessCache = Object.create(null);
  8563. // 1. create public instance / render proxy
  8564. // also mark it raw so it's never observed
  8565. instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers));
  8566. {
  8567. exposePropsOnRenderContext(instance);
  8568. }
  8569. // 2. call setup()
  8570. const { setup } = Component;
  8571. if (setup) {
  8572. const setupContext = (instance.setupContext =
  8573. setup.length > 1 ? createSetupContext(instance) : null);
  8574. setCurrentInstance(instance);
  8575. pauseTracking();
  8576. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  8577. resetTracking();
  8578. unsetCurrentInstance();
  8579. if (isPromise(setupResult)) {
  8580. setupResult.then(unsetCurrentInstance, unsetCurrentInstance);
  8581. if (isSSR) {
  8582. // return the promise so server-renderer can wait on it
  8583. return setupResult
  8584. .then((resolvedResult) => {
  8585. handleSetupResult(instance, resolvedResult, isSSR);
  8586. })
  8587. .catch(e => {
  8588. handleError(e, instance, 0 /* SETUP_FUNCTION */);
  8589. });
  8590. }
  8591. else {
  8592. // async setup returned Promise.
  8593. // bail here and wait for re-entry.
  8594. instance.asyncDep = setupResult;
  8595. if (!instance.suspense) {
  8596. const name = (_a = Component.name) !== null && _a !== void 0 ? _a : 'Anonymous';
  8597. warn$1(`Component <${name}>: setup function returned a promise, but no ` +
  8598. `<Suspense> boundary was found in the parent component tree. ` +
  8599. `A component with async setup() must be nested in a <Suspense> ` +
  8600. `in order to be rendered.`);
  8601. }
  8602. }
  8603. }
  8604. else {
  8605. handleSetupResult(instance, setupResult, isSSR);
  8606. }
  8607. }
  8608. else {
  8609. finishComponentSetup(instance, isSSR);
  8610. }
  8611. }
  8612. function handleSetupResult(instance, setupResult, isSSR) {
  8613. if (isFunction(setupResult)) {
  8614. // setup returned an inline render function
  8615. {
  8616. instance.render = setupResult;
  8617. }
  8618. }
  8619. else if (isObject(setupResult)) {
  8620. if (isVNode(setupResult)) {
  8621. warn$1(`setup() should not return VNodes directly - ` +
  8622. `return a render function instead.`);
  8623. }
  8624. // setup returned bindings.
  8625. // assuming a render function compiled from template is present.
  8626. {
  8627. instance.devtoolsRawSetupState = setupResult;
  8628. }
  8629. instance.setupState = proxyRefs(setupResult);
  8630. {
  8631. exposeSetupStateOnRenderContext(instance);
  8632. }
  8633. }
  8634. else if (setupResult !== undefined) {
  8635. warn$1(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  8636. }
  8637. finishComponentSetup(instance, isSSR);
  8638. }
  8639. let compile;
  8640. let installWithProxy;
  8641. /**
  8642. * For runtime-dom to register the compiler.
  8643. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  8644. */
  8645. function registerRuntimeCompiler(_compile) {
  8646. compile = _compile;
  8647. installWithProxy = i => {
  8648. if (i.render._rc) {
  8649. i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  8650. }
  8651. };
  8652. }
  8653. // dev only
  8654. const isRuntimeOnly = () => !compile;
  8655. function finishComponentSetup(instance, isSSR, skipOptions) {
  8656. const Component = instance.type;
  8657. // template / render function normalization
  8658. // could be already set when returned from setup()
  8659. if (!instance.render) {
  8660. // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
  8661. // is done by server-renderer
  8662. if (!isSSR && compile && !Component.render) {
  8663. const template = Component.template;
  8664. if (template) {
  8665. {
  8666. startMeasure(instance, `compile`);
  8667. }
  8668. const { isCustomElement, compilerOptions } = instance.appContext.config;
  8669. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  8670. const finalCompilerOptions = extend(extend({
  8671. isCustomElement,
  8672. delimiters
  8673. }, compilerOptions), componentCompilerOptions);
  8674. Component.render = compile(template, finalCompilerOptions);
  8675. {
  8676. endMeasure(instance, `compile`);
  8677. }
  8678. }
  8679. }
  8680. instance.render = (Component.render || NOOP);
  8681. // for runtime-compiled render functions using `with` blocks, the render
  8682. // proxy used needs a different `has` handler which is more performant and
  8683. // also only allows a whitelist of globals to fallthrough.
  8684. if (installWithProxy) {
  8685. installWithProxy(instance);
  8686. }
  8687. }
  8688. // support for 2.x options
  8689. {
  8690. setCurrentInstance(instance);
  8691. pauseTracking();
  8692. applyOptions(instance);
  8693. resetTracking();
  8694. unsetCurrentInstance();
  8695. }
  8696. // warn missing template/render
  8697. // the runtime compilation of template in SSR is done by server-render
  8698. if (!Component.render && instance.render === NOOP && !isSSR) {
  8699. /* istanbul ignore if */
  8700. if (!compile && Component.template) {
  8701. warn$1(`Component provided template option but ` +
  8702. `runtime compilation is not supported in this build of Vue.` +
  8703. (` Use "vue.esm-browser.js" instead.`
  8704. ) /* should not happen */);
  8705. }
  8706. else {
  8707. warn$1(`Component is missing template or render function.`);
  8708. }
  8709. }
  8710. }
  8711. function createAttrsProxy(instance) {
  8712. return new Proxy(instance.attrs, {
  8713. get(target, key) {
  8714. markAttrsAccessed();
  8715. track(instance, "get" /* GET */, '$attrs');
  8716. return target[key];
  8717. },
  8718. set() {
  8719. warn$1(`setupContext.attrs is readonly.`);
  8720. return false;
  8721. },
  8722. deleteProperty() {
  8723. warn$1(`setupContext.attrs is readonly.`);
  8724. return false;
  8725. }
  8726. }
  8727. );
  8728. }
  8729. function createSetupContext(instance) {
  8730. const expose = exposed => {
  8731. if (instance.exposed) {
  8732. warn$1(`expose() should be called only once per setup().`);
  8733. }
  8734. instance.exposed = exposed || {};
  8735. };
  8736. let attrs;
  8737. {
  8738. // We use getters in dev in case libs like test-utils overwrite instance
  8739. // properties (overwrites should not be done in prod)
  8740. return Object.freeze({
  8741. get attrs() {
  8742. return attrs || (attrs = createAttrsProxy(instance));
  8743. },
  8744. get slots() {
  8745. return shallowReadonly(instance.slots);
  8746. },
  8747. get emit() {
  8748. return (event, ...args) => instance.emit(event, ...args);
  8749. },
  8750. expose
  8751. });
  8752. }
  8753. }
  8754. function getExposeProxy(instance) {
  8755. if (instance.exposed) {
  8756. return (instance.exposeProxy ||
  8757. (instance.exposeProxy = new Proxy(proxyRefs(markRaw(instance.exposed)), {
  8758. get(target, key) {
  8759. if (key in target) {
  8760. return target[key];
  8761. }
  8762. else if (key in publicPropertiesMap) {
  8763. return publicPropertiesMap[key](instance);
  8764. }
  8765. }
  8766. })));
  8767. }
  8768. }
  8769. const classifyRE = /(?:^|[-_])(\w)/g;
  8770. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  8771. function getComponentName(Component, includeInferred = true) {
  8772. return isFunction(Component)
  8773. ? Component.displayName || Component.name
  8774. : Component.name || (includeInferred && Component.__name);
  8775. }
  8776. /* istanbul ignore next */
  8777. function formatComponentName(instance, Component, isRoot = false) {
  8778. let name = getComponentName(Component);
  8779. if (!name && Component.__file) {
  8780. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  8781. if (match) {
  8782. name = match[1];
  8783. }
  8784. }
  8785. if (!name && instance && instance.parent) {
  8786. // try to infer the name based on reverse resolution
  8787. const inferFromRegistry = (registry) => {
  8788. for (const key in registry) {
  8789. if (registry[key] === Component) {
  8790. return key;
  8791. }
  8792. }
  8793. };
  8794. name =
  8795. inferFromRegistry(instance.components ||
  8796. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  8797. }
  8798. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  8799. }
  8800. function isClassComponent(value) {
  8801. return isFunction(value) && '__vccOpts' in value;
  8802. }
  8803. const computed$1 = ((getterOrOptions, debugOptions) => {
  8804. // @ts-ignore
  8805. return computed(getterOrOptions, debugOptions, isInSSRComponentSetup);
  8806. });
  8807. // dev only
  8808. const warnRuntimeUsage = (method) => warn$1(`${method}() is a compiler-hint helper that is only usable inside ` +
  8809. `<script setup> of a single file component. Its arguments should be ` +
  8810. `compiled away and passing it at runtime has no effect.`);
  8811. // implementation
  8812. function defineProps() {
  8813. {
  8814. warnRuntimeUsage(`defineProps`);
  8815. }
  8816. return null;
  8817. }
  8818. // implementation
  8819. function defineEmits() {
  8820. {
  8821. warnRuntimeUsage(`defineEmits`);
  8822. }
  8823. return null;
  8824. }
  8825. /**
  8826. * Vue `<script setup>` compiler macro for declaring a component's exposed
  8827. * instance properties when it is accessed by a parent component via template
  8828. * refs.
  8829. *
  8830. * `<script setup>` components are closed by default - i.e. variables inside
  8831. * the `<script setup>` scope is not exposed to parent unless explicitly exposed
  8832. * via `defineExpose`.
  8833. *
  8834. * This is only usable inside `<script setup>`, is compiled away in the
  8835. * output and should **not** be actually called at runtime.
  8836. */
  8837. function defineExpose(exposed) {
  8838. {
  8839. warnRuntimeUsage(`defineExpose`);
  8840. }
  8841. }
  8842. /**
  8843. * Vue `<script setup>` compiler macro for providing props default values when
  8844. * using type-based `defineProps` declaration.
  8845. *
  8846. * Example usage:
  8847. * ```ts
  8848. * withDefaults(defineProps<{
  8849. * size?: number
  8850. * labels?: string[]
  8851. * }>(), {
  8852. * size: 3,
  8853. * labels: () => ['default label']
  8854. * })
  8855. * ```
  8856. *
  8857. * This is only usable inside `<script setup>`, is compiled away in the output
  8858. * and should **not** be actually called at runtime.
  8859. */
  8860. function withDefaults(props, defaults) {
  8861. {
  8862. warnRuntimeUsage(`withDefaults`);
  8863. }
  8864. return null;
  8865. }
  8866. function useSlots() {
  8867. return getContext().slots;
  8868. }
  8869. function useAttrs() {
  8870. return getContext().attrs;
  8871. }
  8872. function getContext() {
  8873. const i = getCurrentInstance();
  8874. if (!i) {
  8875. warn$1(`useContext() called without active instance.`);
  8876. }
  8877. return i.setupContext || (i.setupContext = createSetupContext(i));
  8878. }
  8879. /**
  8880. * Runtime helper for merging default declarations. Imported by compiled code
  8881. * only.
  8882. * @internal
  8883. */
  8884. function mergeDefaults(raw, defaults) {
  8885. const props = isArray(raw)
  8886. ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
  8887. : raw;
  8888. for (const key in defaults) {
  8889. const opt = props[key];
  8890. if (opt) {
  8891. if (isArray(opt) || isFunction(opt)) {
  8892. props[key] = { type: opt, default: defaults[key] };
  8893. }
  8894. else {
  8895. opt.default = defaults[key];
  8896. }
  8897. }
  8898. else if (opt === null) {
  8899. props[key] = { default: defaults[key] };
  8900. }
  8901. else {
  8902. warn$1(`props default key "${key}" has no corresponding declaration.`);
  8903. }
  8904. }
  8905. return props;
  8906. }
  8907. /**
  8908. * Used to create a proxy for the rest element when destructuring props with
  8909. * defineProps().
  8910. * @internal
  8911. */
  8912. function createPropsRestProxy(props, excludedKeys) {
  8913. const ret = {};
  8914. for (const key in props) {
  8915. if (!excludedKeys.includes(key)) {
  8916. Object.defineProperty(ret, key, {
  8917. enumerable: true,
  8918. get: () => props[key]
  8919. });
  8920. }
  8921. }
  8922. return ret;
  8923. }
  8924. /**
  8925. * `<script setup>` helper for persisting the current instance context over
  8926. * async/await flows.
  8927. *
  8928. * `@vue/compiler-sfc` converts the following:
  8929. *
  8930. * ```ts
  8931. * const x = await foo()
  8932. * ```
  8933. *
  8934. * into:
  8935. *
  8936. * ```ts
  8937. * let __temp, __restore
  8938. * const x = (([__temp, __restore] = withAsyncContext(() => foo())),__temp=await __temp,__restore(),__temp)
  8939. * ```
  8940. * @internal
  8941. */
  8942. function withAsyncContext(getAwaitable) {
  8943. const ctx = getCurrentInstance();
  8944. if (!ctx) {
  8945. warn$1(`withAsyncContext called without active current instance. ` +
  8946. `This is likely a bug.`);
  8947. }
  8948. let awaitable = getAwaitable();
  8949. unsetCurrentInstance();
  8950. if (isPromise(awaitable)) {
  8951. awaitable = awaitable.catch(e => {
  8952. setCurrentInstance(ctx);
  8953. throw e;
  8954. });
  8955. }
  8956. return [awaitable, () => setCurrentInstance(ctx)];
  8957. }
  8958. // Actual implementation
  8959. function h(type, propsOrChildren, children) {
  8960. const l = arguments.length;
  8961. if (l === 2) {
  8962. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  8963. // single vnode without props
  8964. if (isVNode(propsOrChildren)) {
  8965. return createVNode(type, null, [propsOrChildren]);
  8966. }
  8967. // props without children
  8968. return createVNode(type, propsOrChildren);
  8969. }
  8970. else {
  8971. // omit props
  8972. return createVNode(type, null, propsOrChildren);
  8973. }
  8974. }
  8975. else {
  8976. if (l > 3) {
  8977. children = Array.prototype.slice.call(arguments, 2);
  8978. }
  8979. else if (l === 3 && isVNode(children)) {
  8980. children = [children];
  8981. }
  8982. return createVNode(type, propsOrChildren, children);
  8983. }
  8984. }
  8985. const ssrContextKey = Symbol(`ssrContext` );
  8986. const useSSRContext = () => {
  8987. {
  8988. const ctx = inject(ssrContextKey);
  8989. if (!ctx) {
  8990. warn$1(`Server rendering context not provided. Make sure to only call ` +
  8991. `useSSRContext() conditionally in the server build.`);
  8992. }
  8993. return ctx;
  8994. }
  8995. };
  8996. function initCustomFormatter() {
  8997. /* eslint-disable no-restricted-globals */
  8998. if (typeof window === 'undefined') {
  8999. return;
  9000. }
  9001. const vueStyle = { style: 'color:#3ba776' };
  9002. const numberStyle = { style: 'color:#0b1bc9' };
  9003. const stringStyle = { style: 'color:#b62e24' };
  9004. const keywordStyle = { style: 'color:#9d288c' };
  9005. // custom formatter for Chrome
  9006. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  9007. const formatter = {
  9008. header(obj) {
  9009. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  9010. if (!isObject(obj)) {
  9011. return null;
  9012. }
  9013. if (obj.__isVue) {
  9014. return ['div', vueStyle, `VueInstance`];
  9015. }
  9016. else if (isRef(obj)) {
  9017. return [
  9018. 'div',
  9019. {},
  9020. ['span', vueStyle, genRefFlag(obj)],
  9021. '<',
  9022. formatValue(obj.value),
  9023. `>`
  9024. ];
  9025. }
  9026. else if (isReactive(obj)) {
  9027. return [
  9028. 'div',
  9029. {},
  9030. ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'],
  9031. '<',
  9032. formatValue(obj),
  9033. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  9034. ];
  9035. }
  9036. else if (isReadonly(obj)) {
  9037. return [
  9038. 'div',
  9039. {},
  9040. ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'],
  9041. '<',
  9042. formatValue(obj),
  9043. '>'
  9044. ];
  9045. }
  9046. return null;
  9047. },
  9048. hasBody(obj) {
  9049. return obj && obj.__isVue;
  9050. },
  9051. body(obj) {
  9052. if (obj && obj.__isVue) {
  9053. return [
  9054. 'div',
  9055. {},
  9056. ...formatInstance(obj.$)
  9057. ];
  9058. }
  9059. }
  9060. };
  9061. function formatInstance(instance) {
  9062. const blocks = [];
  9063. if (instance.type.props && instance.props) {
  9064. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  9065. }
  9066. if (instance.setupState !== EMPTY_OBJ) {
  9067. blocks.push(createInstanceBlock('setup', instance.setupState));
  9068. }
  9069. if (instance.data !== EMPTY_OBJ) {
  9070. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  9071. }
  9072. const computed = extractKeys(instance, 'computed');
  9073. if (computed) {
  9074. blocks.push(createInstanceBlock('computed', computed));
  9075. }
  9076. const injected = extractKeys(instance, 'inject');
  9077. if (injected) {
  9078. blocks.push(createInstanceBlock('injected', injected));
  9079. }
  9080. blocks.push([
  9081. 'div',
  9082. {},
  9083. [
  9084. 'span',
  9085. {
  9086. style: keywordStyle.style + ';opacity:0.66'
  9087. },
  9088. '$ (internal): '
  9089. ],
  9090. ['object', { object: instance }]
  9091. ]);
  9092. return blocks;
  9093. }
  9094. function createInstanceBlock(type, target) {
  9095. target = extend({}, target);
  9096. if (!Object.keys(target).length) {
  9097. return ['span', {}];
  9098. }
  9099. return [
  9100. 'div',
  9101. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  9102. [
  9103. 'div',
  9104. {
  9105. style: 'color:#476582'
  9106. },
  9107. type
  9108. ],
  9109. [
  9110. 'div',
  9111. {
  9112. style: 'padding-left:1.25em'
  9113. },
  9114. ...Object.keys(target).map(key => {
  9115. return [
  9116. 'div',
  9117. {},
  9118. ['span', keywordStyle, key + ': '],
  9119. formatValue(target[key], false)
  9120. ];
  9121. })
  9122. ]
  9123. ];
  9124. }
  9125. function formatValue(v, asRaw = true) {
  9126. if (typeof v === 'number') {
  9127. return ['span', numberStyle, v];
  9128. }
  9129. else if (typeof v === 'string') {
  9130. return ['span', stringStyle, JSON.stringify(v)];
  9131. }
  9132. else if (typeof v === 'boolean') {
  9133. return ['span', keywordStyle, v];
  9134. }
  9135. else if (isObject(v)) {
  9136. return ['object', { object: asRaw ? toRaw(v) : v }];
  9137. }
  9138. else {
  9139. return ['span', stringStyle, String(v)];
  9140. }
  9141. }
  9142. function extractKeys(instance, type) {
  9143. const Comp = instance.type;
  9144. if (isFunction(Comp)) {
  9145. return;
  9146. }
  9147. const extracted = {};
  9148. for (const key in instance.ctx) {
  9149. if (isKeyOfType(Comp, key, type)) {
  9150. extracted[key] = instance.ctx[key];
  9151. }
  9152. }
  9153. return extracted;
  9154. }
  9155. function isKeyOfType(Comp, key, type) {
  9156. const opts = Comp[type];
  9157. if ((isArray(opts) && opts.includes(key)) ||
  9158. (isObject(opts) && key in opts)) {
  9159. return true;
  9160. }
  9161. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  9162. return true;
  9163. }
  9164. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  9165. return true;
  9166. }
  9167. }
  9168. function genRefFlag(v) {
  9169. if (isShallow(v)) {
  9170. return `ShallowRef`;
  9171. }
  9172. if (v.effect) {
  9173. return `ComputedRef`;
  9174. }
  9175. return `Ref`;
  9176. }
  9177. if (window.devtoolsFormatters) {
  9178. window.devtoolsFormatters.push(formatter);
  9179. }
  9180. else {
  9181. window.devtoolsFormatters = [formatter];
  9182. }
  9183. }
  9184. function withMemo(memo, render, cache, index) {
  9185. const cached = cache[index];
  9186. if (cached && isMemoSame(cached, memo)) {
  9187. return cached;
  9188. }
  9189. const ret = render();
  9190. // shallow clone
  9191. ret.memo = memo.slice();
  9192. return (cache[index] = ret);
  9193. }
  9194. function isMemoSame(cached, memo) {
  9195. const prev = cached.memo;
  9196. if (prev.length != memo.length) {
  9197. return false;
  9198. }
  9199. for (let i = 0; i < prev.length; i++) {
  9200. if (hasChanged(prev[i], memo[i])) {
  9201. return false;
  9202. }
  9203. }
  9204. // make sure to let parent block track it when returning cached
  9205. if (isBlockTreeEnabled > 0 && currentBlock) {
  9206. currentBlock.push(cached);
  9207. }
  9208. return true;
  9209. }
  9210. // Core API ------------------------------------------------------------------
  9211. const version = "3.2.37";
  9212. /**
  9213. * SSR utils for \@vue/server-renderer. Only exposed in ssr-possible builds.
  9214. * @internal
  9215. */
  9216. const ssrUtils = (null);
  9217. /**
  9218. * @internal only exposed in compat builds
  9219. */
  9220. const resolveFilter = null;
  9221. /**
  9222. * @internal only exposed in compat builds.
  9223. */
  9224. const compatUtils = (null);
  9225. const svgNS = 'http://www.w3.org/2000/svg';
  9226. const doc = (typeof document !== 'undefined' ? document : null);
  9227. const templateContainer = doc && /*#__PURE__*/ doc.createElement('template');
  9228. const nodeOps = {
  9229. insert: (child, parent, anchor) => {
  9230. parent.insertBefore(child, anchor || null);
  9231. },
  9232. remove: child => {
  9233. const parent = child.parentNode;
  9234. if (parent) {
  9235. parent.removeChild(child);
  9236. }
  9237. },
  9238. createElement: (tag, isSVG, is, props) => {
  9239. const el = isSVG
  9240. ? doc.createElementNS(svgNS, tag)
  9241. : doc.createElement(tag, is ? { is } : undefined);
  9242. if (tag === 'select' && props && props.multiple != null) {
  9243. el.setAttribute('multiple', props.multiple);
  9244. }
  9245. return el;
  9246. },
  9247. createText: text => doc.createTextNode(text),
  9248. createComment: text => doc.createComment(text),
  9249. setText: (node, text) => {
  9250. node.nodeValue = text;
  9251. },
  9252. setElementText: (el, text) => {
  9253. el.textContent = text;
  9254. },
  9255. parentNode: node => node.parentNode,
  9256. nextSibling: node => node.nextSibling,
  9257. querySelector: selector => doc.querySelector(selector),
  9258. setScopeId(el, id) {
  9259. el.setAttribute(id, '');
  9260. },
  9261. cloneNode(el) {
  9262. const cloned = el.cloneNode(true);
  9263. // #3072
  9264. // - in `patchDOMProp`, we store the actual value in the `el._value` property.
  9265. // - normally, elements using `:value` bindings will not be hoisted, but if
  9266. // the bound value is a constant, e.g. `:value="true"` - they do get
  9267. // hoisted.
  9268. // - in production, hoisted nodes are cloned when subsequent inserts, but
  9269. // cloneNode() does not copy the custom property we attached.
  9270. // - This may need to account for other custom DOM properties we attach to
  9271. // elements in addition to `_value` in the future.
  9272. if (`_value` in el) {
  9273. cloned._value = el._value;
  9274. }
  9275. return cloned;
  9276. },
  9277. // __UNSAFE__
  9278. // Reason: innerHTML.
  9279. // Static content here can only come from compiled templates.
  9280. // As long as the user only uses trusted templates, this is safe.
  9281. insertStaticContent(content, parent, anchor, isSVG, start, end) {
  9282. // <parent> before | first ... last | anchor </parent>
  9283. const before = anchor ? anchor.previousSibling : parent.lastChild;
  9284. // #5308 can only take cached path if:
  9285. // - has a single root node
  9286. // - nextSibling info is still available
  9287. if (start && (start === end || start.nextSibling)) {
  9288. // cached
  9289. while (true) {
  9290. parent.insertBefore(start.cloneNode(true), anchor);
  9291. if (start === end || !(start = start.nextSibling))
  9292. break;
  9293. }
  9294. }
  9295. else {
  9296. // fresh insert
  9297. templateContainer.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  9298. const template = templateContainer.content;
  9299. if (isSVG) {
  9300. // remove outer svg wrapper
  9301. const wrapper = template.firstChild;
  9302. while (wrapper.firstChild) {
  9303. template.appendChild(wrapper.firstChild);
  9304. }
  9305. template.removeChild(wrapper);
  9306. }
  9307. parent.insertBefore(template, anchor);
  9308. }
  9309. return [
  9310. // first
  9311. before ? before.nextSibling : parent.firstChild,
  9312. // last
  9313. anchor ? anchor.previousSibling : parent.lastChild
  9314. ];
  9315. }
  9316. };
  9317. // compiler should normalize class + :class bindings on the same element
  9318. // into a single binding ['staticClass', dynamic]
  9319. function patchClass(el, value, isSVG) {
  9320. // directly setting className should be faster than setAttribute in theory
  9321. // if this is an element during a transition, take the temporary transition
  9322. // classes into account.
  9323. const transitionClasses = el._vtc;
  9324. if (transitionClasses) {
  9325. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  9326. }
  9327. if (value == null) {
  9328. el.removeAttribute('class');
  9329. }
  9330. else if (isSVG) {
  9331. el.setAttribute('class', value);
  9332. }
  9333. else {
  9334. el.className = value;
  9335. }
  9336. }
  9337. function patchStyle(el, prev, next) {
  9338. const style = el.style;
  9339. const isCssString = isString(next);
  9340. if (next && !isCssString) {
  9341. for (const key in next) {
  9342. setStyle(style, key, next[key]);
  9343. }
  9344. if (prev && !isString(prev)) {
  9345. for (const key in prev) {
  9346. if (next[key] == null) {
  9347. setStyle(style, key, '');
  9348. }
  9349. }
  9350. }
  9351. }
  9352. else {
  9353. const currentDisplay = style.display;
  9354. if (isCssString) {
  9355. if (prev !== next) {
  9356. style.cssText = next;
  9357. }
  9358. }
  9359. else if (prev) {
  9360. el.removeAttribute('style');
  9361. }
  9362. // indicates that the `display` of the element is controlled by `v-show`,
  9363. // so we always keep the current `display` value regardless of the `style`
  9364. // value, thus handing over control to `v-show`.
  9365. if ('_vod' in el) {
  9366. style.display = currentDisplay;
  9367. }
  9368. }
  9369. }
  9370. const importantRE = /\s*!important$/;
  9371. function setStyle(style, name, val) {
  9372. if (isArray(val)) {
  9373. val.forEach(v => setStyle(style, name, v));
  9374. }
  9375. else {
  9376. if (val == null)
  9377. val = '';
  9378. if (name.startsWith('--')) {
  9379. // custom property definition
  9380. style.setProperty(name, val);
  9381. }
  9382. else {
  9383. const prefixed = autoPrefix(style, name);
  9384. if (importantRE.test(val)) {
  9385. // !important
  9386. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  9387. }
  9388. else {
  9389. style[prefixed] = val;
  9390. }
  9391. }
  9392. }
  9393. }
  9394. const prefixes = ['Webkit', 'Moz', 'ms'];
  9395. const prefixCache = {};
  9396. function autoPrefix(style, rawName) {
  9397. const cached = prefixCache[rawName];
  9398. if (cached) {
  9399. return cached;
  9400. }
  9401. let name = camelize(rawName);
  9402. if (name !== 'filter' && name in style) {
  9403. return (prefixCache[rawName] = name);
  9404. }
  9405. name = capitalize(name);
  9406. for (let i = 0; i < prefixes.length; i++) {
  9407. const prefixed = prefixes[i] + name;
  9408. if (prefixed in style) {
  9409. return (prefixCache[rawName] = prefixed);
  9410. }
  9411. }
  9412. return rawName;
  9413. }
  9414. const xlinkNS = 'http://www.w3.org/1999/xlink';
  9415. function patchAttr(el, key, value, isSVG, instance) {
  9416. if (isSVG && key.startsWith('xlink:')) {
  9417. if (value == null) {
  9418. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  9419. }
  9420. else {
  9421. el.setAttributeNS(xlinkNS, key, value);
  9422. }
  9423. }
  9424. else {
  9425. // note we are only checking boolean attributes that don't have a
  9426. // corresponding dom prop of the same name here.
  9427. const isBoolean = isSpecialBooleanAttr(key);
  9428. if (value == null || (isBoolean && !includeBooleanAttr(value))) {
  9429. el.removeAttribute(key);
  9430. }
  9431. else {
  9432. el.setAttribute(key, isBoolean ? '' : value);
  9433. }
  9434. }
  9435. }
  9436. // __UNSAFE__
  9437. // functions. The user is responsible for using them with only trusted content.
  9438. function patchDOMProp(el, key, value,
  9439. // the following args are passed only due to potential innerHTML/textContent
  9440. // overriding existing VNodes, in which case the old tree must be properly
  9441. // unmounted.
  9442. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  9443. if (key === 'innerHTML' || key === 'textContent') {
  9444. if (prevChildren) {
  9445. unmountChildren(prevChildren, parentComponent, parentSuspense);
  9446. }
  9447. el[key] = value == null ? '' : value;
  9448. return;
  9449. }
  9450. if (key === 'value' &&
  9451. el.tagName !== 'PROGRESS' &&
  9452. // custom elements may use _value internally
  9453. !el.tagName.includes('-')) {
  9454. // store value as _value as well since
  9455. // non-string values will be stringified.
  9456. el._value = value;
  9457. const newValue = value == null ? '' : value;
  9458. if (el.value !== newValue ||
  9459. // #4956: always set for OPTION elements because its value falls back to
  9460. // textContent if no value attribute is present. And setting .value for
  9461. // OPTION has no side effect
  9462. el.tagName === 'OPTION') {
  9463. el.value = newValue;
  9464. }
  9465. if (value == null) {
  9466. el.removeAttribute(key);
  9467. }
  9468. return;
  9469. }
  9470. let needRemove = false;
  9471. if (value === '' || value == null) {
  9472. const type = typeof el[key];
  9473. if (type === 'boolean') {
  9474. // e.g. <select multiple> compiles to { multiple: '' }
  9475. value = includeBooleanAttr(value);
  9476. }
  9477. else if (value == null && type === 'string') {
  9478. // e.g. <div :id="null">
  9479. value = '';
  9480. needRemove = true;
  9481. }
  9482. else if (type === 'number') {
  9483. // e.g. <img :width="null">
  9484. // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
  9485. value = 0;
  9486. needRemove = true;
  9487. }
  9488. }
  9489. // some properties perform value validation and throw,
  9490. // some properties has getter, no setter, will error in 'use strict'
  9491. // eg. <select :type="null"></select> <select :willValidate="null"></select>
  9492. try {
  9493. el[key] = value;
  9494. }
  9495. catch (e) {
  9496. {
  9497. warn$1(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  9498. `value ${value} is invalid.`, e);
  9499. }
  9500. }
  9501. needRemove && el.removeAttribute(key);
  9502. }
  9503. // Async edge case fix requires storing an event listener's attach timestamp.
  9504. const [_getNow, skipTimestampCheck] = /*#__PURE__*/ (() => {
  9505. let _getNow = Date.now;
  9506. let skipTimestampCheck = false;
  9507. if (typeof window !== 'undefined') {
  9508. // Determine what event timestamp the browser is using. Annoyingly, the
  9509. // timestamp can either be hi-res (relative to page load) or low-res
  9510. // (relative to UNIX epoch), so in order to compare time we have to use the
  9511. // same timestamp type when saving the flush timestamp.
  9512. if (Date.now() > document.createEvent('Event').timeStamp) {
  9513. // if the low-res timestamp which is bigger than the event timestamp
  9514. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  9515. // and we need to use the hi-res version for event listeners as well.
  9516. _getNow = performance.now.bind(performance);
  9517. }
  9518. // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
  9519. // and does not fire microtasks in between event propagation, so safe to exclude.
  9520. const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
  9521. skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
  9522. }
  9523. return [_getNow, skipTimestampCheck];
  9524. })();
  9525. // To avoid the overhead of repeatedly calling performance.now(), we cache
  9526. // and use the same timestamp for all event listeners attached in the same tick.
  9527. let cachedNow = 0;
  9528. const p = /*#__PURE__*/ Promise.resolve();
  9529. const reset = () => {
  9530. cachedNow = 0;
  9531. };
  9532. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  9533. function addEventListener(el, event, handler, options) {
  9534. el.addEventListener(event, handler, options);
  9535. }
  9536. function removeEventListener(el, event, handler, options) {
  9537. el.removeEventListener(event, handler, options);
  9538. }
  9539. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  9540. // vei = vue event invokers
  9541. const invokers = el._vei || (el._vei = {});
  9542. const existingInvoker = invokers[rawName];
  9543. if (nextValue && existingInvoker) {
  9544. // patch
  9545. existingInvoker.value = nextValue;
  9546. }
  9547. else {
  9548. const [name, options] = parseName(rawName);
  9549. if (nextValue) {
  9550. // add
  9551. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  9552. addEventListener(el, name, invoker, options);
  9553. }
  9554. else if (existingInvoker) {
  9555. // remove
  9556. removeEventListener(el, name, existingInvoker, options);
  9557. invokers[rawName] = undefined;
  9558. }
  9559. }
  9560. }
  9561. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  9562. function parseName(name) {
  9563. let options;
  9564. if (optionsModifierRE.test(name)) {
  9565. options = {};
  9566. let m;
  9567. while ((m = name.match(optionsModifierRE))) {
  9568. name = name.slice(0, name.length - m[0].length);
  9569. options[m[0].toLowerCase()] = true;
  9570. }
  9571. }
  9572. return [hyphenate(name.slice(2)), options];
  9573. }
  9574. function createInvoker(initialValue, instance) {
  9575. const invoker = (e) => {
  9576. // async edge case #6566: inner click event triggers patch, event handler
  9577. // attached to outer element during patch, and triggered again. This
  9578. // happens because browsers fire microtask ticks between event propagation.
  9579. // the solution is simple: we save the timestamp when a handler is attached,
  9580. // and the handler would only fire if the event passed to it was fired
  9581. // AFTER it was attached.
  9582. const timeStamp = e.timeStamp || _getNow();
  9583. if (skipTimestampCheck || timeStamp >= invoker.attached - 1) {
  9584. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  9585. }
  9586. };
  9587. invoker.value = initialValue;
  9588. invoker.attached = getNow();
  9589. return invoker;
  9590. }
  9591. function patchStopImmediatePropagation(e, value) {
  9592. if (isArray(value)) {
  9593. const originalStop = e.stopImmediatePropagation;
  9594. e.stopImmediatePropagation = () => {
  9595. originalStop.call(e);
  9596. e._stopped = true;
  9597. };
  9598. return value.map(fn => (e) => !e._stopped && fn && fn(e));
  9599. }
  9600. else {
  9601. return value;
  9602. }
  9603. }
  9604. const nativeOnRE = /^on[a-z]/;
  9605. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  9606. if (key === 'class') {
  9607. patchClass(el, nextValue, isSVG);
  9608. }
  9609. else if (key === 'style') {
  9610. patchStyle(el, prevValue, nextValue);
  9611. }
  9612. else if (isOn(key)) {
  9613. // ignore v-model listeners
  9614. if (!isModelListener(key)) {
  9615. patchEvent(el, key, prevValue, nextValue, parentComponent);
  9616. }
  9617. }
  9618. else if (key[0] === '.'
  9619. ? ((key = key.slice(1)), true)
  9620. : key[0] === '^'
  9621. ? ((key = key.slice(1)), false)
  9622. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  9623. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  9624. }
  9625. else {
  9626. // special case for <input v-model type="checkbox"> with
  9627. // :true-value & :false-value
  9628. // store value as dom properties since non-string values will be
  9629. // stringified.
  9630. if (key === 'true-value') {
  9631. el._trueValue = nextValue;
  9632. }
  9633. else if (key === 'false-value') {
  9634. el._falseValue = nextValue;
  9635. }
  9636. patchAttr(el, key, nextValue, isSVG);
  9637. }
  9638. };
  9639. function shouldSetAsProp(el, key, value, isSVG) {
  9640. if (isSVG) {
  9641. // most keys must be set as attribute on svg elements to work
  9642. // ...except innerHTML & textContent
  9643. if (key === 'innerHTML' || key === 'textContent') {
  9644. return true;
  9645. }
  9646. // or native onclick with function values
  9647. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  9648. return true;
  9649. }
  9650. return false;
  9651. }
  9652. // these are enumerated attrs, however their corresponding DOM properties
  9653. // are actually booleans - this leads to setting it with a string "false"
  9654. // value leading it to be coerced to `true`, so we need to always treat
  9655. // them as attributes.
  9656. // Note that `contentEditable` doesn't have this problem: its DOM
  9657. // property is also enumerated string values.
  9658. if (key === 'spellcheck' || key === 'draggable' || key === 'translate') {
  9659. return false;
  9660. }
  9661. // #1787, #2840 form property on form elements is readonly and must be set as
  9662. // attribute.
  9663. if (key === 'form') {
  9664. return false;
  9665. }
  9666. // #1526 <input list> must be set as attribute
  9667. if (key === 'list' && el.tagName === 'INPUT') {
  9668. return false;
  9669. }
  9670. // #2766 <textarea type> must be set as attribute
  9671. if (key === 'type' && el.tagName === 'TEXTAREA') {
  9672. return false;
  9673. }
  9674. // native onclick with string value, must be set as attribute
  9675. if (nativeOnRE.test(key) && isString(value)) {
  9676. return false;
  9677. }
  9678. return key in el;
  9679. }
  9680. function defineCustomElement(options, hydrate) {
  9681. const Comp = defineComponent(options);
  9682. class VueCustomElement extends VueElement {
  9683. constructor(initialProps) {
  9684. super(Comp, initialProps, hydrate);
  9685. }
  9686. }
  9687. VueCustomElement.def = Comp;
  9688. return VueCustomElement;
  9689. }
  9690. const defineSSRCustomElement = ((options) => {
  9691. // @ts-ignore
  9692. return defineCustomElement(options, hydrate);
  9693. });
  9694. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  9695. });
  9696. class VueElement extends BaseClass {
  9697. constructor(_def, _props = {}, hydrate) {
  9698. super();
  9699. this._def = _def;
  9700. this._props = _props;
  9701. /**
  9702. * @internal
  9703. */
  9704. this._instance = null;
  9705. this._connected = false;
  9706. this._resolved = false;
  9707. this._numberProps = null;
  9708. if (this.shadowRoot && hydrate) {
  9709. hydrate(this._createVNode(), this.shadowRoot);
  9710. }
  9711. else {
  9712. if (this.shadowRoot) {
  9713. warn$1(`Custom element has pre-rendered declarative shadow root but is not ` +
  9714. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  9715. }
  9716. this.attachShadow({ mode: 'open' });
  9717. }
  9718. }
  9719. connectedCallback() {
  9720. this._connected = true;
  9721. if (!this._instance) {
  9722. this._resolveDef();
  9723. }
  9724. }
  9725. disconnectedCallback() {
  9726. this._connected = false;
  9727. nextTick(() => {
  9728. if (!this._connected) {
  9729. render(null, this.shadowRoot);
  9730. this._instance = null;
  9731. }
  9732. });
  9733. }
  9734. /**
  9735. * resolve inner component definition (handle possible async component)
  9736. */
  9737. _resolveDef() {
  9738. if (this._resolved) {
  9739. return;
  9740. }
  9741. this._resolved = true;
  9742. // set initial attrs
  9743. for (let i = 0; i < this.attributes.length; i++) {
  9744. this._setAttr(this.attributes[i].name);
  9745. }
  9746. // watch future attr changes
  9747. new MutationObserver(mutations => {
  9748. for (const m of mutations) {
  9749. this._setAttr(m.attributeName);
  9750. }
  9751. }).observe(this, { attributes: true });
  9752. const resolve = (def) => {
  9753. const { props, styles } = def;
  9754. const hasOptions = !isArray(props);
  9755. const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
  9756. // cast Number-type props set before resolve
  9757. let numberProps;
  9758. if (hasOptions) {
  9759. for (const key in this._props) {
  9760. const opt = props[key];
  9761. if (opt === Number || (opt && opt.type === Number)) {
  9762. this._props[key] = toNumber(this._props[key]);
  9763. (numberProps || (numberProps = Object.create(null)))[key] = true;
  9764. }
  9765. }
  9766. }
  9767. this._numberProps = numberProps;
  9768. // check if there are props set pre-upgrade or connect
  9769. for (const key of Object.keys(this)) {
  9770. if (key[0] !== '_') {
  9771. this._setProp(key, this[key], true, false);
  9772. }
  9773. }
  9774. // defining getter/setters on prototype
  9775. for (const key of rawKeys.map(camelize)) {
  9776. Object.defineProperty(this, key, {
  9777. get() {
  9778. return this._getProp(key);
  9779. },
  9780. set(val) {
  9781. this._setProp(key, val);
  9782. }
  9783. });
  9784. }
  9785. // apply CSS
  9786. this._applyStyles(styles);
  9787. // initial render
  9788. this._update();
  9789. };
  9790. const asyncDef = this._def.__asyncLoader;
  9791. if (asyncDef) {
  9792. asyncDef().then(resolve);
  9793. }
  9794. else {
  9795. resolve(this._def);
  9796. }
  9797. }
  9798. _setAttr(key) {
  9799. let value = this.getAttribute(key);
  9800. if (this._numberProps && this._numberProps[key]) {
  9801. value = toNumber(value);
  9802. }
  9803. this._setProp(camelize(key), value, false);
  9804. }
  9805. /**
  9806. * @internal
  9807. */
  9808. _getProp(key) {
  9809. return this._props[key];
  9810. }
  9811. /**
  9812. * @internal
  9813. */
  9814. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  9815. if (val !== this._props[key]) {
  9816. this._props[key] = val;
  9817. if (shouldUpdate && this._instance) {
  9818. this._update();
  9819. }
  9820. // reflect
  9821. if (shouldReflect) {
  9822. if (val === true) {
  9823. this.setAttribute(hyphenate(key), '');
  9824. }
  9825. else if (typeof val === 'string' || typeof val === 'number') {
  9826. this.setAttribute(hyphenate(key), val + '');
  9827. }
  9828. else if (!val) {
  9829. this.removeAttribute(hyphenate(key));
  9830. }
  9831. }
  9832. }
  9833. }
  9834. _update() {
  9835. render(this._createVNode(), this.shadowRoot);
  9836. }
  9837. _createVNode() {
  9838. const vnode = createVNode(this._def, extend({}, this._props));
  9839. if (!this._instance) {
  9840. vnode.ce = instance => {
  9841. this._instance = instance;
  9842. instance.isCE = true;
  9843. // HMR
  9844. {
  9845. instance.ceReload = newStyles => {
  9846. // always reset styles
  9847. if (this._styles) {
  9848. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  9849. this._styles.length = 0;
  9850. }
  9851. this._applyStyles(newStyles);
  9852. // if this is an async component, ceReload is called from the inner
  9853. // component so no need to reload the async wrapper
  9854. if (!this._def.__asyncLoader) {
  9855. // reload
  9856. this._instance = null;
  9857. this._update();
  9858. }
  9859. };
  9860. }
  9861. // intercept emit
  9862. instance.emit = (event, ...args) => {
  9863. this.dispatchEvent(new CustomEvent(event, {
  9864. detail: args
  9865. }));
  9866. };
  9867. // locate nearest Vue custom element parent for provide/inject
  9868. let parent = this;
  9869. while ((parent =
  9870. parent && (parent.parentNode || parent.host))) {
  9871. if (parent instanceof VueElement) {
  9872. instance.parent = parent._instance;
  9873. break;
  9874. }
  9875. }
  9876. };
  9877. }
  9878. return vnode;
  9879. }
  9880. _applyStyles(styles) {
  9881. if (styles) {
  9882. styles.forEach(css => {
  9883. const s = document.createElement('style');
  9884. s.textContent = css;
  9885. this.shadowRoot.appendChild(s);
  9886. // record for HMR
  9887. {
  9888. (this._styles || (this._styles = [])).push(s);
  9889. }
  9890. });
  9891. }
  9892. }
  9893. }
  9894. function useCssModule(name = '$style') {
  9895. /* istanbul ignore else */
  9896. {
  9897. const instance = getCurrentInstance();
  9898. if (!instance) {
  9899. warn$1(`useCssModule must be called inside setup()`);
  9900. return EMPTY_OBJ;
  9901. }
  9902. const modules = instance.type.__cssModules;
  9903. if (!modules) {
  9904. warn$1(`Current instance does not have CSS modules injected.`);
  9905. return EMPTY_OBJ;
  9906. }
  9907. const mod = modules[name];
  9908. if (!mod) {
  9909. warn$1(`Current instance does not have CSS module named "${name}".`);
  9910. return EMPTY_OBJ;
  9911. }
  9912. return mod;
  9913. }
  9914. }
  9915. /**
  9916. * Runtime helper for SFC's CSS variable injection feature.
  9917. * @private
  9918. */
  9919. function useCssVars(getter) {
  9920. const instance = getCurrentInstance();
  9921. /* istanbul ignore next */
  9922. if (!instance) {
  9923. warn$1(`useCssVars is called without current active component instance.`);
  9924. return;
  9925. }
  9926. const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
  9927. watchPostEffect(setVars);
  9928. onMounted(() => {
  9929. const ob = new MutationObserver(setVars);
  9930. ob.observe(instance.subTree.el.parentNode, { childList: true });
  9931. onUnmounted(() => ob.disconnect());
  9932. });
  9933. }
  9934. function setVarsOnVNode(vnode, vars) {
  9935. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  9936. const suspense = vnode.suspense;
  9937. vnode = suspense.activeBranch;
  9938. if (suspense.pendingBranch && !suspense.isHydrating) {
  9939. suspense.effects.push(() => {
  9940. setVarsOnVNode(suspense.activeBranch, vars);
  9941. });
  9942. }
  9943. }
  9944. // drill down HOCs until it's a non-component vnode
  9945. while (vnode.component) {
  9946. vnode = vnode.component.subTree;
  9947. }
  9948. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  9949. setVarsOnNode(vnode.el, vars);
  9950. }
  9951. else if (vnode.type === Fragment) {
  9952. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  9953. }
  9954. else if (vnode.type === Static) {
  9955. let { el, anchor } = vnode;
  9956. while (el) {
  9957. setVarsOnNode(el, vars);
  9958. if (el === anchor)
  9959. break;
  9960. el = el.nextSibling;
  9961. }
  9962. }
  9963. }
  9964. function setVarsOnNode(el, vars) {
  9965. if (el.nodeType === 1) {
  9966. const style = el.style;
  9967. for (const key in vars) {
  9968. style.setProperty(`--${key}`, vars[key]);
  9969. }
  9970. }
  9971. }
  9972. const TRANSITION = 'transition';
  9973. const ANIMATION = 'animation';
  9974. // DOM Transition is a higher-order-component based on the platform-agnostic
  9975. // base Transition component, with DOM-specific logic.
  9976. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  9977. Transition.displayName = 'Transition';
  9978. const DOMTransitionPropsValidators = {
  9979. name: String,
  9980. type: String,
  9981. css: {
  9982. type: Boolean,
  9983. default: true
  9984. },
  9985. duration: [String, Number, Object],
  9986. enterFromClass: String,
  9987. enterActiveClass: String,
  9988. enterToClass: String,
  9989. appearFromClass: String,
  9990. appearActiveClass: String,
  9991. appearToClass: String,
  9992. leaveFromClass: String,
  9993. leaveActiveClass: String,
  9994. leaveToClass: String
  9995. };
  9996. const TransitionPropsValidators = (Transition.props =
  9997. /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  9998. /**
  9999. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  10000. * with custom HOCs.
  10001. */
  10002. const callHook$1 = (hook, args = []) => {
  10003. if (isArray(hook)) {
  10004. hook.forEach(h => h(...args));
  10005. }
  10006. else if (hook) {
  10007. hook(...args);
  10008. }
  10009. };
  10010. /**
  10011. * Check if a hook expects a callback (2nd arg), which means the user
  10012. * intends to explicitly control the end of the transition.
  10013. */
  10014. const hasExplicitCallback = (hook) => {
  10015. return hook
  10016. ? isArray(hook)
  10017. ? hook.some(h => h.length > 1)
  10018. : hook.length > 1
  10019. : false;
  10020. };
  10021. function resolveTransitionProps(rawProps) {
  10022. const baseProps = {};
  10023. for (const key in rawProps) {
  10024. if (!(key in DOMTransitionPropsValidators)) {
  10025. baseProps[key] = rawProps[key];
  10026. }
  10027. }
  10028. if (rawProps.css === false) {
  10029. return baseProps;
  10030. }
  10031. const { name = 'v', type, 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;
  10032. const durations = normalizeDuration(duration);
  10033. const enterDuration = durations && durations[0];
  10034. const leaveDuration = durations && durations[1];
  10035. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  10036. const finishEnter = (el, isAppear, done) => {
  10037. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10038. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  10039. done && done();
  10040. };
  10041. const finishLeave = (el, done) => {
  10042. el._isLeaving = false;
  10043. removeTransitionClass(el, leaveFromClass);
  10044. removeTransitionClass(el, leaveToClass);
  10045. removeTransitionClass(el, leaveActiveClass);
  10046. done && done();
  10047. };
  10048. const makeEnterHook = (isAppear) => {
  10049. return (el, done) => {
  10050. const hook = isAppear ? onAppear : onEnter;
  10051. const resolve = () => finishEnter(el, isAppear, done);
  10052. callHook$1(hook, [el, resolve]);
  10053. nextFrame(() => {
  10054. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  10055. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  10056. if (!hasExplicitCallback(hook)) {
  10057. whenTransitionEnds(el, type, enterDuration, resolve);
  10058. }
  10059. });
  10060. };
  10061. };
  10062. return extend(baseProps, {
  10063. onBeforeEnter(el) {
  10064. callHook$1(onBeforeEnter, [el]);
  10065. addTransitionClass(el, enterFromClass);
  10066. addTransitionClass(el, enterActiveClass);
  10067. },
  10068. onBeforeAppear(el) {
  10069. callHook$1(onBeforeAppear, [el]);
  10070. addTransitionClass(el, appearFromClass);
  10071. addTransitionClass(el, appearActiveClass);
  10072. },
  10073. onEnter: makeEnterHook(false),
  10074. onAppear: makeEnterHook(true),
  10075. onLeave(el, done) {
  10076. el._isLeaving = true;
  10077. const resolve = () => finishLeave(el, done);
  10078. addTransitionClass(el, leaveFromClass);
  10079. // force reflow so *-leave-from classes immediately take effect (#2593)
  10080. forceReflow();
  10081. addTransitionClass(el, leaveActiveClass);
  10082. nextFrame(() => {
  10083. if (!el._isLeaving) {
  10084. // cancelled
  10085. return;
  10086. }
  10087. removeTransitionClass(el, leaveFromClass);
  10088. addTransitionClass(el, leaveToClass);
  10089. if (!hasExplicitCallback(onLeave)) {
  10090. whenTransitionEnds(el, type, leaveDuration, resolve);
  10091. }
  10092. });
  10093. callHook$1(onLeave, [el, resolve]);
  10094. },
  10095. onEnterCancelled(el) {
  10096. finishEnter(el, false);
  10097. callHook$1(onEnterCancelled, [el]);
  10098. },
  10099. onAppearCancelled(el) {
  10100. finishEnter(el, true);
  10101. callHook$1(onAppearCancelled, [el]);
  10102. },
  10103. onLeaveCancelled(el) {
  10104. finishLeave(el);
  10105. callHook$1(onLeaveCancelled, [el]);
  10106. }
  10107. });
  10108. }
  10109. function normalizeDuration(duration) {
  10110. if (duration == null) {
  10111. return null;
  10112. }
  10113. else if (isObject(duration)) {
  10114. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  10115. }
  10116. else {
  10117. const n = NumberOf(duration);
  10118. return [n, n];
  10119. }
  10120. }
  10121. function NumberOf(val) {
  10122. const res = toNumber(val);
  10123. validateDuration(res);
  10124. return res;
  10125. }
  10126. function validateDuration(val) {
  10127. if (typeof val !== 'number') {
  10128. warn$1(`<transition> explicit duration is not a valid number - ` +
  10129. `got ${JSON.stringify(val)}.`);
  10130. }
  10131. else if (isNaN(val)) {
  10132. warn$1(`<transition> explicit duration is NaN - ` +
  10133. 'the duration expression might be incorrect.');
  10134. }
  10135. }
  10136. function addTransitionClass(el, cls) {
  10137. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  10138. (el._vtc ||
  10139. (el._vtc = new Set())).add(cls);
  10140. }
  10141. function removeTransitionClass(el, cls) {
  10142. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  10143. const { _vtc } = el;
  10144. if (_vtc) {
  10145. _vtc.delete(cls);
  10146. if (!_vtc.size) {
  10147. el._vtc = undefined;
  10148. }
  10149. }
  10150. }
  10151. function nextFrame(cb) {
  10152. requestAnimationFrame(() => {
  10153. requestAnimationFrame(cb);
  10154. });
  10155. }
  10156. let endId = 0;
  10157. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  10158. const id = (el._endId = ++endId);
  10159. const resolveIfNotStale = () => {
  10160. if (id === el._endId) {
  10161. resolve();
  10162. }
  10163. };
  10164. if (explicitTimeout) {
  10165. return setTimeout(resolveIfNotStale, explicitTimeout);
  10166. }
  10167. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  10168. if (!type) {
  10169. return resolve();
  10170. }
  10171. const endEvent = type + 'end';
  10172. let ended = 0;
  10173. const end = () => {
  10174. el.removeEventListener(endEvent, onEnd);
  10175. resolveIfNotStale();
  10176. };
  10177. const onEnd = (e) => {
  10178. if (e.target === el && ++ended >= propCount) {
  10179. end();
  10180. }
  10181. };
  10182. setTimeout(() => {
  10183. if (ended < propCount) {
  10184. end();
  10185. }
  10186. }, timeout + 1);
  10187. el.addEventListener(endEvent, onEnd);
  10188. }
  10189. function getTransitionInfo(el, expectedType) {
  10190. const styles = window.getComputedStyle(el);
  10191. // JSDOM may return undefined for transition properties
  10192. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  10193. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  10194. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  10195. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  10196. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  10197. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  10198. const animationTimeout = getTimeout(animationDelays, animationDurations);
  10199. let type = null;
  10200. let timeout = 0;
  10201. let propCount = 0;
  10202. /* istanbul ignore if */
  10203. if (expectedType === TRANSITION) {
  10204. if (transitionTimeout > 0) {
  10205. type = TRANSITION;
  10206. timeout = transitionTimeout;
  10207. propCount = transitionDurations.length;
  10208. }
  10209. }
  10210. else if (expectedType === ANIMATION) {
  10211. if (animationTimeout > 0) {
  10212. type = ANIMATION;
  10213. timeout = animationTimeout;
  10214. propCount = animationDurations.length;
  10215. }
  10216. }
  10217. else {
  10218. timeout = Math.max(transitionTimeout, animationTimeout);
  10219. type =
  10220. timeout > 0
  10221. ? transitionTimeout > animationTimeout
  10222. ? TRANSITION
  10223. : ANIMATION
  10224. : null;
  10225. propCount = type
  10226. ? type === TRANSITION
  10227. ? transitionDurations.length
  10228. : animationDurations.length
  10229. : 0;
  10230. }
  10231. const hasTransform = type === TRANSITION &&
  10232. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  10233. return {
  10234. type,
  10235. timeout,
  10236. propCount,
  10237. hasTransform
  10238. };
  10239. }
  10240. function getTimeout(delays, durations) {
  10241. while (delays.length < durations.length) {
  10242. delays = delays.concat(delays);
  10243. }
  10244. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  10245. }
  10246. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  10247. // numbers in a locale-dependent way, using a comma instead of a dot.
  10248. // If comma is not replaced with a dot, the input will be rounded down
  10249. // (i.e. acting as a floor function) causing unexpected behaviors
  10250. function toMs(s) {
  10251. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  10252. }
  10253. // synchronously force layout to put elements into a certain state
  10254. function forceReflow() {
  10255. return document.body.offsetHeight;
  10256. }
  10257. const positionMap = new WeakMap();
  10258. const newPositionMap = new WeakMap();
  10259. const TransitionGroupImpl = {
  10260. name: 'TransitionGroup',
  10261. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  10262. tag: String,
  10263. moveClass: String
  10264. }),
  10265. setup(props, { slots }) {
  10266. const instance = getCurrentInstance();
  10267. const state = useTransitionState();
  10268. let prevChildren;
  10269. let children;
  10270. onUpdated(() => {
  10271. // children is guaranteed to exist after initial render
  10272. if (!prevChildren.length) {
  10273. return;
  10274. }
  10275. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  10276. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  10277. return;
  10278. }
  10279. // we divide the work into three loops to avoid mixing DOM reads and writes
  10280. // in each iteration - which helps prevent layout thrashing.
  10281. prevChildren.forEach(callPendingCbs);
  10282. prevChildren.forEach(recordPosition);
  10283. const movedChildren = prevChildren.filter(applyTranslation);
  10284. // force reflow to put everything in position
  10285. forceReflow();
  10286. movedChildren.forEach(c => {
  10287. const el = c.el;
  10288. const style = el.style;
  10289. addTransitionClass(el, moveClass);
  10290. style.transform = style.webkitTransform = style.transitionDuration = '';
  10291. const cb = (el._moveCb = (e) => {
  10292. if (e && e.target !== el) {
  10293. return;
  10294. }
  10295. if (!e || /transform$/.test(e.propertyName)) {
  10296. el.removeEventListener('transitionend', cb);
  10297. el._moveCb = null;
  10298. removeTransitionClass(el, moveClass);
  10299. }
  10300. });
  10301. el.addEventListener('transitionend', cb);
  10302. });
  10303. });
  10304. return () => {
  10305. const rawProps = toRaw(props);
  10306. const cssTransitionProps = resolveTransitionProps(rawProps);
  10307. let tag = rawProps.tag || Fragment;
  10308. prevChildren = children;
  10309. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  10310. for (let i = 0; i < children.length; i++) {
  10311. const child = children[i];
  10312. if (child.key != null) {
  10313. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10314. }
  10315. else {
  10316. warn$1(`<TransitionGroup> children must be keyed.`);
  10317. }
  10318. }
  10319. if (prevChildren) {
  10320. for (let i = 0; i < prevChildren.length; i++) {
  10321. const child = prevChildren[i];
  10322. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  10323. positionMap.set(child, child.el.getBoundingClientRect());
  10324. }
  10325. }
  10326. return createVNode(tag, null, children);
  10327. };
  10328. }
  10329. };
  10330. const TransitionGroup = TransitionGroupImpl;
  10331. function callPendingCbs(c) {
  10332. const el = c.el;
  10333. if (el._moveCb) {
  10334. el._moveCb();
  10335. }
  10336. if (el._enterCb) {
  10337. el._enterCb();
  10338. }
  10339. }
  10340. function recordPosition(c) {
  10341. newPositionMap.set(c, c.el.getBoundingClientRect());
  10342. }
  10343. function applyTranslation(c) {
  10344. const oldPos = positionMap.get(c);
  10345. const newPos = newPositionMap.get(c);
  10346. const dx = oldPos.left - newPos.left;
  10347. const dy = oldPos.top - newPos.top;
  10348. if (dx || dy) {
  10349. const s = c.el.style;
  10350. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  10351. s.transitionDuration = '0s';
  10352. return c;
  10353. }
  10354. }
  10355. function hasCSSTransform(el, root, moveClass) {
  10356. // Detect whether an element with the move class applied has
  10357. // CSS transitions. Since the element may be inside an entering
  10358. // transition at this very moment, we make a clone of it and remove
  10359. // all other transition classes applied to ensure only the move class
  10360. // is applied.
  10361. const clone = el.cloneNode();
  10362. if (el._vtc) {
  10363. el._vtc.forEach(cls => {
  10364. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  10365. });
  10366. }
  10367. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  10368. clone.style.display = 'none';
  10369. const container = (root.nodeType === 1 ? root : root.parentNode);
  10370. container.appendChild(clone);
  10371. const { hasTransform } = getTransitionInfo(clone);
  10372. container.removeChild(clone);
  10373. return hasTransform;
  10374. }
  10375. const getModelAssigner = (vnode) => {
  10376. const fn = vnode.props['onUpdate:modelValue'] ||
  10377. (false );
  10378. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  10379. };
  10380. function onCompositionStart(e) {
  10381. e.target.composing = true;
  10382. }
  10383. function onCompositionEnd(e) {
  10384. const target = e.target;
  10385. if (target.composing) {
  10386. target.composing = false;
  10387. target.dispatchEvent(new Event('input'));
  10388. }
  10389. }
  10390. // We are exporting the v-model runtime directly as vnode hooks so that it can
  10391. // be tree-shaken in case v-model is never used.
  10392. const vModelText = {
  10393. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  10394. el._assign = getModelAssigner(vnode);
  10395. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  10396. addEventListener(el, lazy ? 'change' : 'input', e => {
  10397. if (e.target.composing)
  10398. return;
  10399. let domValue = el.value;
  10400. if (trim) {
  10401. domValue = domValue.trim();
  10402. }
  10403. if (castToNumber) {
  10404. domValue = toNumber(domValue);
  10405. }
  10406. el._assign(domValue);
  10407. });
  10408. if (trim) {
  10409. addEventListener(el, 'change', () => {
  10410. el.value = el.value.trim();
  10411. });
  10412. }
  10413. if (!lazy) {
  10414. addEventListener(el, 'compositionstart', onCompositionStart);
  10415. addEventListener(el, 'compositionend', onCompositionEnd);
  10416. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  10417. // switching focus before confirming composition choice
  10418. // this also fixes the issue where some browsers e.g. iOS Chrome
  10419. // fires "change" instead of "input" on autocomplete.
  10420. addEventListener(el, 'change', onCompositionEnd);
  10421. }
  10422. },
  10423. // set value on mounted so it's after min/max for type="range"
  10424. mounted(el, { value }) {
  10425. el.value = value == null ? '' : value;
  10426. },
  10427. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  10428. el._assign = getModelAssigner(vnode);
  10429. // avoid clearing unresolved text. #2302
  10430. if (el.composing)
  10431. return;
  10432. if (document.activeElement === el && el.type !== 'range') {
  10433. if (lazy) {
  10434. return;
  10435. }
  10436. if (trim && el.value.trim() === value) {
  10437. return;
  10438. }
  10439. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  10440. return;
  10441. }
  10442. }
  10443. const newValue = value == null ? '' : value;
  10444. if (el.value !== newValue) {
  10445. el.value = newValue;
  10446. }
  10447. }
  10448. };
  10449. const vModelCheckbox = {
  10450. // #4096 array checkboxes need to be deep traversed
  10451. deep: true,
  10452. created(el, _, vnode) {
  10453. el._assign = getModelAssigner(vnode);
  10454. addEventListener(el, 'change', () => {
  10455. const modelValue = el._modelValue;
  10456. const elementValue = getValue(el);
  10457. const checked = el.checked;
  10458. const assign = el._assign;
  10459. if (isArray(modelValue)) {
  10460. const index = looseIndexOf(modelValue, elementValue);
  10461. const found = index !== -1;
  10462. if (checked && !found) {
  10463. assign(modelValue.concat(elementValue));
  10464. }
  10465. else if (!checked && found) {
  10466. const filtered = [...modelValue];
  10467. filtered.splice(index, 1);
  10468. assign(filtered);
  10469. }
  10470. }
  10471. else if (isSet(modelValue)) {
  10472. const cloned = new Set(modelValue);
  10473. if (checked) {
  10474. cloned.add(elementValue);
  10475. }
  10476. else {
  10477. cloned.delete(elementValue);
  10478. }
  10479. assign(cloned);
  10480. }
  10481. else {
  10482. assign(getCheckboxValue(el, checked));
  10483. }
  10484. });
  10485. },
  10486. // set initial checked on mount to wait for true-value/false-value
  10487. mounted: setChecked,
  10488. beforeUpdate(el, binding, vnode) {
  10489. el._assign = getModelAssigner(vnode);
  10490. setChecked(el, binding, vnode);
  10491. }
  10492. };
  10493. function setChecked(el, { value, oldValue }, vnode) {
  10494. el._modelValue = value;
  10495. if (isArray(value)) {
  10496. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  10497. }
  10498. else if (isSet(value)) {
  10499. el.checked = value.has(vnode.props.value);
  10500. }
  10501. else if (value !== oldValue) {
  10502. el.checked = looseEqual(value, getCheckboxValue(el, true));
  10503. }
  10504. }
  10505. const vModelRadio = {
  10506. created(el, { value }, vnode) {
  10507. el.checked = looseEqual(value, vnode.props.value);
  10508. el._assign = getModelAssigner(vnode);
  10509. addEventListener(el, 'change', () => {
  10510. el._assign(getValue(el));
  10511. });
  10512. },
  10513. beforeUpdate(el, { value, oldValue }, vnode) {
  10514. el._assign = getModelAssigner(vnode);
  10515. if (value !== oldValue) {
  10516. el.checked = looseEqual(value, vnode.props.value);
  10517. }
  10518. }
  10519. };
  10520. const vModelSelect = {
  10521. // <select multiple> value need to be deep traversed
  10522. deep: true,
  10523. created(el, { value, modifiers: { number } }, vnode) {
  10524. const isSetModel = isSet(value);
  10525. addEventListener(el, 'change', () => {
  10526. const selectedVal = Array.prototype.filter
  10527. .call(el.options, (o) => o.selected)
  10528. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  10529. el._assign(el.multiple
  10530. ? isSetModel
  10531. ? new Set(selectedVal)
  10532. : selectedVal
  10533. : selectedVal[0]);
  10534. });
  10535. el._assign = getModelAssigner(vnode);
  10536. },
  10537. // set value in mounted & updated because <select> relies on its children
  10538. // <option>s.
  10539. mounted(el, { value }) {
  10540. setSelected(el, value);
  10541. },
  10542. beforeUpdate(el, _binding, vnode) {
  10543. el._assign = getModelAssigner(vnode);
  10544. },
  10545. updated(el, { value }) {
  10546. setSelected(el, value);
  10547. }
  10548. };
  10549. function setSelected(el, value) {
  10550. const isMultiple = el.multiple;
  10551. if (isMultiple && !isArray(value) && !isSet(value)) {
  10552. warn$1(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  10553. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  10554. return;
  10555. }
  10556. for (let i = 0, l = el.options.length; i < l; i++) {
  10557. const option = el.options[i];
  10558. const optionValue = getValue(option);
  10559. if (isMultiple) {
  10560. if (isArray(value)) {
  10561. option.selected = looseIndexOf(value, optionValue) > -1;
  10562. }
  10563. else {
  10564. option.selected = value.has(optionValue);
  10565. }
  10566. }
  10567. else {
  10568. if (looseEqual(getValue(option), value)) {
  10569. if (el.selectedIndex !== i)
  10570. el.selectedIndex = i;
  10571. return;
  10572. }
  10573. }
  10574. }
  10575. if (!isMultiple && el.selectedIndex !== -1) {
  10576. el.selectedIndex = -1;
  10577. }
  10578. }
  10579. // retrieve raw value set via :value bindings
  10580. function getValue(el) {
  10581. return '_value' in el ? el._value : el.value;
  10582. }
  10583. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  10584. function getCheckboxValue(el, checked) {
  10585. const key = checked ? '_trueValue' : '_falseValue';
  10586. return key in el ? el[key] : checked;
  10587. }
  10588. const vModelDynamic = {
  10589. created(el, binding, vnode) {
  10590. callModelHook(el, binding, vnode, null, 'created');
  10591. },
  10592. mounted(el, binding, vnode) {
  10593. callModelHook(el, binding, vnode, null, 'mounted');
  10594. },
  10595. beforeUpdate(el, binding, vnode, prevVNode) {
  10596. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  10597. },
  10598. updated(el, binding, vnode, prevVNode) {
  10599. callModelHook(el, binding, vnode, prevVNode, 'updated');
  10600. }
  10601. };
  10602. function resolveDynamicModel(tagName, type) {
  10603. switch (tagName) {
  10604. case 'SELECT':
  10605. return vModelSelect;
  10606. case 'TEXTAREA':
  10607. return vModelText;
  10608. default:
  10609. switch (type) {
  10610. case 'checkbox':
  10611. return vModelCheckbox;
  10612. case 'radio':
  10613. return vModelRadio;
  10614. default:
  10615. return vModelText;
  10616. }
  10617. }
  10618. }
  10619. function callModelHook(el, binding, vnode, prevVNode, hook) {
  10620. const modelToUse = resolveDynamicModel(el.tagName, vnode.props && vnode.props.type);
  10621. const fn = modelToUse[hook];
  10622. fn && fn(el, binding, vnode, prevVNode);
  10623. }
  10624. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  10625. const modifierGuards = {
  10626. stop: e => e.stopPropagation(),
  10627. prevent: e => e.preventDefault(),
  10628. self: e => e.target !== e.currentTarget,
  10629. ctrl: e => !e.ctrlKey,
  10630. shift: e => !e.shiftKey,
  10631. alt: e => !e.altKey,
  10632. meta: e => !e.metaKey,
  10633. left: e => 'button' in e && e.button !== 0,
  10634. middle: e => 'button' in e && e.button !== 1,
  10635. right: e => 'button' in e && e.button !== 2,
  10636. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  10637. };
  10638. /**
  10639. * @private
  10640. */
  10641. const withModifiers = (fn, modifiers) => {
  10642. return (event, ...args) => {
  10643. for (let i = 0; i < modifiers.length; i++) {
  10644. const guard = modifierGuards[modifiers[i]];
  10645. if (guard && guard(event, modifiers))
  10646. return;
  10647. }
  10648. return fn(event, ...args);
  10649. };
  10650. };
  10651. // Kept for 2.x compat.
  10652. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  10653. const keyNames = {
  10654. esc: 'escape',
  10655. space: ' ',
  10656. up: 'arrow-up',
  10657. left: 'arrow-left',
  10658. right: 'arrow-right',
  10659. down: 'arrow-down',
  10660. delete: 'backspace'
  10661. };
  10662. /**
  10663. * @private
  10664. */
  10665. const withKeys = (fn, modifiers) => {
  10666. return (event) => {
  10667. if (!('key' in event)) {
  10668. return;
  10669. }
  10670. const eventKey = hyphenate(event.key);
  10671. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  10672. return fn(event);
  10673. }
  10674. };
  10675. };
  10676. const vShow = {
  10677. beforeMount(el, { value }, { transition }) {
  10678. el._vod = el.style.display === 'none' ? '' : el.style.display;
  10679. if (transition && value) {
  10680. transition.beforeEnter(el);
  10681. }
  10682. else {
  10683. setDisplay(el, value);
  10684. }
  10685. },
  10686. mounted(el, { value }, { transition }) {
  10687. if (transition && value) {
  10688. transition.enter(el);
  10689. }
  10690. },
  10691. updated(el, { value, oldValue }, { transition }) {
  10692. if (!value === !oldValue)
  10693. return;
  10694. if (transition) {
  10695. if (value) {
  10696. transition.beforeEnter(el);
  10697. setDisplay(el, true);
  10698. transition.enter(el);
  10699. }
  10700. else {
  10701. transition.leave(el, () => {
  10702. setDisplay(el, false);
  10703. });
  10704. }
  10705. }
  10706. else {
  10707. setDisplay(el, value);
  10708. }
  10709. },
  10710. beforeUnmount(el, { value }) {
  10711. setDisplay(el, value);
  10712. }
  10713. };
  10714. function setDisplay(el, value) {
  10715. el.style.display = value ? el._vod : 'none';
  10716. }
  10717. const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps);
  10718. // lazy create the renderer - this makes core renderer logic tree-shakable
  10719. // in case the user only imports reactivity utilities from Vue.
  10720. let renderer;
  10721. let enabledHydration = false;
  10722. function ensureRenderer() {
  10723. return (renderer ||
  10724. (renderer = createRenderer(rendererOptions)));
  10725. }
  10726. function ensureHydrationRenderer() {
  10727. renderer = enabledHydration
  10728. ? renderer
  10729. : createHydrationRenderer(rendererOptions);
  10730. enabledHydration = true;
  10731. return renderer;
  10732. }
  10733. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  10734. const render = ((...args) => {
  10735. ensureRenderer().render(...args);
  10736. });
  10737. const hydrate = ((...args) => {
  10738. ensureHydrationRenderer().hydrate(...args);
  10739. });
  10740. const createApp = ((...args) => {
  10741. const app = ensureRenderer().createApp(...args);
  10742. {
  10743. injectNativeTagCheck(app);
  10744. injectCompilerOptionsCheck(app);
  10745. }
  10746. const { mount } = app;
  10747. app.mount = (containerOrSelector) => {
  10748. const container = normalizeContainer(containerOrSelector);
  10749. if (!container)
  10750. return;
  10751. const component = app._component;
  10752. if (!isFunction(component) && !component.render && !component.template) {
  10753. // __UNSAFE__
  10754. // Reason: potential execution of JS expressions in in-DOM template.
  10755. // The user must make sure the in-DOM template is trusted. If it's
  10756. // rendered by the server, the template should not contain any user data.
  10757. component.template = container.innerHTML;
  10758. }
  10759. // clear content before mounting
  10760. container.innerHTML = '';
  10761. const proxy = mount(container, false, container instanceof SVGElement);
  10762. if (container instanceof Element) {
  10763. container.removeAttribute('v-cloak');
  10764. container.setAttribute('data-v-app', '');
  10765. }
  10766. return proxy;
  10767. };
  10768. return app;
  10769. });
  10770. const createSSRApp = ((...args) => {
  10771. const app = ensureHydrationRenderer().createApp(...args);
  10772. {
  10773. injectNativeTagCheck(app);
  10774. injectCompilerOptionsCheck(app);
  10775. }
  10776. const { mount } = app;
  10777. app.mount = (containerOrSelector) => {
  10778. const container = normalizeContainer(containerOrSelector);
  10779. if (container) {
  10780. return mount(container, true, container instanceof SVGElement);
  10781. }
  10782. };
  10783. return app;
  10784. });
  10785. function injectNativeTagCheck(app) {
  10786. // Inject `isNativeTag`
  10787. // this is used for component name validation (dev only)
  10788. Object.defineProperty(app.config, 'isNativeTag', {
  10789. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  10790. writable: false
  10791. });
  10792. }
  10793. // dev only
  10794. function injectCompilerOptionsCheck(app) {
  10795. if (isRuntimeOnly()) {
  10796. const isCustomElement = app.config.isCustomElement;
  10797. Object.defineProperty(app.config, 'isCustomElement', {
  10798. get() {
  10799. return isCustomElement;
  10800. },
  10801. set() {
  10802. warn$1(`The \`isCustomElement\` config option is deprecated. Use ` +
  10803. `\`compilerOptions.isCustomElement\` instead.`);
  10804. }
  10805. });
  10806. const compilerOptions = app.config.compilerOptions;
  10807. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  10808. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  10809. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  10810. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  10811. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  10812. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  10813. `- For vite: pass it via @vitejs/plugin-vue options. See https://github.com/vitejs/vite/tree/main/packages/plugin-vue#example-for-passing-options-to-vuecompiler-dom`;
  10814. Object.defineProperty(app.config, 'compilerOptions', {
  10815. get() {
  10816. warn$1(msg);
  10817. return compilerOptions;
  10818. },
  10819. set() {
  10820. warn$1(msg);
  10821. }
  10822. });
  10823. }
  10824. }
  10825. function normalizeContainer(container) {
  10826. if (isString(container)) {
  10827. const res = document.querySelector(container);
  10828. if (!res) {
  10829. warn$1(`Failed to mount app: mount target selector "${container}" returned null.`);
  10830. }
  10831. return res;
  10832. }
  10833. if (window.ShadowRoot &&
  10834. container instanceof window.ShadowRoot &&
  10835. container.mode === 'closed') {
  10836. warn$1(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  10837. }
  10838. return container;
  10839. }
  10840. /**
  10841. * @internal
  10842. */
  10843. const initDirectivesForSSR = NOOP;
  10844. var runtimeDom = /*#__PURE__*/Object.freeze({
  10845. __proto__: null,
  10846. render: render,
  10847. hydrate: hydrate,
  10848. createApp: createApp,
  10849. createSSRApp: createSSRApp,
  10850. initDirectivesForSSR: initDirectivesForSSR,
  10851. defineCustomElement: defineCustomElement,
  10852. defineSSRCustomElement: defineSSRCustomElement,
  10853. VueElement: VueElement,
  10854. useCssModule: useCssModule,
  10855. useCssVars: useCssVars,
  10856. Transition: Transition,
  10857. TransitionGroup: TransitionGroup,
  10858. vModelText: vModelText,
  10859. vModelCheckbox: vModelCheckbox,
  10860. vModelRadio: vModelRadio,
  10861. vModelSelect: vModelSelect,
  10862. vModelDynamic: vModelDynamic,
  10863. withModifiers: withModifiers,
  10864. withKeys: withKeys,
  10865. vShow: vShow,
  10866. reactive: reactive,
  10867. ref: ref,
  10868. readonly: readonly,
  10869. unref: unref,
  10870. proxyRefs: proxyRefs,
  10871. isRef: isRef,
  10872. toRef: toRef,
  10873. toRefs: toRefs,
  10874. isProxy: isProxy,
  10875. isReactive: isReactive,
  10876. isReadonly: isReadonly,
  10877. isShallow: isShallow,
  10878. customRef: customRef,
  10879. triggerRef: triggerRef,
  10880. shallowRef: shallowRef,
  10881. shallowReactive: shallowReactive,
  10882. shallowReadonly: shallowReadonly,
  10883. markRaw: markRaw,
  10884. toRaw: toRaw,
  10885. effect: effect,
  10886. stop: stop,
  10887. ReactiveEffect: ReactiveEffect,
  10888. effectScope: effectScope,
  10889. EffectScope: EffectScope,
  10890. getCurrentScope: getCurrentScope,
  10891. onScopeDispose: onScopeDispose,
  10892. computed: computed$1,
  10893. watch: watch,
  10894. watchEffect: watchEffect,
  10895. watchPostEffect: watchPostEffect,
  10896. watchSyncEffect: watchSyncEffect,
  10897. onBeforeMount: onBeforeMount,
  10898. onMounted: onMounted,
  10899. onBeforeUpdate: onBeforeUpdate,
  10900. onUpdated: onUpdated,
  10901. onBeforeUnmount: onBeforeUnmount,
  10902. onUnmounted: onUnmounted,
  10903. onActivated: onActivated,
  10904. onDeactivated: onDeactivated,
  10905. onRenderTracked: onRenderTracked,
  10906. onRenderTriggered: onRenderTriggered,
  10907. onErrorCaptured: onErrorCaptured,
  10908. onServerPrefetch: onServerPrefetch,
  10909. provide: provide,
  10910. inject: inject,
  10911. nextTick: nextTick,
  10912. defineComponent: defineComponent,
  10913. defineAsyncComponent: defineAsyncComponent,
  10914. useAttrs: useAttrs,
  10915. useSlots: useSlots,
  10916. defineProps: defineProps,
  10917. defineEmits: defineEmits,
  10918. defineExpose: defineExpose,
  10919. withDefaults: withDefaults,
  10920. mergeDefaults: mergeDefaults,
  10921. createPropsRestProxy: createPropsRestProxy,
  10922. withAsyncContext: withAsyncContext,
  10923. getCurrentInstance: getCurrentInstance,
  10924. h: h,
  10925. createVNode: createVNode,
  10926. cloneVNode: cloneVNode,
  10927. mergeProps: mergeProps,
  10928. isVNode: isVNode,
  10929. Fragment: Fragment,
  10930. Text: Text,
  10931. Comment: Comment,
  10932. Static: Static,
  10933. Teleport: Teleport,
  10934. Suspense: Suspense,
  10935. KeepAlive: KeepAlive,
  10936. BaseTransition: BaseTransition,
  10937. withDirectives: withDirectives,
  10938. useSSRContext: useSSRContext,
  10939. ssrContextKey: ssrContextKey,
  10940. createRenderer: createRenderer,
  10941. createHydrationRenderer: createHydrationRenderer,
  10942. queuePostFlushCb: queuePostFlushCb,
  10943. warn: warn$1,
  10944. handleError: handleError,
  10945. callWithErrorHandling: callWithErrorHandling,
  10946. callWithAsyncErrorHandling: callWithAsyncErrorHandling,
  10947. resolveComponent: resolveComponent,
  10948. resolveDirective: resolveDirective,
  10949. resolveDynamicComponent: resolveDynamicComponent,
  10950. registerRuntimeCompiler: registerRuntimeCompiler,
  10951. isRuntimeOnly: isRuntimeOnly,
  10952. useTransitionState: useTransitionState,
  10953. resolveTransitionHooks: resolveTransitionHooks,
  10954. setTransitionHooks: setTransitionHooks,
  10955. getTransitionRawChildren: getTransitionRawChildren,
  10956. initCustomFormatter: initCustomFormatter,
  10957. get devtools () { return devtools; },
  10958. setDevtoolsHook: setDevtoolsHook,
  10959. withCtx: withCtx,
  10960. pushScopeId: pushScopeId,
  10961. popScopeId: popScopeId,
  10962. withScopeId: withScopeId,
  10963. renderList: renderList,
  10964. toHandlers: toHandlers,
  10965. renderSlot: renderSlot,
  10966. createSlots: createSlots,
  10967. withMemo: withMemo,
  10968. isMemoSame: isMemoSame,
  10969. openBlock: openBlock,
  10970. createBlock: createBlock,
  10971. setBlockTracking: setBlockTracking,
  10972. createTextVNode: createTextVNode,
  10973. createCommentVNode: createCommentVNode,
  10974. createStaticVNode: createStaticVNode,
  10975. createElementVNode: createBaseVNode,
  10976. createElementBlock: createElementBlock,
  10977. guardReactiveProps: guardReactiveProps,
  10978. toDisplayString: toDisplayString,
  10979. camelize: camelize,
  10980. capitalize: capitalize,
  10981. toHandlerKey: toHandlerKey,
  10982. normalizeProps: normalizeProps,
  10983. normalizeClass: normalizeClass,
  10984. normalizeStyle: normalizeStyle,
  10985. transformVNodeArgs: transformVNodeArgs,
  10986. version: version,
  10987. ssrUtils: ssrUtils,
  10988. resolveFilter: resolveFilter,
  10989. compatUtils: compatUtils
  10990. });
  10991. function initDev() {
  10992. {
  10993. {
  10994. console.info(`You are running a development build of Vue.\n` +
  10995. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  10996. }
  10997. initCustomFormatter();
  10998. }
  10999. }
  11000. function defaultOnError(error) {
  11001. throw error;
  11002. }
  11003. function defaultOnWarn(msg) {
  11004. console.warn(`[Vue warn] ${msg.message}`);
  11005. }
  11006. function createCompilerError(code, loc, messages, additionalMessage) {
  11007. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  11008. ;
  11009. const error = new SyntaxError(String(msg));
  11010. error.code = code;
  11011. error.loc = loc;
  11012. return error;
  11013. }
  11014. const errorMessages = {
  11015. // parse errors
  11016. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  11017. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  11018. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  11019. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  11020. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  11021. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  11022. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  11023. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  11024. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  11025. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  11026. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  11027. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  11028. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  11029. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  11030. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  11031. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  11032. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  11033. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  11034. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  11035. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  11036. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  11037. [20 /* UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
  11038. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  11039. // Vue-specific parse errors
  11040. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  11041. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  11042. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  11043. [27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  11044. 'Note that dynamic directive argument cannot contain spaces.',
  11045. [26 /* X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
  11046. // transform errors
  11047. [28 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  11048. [29 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  11049. [30 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  11050. [31 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  11051. [32 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  11052. [33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  11053. [34 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  11054. [35 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  11055. [36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  11056. [37 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  11057. `When there are multiple named slots, all slots should use <template> ` +
  11058. `syntax to avoid scope ambiguity.`,
  11059. [38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  11060. [39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  11061. `default slot. These children will be ignored.`,
  11062. [40 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  11063. [41 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  11064. [42 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  11065. [43 /* X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  11066. [44 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  11067. [45 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  11068. // generic errors
  11069. [46 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  11070. [47 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  11071. [48 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  11072. [49 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
  11073. // just to fulfill types
  11074. [50 /* __EXTEND_POINT__ */]: ``
  11075. };
  11076. const FRAGMENT = Symbol(`Fragment` );
  11077. const TELEPORT = Symbol(`Teleport` );
  11078. const SUSPENSE = Symbol(`Suspense` );
  11079. const KEEP_ALIVE = Symbol(`KeepAlive` );
  11080. const BASE_TRANSITION = Symbol(`BaseTransition` );
  11081. const OPEN_BLOCK = Symbol(`openBlock` );
  11082. const CREATE_BLOCK = Symbol(`createBlock` );
  11083. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  11084. const CREATE_VNODE = Symbol(`createVNode` );
  11085. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  11086. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  11087. const CREATE_TEXT = Symbol(`createTextVNode` );
  11088. const CREATE_STATIC = Symbol(`createStaticVNode` );
  11089. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  11090. const RESOLVE_DYNAMIC_COMPONENT = Symbol(`resolveDynamicComponent` );
  11091. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  11092. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  11093. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  11094. const RENDER_LIST = Symbol(`renderList` );
  11095. const RENDER_SLOT = Symbol(`renderSlot` );
  11096. const CREATE_SLOTS = Symbol(`createSlots` );
  11097. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  11098. const MERGE_PROPS = Symbol(`mergeProps` );
  11099. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  11100. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  11101. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  11102. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  11103. const TO_HANDLERS = Symbol(`toHandlers` );
  11104. const CAMELIZE = Symbol(`camelize` );
  11105. const CAPITALIZE = Symbol(`capitalize` );
  11106. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  11107. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  11108. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  11109. const POP_SCOPE_ID = Symbol(`popScopeId` );
  11110. const WITH_CTX = Symbol(`withCtx` );
  11111. const UNREF = Symbol(`unref` );
  11112. const IS_REF = Symbol(`isRef` );
  11113. const WITH_MEMO = Symbol(`withMemo` );
  11114. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  11115. // Name mapping for runtime helpers that need to be imported from 'vue' in
  11116. // generated code. Make sure these are correctly exported in the runtime!
  11117. // Using `any` here because TS doesn't allow symbols as index type.
  11118. const helperNameMap = {
  11119. [FRAGMENT]: `Fragment`,
  11120. [TELEPORT]: `Teleport`,
  11121. [SUSPENSE]: `Suspense`,
  11122. [KEEP_ALIVE]: `KeepAlive`,
  11123. [BASE_TRANSITION]: `BaseTransition`,
  11124. [OPEN_BLOCK]: `openBlock`,
  11125. [CREATE_BLOCK]: `createBlock`,
  11126. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  11127. [CREATE_VNODE]: `createVNode`,
  11128. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  11129. [CREATE_COMMENT]: `createCommentVNode`,
  11130. [CREATE_TEXT]: `createTextVNode`,
  11131. [CREATE_STATIC]: `createStaticVNode`,
  11132. [RESOLVE_COMPONENT]: `resolveComponent`,
  11133. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  11134. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  11135. [RESOLVE_FILTER]: `resolveFilter`,
  11136. [WITH_DIRECTIVES]: `withDirectives`,
  11137. [RENDER_LIST]: `renderList`,
  11138. [RENDER_SLOT]: `renderSlot`,
  11139. [CREATE_SLOTS]: `createSlots`,
  11140. [TO_DISPLAY_STRING]: `toDisplayString`,
  11141. [MERGE_PROPS]: `mergeProps`,
  11142. [NORMALIZE_CLASS]: `normalizeClass`,
  11143. [NORMALIZE_STYLE]: `normalizeStyle`,
  11144. [NORMALIZE_PROPS]: `normalizeProps`,
  11145. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  11146. [TO_HANDLERS]: `toHandlers`,
  11147. [CAMELIZE]: `camelize`,
  11148. [CAPITALIZE]: `capitalize`,
  11149. [TO_HANDLER_KEY]: `toHandlerKey`,
  11150. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  11151. [PUSH_SCOPE_ID]: `pushScopeId`,
  11152. [POP_SCOPE_ID]: `popScopeId`,
  11153. [WITH_CTX]: `withCtx`,
  11154. [UNREF]: `unref`,
  11155. [IS_REF]: `isRef`,
  11156. [WITH_MEMO]: `withMemo`,
  11157. [IS_MEMO_SAME]: `isMemoSame`
  11158. };
  11159. function registerRuntimeHelpers(helpers) {
  11160. Object.getOwnPropertySymbols(helpers).forEach(s => {
  11161. helperNameMap[s] = helpers[s];
  11162. });
  11163. }
  11164. // AST Utilities ---------------------------------------------------------------
  11165. // Some expressions, e.g. sequence and conditional expressions, are never
  11166. // associated with template nodes, so their source locations are just a stub.
  11167. // Container types like CompoundExpression also don't need a real location.
  11168. const locStub = {
  11169. source: '',
  11170. start: { line: 1, column: 1, offset: 0 },
  11171. end: { line: 1, column: 1, offset: 0 }
  11172. };
  11173. function createRoot(children, loc = locStub) {
  11174. return {
  11175. type: 0 /* ROOT */,
  11176. children,
  11177. helpers: [],
  11178. components: [],
  11179. directives: [],
  11180. hoists: [],
  11181. imports: [],
  11182. cached: 0,
  11183. temps: 0,
  11184. codegenNode: undefined,
  11185. loc
  11186. };
  11187. }
  11188. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  11189. if (context) {
  11190. if (isBlock) {
  11191. context.helper(OPEN_BLOCK);
  11192. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  11193. }
  11194. else {
  11195. context.helper(getVNodeHelper(context.inSSR, isComponent));
  11196. }
  11197. if (directives) {
  11198. context.helper(WITH_DIRECTIVES);
  11199. }
  11200. }
  11201. return {
  11202. type: 13 /* VNODE_CALL */,
  11203. tag,
  11204. props,
  11205. children,
  11206. patchFlag,
  11207. dynamicProps,
  11208. directives,
  11209. isBlock,
  11210. disableTracking,
  11211. isComponent,
  11212. loc
  11213. };
  11214. }
  11215. function createArrayExpression(elements, loc = locStub) {
  11216. return {
  11217. type: 17 /* JS_ARRAY_EXPRESSION */,
  11218. loc,
  11219. elements
  11220. };
  11221. }
  11222. function createObjectExpression(properties, loc = locStub) {
  11223. return {
  11224. type: 15 /* JS_OBJECT_EXPRESSION */,
  11225. loc,
  11226. properties
  11227. };
  11228. }
  11229. function createObjectProperty(key, value) {
  11230. return {
  11231. type: 16 /* JS_PROPERTY */,
  11232. loc: locStub,
  11233. key: isString(key) ? createSimpleExpression(key, true) : key,
  11234. value
  11235. };
  11236. }
  11237. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
  11238. return {
  11239. type: 4 /* SIMPLE_EXPRESSION */,
  11240. loc,
  11241. content,
  11242. isStatic,
  11243. constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
  11244. };
  11245. }
  11246. function createCompoundExpression(children, loc = locStub) {
  11247. return {
  11248. type: 8 /* COMPOUND_EXPRESSION */,
  11249. loc,
  11250. children
  11251. };
  11252. }
  11253. function createCallExpression(callee, args = [], loc = locStub) {
  11254. return {
  11255. type: 14 /* JS_CALL_EXPRESSION */,
  11256. loc,
  11257. callee,
  11258. arguments: args
  11259. };
  11260. }
  11261. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  11262. return {
  11263. type: 18 /* JS_FUNCTION_EXPRESSION */,
  11264. params,
  11265. returns,
  11266. newline,
  11267. isSlot,
  11268. loc
  11269. };
  11270. }
  11271. function createConditionalExpression(test, consequent, alternate, newline = true) {
  11272. return {
  11273. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  11274. test,
  11275. consequent,
  11276. alternate,
  11277. newline,
  11278. loc: locStub
  11279. };
  11280. }
  11281. function createCacheExpression(index, value, isVNode = false) {
  11282. return {
  11283. type: 20 /* JS_CACHE_EXPRESSION */,
  11284. index,
  11285. value,
  11286. isVNode,
  11287. loc: locStub
  11288. };
  11289. }
  11290. function createBlockStatement(body) {
  11291. return {
  11292. type: 21 /* JS_BLOCK_STATEMENT */,
  11293. body,
  11294. loc: locStub
  11295. };
  11296. }
  11297. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  11298. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  11299. function isCoreComponent(tag) {
  11300. if (isBuiltInType(tag, 'Teleport')) {
  11301. return TELEPORT;
  11302. }
  11303. else if (isBuiltInType(tag, 'Suspense')) {
  11304. return SUSPENSE;
  11305. }
  11306. else if (isBuiltInType(tag, 'KeepAlive')) {
  11307. return KEEP_ALIVE;
  11308. }
  11309. else if (isBuiltInType(tag, 'BaseTransition')) {
  11310. return BASE_TRANSITION;
  11311. }
  11312. }
  11313. const nonIdentifierRE = /^\d|[^\$\w]/;
  11314. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  11315. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  11316. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  11317. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  11318. /**
  11319. * Simple lexer to check if an expression is a member expression. This is
  11320. * lax and only checks validity at the root level (i.e. does not validate exps
  11321. * inside square brackets), but it's ok since these are only used on template
  11322. * expressions and false positives are invalid expressions in the first place.
  11323. */
  11324. const isMemberExpressionBrowser = (path) => {
  11325. // remove whitespaces around . or [ first
  11326. path = path.trim().replace(whitespaceRE, s => s.trim());
  11327. let state = 0 /* inMemberExp */;
  11328. let stateStack = [];
  11329. let currentOpenBracketCount = 0;
  11330. let currentOpenParensCount = 0;
  11331. let currentStringType = null;
  11332. for (let i = 0; i < path.length; i++) {
  11333. const char = path.charAt(i);
  11334. switch (state) {
  11335. case 0 /* inMemberExp */:
  11336. if (char === '[') {
  11337. stateStack.push(state);
  11338. state = 1 /* inBrackets */;
  11339. currentOpenBracketCount++;
  11340. }
  11341. else if (char === '(') {
  11342. stateStack.push(state);
  11343. state = 2 /* inParens */;
  11344. currentOpenParensCount++;
  11345. }
  11346. else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  11347. return false;
  11348. }
  11349. break;
  11350. case 1 /* inBrackets */:
  11351. if (char === `'` || char === `"` || char === '`') {
  11352. stateStack.push(state);
  11353. state = 3 /* inString */;
  11354. currentStringType = char;
  11355. }
  11356. else if (char === `[`) {
  11357. currentOpenBracketCount++;
  11358. }
  11359. else if (char === `]`) {
  11360. if (!--currentOpenBracketCount) {
  11361. state = stateStack.pop();
  11362. }
  11363. }
  11364. break;
  11365. case 2 /* inParens */:
  11366. if (char === `'` || char === `"` || char === '`') {
  11367. stateStack.push(state);
  11368. state = 3 /* inString */;
  11369. currentStringType = char;
  11370. }
  11371. else if (char === `(`) {
  11372. currentOpenParensCount++;
  11373. }
  11374. else if (char === `)`) {
  11375. // if the exp ends as a call then it should not be considered valid
  11376. if (i === path.length - 1) {
  11377. return false;
  11378. }
  11379. if (!--currentOpenParensCount) {
  11380. state = stateStack.pop();
  11381. }
  11382. }
  11383. break;
  11384. case 3 /* inString */:
  11385. if (char === currentStringType) {
  11386. state = stateStack.pop();
  11387. currentStringType = null;
  11388. }
  11389. break;
  11390. }
  11391. }
  11392. return !currentOpenBracketCount && !currentOpenParensCount;
  11393. };
  11394. const isMemberExpression = isMemberExpressionBrowser
  11395. ;
  11396. function getInnerRange(loc, offset, length) {
  11397. const source = loc.source.slice(offset, offset + length);
  11398. const newLoc = {
  11399. source,
  11400. start: advancePositionWithClone(loc.start, loc.source, offset),
  11401. end: loc.end
  11402. };
  11403. if (length != null) {
  11404. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  11405. }
  11406. return newLoc;
  11407. }
  11408. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  11409. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  11410. }
  11411. // advance by mutation without cloning (for performance reasons), since this
  11412. // gets called a lot in the parser
  11413. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  11414. let linesCount = 0;
  11415. let lastNewLinePos = -1;
  11416. for (let i = 0; i < numberOfCharacters; i++) {
  11417. if (source.charCodeAt(i) === 10 /* newline char code */) {
  11418. linesCount++;
  11419. lastNewLinePos = i;
  11420. }
  11421. }
  11422. pos.offset += numberOfCharacters;
  11423. pos.line += linesCount;
  11424. pos.column =
  11425. lastNewLinePos === -1
  11426. ? pos.column + numberOfCharacters
  11427. : numberOfCharacters - lastNewLinePos;
  11428. return pos;
  11429. }
  11430. function assert(condition, msg) {
  11431. /* istanbul ignore if */
  11432. if (!condition) {
  11433. throw new Error(msg || `unexpected compiler condition`);
  11434. }
  11435. }
  11436. function findDir(node, name, allowEmpty = false) {
  11437. for (let i = 0; i < node.props.length; i++) {
  11438. const p = node.props[i];
  11439. if (p.type === 7 /* DIRECTIVE */ &&
  11440. (allowEmpty || p.exp) &&
  11441. (isString(name) ? p.name === name : name.test(p.name))) {
  11442. return p;
  11443. }
  11444. }
  11445. }
  11446. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  11447. for (let i = 0; i < node.props.length; i++) {
  11448. const p = node.props[i];
  11449. if (p.type === 6 /* ATTRIBUTE */) {
  11450. if (dynamicOnly)
  11451. continue;
  11452. if (p.name === name && (p.value || allowEmpty)) {
  11453. return p;
  11454. }
  11455. }
  11456. else if (p.name === 'bind' &&
  11457. (p.exp || allowEmpty) &&
  11458. isStaticArgOf(p.arg, name)) {
  11459. return p;
  11460. }
  11461. }
  11462. }
  11463. function isStaticArgOf(arg, name) {
  11464. return !!(arg && isStaticExp(arg) && arg.content === name);
  11465. }
  11466. function hasDynamicKeyVBind(node) {
  11467. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  11468. p.name === 'bind' &&
  11469. (!p.arg || // v-bind="obj"
  11470. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  11471. !p.arg.isStatic) // v-bind:[foo]
  11472. );
  11473. }
  11474. function isText(node) {
  11475. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  11476. }
  11477. function isVSlot(p) {
  11478. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  11479. }
  11480. function isTemplateNode(node) {
  11481. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  11482. }
  11483. function isSlotOutlet(node) {
  11484. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  11485. }
  11486. function getVNodeHelper(ssr, isComponent) {
  11487. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  11488. }
  11489. function getVNodeBlockHelper(ssr, isComponent) {
  11490. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  11491. }
  11492. const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  11493. function getUnnormalizedProps(props, callPath = []) {
  11494. if (props &&
  11495. !isString(props) &&
  11496. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11497. const callee = props.callee;
  11498. if (!isString(callee) && propsHelperSet.has(callee)) {
  11499. return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
  11500. }
  11501. }
  11502. return [props, callPath];
  11503. }
  11504. function injectProp(node, prop, context) {
  11505. let propsWithInjection;
  11506. /**
  11507. * 1. mergeProps(...)
  11508. * 2. toHandlers(...)
  11509. * 3. normalizeProps(...)
  11510. * 4. normalizeProps(guardReactiveProps(...))
  11511. *
  11512. * we need to get the real props before normalization
  11513. */
  11514. let props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  11515. let callPath = [];
  11516. let parentCall;
  11517. if (props &&
  11518. !isString(props) &&
  11519. props.type === 14 /* JS_CALL_EXPRESSION */) {
  11520. const ret = getUnnormalizedProps(props);
  11521. props = ret[0];
  11522. callPath = ret[1];
  11523. parentCall = callPath[callPath.length - 1];
  11524. }
  11525. if (props == null || isString(props)) {
  11526. propsWithInjection = createObjectExpression([prop]);
  11527. }
  11528. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  11529. // merged props... add ours
  11530. // only inject key to object literal if it's the first argument so that
  11531. // if doesn't override user provided keys
  11532. const first = props.arguments[0];
  11533. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11534. first.properties.unshift(prop);
  11535. }
  11536. else {
  11537. if (props.callee === TO_HANDLERS) {
  11538. // #2366
  11539. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11540. createObjectExpression([prop]),
  11541. props
  11542. ]);
  11543. }
  11544. else {
  11545. props.arguments.unshift(createObjectExpression([prop]));
  11546. }
  11547. }
  11548. !propsWithInjection && (propsWithInjection = props);
  11549. }
  11550. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  11551. let alreadyExists = false;
  11552. // check existing key to avoid overriding user provided keys
  11553. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  11554. const propKeyName = prop.key.content;
  11555. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  11556. p.key.content === propKeyName);
  11557. }
  11558. if (!alreadyExists) {
  11559. props.properties.unshift(prop);
  11560. }
  11561. propsWithInjection = props;
  11562. }
  11563. else {
  11564. // single v-bind with expression, return a merged replacement
  11565. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  11566. createObjectExpression([prop]),
  11567. props
  11568. ]);
  11569. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(props))`,
  11570. // it will be rewritten as `normalizeProps(mergeProps({ key: 0 }, props))`,
  11571. // the `guardReactiveProps` will no longer be needed
  11572. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  11573. parentCall = callPath[callPath.length - 2];
  11574. }
  11575. }
  11576. if (node.type === 13 /* VNODE_CALL */) {
  11577. if (parentCall) {
  11578. parentCall.arguments[0] = propsWithInjection;
  11579. }
  11580. else {
  11581. node.props = propsWithInjection;
  11582. }
  11583. }
  11584. else {
  11585. if (parentCall) {
  11586. parentCall.arguments[0] = propsWithInjection;
  11587. }
  11588. else {
  11589. node.arguments[2] = propsWithInjection;
  11590. }
  11591. }
  11592. }
  11593. function toValidAssetId(name, type) {
  11594. // see issue#4422, we need adding identifier on validAssetId if variable `name` has specific character
  11595. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  11596. return searchValue === '-' ? '_' : name.charCodeAt(replaceValue).toString();
  11597. })}`;
  11598. }
  11599. function getMemoedVNodeCall(node) {
  11600. if (node.type === 14 /* JS_CALL_EXPRESSION */ && node.callee === WITH_MEMO) {
  11601. return node.arguments[1].returns;
  11602. }
  11603. else {
  11604. return node;
  11605. }
  11606. }
  11607. function makeBlock(node, { helper, removeHelper, inSSR }) {
  11608. if (!node.isBlock) {
  11609. node.isBlock = true;
  11610. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  11611. helper(OPEN_BLOCK);
  11612. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  11613. }
  11614. }
  11615. const deprecationData = {
  11616. ["COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */]: {
  11617. message: `Platform-native elements with "is" prop will no longer be ` +
  11618. `treated as components in Vue 3 unless the "is" value is explicitly ` +
  11619. `prefixed with "vue:".`,
  11620. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  11621. },
  11622. ["COMPILER_V_BIND_SYNC" /* COMPILER_V_BIND_SYNC */]: {
  11623. message: key => `.sync modifier for v-bind has been removed. Use v-model with ` +
  11624. `argument instead. \`v-bind:${key}.sync\` should be changed to ` +
  11625. `\`v-model:${key}\`.`,
  11626. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  11627. },
  11628. ["COMPILER_V_BIND_PROP" /* COMPILER_V_BIND_PROP */]: {
  11629. message: `.prop modifier for v-bind has been removed and no longer necessary. ` +
  11630. `Vue 3 will automatically set a binding as DOM property when appropriate.`
  11631. },
  11632. ["COMPILER_V_BIND_OBJECT_ORDER" /* COMPILER_V_BIND_OBJECT_ORDER */]: {
  11633. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
  11634. `object spread: it will now overwrite an existing non-mergeable attribute ` +
  11635. `that appears before v-bind in the case of conflict. ` +
  11636. `To retain 2.x behavior, move v-bind to make it the first attribute. ` +
  11637. `You can also suppress this warning if the usage is intended.`,
  11638. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  11639. },
  11640. ["COMPILER_V_ON_NATIVE" /* COMPILER_V_ON_NATIVE */]: {
  11641. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  11642. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  11643. },
  11644. ["COMPILER_V_IF_V_FOR_PRECEDENCE" /* COMPILER_V_IF_V_FOR_PRECEDENCE */]: {
  11645. message: `v-if / v-for precedence when used on the same element has changed ` +
  11646. `in Vue 3: v-if now takes higher precedence and will no longer have ` +
  11647. `access to v-for scope variables. It is best to avoid the ambiguity ` +
  11648. `with <template> tags or use a computed property that filters v-for ` +
  11649. `data source.`,
  11650. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  11651. },
  11652. ["COMPILER_NATIVE_TEMPLATE" /* COMPILER_NATIVE_TEMPLATE */]: {
  11653. message: `<template> with no special directives will render as a native template ` +
  11654. `element instead of its inner content in Vue 3.`
  11655. },
  11656. ["COMPILER_INLINE_TEMPLATE" /* COMPILER_INLINE_TEMPLATE */]: {
  11657. message: `"inline-template" has been removed in Vue 3.`,
  11658. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  11659. },
  11660. ["COMPILER_FILTER" /* COMPILER_FILTERS */]: {
  11661. message: `filters have been removed in Vue 3. ` +
  11662. `The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
  11663. `Use method calls or computed properties instead.`,
  11664. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  11665. }
  11666. };
  11667. function getCompatValue(key, context) {
  11668. const config = context.options
  11669. ? context.options.compatConfig
  11670. : context.compatConfig;
  11671. const value = config && config[key];
  11672. if (key === 'MODE') {
  11673. return value || 3; // compiler defaults to v3 behavior
  11674. }
  11675. else {
  11676. return value;
  11677. }
  11678. }
  11679. function isCompatEnabled(key, context) {
  11680. const mode = getCompatValue('MODE', context);
  11681. const value = getCompatValue(key, context);
  11682. // in v3 mode, only enable if explicitly set to true
  11683. // otherwise enable for any non-false value
  11684. return mode === 3 ? value === true : value !== false;
  11685. }
  11686. function checkCompatEnabled(key, context, loc, ...args) {
  11687. const enabled = isCompatEnabled(key, context);
  11688. if (enabled) {
  11689. warnDeprecation(key, context, loc, ...args);
  11690. }
  11691. return enabled;
  11692. }
  11693. function warnDeprecation(key, context, loc, ...args) {
  11694. const val = getCompatValue(key, context);
  11695. if (val === 'suppress-warning') {
  11696. return;
  11697. }
  11698. const { message, link } = deprecationData[key];
  11699. const msg = `(deprecation ${key}) ${typeof message === 'function' ? message(...args) : message}${link ? `\n Details: ${link}` : ``}`;
  11700. const err = new SyntaxError(msg);
  11701. err.code = key;
  11702. if (loc)
  11703. err.loc = loc;
  11704. context.onWarn(err);
  11705. }
  11706. // The default decoder only provides escapes for characters reserved as part of
  11707. // the template syntax, and is only used if the custom renderer did not provide
  11708. // a platform-specific decoder.
  11709. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  11710. const decodeMap = {
  11711. gt: '>',
  11712. lt: '<',
  11713. amp: '&',
  11714. apos: "'",
  11715. quot: '"'
  11716. };
  11717. const defaultParserOptions = {
  11718. delimiters: [`{{`, `}}`],
  11719. getNamespace: () => 0 /* HTML */,
  11720. getTextMode: () => 0 /* DATA */,
  11721. isVoidTag: NO,
  11722. isPreTag: NO,
  11723. isCustomElement: NO,
  11724. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  11725. onError: defaultOnError,
  11726. onWarn: defaultOnWarn,
  11727. comments: true
  11728. };
  11729. function baseParse(content, options = {}) {
  11730. const context = createParserContext(content, options);
  11731. const start = getCursor(context);
  11732. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  11733. }
  11734. function createParserContext(content, rawOptions) {
  11735. const options = extend({}, defaultParserOptions);
  11736. let key;
  11737. for (key in rawOptions) {
  11738. // @ts-ignore
  11739. options[key] =
  11740. rawOptions[key] === undefined
  11741. ? defaultParserOptions[key]
  11742. : rawOptions[key];
  11743. }
  11744. return {
  11745. options,
  11746. column: 1,
  11747. line: 1,
  11748. offset: 0,
  11749. originalSource: content,
  11750. source: content,
  11751. inPre: false,
  11752. inVPre: false,
  11753. onWarn: options.onWarn
  11754. };
  11755. }
  11756. function parseChildren(context, mode, ancestors) {
  11757. const parent = last(ancestors);
  11758. const ns = parent ? parent.ns : 0 /* HTML */;
  11759. const nodes = [];
  11760. while (!isEnd(context, mode, ancestors)) {
  11761. const s = context.source;
  11762. let node = undefined;
  11763. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  11764. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  11765. // '{{'
  11766. node = parseInterpolation(context, mode);
  11767. }
  11768. else if (mode === 0 /* DATA */ && s[0] === '<') {
  11769. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  11770. if (s.length === 1) {
  11771. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  11772. }
  11773. else if (s[1] === '!') {
  11774. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  11775. if (startsWith(s, '<!--')) {
  11776. node = parseComment(context);
  11777. }
  11778. else if (startsWith(s, '<!DOCTYPE')) {
  11779. // Ignore DOCTYPE by a limitation.
  11780. node = parseBogusComment(context);
  11781. }
  11782. else if (startsWith(s, '<![CDATA[')) {
  11783. if (ns !== 0 /* HTML */) {
  11784. node = parseCDATA(context, ancestors);
  11785. }
  11786. else {
  11787. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  11788. node = parseBogusComment(context);
  11789. }
  11790. }
  11791. else {
  11792. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  11793. node = parseBogusComment(context);
  11794. }
  11795. }
  11796. else if (s[1] === '/') {
  11797. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  11798. if (s.length === 2) {
  11799. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  11800. }
  11801. else if (s[2] === '>') {
  11802. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  11803. advanceBy(context, 3);
  11804. continue;
  11805. }
  11806. else if (/[a-z]/i.test(s[2])) {
  11807. emitError(context, 23 /* X_INVALID_END_TAG */);
  11808. parseTag(context, 1 /* End */, parent);
  11809. continue;
  11810. }
  11811. else {
  11812. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  11813. node = parseBogusComment(context);
  11814. }
  11815. }
  11816. else if (/[a-z]/i.test(s[1])) {
  11817. node = parseElement(context, ancestors);
  11818. }
  11819. else if (s[1] === '?') {
  11820. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  11821. node = parseBogusComment(context);
  11822. }
  11823. else {
  11824. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  11825. }
  11826. }
  11827. }
  11828. if (!node) {
  11829. node = parseText(context, mode);
  11830. }
  11831. if (isArray(node)) {
  11832. for (let i = 0; i < node.length; i++) {
  11833. pushNode(nodes, node[i]);
  11834. }
  11835. }
  11836. else {
  11837. pushNode(nodes, node);
  11838. }
  11839. }
  11840. // Whitespace handling strategy like v2
  11841. let removedWhitespace = false;
  11842. if (mode !== 2 /* RAWTEXT */ && mode !== 1 /* RCDATA */) {
  11843. const shouldCondense = context.options.whitespace !== 'preserve';
  11844. for (let i = 0; i < nodes.length; i++) {
  11845. const node = nodes[i];
  11846. if (!context.inPre && node.type === 2 /* TEXT */) {
  11847. if (!/[^\t\r\n\f ]/.test(node.content)) {
  11848. const prev = nodes[i - 1];
  11849. const next = nodes[i + 1];
  11850. // Remove if:
  11851. // - the whitespace is the first or last node, or:
  11852. // - (condense mode) the whitespace is adjacent to a comment, or:
  11853. // - (condense mode) the whitespace is between two elements AND contains newline
  11854. if (!prev ||
  11855. !next ||
  11856. (shouldCondense &&
  11857. (prev.type === 3 /* COMMENT */ ||
  11858. next.type === 3 /* COMMENT */ ||
  11859. (prev.type === 1 /* ELEMENT */ &&
  11860. next.type === 1 /* ELEMENT */ &&
  11861. /[\r\n]/.test(node.content))))) {
  11862. removedWhitespace = true;
  11863. nodes[i] = null;
  11864. }
  11865. else {
  11866. // Otherwise, the whitespace is condensed into a single space
  11867. node.content = ' ';
  11868. }
  11869. }
  11870. else if (shouldCondense) {
  11871. // in condense mode, consecutive whitespaces in text are condensed
  11872. // down to a single space.
  11873. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  11874. }
  11875. }
  11876. // Remove comment nodes if desired by configuration.
  11877. else if (node.type === 3 /* COMMENT */ && !context.options.comments) {
  11878. removedWhitespace = true;
  11879. nodes[i] = null;
  11880. }
  11881. }
  11882. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  11883. // remove leading newline per html spec
  11884. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  11885. const first = nodes[0];
  11886. if (first && first.type === 2 /* TEXT */) {
  11887. first.content = first.content.replace(/^\r?\n/, '');
  11888. }
  11889. }
  11890. }
  11891. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  11892. }
  11893. function pushNode(nodes, node) {
  11894. if (node.type === 2 /* TEXT */) {
  11895. const prev = last(nodes);
  11896. // Merge if both this and the previous node are text and those are
  11897. // consecutive. This happens for cases like "a < b".
  11898. if (prev &&
  11899. prev.type === 2 /* TEXT */ &&
  11900. prev.loc.end.offset === node.loc.start.offset) {
  11901. prev.content += node.content;
  11902. prev.loc.end = node.loc.end;
  11903. prev.loc.source += node.loc.source;
  11904. return;
  11905. }
  11906. }
  11907. nodes.push(node);
  11908. }
  11909. function parseCDATA(context, ancestors) {
  11910. advanceBy(context, 9);
  11911. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  11912. if (context.source.length === 0) {
  11913. emitError(context, 6 /* EOF_IN_CDATA */);
  11914. }
  11915. else {
  11916. advanceBy(context, 3);
  11917. }
  11918. return nodes;
  11919. }
  11920. function parseComment(context) {
  11921. const start = getCursor(context);
  11922. let content;
  11923. // Regular comment.
  11924. const match = /--(\!)?>/.exec(context.source);
  11925. if (!match) {
  11926. content = context.source.slice(4);
  11927. advanceBy(context, context.source.length);
  11928. emitError(context, 7 /* EOF_IN_COMMENT */);
  11929. }
  11930. else {
  11931. if (match.index <= 3) {
  11932. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  11933. }
  11934. if (match[1]) {
  11935. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  11936. }
  11937. content = context.source.slice(4, match.index);
  11938. // Advancing with reporting nested comments.
  11939. const s = context.source.slice(0, match.index);
  11940. let prevIndex = 1, nestedIndex = 0;
  11941. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  11942. advanceBy(context, nestedIndex - prevIndex + 1);
  11943. if (nestedIndex + 4 < s.length) {
  11944. emitError(context, 16 /* NESTED_COMMENT */);
  11945. }
  11946. prevIndex = nestedIndex + 1;
  11947. }
  11948. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  11949. }
  11950. return {
  11951. type: 3 /* COMMENT */,
  11952. content,
  11953. loc: getSelection(context, start)
  11954. };
  11955. }
  11956. function parseBogusComment(context) {
  11957. const start = getCursor(context);
  11958. const contentStart = context.source[1] === '?' ? 1 : 2;
  11959. let content;
  11960. const closeIndex = context.source.indexOf('>');
  11961. if (closeIndex === -1) {
  11962. content = context.source.slice(contentStart);
  11963. advanceBy(context, context.source.length);
  11964. }
  11965. else {
  11966. content = context.source.slice(contentStart, closeIndex);
  11967. advanceBy(context, closeIndex + 1);
  11968. }
  11969. return {
  11970. type: 3 /* COMMENT */,
  11971. content,
  11972. loc: getSelection(context, start)
  11973. };
  11974. }
  11975. function parseElement(context, ancestors) {
  11976. // Start tag.
  11977. const wasInPre = context.inPre;
  11978. const wasInVPre = context.inVPre;
  11979. const parent = last(ancestors);
  11980. const element = parseTag(context, 0 /* Start */, parent);
  11981. const isPreBoundary = context.inPre && !wasInPre;
  11982. const isVPreBoundary = context.inVPre && !wasInVPre;
  11983. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  11984. // #4030 self-closing <pre> tag
  11985. if (isPreBoundary) {
  11986. context.inPre = false;
  11987. }
  11988. if (isVPreBoundary) {
  11989. context.inVPre = false;
  11990. }
  11991. return element;
  11992. }
  11993. // Children.
  11994. ancestors.push(element);
  11995. const mode = context.options.getTextMode(element, parent);
  11996. const children = parseChildren(context, mode, ancestors);
  11997. ancestors.pop();
  11998. element.children = children;
  11999. // End tag.
  12000. if (startsWithEndTagOpen(context.source, element.tag)) {
  12001. parseTag(context, 1 /* End */, parent);
  12002. }
  12003. else {
  12004. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  12005. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  12006. const first = children[0];
  12007. if (first && startsWith(first.loc.source, '<!--')) {
  12008. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  12009. }
  12010. }
  12011. }
  12012. element.loc = getSelection(context, element.loc.start);
  12013. if (isPreBoundary) {
  12014. context.inPre = false;
  12015. }
  12016. if (isVPreBoundary) {
  12017. context.inVPre = false;
  12018. }
  12019. return element;
  12020. }
  12021. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  12022. function parseTag(context, type, parent) {
  12023. // Tag open.
  12024. const start = getCursor(context);
  12025. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  12026. const tag = match[1];
  12027. const ns = context.options.getNamespace(tag, parent);
  12028. advanceBy(context, match[0].length);
  12029. advanceSpaces(context);
  12030. // save current state in case we need to re-parse attributes with v-pre
  12031. const cursor = getCursor(context);
  12032. const currentSource = context.source;
  12033. // check <pre> tag
  12034. if (context.options.isPreTag(tag)) {
  12035. context.inPre = true;
  12036. }
  12037. // Attributes.
  12038. let props = parseAttributes(context, type);
  12039. // check v-pre
  12040. if (type === 0 /* Start */ &&
  12041. !context.inVPre &&
  12042. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  12043. context.inVPre = true;
  12044. // reset context
  12045. extend(context, cursor);
  12046. context.source = currentSource;
  12047. // re-parse attrs and filter out v-pre itself
  12048. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  12049. }
  12050. // Tag close.
  12051. let isSelfClosing = false;
  12052. if (context.source.length === 0) {
  12053. emitError(context, 9 /* EOF_IN_TAG */);
  12054. }
  12055. else {
  12056. isSelfClosing = startsWith(context.source, '/>');
  12057. if (type === 1 /* End */ && isSelfClosing) {
  12058. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  12059. }
  12060. advanceBy(context, isSelfClosing ? 2 : 1);
  12061. }
  12062. if (type === 1 /* End */) {
  12063. return;
  12064. }
  12065. let tagType = 0 /* ELEMENT */;
  12066. if (!context.inVPre) {
  12067. if (tag === 'slot') {
  12068. tagType = 2 /* SLOT */;
  12069. }
  12070. else if (tag === 'template') {
  12071. if (props.some(p => p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name))) {
  12072. tagType = 3 /* TEMPLATE */;
  12073. }
  12074. }
  12075. else if (isComponent(tag, props, context)) {
  12076. tagType = 1 /* COMPONENT */;
  12077. }
  12078. }
  12079. return {
  12080. type: 1 /* ELEMENT */,
  12081. ns,
  12082. tag,
  12083. tagType,
  12084. props,
  12085. isSelfClosing,
  12086. children: [],
  12087. loc: getSelection(context, start),
  12088. codegenNode: undefined // to be created during transform phase
  12089. };
  12090. }
  12091. function isComponent(tag, props, context) {
  12092. const options = context.options;
  12093. if (options.isCustomElement(tag)) {
  12094. return false;
  12095. }
  12096. if (tag === 'component' ||
  12097. /^[A-Z]/.test(tag) ||
  12098. isCoreComponent(tag) ||
  12099. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  12100. (options.isNativeTag && !options.isNativeTag(tag))) {
  12101. return true;
  12102. }
  12103. // at this point the tag should be a native tag, but check for potential "is"
  12104. // casting
  12105. for (let i = 0; i < props.length; i++) {
  12106. const p = props[i];
  12107. if (p.type === 6 /* ATTRIBUTE */) {
  12108. if (p.name === 'is' && p.value) {
  12109. if (p.value.content.startsWith('vue:')) {
  12110. return true;
  12111. }
  12112. }
  12113. }
  12114. else {
  12115. // directive
  12116. // v-is (TODO Deprecate)
  12117. if (p.name === 'is') {
  12118. return true;
  12119. }
  12120. else if (
  12121. // :is on plain element - only treat as component in compat mode
  12122. p.name === 'bind' &&
  12123. isStaticArgOf(p.arg, 'is') &&
  12124. false &&
  12125. checkCompatEnabled("COMPILER_IS_ON_ELEMENT" /* COMPILER_IS_ON_ELEMENT */, context, p.loc)) {
  12126. return true;
  12127. }
  12128. }
  12129. }
  12130. }
  12131. function parseAttributes(context, type) {
  12132. const props = [];
  12133. const attributeNames = new Set();
  12134. while (context.source.length > 0 &&
  12135. !startsWith(context.source, '>') &&
  12136. !startsWith(context.source, '/>')) {
  12137. if (startsWith(context.source, '/')) {
  12138. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  12139. advanceBy(context, 1);
  12140. advanceSpaces(context);
  12141. continue;
  12142. }
  12143. if (type === 1 /* End */) {
  12144. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  12145. }
  12146. const attr = parseAttribute(context, attributeNames);
  12147. // Trim whitespace between class
  12148. // https://github.com/vuejs/core/issues/4251
  12149. if (attr.type === 6 /* ATTRIBUTE */ &&
  12150. attr.value &&
  12151. attr.name === 'class') {
  12152. attr.value.content = attr.value.content.replace(/\s+/g, ' ').trim();
  12153. }
  12154. if (type === 0 /* Start */) {
  12155. props.push(attr);
  12156. }
  12157. if (/^[^\t\r\n\f />]/.test(context.source)) {
  12158. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  12159. }
  12160. advanceSpaces(context);
  12161. }
  12162. return props;
  12163. }
  12164. function parseAttribute(context, nameSet) {
  12165. // Name.
  12166. const start = getCursor(context);
  12167. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  12168. const name = match[0];
  12169. if (nameSet.has(name)) {
  12170. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  12171. }
  12172. nameSet.add(name);
  12173. if (name[0] === '=') {
  12174. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  12175. }
  12176. {
  12177. const pattern = /["'<]/g;
  12178. let m;
  12179. while ((m = pattern.exec(name))) {
  12180. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  12181. }
  12182. }
  12183. advanceBy(context, name.length);
  12184. // Value
  12185. let value = undefined;
  12186. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  12187. advanceSpaces(context);
  12188. advanceBy(context, 1);
  12189. advanceSpaces(context);
  12190. value = parseAttributeValue(context);
  12191. if (!value) {
  12192. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  12193. }
  12194. }
  12195. const loc = getSelection(context, start);
  12196. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  12197. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  12198. let isPropShorthand = startsWith(name, '.');
  12199. let dirName = match[1] ||
  12200. (isPropShorthand || startsWith(name, ':')
  12201. ? 'bind'
  12202. : startsWith(name, '@')
  12203. ? 'on'
  12204. : 'slot');
  12205. let arg;
  12206. if (match[2]) {
  12207. const isSlot = dirName === 'slot';
  12208. const startOffset = name.lastIndexOf(match[2]);
  12209. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  12210. let content = match[2];
  12211. let isStatic = true;
  12212. if (content.startsWith('[')) {
  12213. isStatic = false;
  12214. if (!content.endsWith(']')) {
  12215. emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  12216. content = content.slice(1);
  12217. }
  12218. else {
  12219. content = content.slice(1, content.length - 1);
  12220. }
  12221. }
  12222. else if (isSlot) {
  12223. // #1241 special case for v-slot: vuetify relies extensively on slot
  12224. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  12225. // supports such usage so we are keeping it consistent with 2.x.
  12226. content += match[3] || '';
  12227. }
  12228. arg = {
  12229. type: 4 /* SIMPLE_EXPRESSION */,
  12230. content,
  12231. isStatic,
  12232. constType: isStatic
  12233. ? 3 /* CAN_STRINGIFY */
  12234. : 0 /* NOT_CONSTANT */,
  12235. loc
  12236. };
  12237. }
  12238. if (value && value.isQuoted) {
  12239. const valueLoc = value.loc;
  12240. valueLoc.start.offset++;
  12241. valueLoc.start.column++;
  12242. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  12243. valueLoc.source = valueLoc.source.slice(1, -1);
  12244. }
  12245. const modifiers = match[3] ? match[3].slice(1).split('.') : [];
  12246. if (isPropShorthand)
  12247. modifiers.push('prop');
  12248. return {
  12249. type: 7 /* DIRECTIVE */,
  12250. name: dirName,
  12251. exp: value && {
  12252. type: 4 /* SIMPLE_EXPRESSION */,
  12253. content: value.content,
  12254. isStatic: false,
  12255. // Treat as non-constant by default. This can be potentially set to
  12256. // other values by `transformExpression` to make it eligible for hoisting.
  12257. constType: 0 /* NOT_CONSTANT */,
  12258. loc: value.loc
  12259. },
  12260. arg,
  12261. modifiers,
  12262. loc
  12263. };
  12264. }
  12265. // missing directive name or illegal directive name
  12266. if (!context.inVPre && startsWith(name, 'v-')) {
  12267. emitError(context, 26 /* X_MISSING_DIRECTIVE_NAME */);
  12268. }
  12269. return {
  12270. type: 6 /* ATTRIBUTE */,
  12271. name,
  12272. value: value && {
  12273. type: 2 /* TEXT */,
  12274. content: value.content,
  12275. loc: value.loc
  12276. },
  12277. loc
  12278. };
  12279. }
  12280. function parseAttributeValue(context) {
  12281. const start = getCursor(context);
  12282. let content;
  12283. const quote = context.source[0];
  12284. const isQuoted = quote === `"` || quote === `'`;
  12285. if (isQuoted) {
  12286. // Quoted value.
  12287. advanceBy(context, 1);
  12288. const endIndex = context.source.indexOf(quote);
  12289. if (endIndex === -1) {
  12290. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  12291. }
  12292. else {
  12293. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  12294. advanceBy(context, 1);
  12295. }
  12296. }
  12297. else {
  12298. // Unquoted
  12299. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  12300. if (!match) {
  12301. return undefined;
  12302. }
  12303. const unexpectedChars = /["'<=`]/g;
  12304. let m;
  12305. while ((m = unexpectedChars.exec(match[0]))) {
  12306. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  12307. }
  12308. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  12309. }
  12310. return { content, isQuoted, loc: getSelection(context, start) };
  12311. }
  12312. function parseInterpolation(context, mode) {
  12313. const [open, close] = context.options.delimiters;
  12314. const closeIndex = context.source.indexOf(close, open.length);
  12315. if (closeIndex === -1) {
  12316. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  12317. return undefined;
  12318. }
  12319. const start = getCursor(context);
  12320. advanceBy(context, open.length);
  12321. const innerStart = getCursor(context);
  12322. const innerEnd = getCursor(context);
  12323. const rawContentLength = closeIndex - open.length;
  12324. const rawContent = context.source.slice(0, rawContentLength);
  12325. const preTrimContent = parseTextData(context, rawContentLength, mode);
  12326. const content = preTrimContent.trim();
  12327. const startOffset = preTrimContent.indexOf(content);
  12328. if (startOffset > 0) {
  12329. advancePositionWithMutation(innerStart, rawContent, startOffset);
  12330. }
  12331. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  12332. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  12333. advanceBy(context, close.length);
  12334. return {
  12335. type: 5 /* INTERPOLATION */,
  12336. content: {
  12337. type: 4 /* SIMPLE_EXPRESSION */,
  12338. isStatic: false,
  12339. // Set `isConstant` to false by default and will decide in transformExpression
  12340. constType: 0 /* NOT_CONSTANT */,
  12341. content,
  12342. loc: getSelection(context, innerStart, innerEnd)
  12343. },
  12344. loc: getSelection(context, start)
  12345. };
  12346. }
  12347. function parseText(context, mode) {
  12348. const endTokens = mode === 3 /* CDATA */ ? [']]>'] : ['<', context.options.delimiters[0]];
  12349. let endIndex = context.source.length;
  12350. for (let i = 0; i < endTokens.length; i++) {
  12351. const index = context.source.indexOf(endTokens[i], 1);
  12352. if (index !== -1 && endIndex > index) {
  12353. endIndex = index;
  12354. }
  12355. }
  12356. const start = getCursor(context);
  12357. const content = parseTextData(context, endIndex, mode);
  12358. return {
  12359. type: 2 /* TEXT */,
  12360. content,
  12361. loc: getSelection(context, start)
  12362. };
  12363. }
  12364. /**
  12365. * Get text data with a given length from the current location.
  12366. * This translates HTML entities in the text data.
  12367. */
  12368. function parseTextData(context, length, mode) {
  12369. const rawText = context.source.slice(0, length);
  12370. advanceBy(context, length);
  12371. if (mode === 2 /* RAWTEXT */ ||
  12372. mode === 3 /* CDATA */ ||
  12373. !rawText.includes('&')) {
  12374. return rawText;
  12375. }
  12376. else {
  12377. // DATA or RCDATA containing "&"". Entity decoding required.
  12378. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  12379. }
  12380. }
  12381. function getCursor(context) {
  12382. const { column, line, offset } = context;
  12383. return { column, line, offset };
  12384. }
  12385. function getSelection(context, start, end) {
  12386. end = end || getCursor(context);
  12387. return {
  12388. start,
  12389. end,
  12390. source: context.originalSource.slice(start.offset, end.offset)
  12391. };
  12392. }
  12393. function last(xs) {
  12394. return xs[xs.length - 1];
  12395. }
  12396. function startsWith(source, searchString) {
  12397. return source.startsWith(searchString);
  12398. }
  12399. function advanceBy(context, numberOfCharacters) {
  12400. const { source } = context;
  12401. advancePositionWithMutation(context, source, numberOfCharacters);
  12402. context.source = source.slice(numberOfCharacters);
  12403. }
  12404. function advanceSpaces(context) {
  12405. const match = /^[\t\r\n\f ]+/.exec(context.source);
  12406. if (match) {
  12407. advanceBy(context, match[0].length);
  12408. }
  12409. }
  12410. function getNewPosition(context, start, numberOfCharacters) {
  12411. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  12412. }
  12413. function emitError(context, code, offset, loc = getCursor(context)) {
  12414. if (offset) {
  12415. loc.offset += offset;
  12416. loc.column += offset;
  12417. }
  12418. context.options.onError(createCompilerError(code, {
  12419. start: loc,
  12420. end: loc,
  12421. source: ''
  12422. }));
  12423. }
  12424. function isEnd(context, mode, ancestors) {
  12425. const s = context.source;
  12426. switch (mode) {
  12427. case 0 /* DATA */:
  12428. if (startsWith(s, '</')) {
  12429. // TODO: probably bad performance
  12430. for (let i = ancestors.length - 1; i >= 0; --i) {
  12431. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  12432. return true;
  12433. }
  12434. }
  12435. }
  12436. break;
  12437. case 1 /* RCDATA */:
  12438. case 2 /* RAWTEXT */: {
  12439. const parent = last(ancestors);
  12440. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  12441. return true;
  12442. }
  12443. break;
  12444. }
  12445. case 3 /* CDATA */:
  12446. if (startsWith(s, ']]>')) {
  12447. return true;
  12448. }
  12449. break;
  12450. }
  12451. return !s;
  12452. }
  12453. function startsWithEndTagOpen(source, tag) {
  12454. return (startsWith(source, '</') &&
  12455. source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
  12456. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  12457. }
  12458. function hoistStatic(root, context) {
  12459. walk(root, context,
  12460. // Root node is unfortunately non-hoistable due to potential parent
  12461. // fallthrough attributes.
  12462. isSingleElementRoot(root, root.children[0]));
  12463. }
  12464. function isSingleElementRoot(root, child) {
  12465. const { children } = root;
  12466. return (children.length === 1 &&
  12467. child.type === 1 /* ELEMENT */ &&
  12468. !isSlotOutlet(child));
  12469. }
  12470. function walk(node, context, doNotHoistNode = false) {
  12471. const { children } = node;
  12472. const originalCount = children.length;
  12473. let hoistedCount = 0;
  12474. for (let i = 0; i < children.length; i++) {
  12475. const child = children[i];
  12476. // only plain elements & text calls are eligible for hoisting.
  12477. if (child.type === 1 /* ELEMENT */ &&
  12478. child.tagType === 0 /* ELEMENT */) {
  12479. const constantType = doNotHoistNode
  12480. ? 0 /* NOT_CONSTANT */
  12481. : getConstantType(child, context);
  12482. if (constantType > 0 /* NOT_CONSTANT */) {
  12483. if (constantType >= 2 /* CAN_HOIST */) {
  12484. child.codegenNode.patchFlag =
  12485. -1 /* HOISTED */ + (` /* HOISTED */` );
  12486. child.codegenNode = context.hoist(child.codegenNode);
  12487. hoistedCount++;
  12488. continue;
  12489. }
  12490. }
  12491. else {
  12492. // node may contain dynamic children, but its props may be eligible for
  12493. // hoisting.
  12494. const codegenNode = child.codegenNode;
  12495. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12496. const flag = getPatchFlag(codegenNode);
  12497. if ((!flag ||
  12498. flag === 512 /* NEED_PATCH */ ||
  12499. flag === 1 /* TEXT */) &&
  12500. getGeneratedPropsConstantType(child, context) >=
  12501. 2 /* CAN_HOIST */) {
  12502. const props = getNodeProps(child);
  12503. if (props) {
  12504. codegenNode.props = context.hoist(props);
  12505. }
  12506. }
  12507. if (codegenNode.dynamicProps) {
  12508. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  12509. }
  12510. }
  12511. }
  12512. }
  12513. else if (child.type === 12 /* TEXT_CALL */ &&
  12514. getConstantType(child.content, context) >= 2 /* CAN_HOIST */) {
  12515. child.codegenNode = context.hoist(child.codegenNode);
  12516. hoistedCount++;
  12517. }
  12518. // walk further
  12519. if (child.type === 1 /* ELEMENT */) {
  12520. const isComponent = child.tagType === 1 /* COMPONENT */;
  12521. if (isComponent) {
  12522. context.scopes.vSlot++;
  12523. }
  12524. walk(child, context);
  12525. if (isComponent) {
  12526. context.scopes.vSlot--;
  12527. }
  12528. }
  12529. else if (child.type === 11 /* FOR */) {
  12530. // Do not hoist v-for single child because it has to be a block
  12531. walk(child, context, child.children.length === 1);
  12532. }
  12533. else if (child.type === 9 /* IF */) {
  12534. for (let i = 0; i < child.branches.length; i++) {
  12535. // Do not hoist v-if single child because it has to be a block
  12536. walk(child.branches[i], context, child.branches[i].children.length === 1);
  12537. }
  12538. }
  12539. }
  12540. if (hoistedCount && context.transformHoist) {
  12541. context.transformHoist(children, context, node);
  12542. }
  12543. // all children were hoisted - the entire children array is hoistable.
  12544. if (hoistedCount &&
  12545. hoistedCount === originalCount &&
  12546. node.type === 1 /* ELEMENT */ &&
  12547. node.tagType === 0 /* ELEMENT */ &&
  12548. node.codegenNode &&
  12549. node.codegenNode.type === 13 /* VNODE_CALL */ &&
  12550. isArray(node.codegenNode.children)) {
  12551. node.codegenNode.children = context.hoist(createArrayExpression(node.codegenNode.children));
  12552. }
  12553. }
  12554. function getConstantType(node, context) {
  12555. const { constantCache } = context;
  12556. switch (node.type) {
  12557. case 1 /* ELEMENT */:
  12558. if (node.tagType !== 0 /* ELEMENT */) {
  12559. return 0 /* NOT_CONSTANT */;
  12560. }
  12561. const cached = constantCache.get(node);
  12562. if (cached !== undefined) {
  12563. return cached;
  12564. }
  12565. const codegenNode = node.codegenNode;
  12566. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  12567. return 0 /* NOT_CONSTANT */;
  12568. }
  12569. if (codegenNode.isBlock &&
  12570. node.tag !== 'svg' &&
  12571. node.tag !== 'foreignObject') {
  12572. return 0 /* NOT_CONSTANT */;
  12573. }
  12574. const flag = getPatchFlag(codegenNode);
  12575. if (!flag) {
  12576. let returnType = 3 /* CAN_STRINGIFY */;
  12577. // Element itself has no patch flag. However we still need to check:
  12578. // 1. Even for a node with no patch flag, it is possible for it to contain
  12579. // non-hoistable expressions that refers to scope variables, e.g. compiler
  12580. // injected keys or cached event handlers. Therefore we need to always
  12581. // check the codegenNode's props to be sure.
  12582. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  12583. if (generatedPropsType === 0 /* NOT_CONSTANT */) {
  12584. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12585. return 0 /* NOT_CONSTANT */;
  12586. }
  12587. if (generatedPropsType < returnType) {
  12588. returnType = generatedPropsType;
  12589. }
  12590. // 2. its children.
  12591. for (let i = 0; i < node.children.length; i++) {
  12592. const childType = getConstantType(node.children[i], context);
  12593. if (childType === 0 /* NOT_CONSTANT */) {
  12594. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12595. return 0 /* NOT_CONSTANT */;
  12596. }
  12597. if (childType < returnType) {
  12598. returnType = childType;
  12599. }
  12600. }
  12601. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  12602. // type, check if any of the props can cause the type to be lowered
  12603. // we can skip can_patch because it's guaranteed by the absence of a
  12604. // patchFlag.
  12605. if (returnType > 1 /* CAN_SKIP_PATCH */) {
  12606. for (let i = 0; i < node.props.length; i++) {
  12607. const p = node.props[i];
  12608. if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
  12609. const expType = getConstantType(p.exp, context);
  12610. if (expType === 0 /* NOT_CONSTANT */) {
  12611. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12612. return 0 /* NOT_CONSTANT */;
  12613. }
  12614. if (expType < returnType) {
  12615. returnType = expType;
  12616. }
  12617. }
  12618. }
  12619. }
  12620. // only svg/foreignObject could be block here, however if they are
  12621. // static then they don't need to be blocks since there will be no
  12622. // nested updates.
  12623. if (codegenNode.isBlock) {
  12624. // except set custom directives.
  12625. for (let i = 0; i < node.props.length; i++) {
  12626. const p = node.props[i];
  12627. if (p.type === 7 /* DIRECTIVE */) {
  12628. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12629. return 0 /* NOT_CONSTANT */;
  12630. }
  12631. }
  12632. context.removeHelper(OPEN_BLOCK);
  12633. context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
  12634. codegenNode.isBlock = false;
  12635. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  12636. }
  12637. constantCache.set(node, returnType);
  12638. return returnType;
  12639. }
  12640. else {
  12641. constantCache.set(node, 0 /* NOT_CONSTANT */);
  12642. return 0 /* NOT_CONSTANT */;
  12643. }
  12644. case 2 /* TEXT */:
  12645. case 3 /* COMMENT */:
  12646. return 3 /* CAN_STRINGIFY */;
  12647. case 9 /* IF */:
  12648. case 11 /* FOR */:
  12649. case 10 /* IF_BRANCH */:
  12650. return 0 /* NOT_CONSTANT */;
  12651. case 5 /* INTERPOLATION */:
  12652. case 12 /* TEXT_CALL */:
  12653. return getConstantType(node.content, context);
  12654. case 4 /* SIMPLE_EXPRESSION */:
  12655. return node.constType;
  12656. case 8 /* COMPOUND_EXPRESSION */:
  12657. let returnType = 3 /* CAN_STRINGIFY */;
  12658. for (let i = 0; i < node.children.length; i++) {
  12659. const child = node.children[i];
  12660. if (isString(child) || isSymbol(child)) {
  12661. continue;
  12662. }
  12663. const childType = getConstantType(child, context);
  12664. if (childType === 0 /* NOT_CONSTANT */) {
  12665. return 0 /* NOT_CONSTANT */;
  12666. }
  12667. else if (childType < returnType) {
  12668. returnType = childType;
  12669. }
  12670. }
  12671. return returnType;
  12672. default:
  12673. return 0 /* NOT_CONSTANT */;
  12674. }
  12675. }
  12676. const allowHoistedHelperSet = new Set([
  12677. NORMALIZE_CLASS,
  12678. NORMALIZE_STYLE,
  12679. NORMALIZE_PROPS,
  12680. GUARD_REACTIVE_PROPS
  12681. ]);
  12682. function getConstantTypeOfHelperCall(value, context) {
  12683. if (value.type === 14 /* JS_CALL_EXPRESSION */ &&
  12684. !isString(value.callee) &&
  12685. allowHoistedHelperSet.has(value.callee)) {
  12686. const arg = value.arguments[0];
  12687. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12688. return getConstantType(arg, context);
  12689. }
  12690. else if (arg.type === 14 /* JS_CALL_EXPRESSION */) {
  12691. // in the case of nested helper call, e.g. `normalizeProps(guardReactiveProps(exp))`
  12692. return getConstantTypeOfHelperCall(arg, context);
  12693. }
  12694. }
  12695. return 0 /* NOT_CONSTANT */;
  12696. }
  12697. function getGeneratedPropsConstantType(node, context) {
  12698. let returnType = 3 /* CAN_STRINGIFY */;
  12699. const props = getNodeProps(node);
  12700. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  12701. const { properties } = props;
  12702. for (let i = 0; i < properties.length; i++) {
  12703. const { key, value } = properties[i];
  12704. const keyType = getConstantType(key, context);
  12705. if (keyType === 0 /* NOT_CONSTANT */) {
  12706. return keyType;
  12707. }
  12708. if (keyType < returnType) {
  12709. returnType = keyType;
  12710. }
  12711. let valueType;
  12712. if (value.type === 4 /* SIMPLE_EXPRESSION */) {
  12713. valueType = getConstantType(value, context);
  12714. }
  12715. else if (value.type === 14 /* JS_CALL_EXPRESSION */) {
  12716. // some helper calls can be hoisted,
  12717. // such as the `normalizeProps` generated by the compiler for pre-normalize class,
  12718. // in this case we need to respect the ConstantType of the helper's arguments
  12719. valueType = getConstantTypeOfHelperCall(value, context);
  12720. }
  12721. else {
  12722. valueType = 0 /* NOT_CONSTANT */;
  12723. }
  12724. if (valueType === 0 /* NOT_CONSTANT */) {
  12725. return valueType;
  12726. }
  12727. if (valueType < returnType) {
  12728. returnType = valueType;
  12729. }
  12730. }
  12731. }
  12732. return returnType;
  12733. }
  12734. function getNodeProps(node) {
  12735. const codegenNode = node.codegenNode;
  12736. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12737. return codegenNode.props;
  12738. }
  12739. }
  12740. function getPatchFlag(node) {
  12741. const flag = node.patchFlag;
  12742. return flag ? parseInt(flag, 10) : undefined;
  12743. }
  12744. function createTransformContext(root, { filename = '', prefixIdentifiers = false, hoistStatic = false, cacheHandlers = false, nodeTransforms = [], directiveTransforms = {}, transformHoist = null, isBuiltInComponent = NOOP, isCustomElement = NOOP, expressionPlugins = [], scopeId = null, slotted = true, ssr = false, inSSR = false, ssrCssVars = ``, bindingMetadata = EMPTY_OBJ, inline = false, isTS = false, onError = defaultOnError, onWarn = defaultOnWarn, compatConfig }) {
  12745. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  12746. const context = {
  12747. // options
  12748. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  12749. prefixIdentifiers,
  12750. hoistStatic,
  12751. cacheHandlers,
  12752. nodeTransforms,
  12753. directiveTransforms,
  12754. transformHoist,
  12755. isBuiltInComponent,
  12756. isCustomElement,
  12757. expressionPlugins,
  12758. scopeId,
  12759. slotted,
  12760. ssr,
  12761. inSSR,
  12762. ssrCssVars,
  12763. bindingMetadata,
  12764. inline,
  12765. isTS,
  12766. onError,
  12767. onWarn,
  12768. compatConfig,
  12769. // state
  12770. root,
  12771. helpers: new Map(),
  12772. components: new Set(),
  12773. directives: new Set(),
  12774. hoists: [],
  12775. imports: [],
  12776. constantCache: new Map(),
  12777. temps: 0,
  12778. cached: 0,
  12779. identifiers: Object.create(null),
  12780. scopes: {
  12781. vFor: 0,
  12782. vSlot: 0,
  12783. vPre: 0,
  12784. vOnce: 0
  12785. },
  12786. parent: null,
  12787. currentNode: root,
  12788. childIndex: 0,
  12789. inVOnce: false,
  12790. // methods
  12791. helper(name) {
  12792. const count = context.helpers.get(name) || 0;
  12793. context.helpers.set(name, count + 1);
  12794. return name;
  12795. },
  12796. removeHelper(name) {
  12797. const count = context.helpers.get(name);
  12798. if (count) {
  12799. const currentCount = count - 1;
  12800. if (!currentCount) {
  12801. context.helpers.delete(name);
  12802. }
  12803. else {
  12804. context.helpers.set(name, currentCount);
  12805. }
  12806. }
  12807. },
  12808. helperString(name) {
  12809. return `_${helperNameMap[context.helper(name)]}`;
  12810. },
  12811. replaceNode(node) {
  12812. /* istanbul ignore if */
  12813. {
  12814. if (!context.currentNode) {
  12815. throw new Error(`Node being replaced is already removed.`);
  12816. }
  12817. if (!context.parent) {
  12818. throw new Error(`Cannot replace root node.`);
  12819. }
  12820. }
  12821. context.parent.children[context.childIndex] = context.currentNode = node;
  12822. },
  12823. removeNode(node) {
  12824. if (!context.parent) {
  12825. throw new Error(`Cannot remove root node.`);
  12826. }
  12827. const list = context.parent.children;
  12828. const removalIndex = node
  12829. ? list.indexOf(node)
  12830. : context.currentNode
  12831. ? context.childIndex
  12832. : -1;
  12833. /* istanbul ignore if */
  12834. if (removalIndex < 0) {
  12835. throw new Error(`node being removed is not a child of current parent`);
  12836. }
  12837. if (!node || node === context.currentNode) {
  12838. // current node removed
  12839. context.currentNode = null;
  12840. context.onNodeRemoved();
  12841. }
  12842. else {
  12843. // sibling node removed
  12844. if (context.childIndex > removalIndex) {
  12845. context.childIndex--;
  12846. context.onNodeRemoved();
  12847. }
  12848. }
  12849. context.parent.children.splice(removalIndex, 1);
  12850. },
  12851. onNodeRemoved: () => { },
  12852. addIdentifiers(exp) {
  12853. },
  12854. removeIdentifiers(exp) {
  12855. },
  12856. hoist(exp) {
  12857. if (isString(exp))
  12858. exp = createSimpleExpression(exp);
  12859. context.hoists.push(exp);
  12860. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
  12861. identifier.hoisted = exp;
  12862. return identifier;
  12863. },
  12864. cache(exp, isVNode = false) {
  12865. return createCacheExpression(context.cached++, exp, isVNode);
  12866. }
  12867. };
  12868. return context;
  12869. }
  12870. function transform(root, options) {
  12871. const context = createTransformContext(root, options);
  12872. traverseNode(root, context);
  12873. if (options.hoistStatic) {
  12874. hoistStatic(root, context);
  12875. }
  12876. if (!options.ssr) {
  12877. createRootCodegen(root, context);
  12878. }
  12879. // finalize meta information
  12880. root.helpers = [...context.helpers.keys()];
  12881. root.components = [...context.components];
  12882. root.directives = [...context.directives];
  12883. root.imports = context.imports;
  12884. root.hoists = context.hoists;
  12885. root.temps = context.temps;
  12886. root.cached = context.cached;
  12887. }
  12888. function createRootCodegen(root, context) {
  12889. const { helper } = context;
  12890. const { children } = root;
  12891. if (children.length === 1) {
  12892. const child = children[0];
  12893. // if the single child is an element, turn it into a block.
  12894. if (isSingleElementRoot(root, child) && child.codegenNode) {
  12895. // single element root is never hoisted so codegenNode will never be
  12896. // SimpleExpressionNode
  12897. const codegenNode = child.codegenNode;
  12898. if (codegenNode.type === 13 /* VNODE_CALL */) {
  12899. makeBlock(codegenNode, context);
  12900. }
  12901. root.codegenNode = codegenNode;
  12902. }
  12903. else {
  12904. // - single <slot/>, IfNode, ForNode: already blocks.
  12905. // - single text node: always patched.
  12906. // root codegen falls through via genNode()
  12907. root.codegenNode = child;
  12908. }
  12909. }
  12910. else if (children.length > 1) {
  12911. // root has multiple nodes - return a fragment block.
  12912. let patchFlag = 64 /* STABLE_FRAGMENT */;
  12913. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  12914. // check if the fragment actually contains a single valid child with
  12915. // the rest being comments
  12916. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  12917. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  12918. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  12919. }
  12920. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, undefined, false /* isComponent */);
  12921. }
  12922. else ;
  12923. }
  12924. function traverseChildren(parent, context) {
  12925. let i = 0;
  12926. const nodeRemoved = () => {
  12927. i--;
  12928. };
  12929. for (; i < parent.children.length; i++) {
  12930. const child = parent.children[i];
  12931. if (isString(child))
  12932. continue;
  12933. context.parent = parent;
  12934. context.childIndex = i;
  12935. context.onNodeRemoved = nodeRemoved;
  12936. traverseNode(child, context);
  12937. }
  12938. }
  12939. function traverseNode(node, context) {
  12940. context.currentNode = node;
  12941. // apply transform plugins
  12942. const { nodeTransforms } = context;
  12943. const exitFns = [];
  12944. for (let i = 0; i < nodeTransforms.length; i++) {
  12945. const onExit = nodeTransforms[i](node, context);
  12946. if (onExit) {
  12947. if (isArray(onExit)) {
  12948. exitFns.push(...onExit);
  12949. }
  12950. else {
  12951. exitFns.push(onExit);
  12952. }
  12953. }
  12954. if (!context.currentNode) {
  12955. // node was removed
  12956. return;
  12957. }
  12958. else {
  12959. // node may have been replaced
  12960. node = context.currentNode;
  12961. }
  12962. }
  12963. switch (node.type) {
  12964. case 3 /* COMMENT */:
  12965. if (!context.ssr) {
  12966. // inject import for the Comment symbol, which is needed for creating
  12967. // comment nodes with `createVNode`
  12968. context.helper(CREATE_COMMENT);
  12969. }
  12970. break;
  12971. case 5 /* INTERPOLATION */:
  12972. // no need to traverse, but we need to inject toString helper
  12973. if (!context.ssr) {
  12974. context.helper(TO_DISPLAY_STRING);
  12975. }
  12976. break;
  12977. // for container types, further traverse downwards
  12978. case 9 /* IF */:
  12979. for (let i = 0; i < node.branches.length; i++) {
  12980. traverseNode(node.branches[i], context);
  12981. }
  12982. break;
  12983. case 10 /* IF_BRANCH */:
  12984. case 11 /* FOR */:
  12985. case 1 /* ELEMENT */:
  12986. case 0 /* ROOT */:
  12987. traverseChildren(node, context);
  12988. break;
  12989. }
  12990. // exit transforms
  12991. context.currentNode = node;
  12992. let i = exitFns.length;
  12993. while (i--) {
  12994. exitFns[i]();
  12995. }
  12996. }
  12997. function createStructuralDirectiveTransform(name, fn) {
  12998. const matches = isString(name)
  12999. ? (n) => n === name
  13000. : (n) => name.test(n);
  13001. return (node, context) => {
  13002. if (node.type === 1 /* ELEMENT */) {
  13003. const { props } = node;
  13004. // structural directive transforms are not concerned with slots
  13005. // as they are handled separately in vSlot.ts
  13006. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  13007. return;
  13008. }
  13009. const exitFns = [];
  13010. for (let i = 0; i < props.length; i++) {
  13011. const prop = props[i];
  13012. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  13013. // structural directives are removed to avoid infinite recursion
  13014. // also we remove them *before* applying so that it can further
  13015. // traverse itself in case it moves the node around
  13016. props.splice(i, 1);
  13017. i--;
  13018. const onExit = fn(node, prop, context);
  13019. if (onExit)
  13020. exitFns.push(onExit);
  13021. }
  13022. }
  13023. return exitFns;
  13024. }
  13025. };
  13026. }
  13027. const PURE_ANNOTATION = `/*#__PURE__*/`;
  13028. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  13029. function createCodegenContext(ast, { mode = 'function', prefixIdentifiers = mode === 'module', sourceMap = false, filename = `template.vue.html`, scopeId = null, optimizeImports = false, runtimeGlobalName = `Vue`, runtimeModuleName = `vue`, ssrRuntimeModuleName = 'vue/server-renderer', ssr = false, isTS = false, inSSR = false }) {
  13030. const context = {
  13031. mode,
  13032. prefixIdentifiers,
  13033. sourceMap,
  13034. filename,
  13035. scopeId,
  13036. optimizeImports,
  13037. runtimeGlobalName,
  13038. runtimeModuleName,
  13039. ssrRuntimeModuleName,
  13040. ssr,
  13041. isTS,
  13042. inSSR,
  13043. source: ast.loc.source,
  13044. code: ``,
  13045. column: 1,
  13046. line: 1,
  13047. offset: 0,
  13048. indentLevel: 0,
  13049. pure: false,
  13050. map: undefined,
  13051. helper(key) {
  13052. return `_${helperNameMap[key]}`;
  13053. },
  13054. push(code, node) {
  13055. context.code += code;
  13056. },
  13057. indent() {
  13058. newline(++context.indentLevel);
  13059. },
  13060. deindent(withoutNewLine = false) {
  13061. if (withoutNewLine) {
  13062. --context.indentLevel;
  13063. }
  13064. else {
  13065. newline(--context.indentLevel);
  13066. }
  13067. },
  13068. newline() {
  13069. newline(context.indentLevel);
  13070. }
  13071. };
  13072. function newline(n) {
  13073. context.push('\n' + ` `.repeat(n));
  13074. }
  13075. return context;
  13076. }
  13077. function generate(ast, options = {}) {
  13078. const context = createCodegenContext(ast, options);
  13079. if (options.onContextCreated)
  13080. options.onContextCreated(context);
  13081. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  13082. const hasHelpers = ast.helpers.length > 0;
  13083. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  13084. // preambles
  13085. // in setup() inline mode, the preamble is generated in a sub context
  13086. // and returned separately.
  13087. const preambleContext = context;
  13088. {
  13089. genFunctionPreamble(ast, preambleContext);
  13090. }
  13091. // enter render function
  13092. const functionName = ssr ? `ssrRender` : `render`;
  13093. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  13094. const signature = args.join(', ');
  13095. {
  13096. push(`function ${functionName}(${signature}) {`);
  13097. }
  13098. indent();
  13099. if (useWithBlock) {
  13100. push(`with (_ctx) {`);
  13101. indent();
  13102. // function mode const declarations should be inside with block
  13103. // also they should be renamed to avoid collision with user properties
  13104. if (hasHelpers) {
  13105. push(`const { ${ast.helpers.map(aliasHelper).join(', ')} } = _Vue`);
  13106. push(`\n`);
  13107. newline();
  13108. }
  13109. }
  13110. // generate asset resolution statements
  13111. if (ast.components.length) {
  13112. genAssets(ast.components, 'component', context);
  13113. if (ast.directives.length || ast.temps > 0) {
  13114. newline();
  13115. }
  13116. }
  13117. if (ast.directives.length) {
  13118. genAssets(ast.directives, 'directive', context);
  13119. if (ast.temps > 0) {
  13120. newline();
  13121. }
  13122. }
  13123. if (ast.temps > 0) {
  13124. push(`let `);
  13125. for (let i = 0; i < ast.temps; i++) {
  13126. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  13127. }
  13128. }
  13129. if (ast.components.length || ast.directives.length || ast.temps) {
  13130. push(`\n`);
  13131. newline();
  13132. }
  13133. // generate the VNode tree expression
  13134. if (!ssr) {
  13135. push(`return `);
  13136. }
  13137. if (ast.codegenNode) {
  13138. genNode(ast.codegenNode, context);
  13139. }
  13140. else {
  13141. push(`null`);
  13142. }
  13143. if (useWithBlock) {
  13144. deindent();
  13145. push(`}`);
  13146. }
  13147. deindent();
  13148. push(`}`);
  13149. return {
  13150. ast,
  13151. code: context.code,
  13152. preamble: ``,
  13153. // SourceMapGenerator does have toJSON() method but it's not in the types
  13154. map: context.map ? context.map.toJSON() : undefined
  13155. };
  13156. }
  13157. function genFunctionPreamble(ast, context) {
  13158. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
  13159. const VueBinding = runtimeGlobalName;
  13160. // Generate const declaration for helpers
  13161. // In prefix mode, we place the const declaration at top so it's done
  13162. // only once; But if we not prefixing, we place the declaration inside the
  13163. // with block so it doesn't incur the `in` check cost for every helper access.
  13164. if (ast.helpers.length > 0) {
  13165. {
  13166. // "with" mode.
  13167. // save Vue in a separate variable to avoid collision
  13168. push(`const _Vue = ${VueBinding}\n`);
  13169. // in "with" mode, helpers are declared inside the with block to avoid
  13170. // has check cost, but hoists are lifted out of the function - we need
  13171. // to provide the helper here.
  13172. if (ast.hoists.length) {
  13173. const staticHelpers = [
  13174. CREATE_VNODE,
  13175. CREATE_ELEMENT_VNODE,
  13176. CREATE_COMMENT,
  13177. CREATE_TEXT,
  13178. CREATE_STATIC
  13179. ]
  13180. .filter(helper => ast.helpers.includes(helper))
  13181. .map(aliasHelper)
  13182. .join(', ');
  13183. push(`const { ${staticHelpers} } = _Vue\n`);
  13184. }
  13185. }
  13186. }
  13187. genHoists(ast.hoists, context);
  13188. newline();
  13189. push(`return `);
  13190. }
  13191. function genAssets(assets, type, { helper, push, newline, isTS }) {
  13192. const resolver = helper(type === 'component'
  13193. ? RESOLVE_COMPONENT
  13194. : RESOLVE_DIRECTIVE);
  13195. for (let i = 0; i < assets.length; i++) {
  13196. let id = assets[i];
  13197. // potential component implicit self-reference inferred from SFC filename
  13198. const maybeSelfReference = id.endsWith('__self');
  13199. if (maybeSelfReference) {
  13200. id = id.slice(0, -6);
  13201. }
  13202. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`);
  13203. if (i < assets.length - 1) {
  13204. newline();
  13205. }
  13206. }
  13207. }
  13208. function genHoists(hoists, context) {
  13209. if (!hoists.length) {
  13210. return;
  13211. }
  13212. context.pure = true;
  13213. const { push, newline, helper, scopeId, mode } = context;
  13214. newline();
  13215. for (let i = 0; i < hoists.length; i++) {
  13216. const exp = hoists[i];
  13217. if (exp) {
  13218. push(`const _hoisted_${i + 1} = ${``}`);
  13219. genNode(exp, context);
  13220. newline();
  13221. }
  13222. }
  13223. context.pure = false;
  13224. }
  13225. function isText$1(n) {
  13226. return (isString(n) ||
  13227. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  13228. n.type === 2 /* TEXT */ ||
  13229. n.type === 5 /* INTERPOLATION */ ||
  13230. n.type === 8 /* COMPOUND_EXPRESSION */);
  13231. }
  13232. function genNodeListAsArray(nodes, context) {
  13233. const multilines = nodes.length > 3 ||
  13234. (nodes.some(n => isArray(n) || !isText$1(n)));
  13235. context.push(`[`);
  13236. multilines && context.indent();
  13237. genNodeList(nodes, context, multilines);
  13238. multilines && context.deindent();
  13239. context.push(`]`);
  13240. }
  13241. function genNodeList(nodes, context, multilines = false, comma = true) {
  13242. const { push, newline } = context;
  13243. for (let i = 0; i < nodes.length; i++) {
  13244. const node = nodes[i];
  13245. if (isString(node)) {
  13246. push(node);
  13247. }
  13248. else if (isArray(node)) {
  13249. genNodeListAsArray(node, context);
  13250. }
  13251. else {
  13252. genNode(node, context);
  13253. }
  13254. if (i < nodes.length - 1) {
  13255. if (multilines) {
  13256. comma && push(',');
  13257. newline();
  13258. }
  13259. else {
  13260. comma && push(', ');
  13261. }
  13262. }
  13263. }
  13264. }
  13265. function genNode(node, context) {
  13266. if (isString(node)) {
  13267. context.push(node);
  13268. return;
  13269. }
  13270. if (isSymbol(node)) {
  13271. context.push(context.helper(node));
  13272. return;
  13273. }
  13274. switch (node.type) {
  13275. case 1 /* ELEMENT */:
  13276. case 9 /* IF */:
  13277. case 11 /* FOR */:
  13278. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  13279. `Apply appropriate transforms first.`);
  13280. genNode(node.codegenNode, context);
  13281. break;
  13282. case 2 /* TEXT */:
  13283. genText(node, context);
  13284. break;
  13285. case 4 /* SIMPLE_EXPRESSION */:
  13286. genExpression(node, context);
  13287. break;
  13288. case 5 /* INTERPOLATION */:
  13289. genInterpolation(node, context);
  13290. break;
  13291. case 12 /* TEXT_CALL */:
  13292. genNode(node.codegenNode, context);
  13293. break;
  13294. case 8 /* COMPOUND_EXPRESSION */:
  13295. genCompoundExpression(node, context);
  13296. break;
  13297. case 3 /* COMMENT */:
  13298. genComment(node, context);
  13299. break;
  13300. case 13 /* VNODE_CALL */:
  13301. genVNodeCall(node, context);
  13302. break;
  13303. case 14 /* JS_CALL_EXPRESSION */:
  13304. genCallExpression(node, context);
  13305. break;
  13306. case 15 /* JS_OBJECT_EXPRESSION */:
  13307. genObjectExpression(node, context);
  13308. break;
  13309. case 17 /* JS_ARRAY_EXPRESSION */:
  13310. genArrayExpression(node, context);
  13311. break;
  13312. case 18 /* JS_FUNCTION_EXPRESSION */:
  13313. genFunctionExpression(node, context);
  13314. break;
  13315. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  13316. genConditionalExpression(node, context);
  13317. break;
  13318. case 20 /* JS_CACHE_EXPRESSION */:
  13319. genCacheExpression(node, context);
  13320. break;
  13321. case 21 /* JS_BLOCK_STATEMENT */:
  13322. genNodeList(node.body, context, true, false);
  13323. break;
  13324. // SSR only types
  13325. case 22 /* JS_TEMPLATE_LITERAL */:
  13326. break;
  13327. case 23 /* JS_IF_STATEMENT */:
  13328. break;
  13329. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  13330. break;
  13331. case 25 /* JS_SEQUENCE_EXPRESSION */:
  13332. break;
  13333. case 26 /* JS_RETURN_STATEMENT */:
  13334. break;
  13335. /* istanbul ignore next */
  13336. case 10 /* IF_BRANCH */:
  13337. // noop
  13338. break;
  13339. default:
  13340. {
  13341. assert(false, `unhandled codegen node type: ${node.type}`);
  13342. // make sure we exhaust all possible types
  13343. const exhaustiveCheck = node;
  13344. return exhaustiveCheck;
  13345. }
  13346. }
  13347. }
  13348. function genText(node, context) {
  13349. context.push(JSON.stringify(node.content), node);
  13350. }
  13351. function genExpression(node, context) {
  13352. const { content, isStatic } = node;
  13353. context.push(isStatic ? JSON.stringify(content) : content, node);
  13354. }
  13355. function genInterpolation(node, context) {
  13356. const { push, helper, pure } = context;
  13357. if (pure)
  13358. push(PURE_ANNOTATION);
  13359. push(`${helper(TO_DISPLAY_STRING)}(`);
  13360. genNode(node.content, context);
  13361. push(`)`);
  13362. }
  13363. function genCompoundExpression(node, context) {
  13364. for (let i = 0; i < node.children.length; i++) {
  13365. const child = node.children[i];
  13366. if (isString(child)) {
  13367. context.push(child);
  13368. }
  13369. else {
  13370. genNode(child, context);
  13371. }
  13372. }
  13373. }
  13374. function genExpressionAsPropertyKey(node, context) {
  13375. const { push } = context;
  13376. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  13377. push(`[`);
  13378. genCompoundExpression(node, context);
  13379. push(`]`);
  13380. }
  13381. else if (node.isStatic) {
  13382. // only quote keys if necessary
  13383. const text = isSimpleIdentifier(node.content)
  13384. ? node.content
  13385. : JSON.stringify(node.content);
  13386. push(text, node);
  13387. }
  13388. else {
  13389. push(`[${node.content}]`, node);
  13390. }
  13391. }
  13392. function genComment(node, context) {
  13393. const { push, helper, pure } = context;
  13394. if (pure) {
  13395. push(PURE_ANNOTATION);
  13396. }
  13397. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  13398. }
  13399. function genVNodeCall(node, context) {
  13400. const { push, helper, pure } = context;
  13401. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent } = node;
  13402. if (directives) {
  13403. push(helper(WITH_DIRECTIVES) + `(`);
  13404. }
  13405. if (isBlock) {
  13406. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  13407. }
  13408. if (pure) {
  13409. push(PURE_ANNOTATION);
  13410. }
  13411. const callHelper = isBlock
  13412. ? getVNodeBlockHelper(context.inSSR, isComponent)
  13413. : getVNodeHelper(context.inSSR, isComponent);
  13414. push(helper(callHelper) + `(`, node);
  13415. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  13416. push(`)`);
  13417. if (isBlock) {
  13418. push(`)`);
  13419. }
  13420. if (directives) {
  13421. push(`, `);
  13422. genNode(directives, context);
  13423. push(`)`);
  13424. }
  13425. }
  13426. function genNullableArgs(args) {
  13427. let i = args.length;
  13428. while (i--) {
  13429. if (args[i] != null)
  13430. break;
  13431. }
  13432. return args.slice(0, i + 1).map(arg => arg || `null`);
  13433. }
  13434. // JavaScript
  13435. function genCallExpression(node, context) {
  13436. const { push, helper, pure } = context;
  13437. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  13438. if (pure) {
  13439. push(PURE_ANNOTATION);
  13440. }
  13441. push(callee + `(`, node);
  13442. genNodeList(node.arguments, context);
  13443. push(`)`);
  13444. }
  13445. function genObjectExpression(node, context) {
  13446. const { push, indent, deindent, newline } = context;
  13447. const { properties } = node;
  13448. if (!properties.length) {
  13449. push(`{}`, node);
  13450. return;
  13451. }
  13452. const multilines = properties.length > 1 ||
  13453. (properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  13454. push(multilines ? `{` : `{ `);
  13455. multilines && indent();
  13456. for (let i = 0; i < properties.length; i++) {
  13457. const { key, value } = properties[i];
  13458. // key
  13459. genExpressionAsPropertyKey(key, context);
  13460. push(`: `);
  13461. // value
  13462. genNode(value, context);
  13463. if (i < properties.length - 1) {
  13464. // will only reach this if it's multilines
  13465. push(`,`);
  13466. newline();
  13467. }
  13468. }
  13469. multilines && deindent();
  13470. push(multilines ? `}` : ` }`);
  13471. }
  13472. function genArrayExpression(node, context) {
  13473. genNodeListAsArray(node.elements, context);
  13474. }
  13475. function genFunctionExpression(node, context) {
  13476. const { push, indent, deindent } = context;
  13477. const { params, returns, body, newline, isSlot } = node;
  13478. if (isSlot) {
  13479. // wrap slot functions with owner context
  13480. push(`_${helperNameMap[WITH_CTX]}(`);
  13481. }
  13482. push(`(`, node);
  13483. if (isArray(params)) {
  13484. genNodeList(params, context);
  13485. }
  13486. else if (params) {
  13487. genNode(params, context);
  13488. }
  13489. push(`) => `);
  13490. if (newline || body) {
  13491. push(`{`);
  13492. indent();
  13493. }
  13494. if (returns) {
  13495. if (newline) {
  13496. push(`return `);
  13497. }
  13498. if (isArray(returns)) {
  13499. genNodeListAsArray(returns, context);
  13500. }
  13501. else {
  13502. genNode(returns, context);
  13503. }
  13504. }
  13505. else if (body) {
  13506. genNode(body, context);
  13507. }
  13508. if (newline || body) {
  13509. deindent();
  13510. push(`}`);
  13511. }
  13512. if (isSlot) {
  13513. push(`)`);
  13514. }
  13515. }
  13516. function genConditionalExpression(node, context) {
  13517. const { test, consequent, alternate, newline: needNewline } = node;
  13518. const { push, indent, deindent, newline } = context;
  13519. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  13520. const needsParens = !isSimpleIdentifier(test.content);
  13521. needsParens && push(`(`);
  13522. genExpression(test, context);
  13523. needsParens && push(`)`);
  13524. }
  13525. else {
  13526. push(`(`);
  13527. genNode(test, context);
  13528. push(`)`);
  13529. }
  13530. needNewline && indent();
  13531. context.indentLevel++;
  13532. needNewline || push(` `);
  13533. push(`? `);
  13534. genNode(consequent, context);
  13535. context.indentLevel--;
  13536. needNewline && newline();
  13537. needNewline || push(` `);
  13538. push(`: `);
  13539. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  13540. if (!isNested) {
  13541. context.indentLevel++;
  13542. }
  13543. genNode(alternate, context);
  13544. if (!isNested) {
  13545. context.indentLevel--;
  13546. }
  13547. needNewline && deindent(true /* without newline */);
  13548. }
  13549. function genCacheExpression(node, context) {
  13550. const { push, helper, indent, deindent, newline } = context;
  13551. push(`_cache[${node.index}] || (`);
  13552. if (node.isVNode) {
  13553. indent();
  13554. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  13555. newline();
  13556. }
  13557. push(`_cache[${node.index}] = `);
  13558. genNode(node.value, context);
  13559. if (node.isVNode) {
  13560. push(`,`);
  13561. newline();
  13562. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  13563. newline();
  13564. push(`_cache[${node.index}]`);
  13565. deindent();
  13566. }
  13567. push(`)`);
  13568. }
  13569. // these keywords should not appear inside expressions, but operators like
  13570. // typeof, instanceof and in are allowed
  13571. const prohibitedKeywordRE = new RegExp('\\b' +
  13572. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  13573. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  13574. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  13575. .split(',')
  13576. .join('\\b|\\b') +
  13577. '\\b');
  13578. // strip strings in expressions
  13579. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  13580. /**
  13581. * Validate a non-prefixed expression.
  13582. * This is only called when using the in-browser runtime compiler since it
  13583. * doesn't prefix expressions.
  13584. */
  13585. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  13586. const exp = node.content;
  13587. // empty expressions are validated per-directive since some directives
  13588. // do allow empty expressions.
  13589. if (!exp.trim()) {
  13590. return;
  13591. }
  13592. try {
  13593. new Function(asRawStatements
  13594. ? ` ${exp} `
  13595. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  13596. }
  13597. catch (e) {
  13598. let message = e.message;
  13599. const keywordMatch = exp
  13600. .replace(stripStringRE, '')
  13601. .match(prohibitedKeywordRE);
  13602. if (keywordMatch) {
  13603. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  13604. }
  13605. context.onError(createCompilerError(44 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  13606. }
  13607. }
  13608. const transformExpression = (node, context) => {
  13609. if (node.type === 5 /* INTERPOLATION */) {
  13610. node.content = processExpression(node.content, context);
  13611. }
  13612. else if (node.type === 1 /* ELEMENT */) {
  13613. // handle directives on element
  13614. for (let i = 0; i < node.props.length; i++) {
  13615. const dir = node.props[i];
  13616. // do not process for v-on & v-for since they are special handled
  13617. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  13618. const exp = dir.exp;
  13619. const arg = dir.arg;
  13620. // do not process exp if this is v-on:arg - we need special handling
  13621. // for wrapping inline statements.
  13622. if (exp &&
  13623. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  13624. !(dir.name === 'on' && arg)) {
  13625. dir.exp = processExpression(exp, context,
  13626. // slot args must be processed as function params
  13627. dir.name === 'slot');
  13628. }
  13629. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  13630. dir.arg = processExpression(arg, context);
  13631. }
  13632. }
  13633. }
  13634. }
  13635. };
  13636. // Important: since this function uses Node.js only dependencies, it should
  13637. // always be used with a leading !true check so that it can be
  13638. // tree-shaken from the browser build.
  13639. function processExpression(node, context,
  13640. // some expressions like v-slot props & v-for aliases should be parsed as
  13641. // function params
  13642. asParams = false,
  13643. // v-on handler values may contain multiple statements
  13644. asRawStatements = false, localVars = Object.create(context.identifiers)) {
  13645. {
  13646. {
  13647. // simple in-browser validation (same logic in 2.x)
  13648. validateBrowserExpression(node, context, asParams, asRawStatements);
  13649. }
  13650. return node;
  13651. }
  13652. }
  13653. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  13654. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  13655. // #1587: We need to dynamically increment the key based on the current
  13656. // node's sibling nodes, since chained v-if/else branches are
  13657. // rendered at the same depth
  13658. const siblings = context.parent.children;
  13659. let i = siblings.indexOf(ifNode);
  13660. let key = 0;
  13661. while (i-- >= 0) {
  13662. const sibling = siblings[i];
  13663. if (sibling && sibling.type === 9 /* IF */) {
  13664. key += sibling.branches.length;
  13665. }
  13666. }
  13667. // Exit callback. Complete the codegenNode when all children have been
  13668. // transformed.
  13669. return () => {
  13670. if (isRoot) {
  13671. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  13672. }
  13673. else {
  13674. // attach this branch's codegen node to the v-if root.
  13675. const parentCondition = getParentCondition(ifNode.codegenNode);
  13676. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  13677. }
  13678. };
  13679. });
  13680. });
  13681. // target-agnostic transform used for both Client and SSR
  13682. function processIf(node, dir, context, processCodegen) {
  13683. if (dir.name !== 'else' &&
  13684. (!dir.exp || !dir.exp.content.trim())) {
  13685. const loc = dir.exp ? dir.exp.loc : node.loc;
  13686. context.onError(createCompilerError(28 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  13687. dir.exp = createSimpleExpression(`true`, false, loc);
  13688. }
  13689. if (dir.exp) {
  13690. validateBrowserExpression(dir.exp, context);
  13691. }
  13692. if (dir.name === 'if') {
  13693. const branch = createIfBranch(node, dir);
  13694. const ifNode = {
  13695. type: 9 /* IF */,
  13696. loc: node.loc,
  13697. branches: [branch]
  13698. };
  13699. context.replaceNode(ifNode);
  13700. if (processCodegen) {
  13701. return processCodegen(ifNode, branch, true);
  13702. }
  13703. }
  13704. else {
  13705. // locate the adjacent v-if
  13706. const siblings = context.parent.children;
  13707. const comments = [];
  13708. let i = siblings.indexOf(node);
  13709. while (i-- >= -1) {
  13710. const sibling = siblings[i];
  13711. if (sibling && sibling.type === 3 /* COMMENT */) {
  13712. context.removeNode(sibling);
  13713. comments.unshift(sibling);
  13714. continue;
  13715. }
  13716. if (sibling &&
  13717. sibling.type === 2 /* TEXT */ &&
  13718. !sibling.content.trim().length) {
  13719. context.removeNode(sibling);
  13720. continue;
  13721. }
  13722. if (sibling && sibling.type === 9 /* IF */) {
  13723. // Check if v-else was followed by v-else-if
  13724. if (dir.name === 'else-if' &&
  13725. sibling.branches[sibling.branches.length - 1].condition === undefined) {
  13726. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13727. }
  13728. // move the node to the if node's branches
  13729. context.removeNode();
  13730. const branch = createIfBranch(node, dir);
  13731. if (comments.length &&
  13732. // #3619 ignore comments if the v-if is direct child of <transition>
  13733. !(context.parent &&
  13734. context.parent.type === 1 /* ELEMENT */ &&
  13735. isBuiltInType(context.parent.tag, 'transition'))) {
  13736. branch.children = [...comments, ...branch.children];
  13737. }
  13738. // check if user is forcing same key on different branches
  13739. {
  13740. const key = branch.userKey;
  13741. if (key) {
  13742. sibling.branches.forEach(({ userKey }) => {
  13743. if (isSameKey(userKey, key)) {
  13744. context.onError(createCompilerError(29 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  13745. }
  13746. });
  13747. }
  13748. }
  13749. sibling.branches.push(branch);
  13750. const onExit = processCodegen && processCodegen(sibling, branch, false);
  13751. // since the branch was removed, it will not be traversed.
  13752. // make sure to traverse here.
  13753. traverseNode(branch, context);
  13754. // call on exit
  13755. if (onExit)
  13756. onExit();
  13757. // make sure to reset currentNode after traversal to indicate this
  13758. // node has been removed.
  13759. context.currentNode = null;
  13760. }
  13761. else {
  13762. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  13763. }
  13764. break;
  13765. }
  13766. }
  13767. }
  13768. function createIfBranch(node, dir) {
  13769. const isTemplateIf = node.tagType === 3 /* TEMPLATE */;
  13770. return {
  13771. type: 10 /* IF_BRANCH */,
  13772. loc: node.loc,
  13773. condition: dir.name === 'else' ? undefined : dir.exp,
  13774. children: isTemplateIf && !findDir(node, 'for') ? node.children : [node],
  13775. userKey: findProp(node, `key`),
  13776. isTemplateIf
  13777. };
  13778. }
  13779. function createCodegenNodeForBranch(branch, keyIndex, context) {
  13780. if (branch.condition) {
  13781. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  13782. // make sure to pass in asBlock: true so that the comment node call
  13783. // closes the current block.
  13784. createCallExpression(context.helper(CREATE_COMMENT), [
  13785. '"v-if"' ,
  13786. 'true'
  13787. ]));
  13788. }
  13789. else {
  13790. return createChildrenCodegenNode(branch, keyIndex, context);
  13791. }
  13792. }
  13793. function createChildrenCodegenNode(branch, keyIndex, context) {
  13794. const { helper } = context;
  13795. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
  13796. const { children } = branch;
  13797. const firstChild = children[0];
  13798. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  13799. if (needFragmentWrapper) {
  13800. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  13801. // optimize away nested fragments when child is a ForNode
  13802. const vnodeCall = firstChild.codegenNode;
  13803. injectProp(vnodeCall, keyProperty, context);
  13804. return vnodeCall;
  13805. }
  13806. else {
  13807. let patchFlag = 64 /* STABLE_FRAGMENT */;
  13808. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  13809. // check if the fragment actually contains a single valid child with
  13810. // the rest being comments
  13811. if (!branch.isTemplateIf &&
  13812. children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  13813. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  13814. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  13815. }
  13816. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true, false, false /* isComponent */, branch.loc);
  13817. }
  13818. }
  13819. else {
  13820. const ret = firstChild.codegenNode;
  13821. const vnodeCall = getMemoedVNodeCall(ret);
  13822. // Change createVNode to createBlock.
  13823. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  13824. makeBlock(vnodeCall, context);
  13825. }
  13826. // inject branch key
  13827. injectProp(vnodeCall, keyProperty, context);
  13828. return ret;
  13829. }
  13830. }
  13831. function isSameKey(a, b) {
  13832. if (!a || a.type !== b.type) {
  13833. return false;
  13834. }
  13835. if (a.type === 6 /* ATTRIBUTE */) {
  13836. if (a.value.content !== b.value.content) {
  13837. return false;
  13838. }
  13839. }
  13840. else {
  13841. // directive
  13842. const exp = a.exp;
  13843. const branchExp = b.exp;
  13844. if (exp.type !== branchExp.type) {
  13845. return false;
  13846. }
  13847. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  13848. exp.isStatic !== branchExp.isStatic ||
  13849. exp.content !== branchExp.content) {
  13850. return false;
  13851. }
  13852. }
  13853. return true;
  13854. }
  13855. function getParentCondition(node) {
  13856. while (true) {
  13857. if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13858. if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  13859. node = node.alternate;
  13860. }
  13861. else {
  13862. return node;
  13863. }
  13864. }
  13865. else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
  13866. node = node.value;
  13867. }
  13868. }
  13869. }
  13870. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  13871. const { helper, removeHelper } = context;
  13872. return processFor(node, dir, context, forNode => {
  13873. // create the loop render function expression now, and add the
  13874. // iterator on exit after all children have been traversed
  13875. const renderExp = createCallExpression(helper(RENDER_LIST), [
  13876. forNode.source
  13877. ]);
  13878. const isTemplate = isTemplateNode(node);
  13879. const memo = findDir(node, 'memo');
  13880. const keyProp = findProp(node, `key`);
  13881. const keyExp = keyProp &&
  13882. (keyProp.type === 6 /* ATTRIBUTE */
  13883. ? createSimpleExpression(keyProp.value.content, true)
  13884. : keyProp.exp);
  13885. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  13886. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  13887. forNode.source.constType > 0 /* NOT_CONSTANT */;
  13888. const fragmentFlag = isStableFragment
  13889. ? 64 /* STABLE_FRAGMENT */
  13890. : keyProp
  13891. ? 128 /* KEYED_FRAGMENT */
  13892. : 256 /* UNKEYED_FRAGMENT */;
  13893. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  13894. (` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
  13895. return () => {
  13896. // finish the codegen now that all children have been traversed
  13897. let childBlock;
  13898. const { children } = forNode;
  13899. // check <template v-for> key placement
  13900. if (isTemplate) {
  13901. node.children.some(c => {
  13902. if (c.type === 1 /* ELEMENT */) {
  13903. const key = findProp(c, 'key');
  13904. if (key) {
  13905. context.onError(createCompilerError(33 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  13906. return true;
  13907. }
  13908. }
  13909. });
  13910. }
  13911. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  13912. const slotOutlet = isSlotOutlet(node)
  13913. ? node
  13914. : isTemplate &&
  13915. node.children.length === 1 &&
  13916. isSlotOutlet(node.children[0])
  13917. ? node.children[0] // api-extractor somehow fails to infer this
  13918. : null;
  13919. if (slotOutlet) {
  13920. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  13921. childBlock = slotOutlet.codegenNode;
  13922. if (isTemplate && keyProperty) {
  13923. // <template v-for="..." :key="..."><slot/></template>
  13924. // we need to inject the key to the renderSlot() call.
  13925. // the props for renderSlot is passed as the 3rd argument.
  13926. injectProp(childBlock, keyProperty, context);
  13927. }
  13928. }
  13929. else if (needFragmentWrapper) {
  13930. // <template v-for="..."> with text or multi-elements
  13931. // should generate a fragment block for each loop
  13932. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
  13933. (` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  13934. ), undefined, undefined, true, undefined, false /* isComponent */);
  13935. }
  13936. else {
  13937. // Normal element v-for. Directly use the child's codegenNode
  13938. // but mark it as a block.
  13939. childBlock = children[0]
  13940. .codegenNode;
  13941. if (isTemplate && keyProperty) {
  13942. injectProp(childBlock, keyProperty, context);
  13943. }
  13944. if (childBlock.isBlock !== !isStableFragment) {
  13945. if (childBlock.isBlock) {
  13946. // switch from block to vnode
  13947. removeHelper(OPEN_BLOCK);
  13948. removeHelper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13949. }
  13950. else {
  13951. // switch from vnode to block
  13952. removeHelper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13953. }
  13954. }
  13955. childBlock.isBlock = !isStableFragment;
  13956. if (childBlock.isBlock) {
  13957. helper(OPEN_BLOCK);
  13958. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  13959. }
  13960. else {
  13961. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  13962. }
  13963. }
  13964. if (memo) {
  13965. const loop = createFunctionExpression(createForLoopParams(forNode.parseResult, [
  13966. createSimpleExpression(`_cached`)
  13967. ]));
  13968. loop.body = createBlockStatement([
  13969. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  13970. createCompoundExpression([
  13971. `if (_cached`,
  13972. ...(keyExp ? [` && _cached.key === `, keyExp] : []),
  13973. ` && ${context.helperString(IS_MEMO_SAME)}(_cached, _memo)) return _cached`
  13974. ]),
  13975. createCompoundExpression([`const _item = `, childBlock]),
  13976. createSimpleExpression(`_item.memo = _memo`),
  13977. createSimpleExpression(`return _item`)
  13978. ]);
  13979. renderExp.arguments.push(loop, createSimpleExpression(`_cache`), createSimpleExpression(String(context.cached++)));
  13980. }
  13981. else {
  13982. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  13983. }
  13984. };
  13985. });
  13986. });
  13987. // target-agnostic transform used for both Client and SSR
  13988. function processFor(node, dir, context, processCodegen) {
  13989. if (!dir.exp) {
  13990. context.onError(createCompilerError(31 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  13991. return;
  13992. }
  13993. const parseResult = parseForExpression(
  13994. // can only be simple expression because vFor transform is applied
  13995. // before expression transform.
  13996. dir.exp, context);
  13997. if (!parseResult) {
  13998. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  13999. return;
  14000. }
  14001. const { addIdentifiers, removeIdentifiers, scopes } = context;
  14002. const { source, value, key, index } = parseResult;
  14003. const forNode = {
  14004. type: 11 /* FOR */,
  14005. loc: dir.loc,
  14006. source,
  14007. valueAlias: value,
  14008. keyAlias: key,
  14009. objectIndexAlias: index,
  14010. parseResult,
  14011. children: isTemplateNode(node) ? node.children : [node]
  14012. };
  14013. context.replaceNode(forNode);
  14014. // bookkeeping
  14015. scopes.vFor++;
  14016. const onExit = processCodegen && processCodegen(forNode);
  14017. return () => {
  14018. scopes.vFor--;
  14019. if (onExit)
  14020. onExit();
  14021. };
  14022. }
  14023. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  14024. // This regex doesn't cover the case if key or index aliases have destructuring,
  14025. // but those do not make sense in the first place, so this works in practice.
  14026. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  14027. const stripParensRE = /^\(|\)$/g;
  14028. function parseForExpression(input, context) {
  14029. const loc = input.loc;
  14030. const exp = input.content;
  14031. const inMatch = exp.match(forAliasRE);
  14032. if (!inMatch)
  14033. return;
  14034. const [, LHS, RHS] = inMatch;
  14035. const result = {
  14036. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  14037. value: undefined,
  14038. key: undefined,
  14039. index: undefined
  14040. };
  14041. {
  14042. validateBrowserExpression(result.source, context);
  14043. }
  14044. let valueContent = LHS.trim().replace(stripParensRE, '').trim();
  14045. const trimmedOffset = LHS.indexOf(valueContent);
  14046. const iteratorMatch = valueContent.match(forIteratorRE);
  14047. if (iteratorMatch) {
  14048. valueContent = valueContent.replace(forIteratorRE, '').trim();
  14049. const keyContent = iteratorMatch[1].trim();
  14050. let keyOffset;
  14051. if (keyContent) {
  14052. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  14053. result.key = createAliasExpression(loc, keyContent, keyOffset);
  14054. {
  14055. validateBrowserExpression(result.key, context, true);
  14056. }
  14057. }
  14058. if (iteratorMatch[2]) {
  14059. const indexContent = iteratorMatch[2].trim();
  14060. if (indexContent) {
  14061. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  14062. ? keyOffset + keyContent.length
  14063. : trimmedOffset + valueContent.length));
  14064. {
  14065. validateBrowserExpression(result.index, context, true);
  14066. }
  14067. }
  14068. }
  14069. }
  14070. if (valueContent) {
  14071. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  14072. {
  14073. validateBrowserExpression(result.value, context, true);
  14074. }
  14075. }
  14076. return result;
  14077. }
  14078. function createAliasExpression(range, content, offset) {
  14079. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  14080. }
  14081. function createForLoopParams({ value, key, index }, memoArgs = []) {
  14082. return createParamsList([value, key, index, ...memoArgs]);
  14083. }
  14084. function createParamsList(args) {
  14085. let i = args.length;
  14086. while (i--) {
  14087. if (args[i])
  14088. break;
  14089. }
  14090. return args
  14091. .slice(0, i + 1)
  14092. .map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false));
  14093. }
  14094. const defaultFallback = createSimpleExpression(`undefined`, false);
  14095. // A NodeTransform that:
  14096. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  14097. // by transformExpression. This is only applied in non-browser builds with
  14098. // { prefixIdentifiers: true }.
  14099. // 2. Track v-slot depths so that we know a slot is inside another slot.
  14100. // Note the exit callback is executed before buildSlots() on the same node,
  14101. // so only nested slots see positive numbers.
  14102. const trackSlotScopes = (node, context) => {
  14103. if (node.type === 1 /* ELEMENT */ &&
  14104. (node.tagType === 1 /* COMPONENT */ ||
  14105. node.tagType === 3 /* TEMPLATE */)) {
  14106. // We are only checking non-empty v-slot here
  14107. // since we only care about slots that introduce scope variables.
  14108. const vSlot = findDir(node, 'slot');
  14109. if (vSlot) {
  14110. vSlot.exp;
  14111. context.scopes.vSlot++;
  14112. return () => {
  14113. context.scopes.vSlot--;
  14114. };
  14115. }
  14116. }
  14117. };
  14118. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  14119. // Instead of being a DirectiveTransform, v-slot processing is called during
  14120. // transformElement to build the slots object for a component.
  14121. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  14122. context.helper(WITH_CTX);
  14123. const { children, loc } = node;
  14124. const slotsProperties = [];
  14125. const dynamicSlots = [];
  14126. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  14127. // since it likely uses a scope variable.
  14128. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  14129. // 1. Check for slot with slotProps on component itself.
  14130. // <Comp v-slot="{ prop }"/>
  14131. const onComponentSlot = findDir(node, 'slot', true);
  14132. if (onComponentSlot) {
  14133. const { arg, exp } = onComponentSlot;
  14134. if (arg && !isStaticExp(arg)) {
  14135. hasDynamicSlots = true;
  14136. }
  14137. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  14138. }
  14139. // 2. Iterate through children and check for template slots
  14140. // <template v-slot:foo="{ prop }">
  14141. let hasTemplateSlots = false;
  14142. let hasNamedDefaultSlot = false;
  14143. const implicitDefaultChildren = [];
  14144. const seenSlotNames = new Set();
  14145. for (let i = 0; i < children.length; i++) {
  14146. const slotElement = children[i];
  14147. let slotDir;
  14148. if (!isTemplateNode(slotElement) ||
  14149. !(slotDir = findDir(slotElement, 'slot', true))) {
  14150. // not a <template v-slot>, skip.
  14151. if (slotElement.type !== 3 /* COMMENT */) {
  14152. implicitDefaultChildren.push(slotElement);
  14153. }
  14154. continue;
  14155. }
  14156. if (onComponentSlot) {
  14157. // already has on-component slot - this is incorrect usage.
  14158. context.onError(createCompilerError(37 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  14159. break;
  14160. }
  14161. hasTemplateSlots = true;
  14162. const { children: slotChildren, loc: slotLoc } = slotElement;
  14163. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  14164. // check if name is dynamic.
  14165. let staticSlotName;
  14166. if (isStaticExp(slotName)) {
  14167. staticSlotName = slotName ? slotName.content : `default`;
  14168. }
  14169. else {
  14170. hasDynamicSlots = true;
  14171. }
  14172. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  14173. // check if this slot is conditional (v-if/v-for)
  14174. let vIf;
  14175. let vElse;
  14176. let vFor;
  14177. if ((vIf = findDir(slotElement, 'if'))) {
  14178. hasDynamicSlots = true;
  14179. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  14180. }
  14181. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  14182. // find adjacent v-if
  14183. let j = i;
  14184. let prev;
  14185. while (j--) {
  14186. prev = children[j];
  14187. if (prev.type !== 3 /* COMMENT */) {
  14188. break;
  14189. }
  14190. }
  14191. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  14192. // remove node
  14193. children.splice(i, 1);
  14194. i--;
  14195. // attach this slot to previous conditional
  14196. let conditional = dynamicSlots[dynamicSlots.length - 1];
  14197. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  14198. conditional = conditional.alternate;
  14199. }
  14200. conditional.alternate = vElse.exp
  14201. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  14202. : buildDynamicSlot(slotName, slotFunction);
  14203. }
  14204. else {
  14205. context.onError(createCompilerError(30 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  14206. }
  14207. }
  14208. else if ((vFor = findDir(slotElement, 'for'))) {
  14209. hasDynamicSlots = true;
  14210. const parseResult = vFor.parseResult ||
  14211. parseForExpression(vFor.exp, context);
  14212. if (parseResult) {
  14213. // Render the dynamic slots as an array and add it to the createSlot()
  14214. // args. The runtime knows how to handle it appropriately.
  14215. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  14216. parseResult.source,
  14217. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  14218. ]));
  14219. }
  14220. else {
  14221. context.onError(createCompilerError(32 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  14222. }
  14223. }
  14224. else {
  14225. // check duplicate static names
  14226. if (staticSlotName) {
  14227. if (seenSlotNames.has(staticSlotName)) {
  14228. context.onError(createCompilerError(38 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  14229. continue;
  14230. }
  14231. seenSlotNames.add(staticSlotName);
  14232. if (staticSlotName === 'default') {
  14233. hasNamedDefaultSlot = true;
  14234. }
  14235. }
  14236. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  14237. }
  14238. }
  14239. if (!onComponentSlot) {
  14240. const buildDefaultSlotProperty = (props, children) => {
  14241. const fn = buildSlotFn(props, children, loc);
  14242. return createObjectProperty(`default`, fn);
  14243. };
  14244. if (!hasTemplateSlots) {
  14245. // implicit default slot (on component)
  14246. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  14247. }
  14248. else if (implicitDefaultChildren.length &&
  14249. // #3766
  14250. // with whitespace: 'preserve', whitespaces between slots will end up in
  14251. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  14252. implicitDefaultChildren.some(node => isNonWhitespaceContent(node))) {
  14253. // implicit default slot (mixed with named slots)
  14254. if (hasNamedDefaultSlot) {
  14255. context.onError(createCompilerError(39 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  14256. }
  14257. else {
  14258. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  14259. }
  14260. }
  14261. }
  14262. const slotFlag = hasDynamicSlots
  14263. ? 2 /* DYNAMIC */
  14264. : hasForwardedSlots(node.children)
  14265. ? 3 /* FORWARDED */
  14266. : 1 /* STABLE */;
  14267. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  14268. // 2 = compiled but dynamic = can skip normalization, but must run diff
  14269. // 1 = compiled and static = can skip normalization AND diff as optimized
  14270. createSimpleExpression(slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ), false))), loc);
  14271. if (dynamicSlots.length) {
  14272. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  14273. slots,
  14274. createArrayExpression(dynamicSlots)
  14275. ]);
  14276. }
  14277. return {
  14278. slots,
  14279. hasDynamicSlots
  14280. };
  14281. }
  14282. function buildDynamicSlot(name, fn) {
  14283. return createObjectExpression([
  14284. createObjectProperty(`name`, name),
  14285. createObjectProperty(`fn`, fn)
  14286. ]);
  14287. }
  14288. function hasForwardedSlots(children) {
  14289. for (let i = 0; i < children.length; i++) {
  14290. const child = children[i];
  14291. switch (child.type) {
  14292. case 1 /* ELEMENT */:
  14293. if (child.tagType === 2 /* SLOT */ ||
  14294. hasForwardedSlots(child.children)) {
  14295. return true;
  14296. }
  14297. break;
  14298. case 9 /* IF */:
  14299. if (hasForwardedSlots(child.branches))
  14300. return true;
  14301. break;
  14302. case 10 /* IF_BRANCH */:
  14303. case 11 /* FOR */:
  14304. if (hasForwardedSlots(child.children))
  14305. return true;
  14306. break;
  14307. }
  14308. }
  14309. return false;
  14310. }
  14311. function isNonWhitespaceContent(node) {
  14312. if (node.type !== 2 /* TEXT */ && node.type !== 12 /* TEXT_CALL */)
  14313. return true;
  14314. return node.type === 2 /* TEXT */
  14315. ? !!node.content.trim()
  14316. : isNonWhitespaceContent(node.content);
  14317. }
  14318. // some directive transforms (e.g. v-model) may return a symbol for runtime
  14319. // import, which should be used instead of a resolveDirective call.
  14320. const directiveImportMap = new WeakMap();
  14321. // generate a JavaScript AST for this element's codegen
  14322. const transformElement = (node, context) => {
  14323. // perform the work on exit, after all child expressions have been
  14324. // processed and merged.
  14325. return function postTransformElement() {
  14326. node = context.currentNode;
  14327. if (!(node.type === 1 /* ELEMENT */ &&
  14328. (node.tagType === 0 /* ELEMENT */ ||
  14329. node.tagType === 1 /* COMPONENT */))) {
  14330. return;
  14331. }
  14332. const { tag, props } = node;
  14333. const isComponent = node.tagType === 1 /* COMPONENT */;
  14334. // The goal of the transform is to create a codegenNode implementing the
  14335. // VNodeCall interface.
  14336. let vnodeTag = isComponent
  14337. ? resolveComponentType(node, context)
  14338. : `"${tag}"`;
  14339. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  14340. let vnodeProps;
  14341. let vnodeChildren;
  14342. let vnodePatchFlag;
  14343. let patchFlag = 0;
  14344. let vnodeDynamicProps;
  14345. let dynamicPropNames;
  14346. let vnodeDirectives;
  14347. let shouldUseBlock =
  14348. // dynamic component may resolve to plain elements
  14349. isDynamicComponent ||
  14350. vnodeTag === TELEPORT ||
  14351. vnodeTag === SUSPENSE ||
  14352. (!isComponent &&
  14353. // <svg> and <foreignObject> must be forced into blocks so that block
  14354. // updates inside get proper isSVG flag at runtime. (#639, #643)
  14355. // This is technically web-specific, but splitting the logic out of core
  14356. // leads to too much unnecessary complexity.
  14357. (tag === 'svg' || tag === 'foreignObject'));
  14358. // props
  14359. if (props.length > 0) {
  14360. const propsBuildResult = buildProps(node, context, undefined, isComponent, isDynamicComponent);
  14361. vnodeProps = propsBuildResult.props;
  14362. patchFlag = propsBuildResult.patchFlag;
  14363. dynamicPropNames = propsBuildResult.dynamicPropNames;
  14364. const directives = propsBuildResult.directives;
  14365. vnodeDirectives =
  14366. directives && directives.length
  14367. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  14368. : undefined;
  14369. if (propsBuildResult.shouldUseBlock) {
  14370. shouldUseBlock = true;
  14371. }
  14372. }
  14373. // children
  14374. if (node.children.length > 0) {
  14375. if (vnodeTag === KEEP_ALIVE) {
  14376. // Although a built-in component, we compile KeepAlive with raw children
  14377. // instead of slot functions so that it can be used inside Transition
  14378. // or other Transition-wrapping HOCs.
  14379. // To ensure correct updates with block optimizations, we need to:
  14380. // 1. Force keep-alive into a block. This avoids its children being
  14381. // collected by a parent block.
  14382. shouldUseBlock = true;
  14383. // 2. Force keep-alive to always be updated, since it uses raw children.
  14384. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14385. if (node.children.length > 1) {
  14386. context.onError(createCompilerError(45 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  14387. start: node.children[0].loc.start,
  14388. end: node.children[node.children.length - 1].loc.end,
  14389. source: ''
  14390. }));
  14391. }
  14392. }
  14393. const shouldBuildAsSlots = isComponent &&
  14394. // Teleport is not a real component and has dedicated runtime handling
  14395. vnodeTag !== TELEPORT &&
  14396. // explained above.
  14397. vnodeTag !== KEEP_ALIVE;
  14398. if (shouldBuildAsSlots) {
  14399. const { slots, hasDynamicSlots } = buildSlots(node, context);
  14400. vnodeChildren = slots;
  14401. if (hasDynamicSlots) {
  14402. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  14403. }
  14404. }
  14405. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  14406. const child = node.children[0];
  14407. const type = child.type;
  14408. // check for dynamic text children
  14409. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  14410. type === 8 /* COMPOUND_EXPRESSION */;
  14411. if (hasDynamicTextChild &&
  14412. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  14413. patchFlag |= 1 /* TEXT */;
  14414. }
  14415. // pass directly if the only child is a text node
  14416. // (plain / interpolation / expression)
  14417. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  14418. vnodeChildren = child;
  14419. }
  14420. else {
  14421. vnodeChildren = node.children;
  14422. }
  14423. }
  14424. else {
  14425. vnodeChildren = node.children;
  14426. }
  14427. }
  14428. // patchFlag & dynamicPropNames
  14429. if (patchFlag !== 0) {
  14430. {
  14431. if (patchFlag < 0) {
  14432. // special flags (negative and mutually exclusive)
  14433. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  14434. }
  14435. else {
  14436. // bitwise flags
  14437. const flagNames = Object.keys(PatchFlagNames)
  14438. .map(Number)
  14439. .filter(n => n > 0 && patchFlag & n)
  14440. .map(n => PatchFlagNames[n])
  14441. .join(`, `);
  14442. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  14443. }
  14444. }
  14445. if (dynamicPropNames && dynamicPropNames.length) {
  14446. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  14447. }
  14448. }
  14449. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, isComponent, node.loc);
  14450. };
  14451. };
  14452. function resolveComponentType(node, context, ssr = false) {
  14453. let { tag } = node;
  14454. // 1. dynamic component
  14455. const isExplicitDynamic = isComponentTag(tag);
  14456. const isProp = findProp(node, 'is');
  14457. if (isProp) {
  14458. if (isExplicitDynamic ||
  14459. (false )) {
  14460. const exp = isProp.type === 6 /* ATTRIBUTE */
  14461. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  14462. : isProp.exp;
  14463. if (exp) {
  14464. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14465. exp
  14466. ]);
  14467. }
  14468. }
  14469. else if (isProp.type === 6 /* ATTRIBUTE */ &&
  14470. isProp.value.content.startsWith('vue:')) {
  14471. // <button is="vue:xxx">
  14472. // if not <component>, only is value that starts with "vue:" will be
  14473. // treated as component by the parse phase and reach here, unless it's
  14474. // compat mode where all is values are considered components
  14475. tag = isProp.value.content.slice(4);
  14476. }
  14477. }
  14478. // 1.5 v-is (TODO: Deprecate)
  14479. const isDir = !isExplicitDynamic && findDir(node, 'is');
  14480. if (isDir && isDir.exp) {
  14481. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  14482. isDir.exp
  14483. ]);
  14484. }
  14485. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  14486. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  14487. if (builtIn) {
  14488. // built-ins are simply fallthroughs / have special handling during ssr
  14489. // so we don't need to import their runtime equivalents
  14490. if (!ssr)
  14491. context.helper(builtIn);
  14492. return builtIn;
  14493. }
  14494. // 5. user component (resolve)
  14495. context.helper(RESOLVE_COMPONENT);
  14496. context.components.add(tag);
  14497. return toValidAssetId(tag, `component`);
  14498. }
  14499. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  14500. const { tag, loc: elementLoc, children } = node;
  14501. let properties = [];
  14502. const mergeArgs = [];
  14503. const runtimeDirectives = [];
  14504. const hasChildren = children.length > 0;
  14505. let shouldUseBlock = false;
  14506. // patchFlag analysis
  14507. let patchFlag = 0;
  14508. let hasRef = false;
  14509. let hasClassBinding = false;
  14510. let hasStyleBinding = false;
  14511. let hasHydrationEventBinding = false;
  14512. let hasDynamicKeys = false;
  14513. let hasVnodeHook = false;
  14514. const dynamicPropNames = [];
  14515. const analyzePatchFlag = ({ key, value }) => {
  14516. if (isStaticExp(key)) {
  14517. const name = key.content;
  14518. const isEventHandler = isOn(name);
  14519. if (isEventHandler &&
  14520. (!isComponent || isDynamicComponent) &&
  14521. // omit the flag for click handlers because hydration gives click
  14522. // dedicated fast path.
  14523. name.toLowerCase() !== 'onclick' &&
  14524. // omit v-model handlers
  14525. name !== 'onUpdate:modelValue' &&
  14526. // omit onVnodeXXX hooks
  14527. !isReservedProp(name)) {
  14528. hasHydrationEventBinding = true;
  14529. }
  14530. if (isEventHandler && isReservedProp(name)) {
  14531. hasVnodeHook = true;
  14532. }
  14533. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  14534. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  14535. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  14536. getConstantType(value, context) > 0)) {
  14537. // skip if the prop is a cached handler or has constant value
  14538. return;
  14539. }
  14540. if (name === 'ref') {
  14541. hasRef = true;
  14542. }
  14543. else if (name === 'class') {
  14544. hasClassBinding = true;
  14545. }
  14546. else if (name === 'style') {
  14547. hasStyleBinding = true;
  14548. }
  14549. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  14550. dynamicPropNames.push(name);
  14551. }
  14552. // treat the dynamic class and style binding of the component as dynamic props
  14553. if (isComponent &&
  14554. (name === 'class' || name === 'style') &&
  14555. !dynamicPropNames.includes(name)) {
  14556. dynamicPropNames.push(name);
  14557. }
  14558. }
  14559. else {
  14560. hasDynamicKeys = true;
  14561. }
  14562. };
  14563. for (let i = 0; i < props.length; i++) {
  14564. // static attribute
  14565. const prop = props[i];
  14566. if (prop.type === 6 /* ATTRIBUTE */) {
  14567. const { loc, name, value } = prop;
  14568. let isStatic = true;
  14569. if (name === 'ref') {
  14570. hasRef = true;
  14571. if (context.scopes.vFor > 0) {
  14572. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14573. }
  14574. }
  14575. // skip is on <component>, or is="vue:xxx"
  14576. if (name === 'is' &&
  14577. (isComponentTag(tag) ||
  14578. (value && value.content.startsWith('vue:')) ||
  14579. (false ))) {
  14580. continue;
  14581. }
  14582. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  14583. }
  14584. else {
  14585. // directives
  14586. const { name, arg, exp, loc } = prop;
  14587. const isVBind = name === 'bind';
  14588. const isVOn = name === 'on';
  14589. // skip v-slot - it is handled by its dedicated transform.
  14590. if (name === 'slot') {
  14591. if (!isComponent) {
  14592. context.onError(createCompilerError(40 /* X_V_SLOT_MISPLACED */, loc));
  14593. }
  14594. continue;
  14595. }
  14596. // skip v-once/v-memo - they are handled by dedicated transforms.
  14597. if (name === 'once' || name === 'memo') {
  14598. continue;
  14599. }
  14600. // skip v-is and :is on <component>
  14601. if (name === 'is' ||
  14602. (isVBind &&
  14603. isStaticArgOf(arg, 'is') &&
  14604. (isComponentTag(tag) ||
  14605. (false )))) {
  14606. continue;
  14607. }
  14608. // skip v-on in SSR compilation
  14609. if (isVOn && ssr) {
  14610. continue;
  14611. }
  14612. if (
  14613. // #938: elements with dynamic keys should be forced into blocks
  14614. (isVBind && isStaticArgOf(arg, 'key')) ||
  14615. // inline before-update hooks need to force block so that it is invoked
  14616. // before children
  14617. (isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))) {
  14618. shouldUseBlock = true;
  14619. }
  14620. if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) {
  14621. properties.push(createObjectProperty(createSimpleExpression('ref_for', true), createSimpleExpression('true')));
  14622. }
  14623. // special case for v-bind and v-on with no argument
  14624. if (!arg && (isVBind || isVOn)) {
  14625. hasDynamicKeys = true;
  14626. if (exp) {
  14627. if (properties.length) {
  14628. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14629. properties = [];
  14630. }
  14631. if (isVBind) {
  14632. mergeArgs.push(exp);
  14633. }
  14634. else {
  14635. // v-on="obj" -> toHandlers(obj)
  14636. mergeArgs.push({
  14637. type: 14 /* JS_CALL_EXPRESSION */,
  14638. loc,
  14639. callee: context.helper(TO_HANDLERS),
  14640. arguments: [exp]
  14641. });
  14642. }
  14643. }
  14644. else {
  14645. context.onError(createCompilerError(isVBind
  14646. ? 34 /* X_V_BIND_NO_EXPRESSION */
  14647. : 35 /* X_V_ON_NO_EXPRESSION */, loc));
  14648. }
  14649. continue;
  14650. }
  14651. const directiveTransform = context.directiveTransforms[name];
  14652. if (directiveTransform) {
  14653. // has built-in directive transform.
  14654. const { props, needRuntime } = directiveTransform(prop, node, context);
  14655. !ssr && props.forEach(analyzePatchFlag);
  14656. properties.push(...props);
  14657. if (needRuntime) {
  14658. runtimeDirectives.push(prop);
  14659. if (isSymbol(needRuntime)) {
  14660. directiveImportMap.set(prop, needRuntime);
  14661. }
  14662. }
  14663. }
  14664. else if (!isBuiltInDirective(name)) {
  14665. // no built-in transform, this is a user custom directive.
  14666. runtimeDirectives.push(prop);
  14667. // custom dirs may use beforeUpdate so they need to force blocks
  14668. // to ensure before-update gets called before children update
  14669. if (hasChildren) {
  14670. shouldUseBlock = true;
  14671. }
  14672. }
  14673. }
  14674. }
  14675. let propsExpression = undefined;
  14676. // has v-bind="object" or v-on="object", wrap with mergeProps
  14677. if (mergeArgs.length) {
  14678. if (properties.length) {
  14679. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  14680. }
  14681. if (mergeArgs.length > 1) {
  14682. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  14683. }
  14684. else {
  14685. // single v-bind with nothing else - no need for a mergeProps call
  14686. propsExpression = mergeArgs[0];
  14687. }
  14688. }
  14689. else if (properties.length) {
  14690. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  14691. }
  14692. // patchFlag analysis
  14693. if (hasDynamicKeys) {
  14694. patchFlag |= 16 /* FULL_PROPS */;
  14695. }
  14696. else {
  14697. if (hasClassBinding && !isComponent) {
  14698. patchFlag |= 2 /* CLASS */;
  14699. }
  14700. if (hasStyleBinding && !isComponent) {
  14701. patchFlag |= 4 /* STYLE */;
  14702. }
  14703. if (dynamicPropNames.length) {
  14704. patchFlag |= 8 /* PROPS */;
  14705. }
  14706. if (hasHydrationEventBinding) {
  14707. patchFlag |= 32 /* HYDRATE_EVENTS */;
  14708. }
  14709. }
  14710. if (!shouldUseBlock &&
  14711. (patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  14712. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  14713. patchFlag |= 512 /* NEED_PATCH */;
  14714. }
  14715. // pre-normalize props, SSR is skipped for now
  14716. if (!context.inSSR && propsExpression) {
  14717. switch (propsExpression.type) {
  14718. case 15 /* JS_OBJECT_EXPRESSION */:
  14719. // means that there is no v-bind,
  14720. // but still need to deal with dynamic key binding
  14721. let classKeyIndex = -1;
  14722. let styleKeyIndex = -1;
  14723. let hasDynamicKey = false;
  14724. for (let i = 0; i < propsExpression.properties.length; i++) {
  14725. const key = propsExpression.properties[i].key;
  14726. if (isStaticExp(key)) {
  14727. if (key.content === 'class') {
  14728. classKeyIndex = i;
  14729. }
  14730. else if (key.content === 'style') {
  14731. styleKeyIndex = i;
  14732. }
  14733. }
  14734. else if (!key.isHandlerKey) {
  14735. hasDynamicKey = true;
  14736. }
  14737. }
  14738. const classProp = propsExpression.properties[classKeyIndex];
  14739. const styleProp = propsExpression.properties[styleKeyIndex];
  14740. // no dynamic key
  14741. if (!hasDynamicKey) {
  14742. if (classProp && !isStaticExp(classProp.value)) {
  14743. classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
  14744. }
  14745. if (styleProp &&
  14746. // the static style is compiled into an object,
  14747. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  14748. (hasStyleBinding ||
  14749. (styleProp.value.type === 4 /* SIMPLE_EXPRESSION */ &&
  14750. styleProp.value.content.trim()[0] === `[`) ||
  14751. // v-bind:style and style both exist,
  14752. // v-bind:style with static literal object
  14753. styleProp.value.type === 17 /* JS_ARRAY_EXPRESSION */)) {
  14754. styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
  14755. }
  14756. }
  14757. else {
  14758. // dynamic key binding, wrap with `normalizeProps`
  14759. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
  14760. }
  14761. break;
  14762. case 14 /* JS_CALL_EXPRESSION */:
  14763. // mergeProps call, do nothing
  14764. break;
  14765. default:
  14766. // single v-bind
  14767. propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [
  14768. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  14769. propsExpression
  14770. ])
  14771. ]);
  14772. break;
  14773. }
  14774. }
  14775. return {
  14776. props: propsExpression,
  14777. directives: runtimeDirectives,
  14778. patchFlag,
  14779. dynamicPropNames,
  14780. shouldUseBlock
  14781. };
  14782. }
  14783. // Dedupe props in an object literal.
  14784. // Literal duplicated attributes would have been warned during the parse phase,
  14785. // however, it's possible to encounter duplicated `onXXX` handlers with different
  14786. // modifiers. We also need to merge static and dynamic class / style attributes.
  14787. // - onXXX handlers / style: merge into array
  14788. // - class: merge into single expression with concatenation
  14789. function dedupeProperties(properties) {
  14790. const knownProps = new Map();
  14791. const deduped = [];
  14792. for (let i = 0; i < properties.length; i++) {
  14793. const prop = properties[i];
  14794. // dynamic keys are always allowed
  14795. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  14796. deduped.push(prop);
  14797. continue;
  14798. }
  14799. const name = prop.key.content;
  14800. const existing = knownProps.get(name);
  14801. if (existing) {
  14802. if (name === 'style' || name === 'class' || isOn(name)) {
  14803. mergeAsArray$1(existing, prop);
  14804. }
  14805. // unexpected duplicate, should have emitted error during parse
  14806. }
  14807. else {
  14808. knownProps.set(name, prop);
  14809. deduped.push(prop);
  14810. }
  14811. }
  14812. return deduped;
  14813. }
  14814. function mergeAsArray$1(existing, incoming) {
  14815. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  14816. existing.value.elements.push(incoming.value);
  14817. }
  14818. else {
  14819. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  14820. }
  14821. }
  14822. function buildDirectiveArgs(dir, context) {
  14823. const dirArgs = [];
  14824. const runtime = directiveImportMap.get(dir);
  14825. if (runtime) {
  14826. // built-in directive with runtime
  14827. dirArgs.push(context.helperString(runtime));
  14828. }
  14829. else {
  14830. {
  14831. // inject statement for resolving directive
  14832. context.helper(RESOLVE_DIRECTIVE);
  14833. context.directives.add(dir.name);
  14834. dirArgs.push(toValidAssetId(dir.name, `directive`));
  14835. }
  14836. }
  14837. const { loc } = dir;
  14838. if (dir.exp)
  14839. dirArgs.push(dir.exp);
  14840. if (dir.arg) {
  14841. if (!dir.exp) {
  14842. dirArgs.push(`void 0`);
  14843. }
  14844. dirArgs.push(dir.arg);
  14845. }
  14846. if (Object.keys(dir.modifiers).length) {
  14847. if (!dir.arg) {
  14848. if (!dir.exp) {
  14849. dirArgs.push(`void 0`);
  14850. }
  14851. dirArgs.push(`void 0`);
  14852. }
  14853. const trueExpression = createSimpleExpression(`true`, false, loc);
  14854. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  14855. }
  14856. return createArrayExpression(dirArgs, dir.loc);
  14857. }
  14858. function stringifyDynamicPropNames(props) {
  14859. let propsNamesString = `[`;
  14860. for (let i = 0, l = props.length; i < l; i++) {
  14861. propsNamesString += JSON.stringify(props[i]);
  14862. if (i < l - 1)
  14863. propsNamesString += ', ';
  14864. }
  14865. return propsNamesString + `]`;
  14866. }
  14867. function isComponentTag(tag) {
  14868. return tag === 'component' || tag === 'Component';
  14869. }
  14870. const transformSlotOutlet = (node, context) => {
  14871. if (isSlotOutlet(node)) {
  14872. const { children, loc } = node;
  14873. const { slotName, slotProps } = processSlotOutlet(node, context);
  14874. const slotArgs = [
  14875. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  14876. slotName,
  14877. '{}',
  14878. 'undefined',
  14879. 'true'
  14880. ];
  14881. let expectedLen = 2;
  14882. if (slotProps) {
  14883. slotArgs[2] = slotProps;
  14884. expectedLen = 3;
  14885. }
  14886. if (children.length) {
  14887. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  14888. expectedLen = 4;
  14889. }
  14890. if (context.scopeId && !context.slotted) {
  14891. expectedLen = 5;
  14892. }
  14893. slotArgs.splice(expectedLen); // remove unused arguments
  14894. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  14895. }
  14896. };
  14897. function processSlotOutlet(node, context) {
  14898. let slotName = `"default"`;
  14899. let slotProps = undefined;
  14900. const nonNameProps = [];
  14901. for (let i = 0; i < node.props.length; i++) {
  14902. const p = node.props[i];
  14903. if (p.type === 6 /* ATTRIBUTE */) {
  14904. if (p.value) {
  14905. if (p.name === 'name') {
  14906. slotName = JSON.stringify(p.value.content);
  14907. }
  14908. else {
  14909. p.name = camelize(p.name);
  14910. nonNameProps.push(p);
  14911. }
  14912. }
  14913. }
  14914. else {
  14915. if (p.name === 'bind' && isStaticArgOf(p.arg, 'name')) {
  14916. if (p.exp)
  14917. slotName = p.exp;
  14918. }
  14919. else {
  14920. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  14921. p.arg.content = camelize(p.arg.content);
  14922. }
  14923. nonNameProps.push(p);
  14924. }
  14925. }
  14926. }
  14927. if (nonNameProps.length > 0) {
  14928. const { props, directives } = buildProps(node, context, nonNameProps, false, false);
  14929. slotProps = props;
  14930. if (directives.length) {
  14931. context.onError(createCompilerError(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  14932. }
  14933. }
  14934. return {
  14935. slotName,
  14936. slotProps
  14937. };
  14938. }
  14939. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  14940. const transformOn = (dir, node, context, augmentor) => {
  14941. const { loc, modifiers, arg } = dir;
  14942. if (!dir.exp && !modifiers.length) {
  14943. context.onError(createCompilerError(35 /* X_V_ON_NO_EXPRESSION */, loc));
  14944. }
  14945. let eventName;
  14946. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  14947. if (arg.isStatic) {
  14948. let rawName = arg.content;
  14949. // TODO deprecate @vnodeXXX usage
  14950. if (rawName.startsWith('vue:')) {
  14951. rawName = `vnode-${rawName.slice(4)}`;
  14952. }
  14953. // for all event listeners, auto convert it to camelCase. See issue #2249
  14954. eventName = createSimpleExpression(toHandlerKey(camelize(rawName)), true, arg.loc);
  14955. }
  14956. else {
  14957. // #2388
  14958. eventName = createCompoundExpression([
  14959. `${context.helperString(TO_HANDLER_KEY)}(`,
  14960. arg,
  14961. `)`
  14962. ]);
  14963. }
  14964. }
  14965. else {
  14966. // already a compound expression.
  14967. eventName = arg;
  14968. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  14969. eventName.children.push(`)`);
  14970. }
  14971. // handler processing
  14972. let exp = dir.exp;
  14973. if (exp && !exp.content.trim()) {
  14974. exp = undefined;
  14975. }
  14976. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  14977. if (exp) {
  14978. const isMemberExp = isMemberExpression(exp.content);
  14979. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  14980. const hasMultipleStatements = exp.content.includes(`;`);
  14981. {
  14982. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  14983. }
  14984. if (isInlineStatement || (shouldCache && isMemberExp)) {
  14985. // wrap inline statement in a function expression
  14986. exp = createCompoundExpression([
  14987. `${isInlineStatement
  14988. ? `$event`
  14989. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  14990. exp,
  14991. hasMultipleStatements ? `}` : `)`
  14992. ]);
  14993. }
  14994. }
  14995. let ret = {
  14996. props: [
  14997. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  14998. ]
  14999. };
  15000. // apply extended compiler augmentor
  15001. if (augmentor) {
  15002. ret = augmentor(ret);
  15003. }
  15004. if (shouldCache) {
  15005. // cache handlers so that it's always the same handler being passed down.
  15006. // this avoids unnecessary re-renders when users use inline handlers on
  15007. // components.
  15008. ret.props[0].value = context.cache(ret.props[0].value);
  15009. }
  15010. // mark the key as handler for props normalization check
  15011. ret.props.forEach(p => (p.key.isHandlerKey = true));
  15012. return ret;
  15013. };
  15014. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  15015. // codegen for the entire props object. This transform here is only for v-bind
  15016. // *with* args.
  15017. const transformBind = (dir, _node, context) => {
  15018. const { exp, modifiers, loc } = dir;
  15019. const arg = dir.arg;
  15020. if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
  15021. arg.children.unshift(`(`);
  15022. arg.children.push(`) || ""`);
  15023. }
  15024. else if (!arg.isStatic) {
  15025. arg.content = `${arg.content} || ""`;
  15026. }
  15027. // .sync is replaced by v-model:arg
  15028. if (modifiers.includes('camel')) {
  15029. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  15030. if (arg.isStatic) {
  15031. arg.content = camelize(arg.content);
  15032. }
  15033. else {
  15034. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  15035. }
  15036. }
  15037. else {
  15038. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  15039. arg.children.push(`)`);
  15040. }
  15041. }
  15042. if (!context.inSSR) {
  15043. if (modifiers.includes('prop')) {
  15044. injectPrefix(arg, '.');
  15045. }
  15046. if (modifiers.includes('attr')) {
  15047. injectPrefix(arg, '^');
  15048. }
  15049. }
  15050. if (!exp ||
  15051. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  15052. context.onError(createCompilerError(34 /* X_V_BIND_NO_EXPRESSION */, loc));
  15053. return {
  15054. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  15055. };
  15056. }
  15057. return {
  15058. props: [createObjectProperty(arg, exp)]
  15059. };
  15060. };
  15061. const injectPrefix = (arg, prefix) => {
  15062. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  15063. if (arg.isStatic) {
  15064. arg.content = prefix + arg.content;
  15065. }
  15066. else {
  15067. arg.content = `\`${prefix}\${${arg.content}}\``;
  15068. }
  15069. }
  15070. else {
  15071. arg.children.unshift(`'${prefix}' + (`);
  15072. arg.children.push(`)`);
  15073. }
  15074. };
  15075. // Merge adjacent text nodes and expressions into a single expression
  15076. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  15077. const transformText = (node, context) => {
  15078. if (node.type === 0 /* ROOT */ ||
  15079. node.type === 1 /* ELEMENT */ ||
  15080. node.type === 11 /* FOR */ ||
  15081. node.type === 10 /* IF_BRANCH */) {
  15082. // perform the transform on node exit so that all expressions have already
  15083. // been processed.
  15084. return () => {
  15085. const children = node.children;
  15086. let currentContainer = undefined;
  15087. let hasText = false;
  15088. for (let i = 0; i < children.length; i++) {
  15089. const child = children[i];
  15090. if (isText(child)) {
  15091. hasText = true;
  15092. for (let j = i + 1; j < children.length; j++) {
  15093. const next = children[j];
  15094. if (isText(next)) {
  15095. if (!currentContainer) {
  15096. currentContainer = children[i] = createCompoundExpression([child], child.loc);
  15097. }
  15098. // merge adjacent text node into current
  15099. currentContainer.children.push(` + `, next);
  15100. children.splice(j, 1);
  15101. j--;
  15102. }
  15103. else {
  15104. currentContainer = undefined;
  15105. break;
  15106. }
  15107. }
  15108. }
  15109. }
  15110. if (!hasText ||
  15111. // if this is a plain element with a single text child, leave it
  15112. // as-is since the runtime has dedicated fast path for this by directly
  15113. // setting textContent of the element.
  15114. // for component root it's always normalized anyway.
  15115. (children.length === 1 &&
  15116. (node.type === 0 /* ROOT */ ||
  15117. (node.type === 1 /* ELEMENT */ &&
  15118. node.tagType === 0 /* ELEMENT */ &&
  15119. // #3756
  15120. // custom directives can potentially add DOM elements arbitrarily,
  15121. // we need to avoid setting textContent of the element at runtime
  15122. // to avoid accidentally overwriting the DOM elements added
  15123. // by the user through custom directives.
  15124. !node.props.find(p => p.type === 7 /* DIRECTIVE */ &&
  15125. !context.directiveTransforms[p.name]) &&
  15126. // in compat mode, <template> tags with no special directives
  15127. // will be rendered as a fragment so its children must be
  15128. // converted into vnodes.
  15129. !(false ))))) {
  15130. return;
  15131. }
  15132. // pre-convert text nodes into createTextVNode(text) calls to avoid
  15133. // runtime normalization.
  15134. for (let i = 0; i < children.length; i++) {
  15135. const child = children[i];
  15136. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  15137. const callArgs = [];
  15138. // createTextVNode defaults to single whitespace, so if it is a
  15139. // single space the code could be an empty call to save bytes.
  15140. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  15141. callArgs.push(child);
  15142. }
  15143. // mark dynamic text with flag so it gets patched inside a block
  15144. if (!context.ssr &&
  15145. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  15146. callArgs.push(1 /* TEXT */ +
  15147. (` /* ${PatchFlagNames[1 /* TEXT */]} */` ));
  15148. }
  15149. children[i] = {
  15150. type: 12 /* TEXT_CALL */,
  15151. content: child,
  15152. loc: child.loc,
  15153. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  15154. };
  15155. }
  15156. }
  15157. };
  15158. }
  15159. };
  15160. const seen = new WeakSet();
  15161. const transformOnce = (node, context) => {
  15162. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  15163. if (seen.has(node) || context.inVOnce) {
  15164. return;
  15165. }
  15166. seen.add(node);
  15167. context.inVOnce = true;
  15168. context.helper(SET_BLOCK_TRACKING);
  15169. return () => {
  15170. context.inVOnce = false;
  15171. const cur = context.currentNode;
  15172. if (cur.codegenNode) {
  15173. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  15174. }
  15175. };
  15176. }
  15177. };
  15178. const transformModel = (dir, node, context) => {
  15179. const { exp, arg } = dir;
  15180. if (!exp) {
  15181. context.onError(createCompilerError(41 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  15182. return createTransformProps();
  15183. }
  15184. const rawExp = exp.loc.source;
  15185. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  15186. // im SFC <script setup> inline mode, the exp may have been transformed into
  15187. // _unref(exp)
  15188. context.bindingMetadata[rawExp];
  15189. const maybeRef = !true /* SETUP_CONST */;
  15190. if (!expString.trim() ||
  15191. (!isMemberExpression(expString) && !maybeRef)) {
  15192. context.onError(createCompilerError(42 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  15193. return createTransformProps();
  15194. }
  15195. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  15196. const eventName = arg
  15197. ? isStaticExp(arg)
  15198. ? `onUpdate:${arg.content}`
  15199. : createCompoundExpression(['"onUpdate:" + ', arg])
  15200. : `onUpdate:modelValue`;
  15201. let assignmentExp;
  15202. const eventArg = context.isTS ? `($event: any)` : `$event`;
  15203. {
  15204. assignmentExp = createCompoundExpression([
  15205. `${eventArg} => ((`,
  15206. exp,
  15207. `) = $event)`
  15208. ]);
  15209. }
  15210. const props = [
  15211. // modelValue: foo
  15212. createObjectProperty(propName, dir.exp),
  15213. // "onUpdate:modelValue": $event => (foo = $event)
  15214. createObjectProperty(eventName, assignmentExp)
  15215. ];
  15216. // modelModifiers: { foo: true, "bar-baz": true }
  15217. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  15218. const modifiers = dir.modifiers
  15219. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  15220. .join(`, `);
  15221. const modifiersKey = arg
  15222. ? isStaticExp(arg)
  15223. ? `${arg.content}Modifiers`
  15224. : createCompoundExpression([arg, ' + "Modifiers"'])
  15225. : `modelModifiers`;
  15226. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
  15227. }
  15228. return createTransformProps(props);
  15229. };
  15230. function createTransformProps(props = []) {
  15231. return { props };
  15232. }
  15233. const seen$1 = new WeakSet();
  15234. const transformMemo = (node, context) => {
  15235. if (node.type === 1 /* ELEMENT */) {
  15236. const dir = findDir(node, 'memo');
  15237. if (!dir || seen$1.has(node)) {
  15238. return;
  15239. }
  15240. seen$1.add(node);
  15241. return () => {
  15242. const codegenNode = node.codegenNode ||
  15243. context.currentNode.codegenNode;
  15244. if (codegenNode && codegenNode.type === 13 /* VNODE_CALL */) {
  15245. // non-component sub tree should be turned into a block
  15246. if (node.tagType !== 1 /* COMPONENT */) {
  15247. makeBlock(codegenNode, context);
  15248. }
  15249. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  15250. dir.exp,
  15251. createFunctionExpression(undefined, codegenNode),
  15252. `_cache`,
  15253. String(context.cached++)
  15254. ]);
  15255. }
  15256. };
  15257. }
  15258. };
  15259. function getBaseTransformPreset(prefixIdentifiers) {
  15260. return [
  15261. [
  15262. transformOnce,
  15263. transformIf,
  15264. transformMemo,
  15265. transformFor,
  15266. ...([]),
  15267. ...([transformExpression]
  15268. ),
  15269. transformSlotOutlet,
  15270. transformElement,
  15271. trackSlotScopes,
  15272. transformText
  15273. ],
  15274. {
  15275. on: transformOn,
  15276. bind: transformBind,
  15277. model: transformModel
  15278. }
  15279. ];
  15280. }
  15281. // we name it `baseCompile` so that higher order compilers like
  15282. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  15283. function baseCompile(template, options = {}) {
  15284. const onError = options.onError || defaultOnError;
  15285. const isModuleMode = options.mode === 'module';
  15286. /* istanbul ignore if */
  15287. {
  15288. if (options.prefixIdentifiers === true) {
  15289. onError(createCompilerError(46 /* X_PREFIX_ID_NOT_SUPPORTED */));
  15290. }
  15291. else if (isModuleMode) {
  15292. onError(createCompilerError(47 /* X_MODULE_MODE_NOT_SUPPORTED */));
  15293. }
  15294. }
  15295. const prefixIdentifiers = !true ;
  15296. if (options.cacheHandlers) {
  15297. onError(createCompilerError(48 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  15298. }
  15299. if (options.scopeId && !isModuleMode) {
  15300. onError(createCompilerError(49 /* X_SCOPE_ID_NOT_SUPPORTED */));
  15301. }
  15302. const ast = isString(template) ? baseParse(template, options) : template;
  15303. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  15304. transform(ast, extend({}, options, {
  15305. prefixIdentifiers,
  15306. nodeTransforms: [
  15307. ...nodeTransforms,
  15308. ...(options.nodeTransforms || []) // user transforms
  15309. ],
  15310. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  15311. )
  15312. }));
  15313. return generate(ast, extend({}, options, {
  15314. prefixIdentifiers
  15315. }));
  15316. }
  15317. const noopDirectiveTransform = () => ({ props: [] });
  15318. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  15319. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  15320. const V_MODEL_TEXT = Symbol(`vModelText` );
  15321. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  15322. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  15323. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  15324. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  15325. const V_SHOW = Symbol(`vShow` );
  15326. const TRANSITION$1 = Symbol(`Transition` );
  15327. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  15328. registerRuntimeHelpers({
  15329. [V_MODEL_RADIO]: `vModelRadio`,
  15330. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  15331. [V_MODEL_TEXT]: `vModelText`,
  15332. [V_MODEL_SELECT]: `vModelSelect`,
  15333. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  15334. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  15335. [V_ON_WITH_KEYS]: `withKeys`,
  15336. [V_SHOW]: `vShow`,
  15337. [TRANSITION$1]: `Transition`,
  15338. [TRANSITION_GROUP]: `TransitionGroup`
  15339. });
  15340. /* eslint-disable no-restricted-globals */
  15341. let decoder;
  15342. function decodeHtmlBrowser(raw, asAttr = false) {
  15343. if (!decoder) {
  15344. decoder = document.createElement('div');
  15345. }
  15346. if (asAttr) {
  15347. decoder.innerHTML = `<div foo="${raw.replace(/"/g, '&quot;')}">`;
  15348. return decoder.children[0].getAttribute('foo');
  15349. }
  15350. else {
  15351. decoder.innerHTML = raw;
  15352. return decoder.textContent;
  15353. }
  15354. }
  15355. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  15356. const parserOptions = {
  15357. isVoidTag,
  15358. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  15359. isPreTag: tag => tag === 'pre',
  15360. decodeEntities: decodeHtmlBrowser ,
  15361. isBuiltInComponent: (tag) => {
  15362. if (isBuiltInType(tag, `Transition`)) {
  15363. return TRANSITION$1;
  15364. }
  15365. else if (isBuiltInType(tag, `TransitionGroup`)) {
  15366. return TRANSITION_GROUP;
  15367. }
  15368. },
  15369. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  15370. getNamespace(tag, parent) {
  15371. let ns = parent ? parent.ns : 0 /* HTML */;
  15372. if (parent && ns === 2 /* MATH_ML */) {
  15373. if (parent.tag === 'annotation-xml') {
  15374. if (tag === 'svg') {
  15375. return 1 /* SVG */;
  15376. }
  15377. if (parent.props.some(a => a.type === 6 /* ATTRIBUTE */ &&
  15378. a.name === 'encoding' &&
  15379. a.value != null &&
  15380. (a.value.content === 'text/html' ||
  15381. a.value.content === 'application/xhtml+xml'))) {
  15382. ns = 0 /* HTML */;
  15383. }
  15384. }
  15385. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  15386. tag !== 'mglyph' &&
  15387. tag !== 'malignmark') {
  15388. ns = 0 /* HTML */;
  15389. }
  15390. }
  15391. else if (parent && ns === 1 /* SVG */) {
  15392. if (parent.tag === 'foreignObject' ||
  15393. parent.tag === 'desc' ||
  15394. parent.tag === 'title') {
  15395. ns = 0 /* HTML */;
  15396. }
  15397. }
  15398. if (ns === 0 /* HTML */) {
  15399. if (tag === 'svg') {
  15400. return 1 /* SVG */;
  15401. }
  15402. if (tag === 'math') {
  15403. return 2 /* MATH_ML */;
  15404. }
  15405. }
  15406. return ns;
  15407. },
  15408. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  15409. getTextMode({ tag, ns }) {
  15410. if (ns === 0 /* HTML */) {
  15411. if (tag === 'textarea' || tag === 'title') {
  15412. return 1 /* RCDATA */;
  15413. }
  15414. if (isRawTextContainer(tag)) {
  15415. return 2 /* RAWTEXT */;
  15416. }
  15417. }
  15418. return 0 /* DATA */;
  15419. }
  15420. };
  15421. // Parse inline CSS strings for static style attributes into an object.
  15422. // This is a NodeTransform since it works on the static `style` attribute and
  15423. // converts it into a dynamic equivalent:
  15424. // style="color: red" -> :style='{ "color": "red" }'
  15425. // It is then processed by `transformElement` and included in the generated
  15426. // props.
  15427. const transformStyle = node => {
  15428. if (node.type === 1 /* ELEMENT */) {
  15429. node.props.forEach((p, i) => {
  15430. if (p.type === 6 /* ATTRIBUTE */ && p.name === 'style' && p.value) {
  15431. // replace p with an expression node
  15432. node.props[i] = {
  15433. type: 7 /* DIRECTIVE */,
  15434. name: `bind`,
  15435. arg: createSimpleExpression(`style`, true, p.loc),
  15436. exp: parseInlineCSS(p.value.content, p.loc),
  15437. modifiers: [],
  15438. loc: p.loc
  15439. };
  15440. }
  15441. });
  15442. }
  15443. };
  15444. const parseInlineCSS = (cssText, loc) => {
  15445. const normalized = parseStringStyle(cssText);
  15446. return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* CAN_STRINGIFY */);
  15447. };
  15448. function createDOMCompilerError(code, loc) {
  15449. return createCompilerError(code, loc, DOMErrorMessages );
  15450. }
  15451. const DOMErrorMessages = {
  15452. [50 /* X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  15453. [51 /* X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  15454. [52 /* X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  15455. [53 /* X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  15456. [54 /* X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  15457. [55 /* X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  15458. [56 /* 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.`,
  15459. [57 /* X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  15460. [58 /* X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  15461. [59 /* X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  15462. [60 /* X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  15463. };
  15464. const transformVHtml = (dir, node, context) => {
  15465. const { exp, loc } = dir;
  15466. if (!exp) {
  15467. context.onError(createDOMCompilerError(50 /* X_V_HTML_NO_EXPRESSION */, loc));
  15468. }
  15469. if (node.children.length) {
  15470. context.onError(createDOMCompilerError(51 /* X_V_HTML_WITH_CHILDREN */, loc));
  15471. node.children.length = 0;
  15472. }
  15473. return {
  15474. props: [
  15475. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  15476. ]
  15477. };
  15478. };
  15479. const transformVText = (dir, node, context) => {
  15480. const { exp, loc } = dir;
  15481. if (!exp) {
  15482. context.onError(createDOMCompilerError(52 /* X_V_TEXT_NO_EXPRESSION */, loc));
  15483. }
  15484. if (node.children.length) {
  15485. context.onError(createDOMCompilerError(53 /* X_V_TEXT_WITH_CHILDREN */, loc));
  15486. node.children.length = 0;
  15487. }
  15488. return {
  15489. props: [
  15490. createObjectProperty(createSimpleExpression(`textContent`, true), exp
  15491. ? getConstantType(exp, context) > 0
  15492. ? exp
  15493. : createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
  15494. : createSimpleExpression('', true))
  15495. ]
  15496. };
  15497. };
  15498. const transformModel$1 = (dir, node, context) => {
  15499. const baseResult = transformModel(dir, node, context);
  15500. // base transform has errors OR component v-model (only need props)
  15501. if (!baseResult.props.length || node.tagType === 1 /* COMPONENT */) {
  15502. return baseResult;
  15503. }
  15504. if (dir.arg) {
  15505. context.onError(createDOMCompilerError(55 /* X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  15506. }
  15507. function checkDuplicatedValue() {
  15508. const value = findProp(node, 'value');
  15509. if (value) {
  15510. context.onError(createDOMCompilerError(57 /* X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  15511. }
  15512. }
  15513. const { tag } = node;
  15514. const isCustomElement = context.isCustomElement(tag);
  15515. if (tag === 'input' ||
  15516. tag === 'textarea' ||
  15517. tag === 'select' ||
  15518. isCustomElement) {
  15519. let directiveToUse = V_MODEL_TEXT;
  15520. let isInvalidType = false;
  15521. if (tag === 'input' || isCustomElement) {
  15522. const type = findProp(node, `type`);
  15523. if (type) {
  15524. if (type.type === 7 /* DIRECTIVE */) {
  15525. // :type="foo"
  15526. directiveToUse = V_MODEL_DYNAMIC;
  15527. }
  15528. else if (type.value) {
  15529. switch (type.value.content) {
  15530. case 'radio':
  15531. directiveToUse = V_MODEL_RADIO;
  15532. break;
  15533. case 'checkbox':
  15534. directiveToUse = V_MODEL_CHECKBOX;
  15535. break;
  15536. case 'file':
  15537. isInvalidType = true;
  15538. context.onError(createDOMCompilerError(56 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  15539. break;
  15540. default:
  15541. // text type
  15542. checkDuplicatedValue();
  15543. break;
  15544. }
  15545. }
  15546. }
  15547. else if (hasDynamicKeyVBind(node)) {
  15548. // element has bindings with dynamic keys, which can possibly contain
  15549. // "type".
  15550. directiveToUse = V_MODEL_DYNAMIC;
  15551. }
  15552. else {
  15553. // text type
  15554. checkDuplicatedValue();
  15555. }
  15556. }
  15557. else if (tag === 'select') {
  15558. directiveToUse = V_MODEL_SELECT;
  15559. }
  15560. else {
  15561. // textarea
  15562. checkDuplicatedValue();
  15563. }
  15564. // inject runtime directive
  15565. // by returning the helper symbol via needRuntime
  15566. // the import will replaced a resolveDirective call.
  15567. if (!isInvalidType) {
  15568. baseResult.needRuntime = context.helper(directiveToUse);
  15569. }
  15570. }
  15571. else {
  15572. context.onError(createDOMCompilerError(54 /* X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  15573. }
  15574. // native vmodel doesn't need the `modelValue` props since they are also
  15575. // passed to the runtime as `binding.value`. removing it reduces code size.
  15576. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  15577. p.key.content === 'modelValue'));
  15578. return baseResult;
  15579. };
  15580. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  15581. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  15582. // event propagation management
  15583. `stop,prevent,self,` +
  15584. // system modifiers + exact
  15585. `ctrl,shift,alt,meta,exact,` +
  15586. // mouse
  15587. `middle`);
  15588. // left & right could be mouse or key modifiers based on event type
  15589. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  15590. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  15591. const resolveModifiers = (key, modifiers, context, loc) => {
  15592. const keyModifiers = [];
  15593. const nonKeyModifiers = [];
  15594. const eventOptionModifiers = [];
  15595. for (let i = 0; i < modifiers.length; i++) {
  15596. const modifier = modifiers[i];
  15597. if (isEventOptionModifier(modifier)) {
  15598. // eventOptionModifiers: modifiers for addEventListener() options,
  15599. // e.g. .passive & .capture
  15600. eventOptionModifiers.push(modifier);
  15601. }
  15602. else {
  15603. // runtimeModifiers: modifiers that needs runtime guards
  15604. if (maybeKeyModifier(modifier)) {
  15605. if (isStaticExp(key)) {
  15606. if (isKeyboardEvent(key.content)) {
  15607. keyModifiers.push(modifier);
  15608. }
  15609. else {
  15610. nonKeyModifiers.push(modifier);
  15611. }
  15612. }
  15613. else {
  15614. keyModifiers.push(modifier);
  15615. nonKeyModifiers.push(modifier);
  15616. }
  15617. }
  15618. else {
  15619. if (isNonKeyModifier(modifier)) {
  15620. nonKeyModifiers.push(modifier);
  15621. }
  15622. else {
  15623. keyModifiers.push(modifier);
  15624. }
  15625. }
  15626. }
  15627. }
  15628. return {
  15629. keyModifiers,
  15630. nonKeyModifiers,
  15631. eventOptionModifiers
  15632. };
  15633. };
  15634. const transformClick = (key, event) => {
  15635. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  15636. return isStaticClick
  15637. ? createSimpleExpression(event, true)
  15638. : key.type !== 4 /* SIMPLE_EXPRESSION */
  15639. ? createCompoundExpression([
  15640. `(`,
  15641. key,
  15642. `) === "onClick" ? "${event}" : (`,
  15643. key,
  15644. `)`
  15645. ])
  15646. : key;
  15647. };
  15648. const transformOn$1 = (dir, node, context) => {
  15649. return transformOn(dir, node, context, baseResult => {
  15650. const { modifiers } = dir;
  15651. if (!modifiers.length)
  15652. return baseResult;
  15653. let { key, value: handlerExp } = baseResult.props[0];
  15654. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  15655. // normalize click.right and click.middle since they don't actually fire
  15656. if (nonKeyModifiers.includes('right')) {
  15657. key = transformClick(key, `onContextmenu`);
  15658. }
  15659. if (nonKeyModifiers.includes('middle')) {
  15660. key = transformClick(key, `onMouseup`);
  15661. }
  15662. if (nonKeyModifiers.length) {
  15663. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  15664. handlerExp,
  15665. JSON.stringify(nonKeyModifiers)
  15666. ]);
  15667. }
  15668. if (keyModifiers.length &&
  15669. // if event name is dynamic, always wrap with keys guard
  15670. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  15671. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  15672. handlerExp,
  15673. JSON.stringify(keyModifiers)
  15674. ]);
  15675. }
  15676. if (eventOptionModifiers.length) {
  15677. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  15678. key = isStaticExp(key)
  15679. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  15680. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  15681. }
  15682. return {
  15683. props: [createObjectProperty(key, handlerExp)]
  15684. };
  15685. });
  15686. };
  15687. const transformShow = (dir, node, context) => {
  15688. const { exp, loc } = dir;
  15689. if (!exp) {
  15690. context.onError(createDOMCompilerError(58 /* X_V_SHOW_NO_EXPRESSION */, loc));
  15691. }
  15692. return {
  15693. props: [],
  15694. needRuntime: context.helper(V_SHOW)
  15695. };
  15696. };
  15697. const transformTransition = (node, context) => {
  15698. if (node.type === 1 /* ELEMENT */ &&
  15699. node.tagType === 1 /* COMPONENT */) {
  15700. const component = context.isBuiltInComponent(node.tag);
  15701. if (component === TRANSITION$1) {
  15702. return () => {
  15703. if (!node.children.length) {
  15704. return;
  15705. }
  15706. // warn multiple transition children
  15707. if (hasMultipleChildren(node)) {
  15708. context.onError(createDOMCompilerError(59 /* X_TRANSITION_INVALID_CHILDREN */, {
  15709. start: node.children[0].loc.start,
  15710. end: node.children[node.children.length - 1].loc.end,
  15711. source: ''
  15712. }));
  15713. }
  15714. // check if it's s single child w/ v-show
  15715. // if yes, inject "persisted: true" to the transition props
  15716. const child = node.children[0];
  15717. if (child.type === 1 /* ELEMENT */) {
  15718. for (const p of child.props) {
  15719. if (p.type === 7 /* DIRECTIVE */ && p.name === 'show') {
  15720. node.props.push({
  15721. type: 6 /* ATTRIBUTE */,
  15722. name: 'persisted',
  15723. value: undefined,
  15724. loc: node.loc
  15725. });
  15726. }
  15727. }
  15728. }
  15729. };
  15730. }
  15731. }
  15732. };
  15733. function hasMultipleChildren(node) {
  15734. // #1352 filter out potential comment nodes.
  15735. const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */ &&
  15736. !(c.type === 2 /* TEXT */ && !c.content.trim())));
  15737. const child = children[0];
  15738. return (children.length !== 1 ||
  15739. child.type === 11 /* FOR */ ||
  15740. (child.type === 9 /* IF */ && child.branches.some(hasMultipleChildren)));
  15741. }
  15742. const ignoreSideEffectTags = (node, context) => {
  15743. if (node.type === 1 /* ELEMENT */ &&
  15744. node.tagType === 0 /* ELEMENT */ &&
  15745. (node.tag === 'script' || node.tag === 'style')) {
  15746. context.onError(createDOMCompilerError(60 /* X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  15747. context.removeNode();
  15748. }
  15749. };
  15750. const DOMNodeTransforms = [
  15751. transformStyle,
  15752. ...([transformTransition] )
  15753. ];
  15754. const DOMDirectiveTransforms = {
  15755. cloak: noopDirectiveTransform,
  15756. html: transformVHtml,
  15757. text: transformVText,
  15758. model: transformModel$1,
  15759. on: transformOn$1,
  15760. show: transformShow
  15761. };
  15762. function compile$1(template, options = {}) {
  15763. return baseCompile(template, extend({}, parserOptions, options, {
  15764. nodeTransforms: [
  15765. // ignore <script> and <tag>
  15766. // this is not put inside DOMNodeTransforms because that list is used
  15767. // by compiler-ssr to generate vnode fallback branches
  15768. ignoreSideEffectTags,
  15769. ...DOMNodeTransforms,
  15770. ...(options.nodeTransforms || [])
  15771. ],
  15772. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  15773. transformHoist: null
  15774. }));
  15775. }
  15776. // This entry is the "full-build" that includes both the runtime
  15777. {
  15778. initDev();
  15779. }
  15780. const compileCache = Object.create(null);
  15781. function compileToFunction(template, options) {
  15782. if (!isString(template)) {
  15783. if (template.nodeType) {
  15784. template = template.innerHTML;
  15785. }
  15786. else {
  15787. warn$1(`invalid template option: `, template);
  15788. return NOOP;
  15789. }
  15790. }
  15791. const key = template;
  15792. const cached = compileCache[key];
  15793. if (cached) {
  15794. return cached;
  15795. }
  15796. if (template[0] === '#') {
  15797. const el = document.querySelector(template);
  15798. if (!el) {
  15799. warn$1(`Template element not found or is empty: ${template}`);
  15800. }
  15801. // __UNSAFE__
  15802. // Reason: potential execution of JS expressions in in-DOM template.
  15803. // The user must make sure the in-DOM template is trusted. If it's rendered
  15804. // by the server, the template should not contain any user data.
  15805. template = el ? el.innerHTML : ``;
  15806. }
  15807. const { code } = compile$1(template, extend({
  15808. hoistStatic: true,
  15809. onError: onError ,
  15810. onWarn: e => onError(e, true)
  15811. }, options));
  15812. function onError(err, asWarning = false) {
  15813. const message = asWarning
  15814. ? err.message
  15815. : `Template compilation error: ${err.message}`;
  15816. const codeFrame = err.loc &&
  15817. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  15818. warn$1(codeFrame ? `${message}\n${codeFrame}` : message);
  15819. }
  15820. // The wildcard import results in a huge object with every export
  15821. // with keys that cannot be mangled, and can be quite heavy size-wise.
  15822. // In the global build we know `Vue` is available globally so we can avoid
  15823. // the wildcard object.
  15824. const render = (new Function('Vue', code)(runtimeDom));
  15825. render._rc = true;
  15826. return (compileCache[key] = render);
  15827. }
  15828. registerRuntimeCompiler(compileToFunction);
  15829. export { BaseTransition, Comment, EffectScope, Fragment, KeepAlive, ReactiveEffect, Static, Suspense, Teleport, Text, Transition, TransitionGroup, VueElement, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compatUtils, compileToFunction as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createElementBlock, createBaseVNode as createElementVNode, createHydrationRenderer, createPropsRestProxy, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, defineCustomElement, defineEmits, defineExpose, defineProps, defineSSRCustomElement, devtools, effect, effectScope, getCurrentInstance, getCurrentScope, getTransitionRawChildren, guardReactiveProps, h, handleError, hydrate, initCustomFormatter, initDirectivesForSSR, inject, isMemoSame, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isShallow, isVNode, markRaw, mergeDefaults, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, stop, toDisplayString, toHandlerKey, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withKeys, withMemo, withModifiers, withScopeId };