vue3.js 547 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738
  1. var Vue = (function (exports) {
  2. 'use strict';
  3. /**
  4. * Make a map and return a function for checking if a key
  5. * is in that map.
  6. * IMPORTANT: all calls of this function must be prefixed with
  7. * \/\*#\_\_PURE\_\_\*\/
  8. * So that rollup can tree-shake them if necessary.
  9. */
  10. function makeMap(str, expectsLowerCase) {
  11. const map = Object.create(null);
  12. const list = str.split(',');
  13. for (let i = 0; i < list.length; i++) {
  14. map[list[i]] = true;
  15. }
  16. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  17. }
  18. /**
  19. * dev only flag -> name mapping
  20. */
  21. const PatchFlagNames = {
  22. [1 /* TEXT */]: `TEXT`,
  23. [2 /* CLASS */]: `CLASS`,
  24. [4 /* STYLE */]: `STYLE`,
  25. [8 /* PROPS */]: `PROPS`,
  26. [16 /* FULL_PROPS */]: `FULL_PROPS`,
  27. [32 /* HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  28. [64 /* STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  29. [128 /* KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  30. [256 /* UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  31. [512 /* NEED_PATCH */]: `NEED_PATCH`,
  32. [1024 /* DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  33. [2048 /* DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
  34. [-1 /* HOISTED */]: `HOISTED`,
  35. [-2 /* BAIL */]: `BAIL`
  36. };
  37. /**
  38. * Dev only
  39. */
  40. const slotFlagsText = {
  41. [1 /* STABLE */]: 'STABLE',
  42. [2 /* DYNAMIC */]: 'DYNAMIC',
  43. [3 /* FORWARDED */]: 'FORWARDED'
  44. };
  45. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  46. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  47. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt';
  48. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  49. const range = 2;
  50. function generateCodeFrame(source, start = 0, end = source.length) {
  51. const lines = source.split(/\r?\n/);
  52. let count = 0;
  53. const res = [];
  54. for (let i = 0; i < lines.length; i++) {
  55. count += lines[i].length + 1;
  56. if (count >= start) {
  57. for (let j = i - range; j <= i + range || end > count; j++) {
  58. if (j < 0 || j >= lines.length)
  59. continue;
  60. const line = j + 1;
  61. res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
  62. const lineLength = lines[j].length;
  63. if (j === i) {
  64. // push underline
  65. const pad = start - (count - lineLength) + 1;
  66. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  67. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  68. }
  69. else if (j > i) {
  70. if (end > count) {
  71. const length = Math.max(Math.min(end - count, lineLength), 1);
  72. res.push(` | ` + '^'.repeat(length));
  73. }
  74. count += lineLength + 1;
  75. }
  76. }
  77. break;
  78. }
  79. }
  80. return res.join('\n');
  81. }
  82. /**
  83. * On the client we only need to offer special cases for boolean attributes that
  84. * have different names from their corresponding dom properties:
  85. * - itemscope -> N/A
  86. * - allowfullscreen -> allowFullscreen
  87. * - formnovalidate -> formNoValidate
  88. * - ismap -> isMap
  89. * - nomodule -> noModule
  90. * - novalidate -> noValidate
  91. * - readonly -> readOnly
  92. */
  93. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  94. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  95. function normalizeStyle(value) {
  96. if (isArray(value)) {
  97. const res = {};
  98. for (let i = 0; i < value.length; i++) {
  99. const item = value[i];
  100. const normalized = normalizeStyle(isString(item) ? parseStringStyle(item) : item);
  101. if (normalized) {
  102. for (const key in normalized) {
  103. res[key] = normalized[key];
  104. }
  105. }
  106. }
  107. return res;
  108. }
  109. else if (isObject(value)) {
  110. return value;
  111. }
  112. }
  113. const listDelimiterRE = /;(?![^(]*\))/g;
  114. const propertyDelimiterRE = /:(.+)/;
  115. function parseStringStyle(cssText) {
  116. const ret = {};
  117. cssText.split(listDelimiterRE).forEach(item => {
  118. if (item) {
  119. const tmp = item.split(propertyDelimiterRE);
  120. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  121. }
  122. });
  123. return ret;
  124. }
  125. function normalizeClass(value) {
  126. let res = '';
  127. if (isString(value)) {
  128. res = value;
  129. }
  130. else if (isArray(value)) {
  131. for (let i = 0; i < value.length; i++) {
  132. const normalized = normalizeClass(value[i]);
  133. if (normalized) {
  134. res += normalized + ' ';
  135. }
  136. }
  137. }
  138. else if (isObject(value)) {
  139. for (const name in value) {
  140. if (value[name]) {
  141. res += name + ' ';
  142. }
  143. }
  144. }
  145. return res.trim();
  146. }
  147. // These tag configs are shared between compiler-dom and runtime-dom, so they
  148. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  149. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  150. 'header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,div,dd,dl,dt,figcaption,' +
  151. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  152. 'data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,s,samp,small,span,strong,sub,sup,' +
  153. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  154. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  155. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  156. 'option,output,progress,select,textarea,details,dialog,menu,' +
  157. 'summary,template,blockquote,iframe,tfoot';
  158. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  159. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  160. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  161. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  162. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  163. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  164. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  165. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  166. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  167. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  168. 'text,textPath,title,tspan,unknown,use,view';
  169. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  170. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  171. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  172. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  173. function looseCompareArrays(a, b) {
  174. if (a.length !== b.length)
  175. return false;
  176. let equal = true;
  177. for (let i = 0; equal && i < a.length; i++) {
  178. equal = looseEqual(a[i], b[i]);
  179. }
  180. return equal;
  181. }
  182. function looseEqual(a, b) {
  183. if (a === b)
  184. return true;
  185. let aValidType = isDate(a);
  186. let bValidType = isDate(b);
  187. if (aValidType || bValidType) {
  188. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  189. }
  190. aValidType = isArray(a);
  191. bValidType = isArray(b);
  192. if (aValidType || bValidType) {
  193. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  194. }
  195. aValidType = isObject(a);
  196. bValidType = isObject(b);
  197. if (aValidType || bValidType) {
  198. /* istanbul ignore if: this if will probably never be called */
  199. if (!aValidType || !bValidType) {
  200. return false;
  201. }
  202. const aKeysCount = Object.keys(a).length;
  203. const bKeysCount = Object.keys(b).length;
  204. if (aKeysCount !== bKeysCount) {
  205. return false;
  206. }
  207. for (const key in a) {
  208. const aHasKey = a.hasOwnProperty(key);
  209. const bHasKey = b.hasOwnProperty(key);
  210. if ((aHasKey && !bHasKey) ||
  211. (!aHasKey && bHasKey) ||
  212. !looseEqual(a[key], b[key])) {
  213. return false;
  214. }
  215. }
  216. }
  217. return String(a) === String(b);
  218. }
  219. function looseIndexOf(arr, val) {
  220. return arr.findIndex(item => looseEqual(item, val));
  221. }
  222. /**
  223. * For converting {{ interpolation }} values to displayed strings.
  224. * @private
  225. */
  226. const toDisplayString = (val) => {
  227. return val == null
  228. ? ''
  229. : isObject(val)
  230. ? JSON.stringify(val, replacer, 2)
  231. : String(val);
  232. };
  233. const replacer = (_key, val) => {
  234. if (isMap(val)) {
  235. return {
  236. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  237. entries[`${key} =>`] = val;
  238. return entries;
  239. }, {})
  240. };
  241. }
  242. else if (isSet(val)) {
  243. return {
  244. [`Set(${val.size})`]: [...val.values()]
  245. };
  246. }
  247. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  248. return String(val);
  249. }
  250. return val;
  251. };
  252. const EMPTY_OBJ = Object.freeze({})
  253. ;
  254. const EMPTY_ARR = Object.freeze([]) ;
  255. const NOOP = () => { };
  256. /**
  257. * Always return false.
  258. */
  259. const NO = () => false;
  260. const onRE = /^on[^a-z]/;
  261. const isOn = (key) => onRE.test(key);
  262. const isModelListener = (key) => key.startsWith('onUpdate:');
  263. const extend = Object.assign;
  264. const remove = (arr, el) => {
  265. const i = arr.indexOf(el);
  266. if (i > -1) {
  267. arr.splice(i, 1);
  268. }
  269. };
  270. const hasOwnProperty = Object.prototype.hasOwnProperty;
  271. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  272. const isArray = Array.isArray;
  273. const isMap = (val) => toTypeString(val) === '[object Map]';
  274. const isSet = (val) => toTypeString(val) === '[object Set]';
  275. const isDate = (val) => val instanceof Date;
  276. const isFunction = (val) => typeof val === 'function';
  277. const isString = (val) => typeof val === 'string';
  278. const isSymbol = (val) => typeof val === 'symbol';
  279. const isObject = (val) => val !== null && typeof val === 'object';
  280. const isPromise = (val) => {
  281. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  282. };
  283. const objectToString = Object.prototype.toString;
  284. const toTypeString = (value) => objectToString.call(value);
  285. const toRawType = (value) => {
  286. // extract "RawType" from strings like "[object RawType]"
  287. return toTypeString(value).slice(8, -1);
  288. };
  289. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  290. const isIntegerKey = (key) => isString(key) &&
  291. key !== 'NaN' &&
  292. key[0] !== '-' &&
  293. '' + parseInt(key, 10) === key;
  294. const isReservedProp = /*#__PURE__*/ makeMap(
  295. // the leading comma is intentional so empty string "" is also included
  296. ',key,ref,' +
  297. 'onVnodeBeforeMount,onVnodeMounted,' +
  298. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  299. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  300. const cacheStringFunction = (fn) => {
  301. const cache = Object.create(null);
  302. return ((str) => {
  303. const hit = cache[str];
  304. return hit || (cache[str] = fn(str));
  305. });
  306. };
  307. const camelizeRE = /-(\w)/g;
  308. /**
  309. * @private
  310. */
  311. const camelize = cacheStringFunction((str) => {
  312. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  313. });
  314. const hyphenateRE = /\B([A-Z])/g;
  315. /**
  316. * @private
  317. */
  318. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  319. /**
  320. * @private
  321. */
  322. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  323. /**
  324. * @private
  325. */
  326. const toHandlerKey = cacheStringFunction((str) => (str ? `on${capitalize(str)}` : ``));
  327. // compare whether a value has changed, accounting for NaN.
  328. const hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
  329. const invokeArrayFns = (fns, arg) => {
  330. for (let i = 0; i < fns.length; i++) {
  331. fns[i](arg);
  332. }
  333. };
  334. const def = (obj, key, value) => {
  335. Object.defineProperty(obj, key, {
  336. configurable: true,
  337. enumerable: false,
  338. value
  339. });
  340. };
  341. const toNumber = (val) => {
  342. const n = parseFloat(val);
  343. return isNaN(n) ? val : n;
  344. };
  345. let _globalThis;
  346. const getGlobalThis = () => {
  347. return (_globalThis ||
  348. (_globalThis =
  349. typeof globalThis !== 'undefined'
  350. ? globalThis
  351. : typeof self !== 'undefined'
  352. ? self
  353. : typeof window !== 'undefined'
  354. ? window
  355. : typeof global !== 'undefined'
  356. ? global
  357. : {}));
  358. };
  359. const targetMap = new WeakMap();
  360. const effectStack = [];
  361. let activeEffect;
  362. const ITERATE_KEY = Symbol('iterate' );
  363. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  364. function isEffect(fn) {
  365. return fn && fn._isEffect === true;
  366. }
  367. function effect(fn, options = EMPTY_OBJ) {
  368. if (isEffect(fn)) {
  369. fn = fn.raw;
  370. }
  371. const effect = createReactiveEffect(fn, options);
  372. if (!options.lazy) {
  373. effect();
  374. }
  375. return effect;
  376. }
  377. function stop(effect) {
  378. if (effect.active) {
  379. cleanup(effect);
  380. if (effect.options.onStop) {
  381. effect.options.onStop();
  382. }
  383. effect.active = false;
  384. }
  385. }
  386. let uid = 0;
  387. function createReactiveEffect(fn, options) {
  388. const effect = function reactiveEffect() {
  389. if (!effect.active) {
  390. return options.scheduler ? undefined : fn();
  391. }
  392. if (!effectStack.includes(effect)) {
  393. cleanup(effect);
  394. try {
  395. enableTracking();
  396. effectStack.push(effect);
  397. activeEffect = effect;
  398. return fn();
  399. }
  400. finally {
  401. effectStack.pop();
  402. resetTracking();
  403. activeEffect = effectStack[effectStack.length - 1];
  404. }
  405. }
  406. };
  407. effect.id = uid++;
  408. effect.allowRecurse = !!options.allowRecurse;
  409. effect._isEffect = true;
  410. effect.active = true;
  411. effect.raw = fn;
  412. effect.deps = [];
  413. effect.options = options;
  414. return effect;
  415. }
  416. function cleanup(effect) {
  417. const { deps } = effect;
  418. if (deps.length) {
  419. for (let i = 0; i < deps.length; i++) {
  420. deps[i].delete(effect);
  421. }
  422. deps.length = 0;
  423. }
  424. }
  425. let shouldTrack = true;
  426. const trackStack = [];
  427. function pauseTracking() {
  428. trackStack.push(shouldTrack);
  429. shouldTrack = false;
  430. }
  431. function enableTracking() {
  432. trackStack.push(shouldTrack);
  433. shouldTrack = true;
  434. }
  435. function resetTracking() {
  436. const last = trackStack.pop();
  437. shouldTrack = last === undefined ? true : last;
  438. }
  439. function track(target, type, key) {
  440. if (!shouldTrack || activeEffect === undefined) {
  441. return;
  442. }
  443. let depsMap = targetMap.get(target);
  444. if (!depsMap) {
  445. targetMap.set(target, (depsMap = new Map()));
  446. }
  447. let dep = depsMap.get(key);
  448. if (!dep) {
  449. depsMap.set(key, (dep = new Set()));
  450. }
  451. if (!dep.has(activeEffect)) {
  452. dep.add(activeEffect);
  453. activeEffect.deps.push(dep);
  454. if (activeEffect.options.onTrack) {
  455. activeEffect.options.onTrack({
  456. effect: activeEffect,
  457. target,
  458. type,
  459. key
  460. });
  461. }
  462. }
  463. }
  464. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  465. const depsMap = targetMap.get(target);
  466. if (!depsMap) {
  467. // never been tracked
  468. return;
  469. }
  470. const effects = new Set();
  471. const add = (effectsToAdd) => {
  472. if (effectsToAdd) {
  473. effectsToAdd.forEach(effect => {
  474. if (effect !== activeEffect || effect.allowRecurse) {
  475. effects.add(effect);
  476. }
  477. });
  478. }
  479. };
  480. if (type === "clear" /* CLEAR */) {
  481. // collection being cleared
  482. // trigger all effects for target
  483. depsMap.forEach(add);
  484. }
  485. else if (key === 'length' && isArray(target)) {
  486. depsMap.forEach((dep, key) => {
  487. if (key === 'length' || key >= newValue) {
  488. add(dep);
  489. }
  490. });
  491. }
  492. else {
  493. // schedule runs for SET | ADD | DELETE
  494. if (key !== void 0) {
  495. add(depsMap.get(key));
  496. }
  497. // also run for iteration key on ADD | DELETE | Map.SET
  498. switch (type) {
  499. case "add" /* ADD */:
  500. if (!isArray(target)) {
  501. add(depsMap.get(ITERATE_KEY));
  502. if (isMap(target)) {
  503. add(depsMap.get(MAP_KEY_ITERATE_KEY));
  504. }
  505. }
  506. else if (isIntegerKey(key)) {
  507. // new index added to array -> length changes
  508. add(depsMap.get('length'));
  509. }
  510. break;
  511. case "delete" /* DELETE */:
  512. if (!isArray(target)) {
  513. add(depsMap.get(ITERATE_KEY));
  514. if (isMap(target)) {
  515. add(depsMap.get(MAP_KEY_ITERATE_KEY));
  516. }
  517. }
  518. break;
  519. case "set" /* SET */:
  520. if (isMap(target)) {
  521. add(depsMap.get(ITERATE_KEY));
  522. }
  523. break;
  524. }
  525. }
  526. const run = (effect) => {
  527. if (effect.options.onTrigger) {
  528. effect.options.onTrigger({
  529. effect,
  530. target,
  531. key,
  532. type,
  533. newValue,
  534. oldValue,
  535. oldTarget
  536. });
  537. }
  538. if (effect.options.scheduler) {
  539. effect.options.scheduler(effect);
  540. }
  541. else {
  542. effect();
  543. }
  544. };
  545. effects.forEach(run);
  546. }
  547. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  548. const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
  549. .map(key => Symbol[key])
  550. .filter(isSymbol));
  551. const get = /*#__PURE__*/ createGetter();
  552. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  553. const readonlyGet = /*#__PURE__*/ createGetter(true);
  554. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  555. const arrayInstrumentations = {};
  556. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  557. const method = Array.prototype[key];
  558. arrayInstrumentations[key] = function (...args) {
  559. const arr = toRaw(this);
  560. for (let i = 0, l = this.length; i < l; i++) {
  561. track(arr, "get" /* GET */, i + '');
  562. }
  563. // we run the method using the original args first (which may be reactive)
  564. const res = method.apply(arr, args);
  565. if (res === -1 || res === false) {
  566. // if that didn't work, run it again using raw values.
  567. return method.apply(arr, args.map(toRaw));
  568. }
  569. else {
  570. return res;
  571. }
  572. };
  573. });
  574. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  575. const method = Array.prototype[key];
  576. arrayInstrumentations[key] = function (...args) {
  577. pauseTracking();
  578. const res = method.apply(this, args);
  579. resetTracking();
  580. return res;
  581. };
  582. });
  583. function createGetter(isReadonly = false, shallow = false) {
  584. return function get(target, key, receiver) {
  585. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  586. return !isReadonly;
  587. }
  588. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  589. return isReadonly;
  590. }
  591. else if (key === "__v_raw" /* RAW */ &&
  592. receiver === (isReadonly ? readonlyMap : reactiveMap).get(target)) {
  593. return target;
  594. }
  595. const targetIsArray = isArray(target);
  596. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  597. return Reflect.get(arrayInstrumentations, key, receiver);
  598. }
  599. const res = Reflect.get(target, key, receiver);
  600. if (isSymbol(key)
  601. ? builtInSymbols.has(key)
  602. : isNonTrackableKeys(key)) {
  603. return res;
  604. }
  605. if (!isReadonly) {
  606. track(target, "get" /* GET */, key);
  607. }
  608. if (shallow) {
  609. return res;
  610. }
  611. if (isRef(res)) {
  612. // ref unwrapping - does not apply for Array + integer key.
  613. const shouldUnwrap = !targetIsArray || !isIntegerKey(key);
  614. return shouldUnwrap ? res.value : res;
  615. }
  616. if (isObject(res)) {
  617. // Convert returned value into a proxy as well. we do the isObject check
  618. // here to avoid invalid value warning. Also need to lazy access readonly
  619. // and reactive here to avoid circular dependency.
  620. return isReadonly ? readonly(res) : reactive(res);
  621. }
  622. return res;
  623. };
  624. }
  625. const set = /*#__PURE__*/ createSetter();
  626. const shallowSet = /*#__PURE__*/ createSetter(true);
  627. function createSetter(shallow = false) {
  628. return function set(target, key, value, receiver) {
  629. const oldValue = target[key];
  630. if (!shallow) {
  631. value = toRaw(value);
  632. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  633. oldValue.value = value;
  634. return true;
  635. }
  636. }
  637. const hadKey = isArray(target) && isIntegerKey(key)
  638. ? Number(key) < target.length
  639. : hasOwn(target, key);
  640. const result = Reflect.set(target, key, value, receiver);
  641. // don't trigger if target is something up in the prototype chain of original
  642. if (target === toRaw(receiver)) {
  643. if (!hadKey) {
  644. trigger(target, "add" /* ADD */, key, value);
  645. }
  646. else if (hasChanged(value, oldValue)) {
  647. trigger(target, "set" /* SET */, key, value, oldValue);
  648. }
  649. }
  650. return result;
  651. };
  652. }
  653. function deleteProperty(target, key) {
  654. const hadKey = hasOwn(target, key);
  655. const oldValue = target[key];
  656. const result = Reflect.deleteProperty(target, key);
  657. if (result && hadKey) {
  658. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  659. }
  660. return result;
  661. }
  662. function has(target, key) {
  663. const result = Reflect.has(target, key);
  664. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  665. track(target, "has" /* HAS */, key);
  666. }
  667. return result;
  668. }
  669. function ownKeys(target) {
  670. track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  671. return Reflect.ownKeys(target);
  672. }
  673. const mutableHandlers = {
  674. get,
  675. set,
  676. deleteProperty,
  677. has,
  678. ownKeys
  679. };
  680. const readonlyHandlers = {
  681. get: readonlyGet,
  682. set(target, key) {
  683. {
  684. console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  685. }
  686. return true;
  687. },
  688. deleteProperty(target, key) {
  689. {
  690. console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  691. }
  692. return true;
  693. }
  694. };
  695. const shallowReactiveHandlers = extend({}, mutableHandlers, {
  696. get: shallowGet,
  697. set: shallowSet
  698. });
  699. // Props handlers are special in the sense that it should not unwrap top-level
  700. // refs (in order to allow refs to be explicitly passed down), but should
  701. // retain the reactivity of the normal readonly object.
  702. const shallowReadonlyHandlers = extend({}, readonlyHandlers, {
  703. get: shallowReadonlyGet
  704. });
  705. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  706. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  707. const toShallow = (value) => value;
  708. const getProto = (v) => Reflect.getPrototypeOf(v);
  709. function get$1(target, key, isReadonly = false, isShallow = false) {
  710. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  711. // of the value
  712. target = target["__v_raw" /* RAW */];
  713. const rawTarget = toRaw(target);
  714. const rawKey = toRaw(key);
  715. if (key !== rawKey) {
  716. !isReadonly && track(rawTarget, "get" /* GET */, key);
  717. }
  718. !isReadonly && track(rawTarget, "get" /* GET */, rawKey);
  719. const { has } = getProto(rawTarget);
  720. const wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive;
  721. if (has.call(rawTarget, key)) {
  722. return wrap(target.get(key));
  723. }
  724. else if (has.call(rawTarget, rawKey)) {
  725. return wrap(target.get(rawKey));
  726. }
  727. }
  728. function has$1(key, isReadonly = false) {
  729. const target = this["__v_raw" /* RAW */];
  730. const rawTarget = toRaw(target);
  731. const rawKey = toRaw(key);
  732. if (key !== rawKey) {
  733. !isReadonly && track(rawTarget, "has" /* HAS */, key);
  734. }
  735. !isReadonly && track(rawTarget, "has" /* HAS */, rawKey);
  736. return key === rawKey
  737. ? target.has(key)
  738. : target.has(key) || target.has(rawKey);
  739. }
  740. function size(target, isReadonly = false) {
  741. target = target["__v_raw" /* RAW */];
  742. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  743. return Reflect.get(target, 'size', target);
  744. }
  745. function add(value) {
  746. value = toRaw(value);
  747. const target = toRaw(this);
  748. const proto = getProto(target);
  749. const hadKey = proto.has.call(target, value);
  750. if (!hadKey) {
  751. target.add(value);
  752. trigger(target, "add" /* ADD */, value, value);
  753. }
  754. return this;
  755. }
  756. function set$1(key, value) {
  757. value = toRaw(value);
  758. const target = toRaw(this);
  759. const { has, get } = getProto(target);
  760. let hadKey = has.call(target, key);
  761. if (!hadKey) {
  762. key = toRaw(key);
  763. hadKey = has.call(target, key);
  764. }
  765. else {
  766. checkIdentityKeys(target, has, key);
  767. }
  768. const oldValue = get.call(target, key);
  769. target.set(key, value);
  770. if (!hadKey) {
  771. trigger(target, "add" /* ADD */, key, value);
  772. }
  773. else if (hasChanged(value, oldValue)) {
  774. trigger(target, "set" /* SET */, key, value, oldValue);
  775. }
  776. return this;
  777. }
  778. function deleteEntry(key) {
  779. const target = toRaw(this);
  780. const { has, get } = getProto(target);
  781. let hadKey = has.call(target, key);
  782. if (!hadKey) {
  783. key = toRaw(key);
  784. hadKey = has.call(target, key);
  785. }
  786. else {
  787. checkIdentityKeys(target, has, key);
  788. }
  789. const oldValue = get ? get.call(target, key) : undefined;
  790. // forward the operation before queueing reactions
  791. const result = target.delete(key);
  792. if (hadKey) {
  793. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  794. }
  795. return result;
  796. }
  797. function clear() {
  798. const target = toRaw(this);
  799. const hadItems = target.size !== 0;
  800. const oldTarget = isMap(target)
  801. ? new Map(target)
  802. : new Set(target)
  803. ;
  804. // forward the operation before queueing reactions
  805. const result = target.clear();
  806. if (hadItems) {
  807. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  808. }
  809. return result;
  810. }
  811. function createForEach(isReadonly, isShallow) {
  812. return function forEach(callback, thisArg) {
  813. const observed = this;
  814. const target = observed["__v_raw" /* RAW */];
  815. const rawTarget = toRaw(target);
  816. const wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive;
  817. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  818. return target.forEach((value, key) => {
  819. // important: make sure the callback is
  820. // 1. invoked with the reactive map as `this` and 3rd arg
  821. // 2. the value received should be a corresponding reactive/readonly.
  822. return callback.call(thisArg, wrap(value), wrap(key), observed);
  823. });
  824. };
  825. }
  826. function createIterableMethod(method, isReadonly, isShallow) {
  827. return function (...args) {
  828. const target = this["__v_raw" /* RAW */];
  829. const rawTarget = toRaw(target);
  830. const targetIsMap = isMap(rawTarget);
  831. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  832. const isKeyOnly = method === 'keys' && targetIsMap;
  833. const innerIterator = target[method](...args);
  834. const wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive;
  835. !isReadonly &&
  836. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  837. // return a wrapped iterator which returns observed versions of the
  838. // values emitted from the real iterator
  839. return {
  840. // iterator protocol
  841. next() {
  842. const { value, done } = innerIterator.next();
  843. return done
  844. ? { value, done }
  845. : {
  846. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  847. done
  848. };
  849. },
  850. // iterable protocol
  851. [Symbol.iterator]() {
  852. return this;
  853. }
  854. };
  855. };
  856. }
  857. function createReadonlyMethod(type) {
  858. return function (...args) {
  859. {
  860. const key = args[0] ? `on key "${args[0]}" ` : ``;
  861. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  862. }
  863. return type === "delete" /* DELETE */ ? false : this;
  864. };
  865. }
  866. const mutableInstrumentations = {
  867. get(key) {
  868. return get$1(this, key);
  869. },
  870. get size() {
  871. return size(this);
  872. },
  873. has: has$1,
  874. add,
  875. set: set$1,
  876. delete: deleteEntry,
  877. clear,
  878. forEach: createForEach(false, false)
  879. };
  880. const shallowInstrumentations = {
  881. get(key) {
  882. return get$1(this, key, false, true);
  883. },
  884. get size() {
  885. return size(this);
  886. },
  887. has: has$1,
  888. add,
  889. set: set$1,
  890. delete: deleteEntry,
  891. clear,
  892. forEach: createForEach(false, true)
  893. };
  894. const readonlyInstrumentations = {
  895. get(key) {
  896. return get$1(this, key, true);
  897. },
  898. get size() {
  899. return size(this, true);
  900. },
  901. has(key) {
  902. return has$1.call(this, key, true);
  903. },
  904. add: createReadonlyMethod("add" /* ADD */),
  905. set: createReadonlyMethod("set" /* SET */),
  906. delete: createReadonlyMethod("delete" /* DELETE */),
  907. clear: createReadonlyMethod("clear" /* CLEAR */),
  908. forEach: createForEach(true, false)
  909. };
  910. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  911. iteratorMethods.forEach(method => {
  912. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  913. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  914. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  915. });
  916. function createInstrumentationGetter(isReadonly, shallow) {
  917. const instrumentations = shallow
  918. ? shallowInstrumentations
  919. : isReadonly
  920. ? readonlyInstrumentations
  921. : mutableInstrumentations;
  922. return (target, key, receiver) => {
  923. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  924. return !isReadonly;
  925. }
  926. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  927. return isReadonly;
  928. }
  929. else if (key === "__v_raw" /* RAW */) {
  930. return target;
  931. }
  932. return Reflect.get(hasOwn(instrumentations, key) && key in target
  933. ? instrumentations
  934. : target, key, receiver);
  935. };
  936. }
  937. const mutableCollectionHandlers = {
  938. get: createInstrumentationGetter(false, false)
  939. };
  940. const shallowCollectionHandlers = {
  941. get: createInstrumentationGetter(false, true)
  942. };
  943. const readonlyCollectionHandlers = {
  944. get: createInstrumentationGetter(true, false)
  945. };
  946. function checkIdentityKeys(target, has, key) {
  947. const rawKey = toRaw(key);
  948. if (rawKey !== key && has.call(target, rawKey)) {
  949. const type = toRawType(target);
  950. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  951. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  952. `which can lead to inconsistencies. ` +
  953. `Avoid differentiating between the raw and reactive versions ` +
  954. `of an object and only use the reactive version if possible.`);
  955. }
  956. }
  957. const reactiveMap = new WeakMap();
  958. const readonlyMap = new WeakMap();
  959. function targetTypeMap(rawType) {
  960. switch (rawType) {
  961. case 'Object':
  962. case 'Array':
  963. return 1 /* COMMON */;
  964. case 'Map':
  965. case 'Set':
  966. case 'WeakMap':
  967. case 'WeakSet':
  968. return 2 /* COLLECTION */;
  969. default:
  970. return 0 /* INVALID */;
  971. }
  972. }
  973. function getTargetType(value) {
  974. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  975. ? 0 /* INVALID */
  976. : targetTypeMap(toRawType(value));
  977. }
  978. function reactive(target) {
  979. // if trying to observe a readonly proxy, return the readonly version.
  980. if (target && target["__v_isReadonly" /* IS_READONLY */]) {
  981. return target;
  982. }
  983. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers);
  984. }
  985. /**
  986. * Return a shallowly-reactive copy of the original object, where only the root
  987. * level properties are reactive. It also does not auto-unwrap refs (even at the
  988. * root level).
  989. */
  990. function shallowReactive(target) {
  991. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers);
  992. }
  993. /**
  994. * Creates a readonly copy of the original object. Note the returned copy is not
  995. * made reactive, but `readonly` can be called on an already reactive object.
  996. */
  997. function readonly(target) {
  998. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers);
  999. }
  1000. /**
  1001. * Returns a reactive-copy of the original object, where only the root level
  1002. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1003. * returned properties.
  1004. * This is used for creating the props proxy object for stateful components.
  1005. */
  1006. function shallowReadonly(target) {
  1007. return createReactiveObject(target, true, shallowReadonlyHandlers, readonlyCollectionHandlers);
  1008. }
  1009. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers) {
  1010. if (!isObject(target)) {
  1011. {
  1012. console.warn(`value cannot be made reactive: ${String(target)}`);
  1013. }
  1014. return target;
  1015. }
  1016. // target is already a Proxy, return it.
  1017. // exception: calling readonly() on a reactive object
  1018. if (target["__v_raw" /* RAW */] &&
  1019. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1020. return target;
  1021. }
  1022. // target already has corresponding Proxy
  1023. const proxyMap = isReadonly ? readonlyMap : reactiveMap;
  1024. const existingProxy = proxyMap.get(target);
  1025. if (existingProxy) {
  1026. return existingProxy;
  1027. }
  1028. // only a whitelist of value types can be observed.
  1029. const targetType = getTargetType(target);
  1030. if (targetType === 0 /* INVALID */) {
  1031. return target;
  1032. }
  1033. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1034. proxyMap.set(target, proxy);
  1035. return proxy;
  1036. }
  1037. function isReactive(value) {
  1038. if (isReadonly(value)) {
  1039. return isReactive(value["__v_raw" /* RAW */]);
  1040. }
  1041. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1042. }
  1043. function isReadonly(value) {
  1044. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1045. }
  1046. function isProxy(value) {
  1047. return isReactive(value) || isReadonly(value);
  1048. }
  1049. function toRaw(observed) {
  1050. return ((observed && toRaw(observed["__v_raw" /* RAW */])) || observed);
  1051. }
  1052. function markRaw(value) {
  1053. def(value, "__v_skip" /* SKIP */, true);
  1054. return value;
  1055. }
  1056. const convert = (val) => isObject(val) ? reactive(val) : val;
  1057. function isRef(r) {
  1058. return Boolean(r && r.__v_isRef === true);
  1059. }
  1060. function ref(value) {
  1061. return createRef(value);
  1062. }
  1063. function shallowRef(value) {
  1064. return createRef(value, true);
  1065. }
  1066. class RefImpl {
  1067. constructor(_rawValue, _shallow = false) {
  1068. this._rawValue = _rawValue;
  1069. this._shallow = _shallow;
  1070. this.__v_isRef = true;
  1071. this._value = _shallow ? _rawValue : convert(_rawValue);
  1072. }
  1073. get value() {
  1074. track(toRaw(this), "get" /* GET */, 'value');
  1075. return this._value;
  1076. }
  1077. set value(newVal) {
  1078. if (hasChanged(toRaw(newVal), this._rawValue)) {
  1079. this._rawValue = newVal;
  1080. this._value = this._shallow ? newVal : convert(newVal);
  1081. trigger(toRaw(this), "set" /* SET */, 'value', newVal);
  1082. }
  1083. }
  1084. }
  1085. function createRef(rawValue, shallow = false) {
  1086. if (isRef(rawValue)) {
  1087. return rawValue;
  1088. }
  1089. return new RefImpl(rawValue, shallow);
  1090. }
  1091. function triggerRef(ref) {
  1092. trigger(toRaw(ref), "set" /* SET */, 'value', ref.value );
  1093. }
  1094. function unref(ref) {
  1095. return isRef(ref) ? ref.value : ref;
  1096. }
  1097. const shallowUnwrapHandlers = {
  1098. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1099. set: (target, key, value, receiver) => {
  1100. const oldValue = target[key];
  1101. if (isRef(oldValue) && !isRef(value)) {
  1102. oldValue.value = value;
  1103. return true;
  1104. }
  1105. else {
  1106. return Reflect.set(target, key, value, receiver);
  1107. }
  1108. }
  1109. };
  1110. function proxyRefs(objectWithRefs) {
  1111. return isReactive(objectWithRefs)
  1112. ? objectWithRefs
  1113. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1114. }
  1115. class CustomRefImpl {
  1116. constructor(factory) {
  1117. this.__v_isRef = true;
  1118. const { get, set } = factory(() => track(this, "get" /* GET */, 'value'), () => trigger(this, "set" /* SET */, 'value'));
  1119. this._get = get;
  1120. this._set = set;
  1121. }
  1122. get value() {
  1123. return this._get();
  1124. }
  1125. set value(newVal) {
  1126. this._set(newVal);
  1127. }
  1128. }
  1129. function customRef(factory) {
  1130. return new CustomRefImpl(factory);
  1131. }
  1132. function toRefs(object) {
  1133. if (!isProxy(object)) {
  1134. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1135. }
  1136. const ret = isArray(object) ? new Array(object.length) : {};
  1137. for (const key in object) {
  1138. ret[key] = toRef(object, key);
  1139. }
  1140. return ret;
  1141. }
  1142. class ObjectRefImpl {
  1143. constructor(_object, _key) {
  1144. this._object = _object;
  1145. this._key = _key;
  1146. this.__v_isRef = true;
  1147. }
  1148. get value() {
  1149. return this._object[this._key];
  1150. }
  1151. set value(newVal) {
  1152. this._object[this._key] = newVal;
  1153. }
  1154. }
  1155. function toRef(object, key) {
  1156. return isRef(object[key])
  1157. ? object[key]
  1158. : new ObjectRefImpl(object, key);
  1159. }
  1160. class ComputedRefImpl {
  1161. constructor(getter, _setter, isReadonly) {
  1162. this._setter = _setter;
  1163. this._dirty = true;
  1164. this.__v_isRef = true;
  1165. this.effect = effect(getter, {
  1166. lazy: true,
  1167. scheduler: () => {
  1168. if (!this._dirty) {
  1169. this._dirty = true;
  1170. trigger(toRaw(this), "set" /* SET */, 'value');
  1171. }
  1172. }
  1173. });
  1174. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1175. }
  1176. get value() {
  1177. if (this._dirty) {
  1178. this._value = this.effect();
  1179. this._dirty = false;
  1180. }
  1181. track(toRaw(this), "get" /* GET */, 'value');
  1182. return this._value;
  1183. }
  1184. set value(newValue) {
  1185. this._setter(newValue);
  1186. }
  1187. }
  1188. function computed(getterOrOptions) {
  1189. let getter;
  1190. let setter;
  1191. if (isFunction(getterOrOptions)) {
  1192. getter = getterOrOptions;
  1193. setter = () => {
  1194. console.warn('Write operation failed: computed value is readonly');
  1195. }
  1196. ;
  1197. }
  1198. else {
  1199. getter = getterOrOptions.get;
  1200. setter = getterOrOptions.set;
  1201. }
  1202. return new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set);
  1203. }
  1204. const stack = [];
  1205. function pushWarningContext(vnode) {
  1206. stack.push(vnode);
  1207. }
  1208. function popWarningContext() {
  1209. stack.pop();
  1210. }
  1211. function warn(msg, ...args) {
  1212. // avoid props formatting or warn handler tracking deps that might be mutated
  1213. // during patch, leading to infinite recursion.
  1214. pauseTracking();
  1215. const instance = stack.length ? stack[stack.length - 1].component : null;
  1216. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1217. const trace = getComponentTrace();
  1218. if (appWarnHandler) {
  1219. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  1220. msg + args.join(''),
  1221. instance && instance.proxy,
  1222. trace
  1223. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1224. .join('\n'),
  1225. trace
  1226. ]);
  1227. }
  1228. else {
  1229. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1230. /* istanbul ignore if */
  1231. if (trace.length &&
  1232. // avoid spamming console during tests
  1233. !false) {
  1234. warnArgs.push(`\n`, ...formatTrace(trace));
  1235. }
  1236. console.warn(...warnArgs);
  1237. }
  1238. resetTracking();
  1239. }
  1240. function getComponentTrace() {
  1241. let currentVNode = stack[stack.length - 1];
  1242. if (!currentVNode) {
  1243. return [];
  1244. }
  1245. // we can't just use the stack because it will be incomplete during updates
  1246. // that did not start from the root. Re-construct the parent chain using
  1247. // instance parent pointers.
  1248. const normalizedStack = [];
  1249. while (currentVNode) {
  1250. const last = normalizedStack[0];
  1251. if (last && last.vnode === currentVNode) {
  1252. last.recurseCount++;
  1253. }
  1254. else {
  1255. normalizedStack.push({
  1256. vnode: currentVNode,
  1257. recurseCount: 0
  1258. });
  1259. }
  1260. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1261. currentVNode = parentInstance && parentInstance.vnode;
  1262. }
  1263. return normalizedStack;
  1264. }
  1265. /* istanbul ignore next */
  1266. function formatTrace(trace) {
  1267. const logs = [];
  1268. trace.forEach((entry, i) => {
  1269. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1270. });
  1271. return logs;
  1272. }
  1273. function formatTraceEntry({ vnode, recurseCount }) {
  1274. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1275. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1276. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1277. const close = `>` + postfix;
  1278. return vnode.props
  1279. ? [open, ...formatProps(vnode.props), close]
  1280. : [open + close];
  1281. }
  1282. /* istanbul ignore next */
  1283. function formatProps(props) {
  1284. const res = [];
  1285. const keys = Object.keys(props);
  1286. keys.slice(0, 3).forEach(key => {
  1287. res.push(...formatProp(key, props[key]));
  1288. });
  1289. if (keys.length > 3) {
  1290. res.push(` ...`);
  1291. }
  1292. return res;
  1293. }
  1294. /* istanbul ignore next */
  1295. function formatProp(key, value, raw) {
  1296. if (isString(value)) {
  1297. value = JSON.stringify(value);
  1298. return raw ? value : [`${key}=${value}`];
  1299. }
  1300. else if (typeof value === 'number' ||
  1301. typeof value === 'boolean' ||
  1302. value == null) {
  1303. return raw ? value : [`${key}=${value}`];
  1304. }
  1305. else if (isRef(value)) {
  1306. value = formatProp(key, toRaw(value.value), true);
  1307. return raw ? value : [`${key}=Ref<`, value, `>`];
  1308. }
  1309. else if (isFunction(value)) {
  1310. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1311. }
  1312. else {
  1313. value = toRaw(value);
  1314. return raw ? value : [`${key}=`, value];
  1315. }
  1316. }
  1317. const ErrorTypeStrings = {
  1318. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  1319. ["c" /* CREATED */]: 'created hook',
  1320. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  1321. ["m" /* MOUNTED */]: 'mounted hook',
  1322. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  1323. ["u" /* UPDATED */]: 'updated',
  1324. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1325. ["um" /* UNMOUNTED */]: 'unmounted hook',
  1326. ["a" /* ACTIVATED */]: 'activated hook',
  1327. ["da" /* DEACTIVATED */]: 'deactivated hook',
  1328. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  1329. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  1330. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  1331. [0 /* SETUP_FUNCTION */]: 'setup function',
  1332. [1 /* RENDER_FUNCTION */]: 'render function',
  1333. [2 /* WATCH_GETTER */]: 'watcher getter',
  1334. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  1335. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  1336. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  1337. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1338. [7 /* VNODE_HOOK */]: 'vnode hook',
  1339. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  1340. [9 /* TRANSITION_HOOK */]: 'transition hook',
  1341. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  1342. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  1343. [12 /* FUNCTION_REF */]: 'ref function',
  1344. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1345. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1346. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-next'
  1347. };
  1348. function callWithErrorHandling(fn, instance, type, args) {
  1349. let res;
  1350. try {
  1351. res = args ? fn(...args) : fn();
  1352. }
  1353. catch (err) {
  1354. handleError(err, instance, type);
  1355. }
  1356. return res;
  1357. }
  1358. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1359. if (isFunction(fn)) {
  1360. const res = callWithErrorHandling(fn, instance, type, args);
  1361. if (res && isPromise(res)) {
  1362. res.catch(err => {
  1363. handleError(err, instance, type);
  1364. });
  1365. }
  1366. return res;
  1367. }
  1368. const values = [];
  1369. for (let i = 0; i < fn.length; i++) {
  1370. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1371. }
  1372. return values;
  1373. }
  1374. function handleError(err, instance, type, throwInDev = true) {
  1375. const contextVNode = instance ? instance.vnode : null;
  1376. if (instance) {
  1377. let cur = instance.parent;
  1378. // the exposed instance is the render proxy to keep it consistent with 2.x
  1379. const exposedInstance = instance.proxy;
  1380. // in production the hook receives only the error code
  1381. const errorInfo = ErrorTypeStrings[type] ;
  1382. while (cur) {
  1383. const errorCapturedHooks = cur.ec;
  1384. if (errorCapturedHooks) {
  1385. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1386. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1387. return;
  1388. }
  1389. }
  1390. }
  1391. cur = cur.parent;
  1392. }
  1393. // app-level handling
  1394. const appErrorHandler = instance.appContext.config.errorHandler;
  1395. if (appErrorHandler) {
  1396. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1397. return;
  1398. }
  1399. }
  1400. logError(err, type, contextVNode, throwInDev);
  1401. }
  1402. function logError(err, type, contextVNode, throwInDev = true) {
  1403. {
  1404. const info = ErrorTypeStrings[type];
  1405. if (contextVNode) {
  1406. pushWarningContext(contextVNode);
  1407. }
  1408. warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1409. if (contextVNode) {
  1410. popWarningContext();
  1411. }
  1412. // crash in dev by default so it's more noticeable
  1413. if (throwInDev) {
  1414. throw err;
  1415. }
  1416. else {
  1417. console.error(err);
  1418. }
  1419. }
  1420. }
  1421. let isFlushing = false;
  1422. let isFlushPending = false;
  1423. const queue = [];
  1424. let flushIndex = 0;
  1425. const pendingPreFlushCbs = [];
  1426. let activePreFlushCbs = null;
  1427. let preFlushIndex = 0;
  1428. const pendingPostFlushCbs = [];
  1429. let activePostFlushCbs = null;
  1430. let postFlushIndex = 0;
  1431. const resolvedPromise = Promise.resolve();
  1432. let currentFlushPromise = null;
  1433. let currentPreFlushParentJob = null;
  1434. const RECURSION_LIMIT = 100;
  1435. function nextTick(fn) {
  1436. const p = currentFlushPromise || resolvedPromise;
  1437. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1438. }
  1439. // #2768
  1440. // Use binary-search to find a suitable position in the queue,
  1441. // so that the queue maintains the increasing order of job's id,
  1442. // which can prevent the job from being skipped and also can avoid repeated patching.
  1443. function findInsertionIndex(job) {
  1444. // the start index should be `flushIndex + 1`
  1445. let start = flushIndex + 1;
  1446. let end = queue.length;
  1447. const jobId = getId(job);
  1448. while (start < end) {
  1449. const middle = (start + end) >>> 1;
  1450. const middleJobId = getId(queue[middle]);
  1451. middleJobId < jobId ? (start = middle + 1) : (end = middle);
  1452. }
  1453. return start;
  1454. }
  1455. function queueJob(job) {
  1456. // the dedupe search uses the startIndex argument of Array.includes()
  1457. // by default the search index includes the current job that is being run
  1458. // so it cannot recursively trigger itself again.
  1459. // if the job is a watch() callback, the search will start with a +1 index to
  1460. // allow it recursively trigger itself - it is the user's responsibility to
  1461. // ensure it doesn't end up in an infinite loop.
  1462. if ((!queue.length ||
  1463. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  1464. job !== currentPreFlushParentJob) {
  1465. const pos = findInsertionIndex(job);
  1466. if (pos > -1) {
  1467. queue.splice(pos, 0, job);
  1468. }
  1469. else {
  1470. queue.push(job);
  1471. }
  1472. queueFlush();
  1473. }
  1474. }
  1475. function queueFlush() {
  1476. if (!isFlushing && !isFlushPending) {
  1477. isFlushPending = true;
  1478. currentFlushPromise = resolvedPromise.then(flushJobs);
  1479. }
  1480. }
  1481. function invalidateJob(job) {
  1482. const i = queue.indexOf(job);
  1483. if (i > -1) {
  1484. queue.splice(i, 1);
  1485. }
  1486. }
  1487. function queueCb(cb, activeQueue, pendingQueue, index) {
  1488. if (!isArray(cb)) {
  1489. if (!activeQueue ||
  1490. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  1491. pendingQueue.push(cb);
  1492. }
  1493. }
  1494. else {
  1495. // if cb is an array, it is a component lifecycle hook which can only be
  1496. // triggered by a job, which is already deduped in the main queue, so
  1497. // we can skip duplicate check here to improve perf
  1498. pendingQueue.push(...cb);
  1499. }
  1500. queueFlush();
  1501. }
  1502. function queuePreFlushCb(cb) {
  1503. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  1504. }
  1505. function queuePostFlushCb(cb) {
  1506. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  1507. }
  1508. function flushPreFlushCbs(seen, parentJob = null) {
  1509. if (pendingPreFlushCbs.length) {
  1510. currentPreFlushParentJob = parentJob;
  1511. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  1512. pendingPreFlushCbs.length = 0;
  1513. {
  1514. seen = seen || new Map();
  1515. }
  1516. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  1517. {
  1518. checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex]);
  1519. }
  1520. activePreFlushCbs[preFlushIndex]();
  1521. }
  1522. activePreFlushCbs = null;
  1523. preFlushIndex = 0;
  1524. currentPreFlushParentJob = null;
  1525. // recursively flush until it drains
  1526. flushPreFlushCbs(seen, parentJob);
  1527. }
  1528. }
  1529. function flushPostFlushCbs(seen) {
  1530. if (pendingPostFlushCbs.length) {
  1531. const deduped = [...new Set(pendingPostFlushCbs)];
  1532. pendingPostFlushCbs.length = 0;
  1533. // #1947 already has active queue, nested flushPostFlushCbs call
  1534. if (activePostFlushCbs) {
  1535. activePostFlushCbs.push(...deduped);
  1536. return;
  1537. }
  1538. activePostFlushCbs = deduped;
  1539. {
  1540. seen = seen || new Map();
  1541. }
  1542. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1543. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1544. {
  1545. checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex]);
  1546. }
  1547. activePostFlushCbs[postFlushIndex]();
  1548. }
  1549. activePostFlushCbs = null;
  1550. postFlushIndex = 0;
  1551. }
  1552. }
  1553. const getId = (job) => job.id == null ? Infinity : job.id;
  1554. function flushJobs(seen) {
  1555. isFlushPending = false;
  1556. isFlushing = true;
  1557. {
  1558. seen = seen || new Map();
  1559. }
  1560. flushPreFlushCbs(seen);
  1561. // Sort queue before flush.
  1562. // This ensures that:
  1563. // 1. Components are updated from parent to child. (because parent is always
  1564. // created before the child so its render effect will have smaller
  1565. // priority number)
  1566. // 2. If a component is unmounted during a parent component's update,
  1567. // its update can be skipped.
  1568. queue.sort((a, b) => getId(a) - getId(b));
  1569. try {
  1570. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1571. const job = queue[flushIndex];
  1572. if (job) {
  1573. if (true) {
  1574. checkRecursiveUpdates(seen, job);
  1575. }
  1576. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  1577. }
  1578. }
  1579. }
  1580. finally {
  1581. flushIndex = 0;
  1582. queue.length = 0;
  1583. flushPostFlushCbs(seen);
  1584. isFlushing = false;
  1585. currentFlushPromise = null;
  1586. // some postFlushCb queued jobs!
  1587. // keep flushing until it drains.
  1588. if (queue.length || pendingPostFlushCbs.length) {
  1589. flushJobs(seen);
  1590. }
  1591. }
  1592. }
  1593. function checkRecursiveUpdates(seen, fn) {
  1594. if (!seen.has(fn)) {
  1595. seen.set(fn, 1);
  1596. }
  1597. else {
  1598. const count = seen.get(fn);
  1599. if (count > RECURSION_LIMIT) {
  1600. throw new Error(`Maximum recursive updates exceeded. ` +
  1601. `This means you have a reactive effect that is mutating its own ` +
  1602. `dependencies and thus recursively triggering itself. Possible sources ` +
  1603. `include component template, render function, updated hook or ` +
  1604. `watcher source function.`);
  1605. }
  1606. else {
  1607. seen.set(fn, count + 1);
  1608. }
  1609. }
  1610. }
  1611. /* eslint-disable no-restricted-globals */
  1612. let isHmrUpdating = false;
  1613. const hmrDirtyComponents = new Set();
  1614. // Expose the HMR runtime on the global object
  1615. // This makes it entirely tree-shakable without polluting the exports and makes
  1616. // it easier to be used in toolings like vue-loader
  1617. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1618. // to be set so that its instances can be registered / removed.
  1619. {
  1620. const globalObject = typeof global !== 'undefined'
  1621. ? global
  1622. : typeof self !== 'undefined'
  1623. ? self
  1624. : typeof window !== 'undefined'
  1625. ? window
  1626. : {};
  1627. globalObject.__VUE_HMR_RUNTIME__ = {
  1628. createRecord: tryWrap(createRecord),
  1629. rerender: tryWrap(rerender),
  1630. reload: tryWrap(reload)
  1631. };
  1632. }
  1633. const map = new Map();
  1634. function registerHMR(instance) {
  1635. const id = instance.type.__hmrId;
  1636. let record = map.get(id);
  1637. if (!record) {
  1638. createRecord(id, instance.type);
  1639. record = map.get(id);
  1640. }
  1641. record.instances.add(instance);
  1642. }
  1643. function unregisterHMR(instance) {
  1644. map.get(instance.type.__hmrId).instances.delete(instance);
  1645. }
  1646. function createRecord(id, component) {
  1647. if (!component) {
  1648. warn(`HMR API usage is out of date.\n` +
  1649. `Please upgrade vue-loader/vite/rollup-plugin-vue or other relevant ` +
  1650. `dependency that handles Vue SFC compilation.`);
  1651. component = {};
  1652. }
  1653. if (map.has(id)) {
  1654. return false;
  1655. }
  1656. map.set(id, {
  1657. component: isClassComponent(component) ? component.__vccOpts : component,
  1658. instances: new Set()
  1659. });
  1660. return true;
  1661. }
  1662. function rerender(id, newRender) {
  1663. const record = map.get(id);
  1664. if (!record)
  1665. return;
  1666. if (newRender)
  1667. record.component.render = newRender;
  1668. // Array.from creates a snapshot which avoids the set being mutated during
  1669. // updates
  1670. Array.from(record.instances).forEach(instance => {
  1671. if (newRender) {
  1672. instance.render = newRender;
  1673. }
  1674. instance.renderCache = [];
  1675. // this flag forces child components with slot content to update
  1676. isHmrUpdating = true;
  1677. instance.update();
  1678. isHmrUpdating = false;
  1679. });
  1680. }
  1681. function reload(id, newComp) {
  1682. const record = map.get(id);
  1683. if (!record)
  1684. return;
  1685. // Array.from creates a snapshot which avoids the set being mutated during
  1686. // updates
  1687. const { component, instances } = record;
  1688. if (!hmrDirtyComponents.has(component)) {
  1689. // 1. Update existing comp definition to match new one
  1690. newComp = isClassComponent(newComp) ? newComp.__vccOpts : newComp;
  1691. extend(component, newComp);
  1692. for (const key in component) {
  1693. if (!(key in newComp)) {
  1694. delete component[key];
  1695. }
  1696. }
  1697. // 2. Mark component dirty. This forces the renderer to replace the component
  1698. // on patch.
  1699. hmrDirtyComponents.add(component);
  1700. // 3. Make sure to unmark the component after the reload.
  1701. queuePostFlushCb(() => {
  1702. hmrDirtyComponents.delete(component);
  1703. });
  1704. }
  1705. Array.from(instances).forEach(instance => {
  1706. if (instance.parent) {
  1707. // 4. Force the parent instance to re-render. This will cause all updated
  1708. // components to be unmounted and re-mounted. Queue the update so that we
  1709. // don't end up forcing the same parent to re-render multiple times.
  1710. queueJob(instance.parent.update);
  1711. }
  1712. else if (instance.appContext.reload) {
  1713. // root instance mounted via createApp() has a reload method
  1714. instance.appContext.reload();
  1715. }
  1716. else if (typeof window !== 'undefined') {
  1717. // root instance inside tree created via raw render(). Force reload.
  1718. window.location.reload();
  1719. }
  1720. else {
  1721. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  1722. }
  1723. });
  1724. }
  1725. function tryWrap(fn) {
  1726. return (id, arg) => {
  1727. try {
  1728. return fn(id, arg);
  1729. }
  1730. catch (e) {
  1731. console.error(e);
  1732. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  1733. `Full reload required.`);
  1734. }
  1735. };
  1736. }
  1737. function setDevtoolsHook(hook) {
  1738. exports.devtools = hook;
  1739. }
  1740. function devtoolsInitApp(app, version) {
  1741. // TODO queue if devtools is undefined
  1742. if (!exports.devtools)
  1743. return;
  1744. exports.devtools.emit("app:init" /* APP_INIT */, app, version, {
  1745. Fragment,
  1746. Text,
  1747. Comment,
  1748. Static
  1749. });
  1750. }
  1751. function devtoolsUnmountApp(app) {
  1752. if (!exports.devtools)
  1753. return;
  1754. exports.devtools.emit("app:unmount" /* APP_UNMOUNT */, app);
  1755. }
  1756. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  1757. const devtoolsComponentUpdated = /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  1758. const devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  1759. function createDevtoolsComponentHook(hook) {
  1760. return (component) => {
  1761. if (!exports.devtools)
  1762. return;
  1763. exports.devtools.emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  1764. };
  1765. }
  1766. function devtoolsComponentEmit(component, event, params) {
  1767. if (!exports.devtools)
  1768. return;
  1769. exports.devtools.emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  1770. }
  1771. function emit(instance, event, ...rawArgs) {
  1772. const props = instance.vnode.props || EMPTY_OBJ;
  1773. {
  1774. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  1775. if (emitsOptions) {
  1776. if (!(event in emitsOptions)) {
  1777. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  1778. warn(`Component emitted event "${event}" but it is neither declared in ` +
  1779. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  1780. }
  1781. }
  1782. else {
  1783. const validator = emitsOptions[event];
  1784. if (isFunction(validator)) {
  1785. const isValid = validator(...rawArgs);
  1786. if (!isValid) {
  1787. warn(`Invalid event arguments: event validation failed for event "${event}".`);
  1788. }
  1789. }
  1790. }
  1791. }
  1792. }
  1793. let args = rawArgs;
  1794. const isModelListener = event.startsWith('update:');
  1795. // for v-model update:xxx events, apply modifiers on args
  1796. const modelArg = isModelListener && event.slice(7);
  1797. if (modelArg && modelArg in props) {
  1798. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  1799. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  1800. if (trim) {
  1801. args = rawArgs.map(a => a.trim());
  1802. }
  1803. else if (number) {
  1804. args = rawArgs.map(toNumber);
  1805. }
  1806. }
  1807. {
  1808. devtoolsComponentEmit(instance, event, args);
  1809. }
  1810. {
  1811. const lowerCaseEvent = event.toLowerCase();
  1812. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  1813. warn(`Event "${lowerCaseEvent}" is emitted in component ` +
  1814. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  1815. `Note that HTML attributes are case-insensitive and you cannot use ` +
  1816. `v-on to listen to camelCase events when using in-DOM templates. ` +
  1817. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  1818. }
  1819. }
  1820. // convert handler name to camelCase. See issue #2249
  1821. let handlerName = toHandlerKey(camelize(event));
  1822. let handler = props[handlerName];
  1823. // for v-model update:xxx events, also trigger kebab-case equivalent
  1824. // for props passed via kebab-case
  1825. if (!handler && isModelListener) {
  1826. handlerName = toHandlerKey(hyphenate(event));
  1827. handler = props[handlerName];
  1828. }
  1829. if (handler) {
  1830. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  1831. }
  1832. const onceHandler = props[handlerName + `Once`];
  1833. if (onceHandler) {
  1834. if (!instance.emitted) {
  1835. (instance.emitted = {})[handlerName] = true;
  1836. }
  1837. else if (instance.emitted[handlerName]) {
  1838. return;
  1839. }
  1840. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  1841. }
  1842. }
  1843. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  1844. if (!appContext.deopt && comp.__emits !== undefined) {
  1845. return comp.__emits;
  1846. }
  1847. const raw = comp.emits;
  1848. let normalized = {};
  1849. // apply mixin/extends props
  1850. let hasExtends = false;
  1851. if (!isFunction(comp)) {
  1852. const extendEmits = (raw) => {
  1853. hasExtends = true;
  1854. extend(normalized, normalizeEmitsOptions(raw, appContext, true));
  1855. };
  1856. if (!asMixin && appContext.mixins.length) {
  1857. appContext.mixins.forEach(extendEmits);
  1858. }
  1859. if (comp.extends) {
  1860. extendEmits(comp.extends);
  1861. }
  1862. if (comp.mixins) {
  1863. comp.mixins.forEach(extendEmits);
  1864. }
  1865. }
  1866. if (!raw && !hasExtends) {
  1867. return (comp.__emits = null);
  1868. }
  1869. if (isArray(raw)) {
  1870. raw.forEach(key => (normalized[key] = null));
  1871. }
  1872. else {
  1873. extend(normalized, raw);
  1874. }
  1875. return (comp.__emits = normalized);
  1876. }
  1877. // Check if an incoming prop key is a declared emit event listener.
  1878. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  1879. // both considered matched listeners.
  1880. function isEmitListener(options, key) {
  1881. if (!options || !isOn(key)) {
  1882. return false;
  1883. }
  1884. key = key.slice(2).replace(/Once$/, '');
  1885. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  1886. hasOwn(options, hyphenate(key)) ||
  1887. hasOwn(options, key));
  1888. }
  1889. /**
  1890. * mark the current rendering instance for asset resolution (e.g.
  1891. * resolveComponent, resolveDirective) during render
  1892. */
  1893. let currentRenderingInstance = null;
  1894. function setCurrentRenderingInstance(instance) {
  1895. currentRenderingInstance = instance;
  1896. }
  1897. /**
  1898. * dev only flag to track whether $attrs was used during render.
  1899. * If $attrs was used during render then the warning for failed attrs
  1900. * fallthrough can be suppressed.
  1901. */
  1902. let accessedAttrs = false;
  1903. function markAttrsAccessed() {
  1904. accessedAttrs = true;
  1905. }
  1906. function renderComponentRoot(instance) {
  1907. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx } = instance;
  1908. let result;
  1909. currentRenderingInstance = instance;
  1910. {
  1911. accessedAttrs = false;
  1912. }
  1913. try {
  1914. let fallthroughAttrs;
  1915. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  1916. // withProxy is a proxy with a different `has` trap only for
  1917. // runtime-compiled render functions using `with` block.
  1918. const proxyToUse = withProxy || proxy;
  1919. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  1920. fallthroughAttrs = attrs;
  1921. }
  1922. else {
  1923. // functional
  1924. const render = Component;
  1925. // in dev, mark attrs accessed if optional props (attrs === props)
  1926. if (true && attrs === props) {
  1927. markAttrsAccessed();
  1928. }
  1929. result = normalizeVNode(render.length > 1
  1930. ? render(props, true
  1931. ? {
  1932. get attrs() {
  1933. markAttrsAccessed();
  1934. return attrs;
  1935. },
  1936. slots,
  1937. emit
  1938. }
  1939. : { attrs, slots, emit })
  1940. : render(props, null /* we know it doesn't need it */));
  1941. fallthroughAttrs = Component.props
  1942. ? attrs
  1943. : getFunctionalFallthrough(attrs);
  1944. }
  1945. // attr merging
  1946. // in dev mode, comments are preserved, and it's possible for a template
  1947. // to have comments along side the root element which makes it a fragment
  1948. let root = result;
  1949. let setRoot = undefined;
  1950. if (true &&
  1951. result.patchFlag > 0 &&
  1952. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  1953. ;
  1954. [root, setRoot] = getChildRoot(result);
  1955. }
  1956. if (Component.inheritAttrs !== false && fallthroughAttrs) {
  1957. const keys = Object.keys(fallthroughAttrs);
  1958. const { shapeFlag } = root;
  1959. if (keys.length) {
  1960. if (shapeFlag & 1 /* ELEMENT */ ||
  1961. shapeFlag & 6 /* COMPONENT */) {
  1962. if (propsOptions && keys.some(isModelListener)) {
  1963. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  1964. // prop, it indicates this component expects to handle v-model and
  1965. // it should not fallthrough.
  1966. // related: #1543, #1643, #1989
  1967. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  1968. }
  1969. root = cloneVNode(root, fallthroughAttrs);
  1970. }
  1971. else if (true && !accessedAttrs && root.type !== Comment) {
  1972. const allAttrs = Object.keys(attrs);
  1973. const eventAttrs = [];
  1974. const extraAttrs = [];
  1975. for (let i = 0, l = allAttrs.length; i < l; i++) {
  1976. const key = allAttrs[i];
  1977. if (isOn(key)) {
  1978. // ignore v-model handlers when they fail to fallthrough
  1979. if (!isModelListener(key)) {
  1980. // remove `on`, lowercase first letter to reflect event casing
  1981. // accurately
  1982. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  1983. }
  1984. }
  1985. else {
  1986. extraAttrs.push(key);
  1987. }
  1988. }
  1989. if (extraAttrs.length) {
  1990. warn(`Extraneous non-props attributes (` +
  1991. `${extraAttrs.join(', ')}) ` +
  1992. `were passed to component but could not be automatically inherited ` +
  1993. `because component renders fragment or text root nodes.`);
  1994. }
  1995. if (eventAttrs.length) {
  1996. warn(`Extraneous non-emits event listeners (` +
  1997. `${eventAttrs.join(', ')}) ` +
  1998. `were passed to component but could not be automatically inherited ` +
  1999. `because component renders fragment or text root nodes. ` +
  2000. `If the listener is intended to be a component custom event listener only, ` +
  2001. `declare it using the "emits" option.`);
  2002. }
  2003. }
  2004. }
  2005. }
  2006. // inherit directives
  2007. if (vnode.dirs) {
  2008. if (true && !isElementRoot(root)) {
  2009. warn(`Runtime directive used on component with non-element root node. ` +
  2010. `The directives will not function as intended.`);
  2011. }
  2012. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  2013. }
  2014. // inherit transition data
  2015. if (vnode.transition) {
  2016. if (true && !isElementRoot(root)) {
  2017. warn(`Component inside <Transition> renders non-element root node ` +
  2018. `that cannot be animated.`);
  2019. }
  2020. root.transition = vnode.transition;
  2021. }
  2022. if (true && setRoot) {
  2023. setRoot(root);
  2024. }
  2025. else {
  2026. result = root;
  2027. }
  2028. }
  2029. catch (err) {
  2030. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  2031. result = createVNode(Comment);
  2032. }
  2033. currentRenderingInstance = null;
  2034. return result;
  2035. }
  2036. /**
  2037. * dev only
  2038. * In dev mode, template root level comments are rendered, which turns the
  2039. * template into a fragment root, but we need to locate the single element
  2040. * root for attrs and scope id processing.
  2041. */
  2042. const getChildRoot = (vnode) => {
  2043. const rawChildren = vnode.children;
  2044. const dynamicChildren = vnode.dynamicChildren;
  2045. const childRoot = filterSingleRoot(rawChildren);
  2046. if (!childRoot) {
  2047. return [vnode, undefined];
  2048. }
  2049. const index = rawChildren.indexOf(childRoot);
  2050. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2051. const setRoot = (updatedRoot) => {
  2052. rawChildren[index] = updatedRoot;
  2053. if (dynamicChildren) {
  2054. if (dynamicIndex > -1) {
  2055. dynamicChildren[dynamicIndex] = updatedRoot;
  2056. }
  2057. else if (updatedRoot.patchFlag > 0) {
  2058. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2059. }
  2060. }
  2061. };
  2062. return [normalizeVNode(childRoot), setRoot];
  2063. };
  2064. function filterSingleRoot(children) {
  2065. let singleRoot;
  2066. for (let i = 0; i < children.length; i++) {
  2067. const child = children[i];
  2068. if (isVNode(child)) {
  2069. // ignore user comment
  2070. if (child.type !== Comment || child.children === 'v-if') {
  2071. if (singleRoot) {
  2072. // has more than 1 non-comment child, return now
  2073. return;
  2074. }
  2075. else {
  2076. singleRoot = child;
  2077. }
  2078. }
  2079. }
  2080. else {
  2081. return;
  2082. }
  2083. }
  2084. return singleRoot;
  2085. }
  2086. const getFunctionalFallthrough = (attrs) => {
  2087. let res;
  2088. for (const key in attrs) {
  2089. if (key === 'class' || key === 'style' || isOn(key)) {
  2090. (res || (res = {}))[key] = attrs[key];
  2091. }
  2092. }
  2093. return res;
  2094. };
  2095. const filterModelListeners = (attrs, props) => {
  2096. const res = {};
  2097. for (const key in attrs) {
  2098. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2099. res[key] = attrs[key];
  2100. }
  2101. }
  2102. return res;
  2103. };
  2104. const isElementRoot = (vnode) => {
  2105. return (vnode.shapeFlag & 6 /* COMPONENT */ ||
  2106. vnode.shapeFlag & 1 /* ELEMENT */ ||
  2107. vnode.type === Comment // potential v-if branch switch
  2108. );
  2109. };
  2110. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2111. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2112. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2113. const emits = component.emitsOptions;
  2114. // Parent component's render function was hot-updated. Since this may have
  2115. // caused the child component's slots content to have changed, we need to
  2116. // force the child to update as well.
  2117. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2118. return true;
  2119. }
  2120. // force child update for runtime directive or transition on component vnode.
  2121. if (nextVNode.dirs || nextVNode.transition) {
  2122. return true;
  2123. }
  2124. if (optimized && patchFlag >= 0) {
  2125. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2126. // slot content that references values that might have changed,
  2127. // e.g. in a v-for
  2128. return true;
  2129. }
  2130. if (patchFlag & 16 /* FULL_PROPS */) {
  2131. if (!prevProps) {
  2132. return !!nextProps;
  2133. }
  2134. // presence of this flag indicates props are always non-null
  2135. return hasPropsChanged(prevProps, nextProps, emits);
  2136. }
  2137. else if (patchFlag & 8 /* PROPS */) {
  2138. const dynamicProps = nextVNode.dynamicProps;
  2139. for (let i = 0; i < dynamicProps.length; i++) {
  2140. const key = dynamicProps[i];
  2141. if (nextProps[key] !== prevProps[key] &&
  2142. !isEmitListener(emits, key)) {
  2143. return true;
  2144. }
  2145. }
  2146. }
  2147. }
  2148. else {
  2149. // this path is only taken by manually written render functions
  2150. // so presence of any children leads to a forced update
  2151. if (prevChildren || nextChildren) {
  2152. if (!nextChildren || !nextChildren.$stable) {
  2153. return true;
  2154. }
  2155. }
  2156. if (prevProps === nextProps) {
  2157. return false;
  2158. }
  2159. if (!prevProps) {
  2160. return !!nextProps;
  2161. }
  2162. if (!nextProps) {
  2163. return true;
  2164. }
  2165. return hasPropsChanged(prevProps, nextProps, emits);
  2166. }
  2167. return false;
  2168. }
  2169. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2170. const nextKeys = Object.keys(nextProps);
  2171. if (nextKeys.length !== Object.keys(prevProps).length) {
  2172. return true;
  2173. }
  2174. for (let i = 0; i < nextKeys.length; i++) {
  2175. const key = nextKeys[i];
  2176. if (nextProps[key] !== prevProps[key] &&
  2177. !isEmitListener(emitsOptions, key)) {
  2178. return true;
  2179. }
  2180. }
  2181. return false;
  2182. }
  2183. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2184. ) {
  2185. while (parent && parent.subTree === vnode) {
  2186. (vnode = parent.vnode).el = el;
  2187. parent = parent.parent;
  2188. }
  2189. }
  2190. const isSuspense = (type) => type.__isSuspense;
  2191. // Suspense exposes a component-like API, and is treated like a component
  2192. // in the compiler, but internally it's a special built-in type that hooks
  2193. // directly into the renderer.
  2194. const SuspenseImpl = {
  2195. // In order to make Suspense tree-shakable, we need to avoid importing it
  2196. // directly in the renderer. The renderer checks for the __isSuspense flag
  2197. // on a vnode's type and calls the `process` method, passing in renderer
  2198. // internals.
  2199. __isSuspense: true,
  2200. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized,
  2201. // platform-specific impl passed from renderer
  2202. rendererInternals) {
  2203. if (n1 == null) {
  2204. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, rendererInternals);
  2205. }
  2206. else {
  2207. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, rendererInternals);
  2208. }
  2209. },
  2210. hydrate: hydrateSuspense,
  2211. create: createSuspenseBoundary
  2212. };
  2213. // Force-casted public typing for h and TSX props inference
  2214. const Suspense = (SuspenseImpl
  2215. );
  2216. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, optimized, rendererInternals) {
  2217. const { p: patch, o: { createElement } } = rendererInternals;
  2218. const hiddenContainer = createElement('div');
  2219. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, optimized, rendererInternals));
  2220. // start mounting the content subtree in an off-dom container
  2221. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG);
  2222. // now check if we have encountered any async deps
  2223. if (suspense.deps > 0) {
  2224. // has async
  2225. // mount the fallback tree
  2226. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2227. isSVG);
  2228. setActiveBranch(suspense, vnode.ssFallback);
  2229. }
  2230. else {
  2231. // Suspense has no async deps. Just resolve.
  2232. suspense.resolve();
  2233. }
  2234. }
  2235. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, { p: patch, um: unmount, o: { createElement } }) {
  2236. const suspense = (n2.suspense = n1.suspense);
  2237. suspense.vnode = n2;
  2238. n2.el = n1.el;
  2239. const newBranch = n2.ssContent;
  2240. const newFallback = n2.ssFallback;
  2241. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2242. if (pendingBranch) {
  2243. suspense.pendingBranch = newBranch;
  2244. if (isSameVNodeType(newBranch, pendingBranch)) {
  2245. // same root type but content may have changed.
  2246. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  2247. if (suspense.deps <= 0) {
  2248. suspense.resolve();
  2249. }
  2250. else if (isInFallback) {
  2251. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2252. isSVG);
  2253. setActiveBranch(suspense, newFallback);
  2254. }
  2255. }
  2256. else {
  2257. // toggled before pending tree is resolved
  2258. suspense.pendingId++;
  2259. if (isHydrating) {
  2260. // if toggled before hydration is finished, the current DOM tree is
  2261. // no longer valid. set it as the active branch so it will be unmounted
  2262. // when resolved
  2263. suspense.isHydrating = false;
  2264. suspense.activeBranch = pendingBranch;
  2265. }
  2266. else {
  2267. unmount(pendingBranch, parentComponent, suspense);
  2268. }
  2269. // increment pending ID. this is used to invalidate async callbacks
  2270. // reset suspense state
  2271. suspense.deps = 0;
  2272. // discard effects from pending branch
  2273. suspense.effects.length = 0;
  2274. // discard previous container
  2275. suspense.hiddenContainer = createElement('div');
  2276. if (isInFallback) {
  2277. // already in fallback state
  2278. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  2279. if (suspense.deps <= 0) {
  2280. suspense.resolve();
  2281. }
  2282. else {
  2283. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2284. isSVG);
  2285. setActiveBranch(suspense, newFallback);
  2286. }
  2287. }
  2288. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2289. // toggled "back" to current active branch
  2290. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG);
  2291. // force resolve
  2292. suspense.resolve(true);
  2293. }
  2294. else {
  2295. // switched to a 3rd branch
  2296. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  2297. if (suspense.deps <= 0) {
  2298. suspense.resolve();
  2299. }
  2300. }
  2301. }
  2302. }
  2303. else {
  2304. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2305. // root did not change, just normal patch
  2306. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG);
  2307. setActiveBranch(suspense, newBranch);
  2308. }
  2309. else {
  2310. // root node toggled
  2311. // invoke @pending event
  2312. const onPending = n2.props && n2.props.onPending;
  2313. if (isFunction(onPending)) {
  2314. onPending();
  2315. }
  2316. // mount pending branch in off-dom container
  2317. suspense.pendingBranch = newBranch;
  2318. suspense.pendingId++;
  2319. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  2320. if (suspense.deps <= 0) {
  2321. // incoming branch has no async deps, resolve now.
  2322. suspense.resolve();
  2323. }
  2324. else {
  2325. const { timeout, pendingId } = suspense;
  2326. if (timeout > 0) {
  2327. setTimeout(() => {
  2328. if (suspense.pendingId === pendingId) {
  2329. suspense.fallback(newFallback);
  2330. }
  2331. }, timeout);
  2332. }
  2333. else if (timeout === 0) {
  2334. suspense.fallback(newFallback);
  2335. }
  2336. }
  2337. }
  2338. }
  2339. }
  2340. let hasWarned = false;
  2341. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, optimized, rendererInternals, isHydrating = false) {
  2342. /* istanbul ignore if */
  2343. if (!hasWarned) {
  2344. hasWarned = true;
  2345. // @ts-ignore `console.info` cannot be null error
  2346. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2347. }
  2348. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2349. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2350. const suspense = {
  2351. vnode,
  2352. parent,
  2353. parentComponent,
  2354. isSVG,
  2355. container,
  2356. hiddenContainer,
  2357. anchor,
  2358. deps: 0,
  2359. pendingId: 0,
  2360. timeout: typeof timeout === 'number' ? timeout : -1,
  2361. activeBranch: null,
  2362. pendingBranch: null,
  2363. isInFallback: true,
  2364. isHydrating,
  2365. isUnmounted: false,
  2366. effects: [],
  2367. resolve(resume = false) {
  2368. {
  2369. if (!resume && !suspense.pendingBranch) {
  2370. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2371. }
  2372. if (suspense.isUnmounted) {
  2373. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2374. }
  2375. }
  2376. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2377. if (suspense.isHydrating) {
  2378. suspense.isHydrating = false;
  2379. }
  2380. else if (!resume) {
  2381. const delayEnter = activeBranch &&
  2382. pendingBranch.transition &&
  2383. pendingBranch.transition.mode === 'out-in';
  2384. if (delayEnter) {
  2385. activeBranch.transition.afterLeave = () => {
  2386. if (pendingId === suspense.pendingId) {
  2387. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2388. }
  2389. };
  2390. }
  2391. // this is initial anchor on mount
  2392. let { anchor } = suspense;
  2393. // unmount current active tree
  2394. if (activeBranch) {
  2395. // if the fallback tree was mounted, it may have been moved
  2396. // as part of a parent suspense. get the latest anchor for insertion
  2397. anchor = next(activeBranch);
  2398. unmount(activeBranch, parentComponent, suspense, true);
  2399. }
  2400. if (!delayEnter) {
  2401. // move content from off-dom container to actual container
  2402. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2403. }
  2404. }
  2405. setActiveBranch(suspense, pendingBranch);
  2406. suspense.pendingBranch = null;
  2407. suspense.isInFallback = false;
  2408. // flush buffered effects
  2409. // check if there is a pending parent suspense
  2410. let parent = suspense.parent;
  2411. let hasUnresolvedAncestor = false;
  2412. while (parent) {
  2413. if (parent.pendingBranch) {
  2414. // found a pending parent suspense, merge buffered post jobs
  2415. // into that parent
  2416. parent.effects.push(...effects);
  2417. hasUnresolvedAncestor = true;
  2418. break;
  2419. }
  2420. parent = parent.parent;
  2421. }
  2422. // no pending parent suspense, flush all jobs
  2423. if (!hasUnresolvedAncestor) {
  2424. queuePostFlushCb(effects);
  2425. }
  2426. suspense.effects = [];
  2427. // invoke @resolve event
  2428. const onResolve = vnode.props && vnode.props.onResolve;
  2429. if (isFunction(onResolve)) {
  2430. onResolve();
  2431. }
  2432. },
  2433. fallback(fallbackVNode) {
  2434. if (!suspense.pendingBranch) {
  2435. return;
  2436. }
  2437. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2438. // invoke @fallback event
  2439. const onFallback = vnode.props && vnode.props.onFallback;
  2440. if (isFunction(onFallback)) {
  2441. onFallback();
  2442. }
  2443. const anchor = next(activeBranch);
  2444. const mountFallback = () => {
  2445. if (!suspense.isInFallback) {
  2446. return;
  2447. }
  2448. // mount the fallback tree
  2449. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2450. isSVG);
  2451. setActiveBranch(suspense, fallbackVNode);
  2452. };
  2453. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2454. if (delayEnter) {
  2455. activeBranch.transition.afterLeave = mountFallback;
  2456. }
  2457. // unmount current active branch
  2458. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2459. true // shouldRemove
  2460. );
  2461. suspense.isInFallback = true;
  2462. if (!delayEnter) {
  2463. mountFallback();
  2464. }
  2465. },
  2466. move(container, anchor, type) {
  2467. suspense.activeBranch &&
  2468. move(suspense.activeBranch, container, anchor, type);
  2469. suspense.container = container;
  2470. },
  2471. next() {
  2472. return suspense.activeBranch && next(suspense.activeBranch);
  2473. },
  2474. registerDep(instance, setupRenderEffect) {
  2475. const isInPendingSuspense = !!suspense.pendingBranch;
  2476. if (isInPendingSuspense) {
  2477. suspense.deps++;
  2478. }
  2479. const hydratedEl = instance.vnode.el;
  2480. instance
  2481. .asyncDep.catch(err => {
  2482. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  2483. })
  2484. .then(asyncSetupResult => {
  2485. // retry when the setup() promise resolves.
  2486. // component may have been unmounted before resolve.
  2487. if (instance.isUnmounted ||
  2488. suspense.isUnmounted ||
  2489. suspense.pendingId !== instance.suspenseId) {
  2490. return;
  2491. }
  2492. // retry from this component
  2493. instance.asyncResolved = true;
  2494. const { vnode } = instance;
  2495. {
  2496. pushWarningContext(vnode);
  2497. }
  2498. handleSetupResult(instance, asyncSetupResult);
  2499. if (hydratedEl) {
  2500. // vnode may have been replaced if an update happened before the
  2501. // async dep is resolved.
  2502. vnode.el = hydratedEl;
  2503. }
  2504. const placeholder = !hydratedEl && instance.subTree.el;
  2505. setupRenderEffect(instance, vnode,
  2506. // component may have been moved before resolve.
  2507. // if this is not a hydration, instance.subTree will be the comment
  2508. // placeholder.
  2509. parentNode(hydratedEl || instance.subTree.el),
  2510. // anchor will not be used if this is hydration, so only need to
  2511. // consider the comment placeholder case.
  2512. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  2513. if (placeholder) {
  2514. remove(placeholder);
  2515. }
  2516. updateHOCHostEl(instance, vnode.el);
  2517. {
  2518. popWarningContext();
  2519. }
  2520. // only decrease deps count if suspense is not already resolved
  2521. if (isInPendingSuspense && --suspense.deps === 0) {
  2522. suspense.resolve();
  2523. }
  2524. });
  2525. },
  2526. unmount(parentSuspense, doRemove) {
  2527. suspense.isUnmounted = true;
  2528. if (suspense.activeBranch) {
  2529. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  2530. }
  2531. if (suspense.pendingBranch) {
  2532. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  2533. }
  2534. }
  2535. };
  2536. return suspense;
  2537. }
  2538. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, optimized, rendererInternals, hydrateNode) {
  2539. /* eslint-disable no-restricted-globals */
  2540. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, optimized, rendererInternals, true /* hydrating */));
  2541. // there are two possible scenarios for server-rendered suspense:
  2542. // - success: ssr content should be fully resolved
  2543. // - failure: ssr content should be the fallback branch.
  2544. // however, on the client we don't really know if it has failed or not
  2545. // attempt to hydrate the DOM assuming it has succeeded, but we still
  2546. // need to construct a suspense boundary first
  2547. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, optimized);
  2548. if (suspense.deps === 0) {
  2549. suspense.resolve();
  2550. }
  2551. return result;
  2552. /* eslint-enable no-restricted-globals */
  2553. }
  2554. function normalizeSuspenseChildren(vnode) {
  2555. const { shapeFlag, children } = vnode;
  2556. let content;
  2557. let fallback;
  2558. if (shapeFlag & 32 /* SLOTS_CHILDREN */) {
  2559. content = normalizeSuspenseSlot(children.default);
  2560. fallback = normalizeSuspenseSlot(children.fallback);
  2561. }
  2562. else {
  2563. content = normalizeSuspenseSlot(children);
  2564. fallback = normalizeVNode(null);
  2565. }
  2566. return {
  2567. content,
  2568. fallback
  2569. };
  2570. }
  2571. function normalizeSuspenseSlot(s) {
  2572. if (isFunction(s)) {
  2573. s = s();
  2574. }
  2575. if (isArray(s)) {
  2576. const singleChild = filterSingleRoot(s);
  2577. if (!singleChild) {
  2578. warn(`<Suspense> slots expect a single root node.`);
  2579. }
  2580. s = singleChild;
  2581. }
  2582. return normalizeVNode(s);
  2583. }
  2584. function queueEffectWithSuspense(fn, suspense) {
  2585. if (suspense && suspense.pendingBranch) {
  2586. if (isArray(fn)) {
  2587. suspense.effects.push(...fn);
  2588. }
  2589. else {
  2590. suspense.effects.push(fn);
  2591. }
  2592. }
  2593. else {
  2594. queuePostFlushCb(fn);
  2595. }
  2596. }
  2597. function setActiveBranch(suspense, branch) {
  2598. suspense.activeBranch = branch;
  2599. const { vnode, parentComponent } = suspense;
  2600. const el = (vnode.el = branch.el);
  2601. // in case suspense is the root node of a component,
  2602. // recursively update the HOC el
  2603. if (parentComponent && parentComponent.subTree === vnode) {
  2604. parentComponent.vnode.el = el;
  2605. updateHOCHostEl(parentComponent, el);
  2606. }
  2607. }
  2608. let isRenderingCompiledSlot = 0;
  2609. const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
  2610. /**
  2611. * Compiler runtime helper for rendering `<slot/>`
  2612. * @private
  2613. */
  2614. function renderSlot(slots, name, props = {},
  2615. // this is not a user-facing function, so the fallback is always generated by
  2616. // the compiler and guaranteed to be a function returning an array
  2617. fallback) {
  2618. let slot = slots[name];
  2619. if (slot && slot.length > 1) {
  2620. warn(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  2621. `function. You need to mark this component with $dynamic-slots in the ` +
  2622. `parent template.`);
  2623. slot = () => [];
  2624. }
  2625. // a compiled slot disables block tracking by default to avoid manual
  2626. // invocation interfering with template-based block tracking, but in
  2627. // `renderSlot` we can be sure that it's template-based so we can force
  2628. // enable it.
  2629. isRenderingCompiledSlot++;
  2630. openBlock();
  2631. const validSlotContent = slot && ensureValidVNode(slot(props));
  2632. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  2633. ? 64 /* STABLE_FRAGMENT */
  2634. : -2 /* BAIL */);
  2635. isRenderingCompiledSlot--;
  2636. return rendered;
  2637. }
  2638. function ensureValidVNode(vnodes) {
  2639. return vnodes.some(child => {
  2640. if (!isVNode(child))
  2641. return true;
  2642. if (child.type === Comment)
  2643. return false;
  2644. if (child.type === Fragment &&
  2645. !ensureValidVNode(child.children))
  2646. return false;
  2647. return true;
  2648. })
  2649. ? vnodes
  2650. : null;
  2651. }
  2652. /**
  2653. * Wrap a slot function to memoize current rendering instance
  2654. * @private
  2655. */
  2656. function withCtx(fn, ctx = currentRenderingInstance) {
  2657. if (!ctx)
  2658. return fn;
  2659. const renderFnWithContext = (...args) => {
  2660. // If a user calls a compiled slot inside a template expression (#1745), it
  2661. // can mess up block tracking, so by default we need to push a null block to
  2662. // avoid that. This isn't necessary if rendering a compiled `<slot>`.
  2663. if (!isRenderingCompiledSlot) {
  2664. openBlock(true /* null block that disables tracking */);
  2665. }
  2666. const owner = currentRenderingInstance;
  2667. setCurrentRenderingInstance(ctx);
  2668. const res = fn(...args);
  2669. setCurrentRenderingInstance(owner);
  2670. if (!isRenderingCompiledSlot) {
  2671. closeBlock();
  2672. }
  2673. return res;
  2674. };
  2675. renderFnWithContext._c = true;
  2676. return renderFnWithContext;
  2677. }
  2678. // SFC scoped style ID management.
  2679. let currentScopeId = null;
  2680. const scopeIdStack = [];
  2681. /**
  2682. * @private
  2683. */
  2684. function pushScopeId(id) {
  2685. scopeIdStack.push((currentScopeId = id));
  2686. }
  2687. /**
  2688. * @private
  2689. */
  2690. function popScopeId() {
  2691. scopeIdStack.pop();
  2692. currentScopeId = scopeIdStack[scopeIdStack.length - 1] || null;
  2693. }
  2694. /**
  2695. * @private
  2696. */
  2697. function withScopeId(id) {
  2698. return ((fn) => withCtx(function () {
  2699. pushScopeId(id);
  2700. const res = fn.apply(this, arguments);
  2701. popScopeId();
  2702. return res;
  2703. }));
  2704. }
  2705. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  2706. isSSR = false) {
  2707. const props = {};
  2708. const attrs = {};
  2709. def(attrs, InternalObjectKey, 1);
  2710. setFullProps(instance, rawProps, props, attrs);
  2711. // validation
  2712. {
  2713. validateProps(props, instance);
  2714. }
  2715. if (isStateful) {
  2716. // stateful
  2717. instance.props = isSSR ? props : shallowReactive(props);
  2718. }
  2719. else {
  2720. if (!instance.type.props) {
  2721. // functional w/ optional props, props === attrs
  2722. instance.props = attrs;
  2723. }
  2724. else {
  2725. // functional w/ declared props
  2726. instance.props = props;
  2727. }
  2728. }
  2729. instance.attrs = attrs;
  2730. }
  2731. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  2732. const { props, attrs, vnode: { patchFlag } } = instance;
  2733. const rawCurrentProps = toRaw(props);
  2734. const [options] = instance.propsOptions;
  2735. if (
  2736. // always force full diff in dev
  2737. // - #1942 if hmr is enabled with sfc component
  2738. // - vite#872 non-sfc component used by sfc component
  2739. !((instance.type.__hmrId ||
  2740. (instance.parent && instance.parent.type.__hmrId))) &&
  2741. (optimized || patchFlag > 0) &&
  2742. !(patchFlag & 16 /* FULL_PROPS */)) {
  2743. if (patchFlag & 8 /* PROPS */) {
  2744. // Compiler-generated props & no keys change, just set the updated
  2745. // the props.
  2746. const propsToUpdate = instance.vnode.dynamicProps;
  2747. for (let i = 0; i < propsToUpdate.length; i++) {
  2748. const key = propsToUpdate[i];
  2749. // PROPS flag guarantees rawProps to be non-null
  2750. const value = rawProps[key];
  2751. if (options) {
  2752. // attr / props separation was done on init and will be consistent
  2753. // in this code path, so just check if attrs have it.
  2754. if (hasOwn(attrs, key)) {
  2755. attrs[key] = value;
  2756. }
  2757. else {
  2758. const camelizedKey = camelize(key);
  2759. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance);
  2760. }
  2761. }
  2762. else {
  2763. attrs[key] = value;
  2764. }
  2765. }
  2766. }
  2767. }
  2768. else {
  2769. // full props update.
  2770. setFullProps(instance, rawProps, props, attrs);
  2771. // in case of dynamic props, check if we need to delete keys from
  2772. // the props object
  2773. let kebabKey;
  2774. for (const key in rawCurrentProps) {
  2775. if (!rawProps ||
  2776. // for camelCase
  2777. (!hasOwn(rawProps, key) &&
  2778. // it's possible the original props was passed in as kebab-case
  2779. // and converted to camelCase (#955)
  2780. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  2781. if (options) {
  2782. if (rawPrevProps &&
  2783. // for camelCase
  2784. (rawPrevProps[key] !== undefined ||
  2785. // for kebab-case
  2786. rawPrevProps[kebabKey] !== undefined)) {
  2787. props[key] = resolvePropValue(options, rawProps || EMPTY_OBJ, key, undefined, instance);
  2788. }
  2789. }
  2790. else {
  2791. delete props[key];
  2792. }
  2793. }
  2794. }
  2795. // in the case of functional component w/o props declaration, props and
  2796. // attrs point to the same object so it should already have been updated.
  2797. if (attrs !== rawCurrentProps) {
  2798. for (const key in attrs) {
  2799. if (!rawProps || !hasOwn(rawProps, key)) {
  2800. delete attrs[key];
  2801. }
  2802. }
  2803. }
  2804. }
  2805. // trigger updates for $attrs in case it's used in component slots
  2806. trigger(instance, "set" /* SET */, '$attrs');
  2807. if (rawProps) {
  2808. validateProps(props, instance);
  2809. }
  2810. }
  2811. function setFullProps(instance, rawProps, props, attrs) {
  2812. const [options, needCastKeys] = instance.propsOptions;
  2813. if (rawProps) {
  2814. for (const key in rawProps) {
  2815. const value = rawProps[key];
  2816. // key, ref are reserved and never passed down
  2817. if (isReservedProp(key)) {
  2818. continue;
  2819. }
  2820. // prop option names are camelized during normalization, so to support
  2821. // kebab -> camel conversion here we need to camelize the key.
  2822. let camelKey;
  2823. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  2824. props[camelKey] = value;
  2825. }
  2826. else if (!isEmitListener(instance.emitsOptions, key)) {
  2827. // Any non-declared (either as a prop or an emitted event) props are put
  2828. // into a separate `attrs` object for spreading. Make sure to preserve
  2829. // original key casing
  2830. attrs[key] = value;
  2831. }
  2832. }
  2833. }
  2834. if (needCastKeys) {
  2835. const rawCurrentProps = toRaw(props);
  2836. for (let i = 0; i < needCastKeys.length; i++) {
  2837. const key = needCastKeys[i];
  2838. props[key] = resolvePropValue(options, rawCurrentProps, key, rawCurrentProps[key], instance);
  2839. }
  2840. }
  2841. }
  2842. function resolvePropValue(options, props, key, value, instance) {
  2843. const opt = options[key];
  2844. if (opt != null) {
  2845. const hasDefault = hasOwn(opt, 'default');
  2846. // default values
  2847. if (hasDefault && value === undefined) {
  2848. const defaultValue = opt.default;
  2849. if (opt.type !== Function && isFunction(defaultValue)) {
  2850. setCurrentInstance(instance);
  2851. value = defaultValue(props);
  2852. setCurrentInstance(null);
  2853. }
  2854. else {
  2855. value = defaultValue;
  2856. }
  2857. }
  2858. // boolean casting
  2859. if (opt[0 /* shouldCast */]) {
  2860. if (!hasOwn(props, key) && !hasDefault) {
  2861. value = false;
  2862. }
  2863. else if (opt[1 /* shouldCastTrue */] &&
  2864. (value === '' || value === hyphenate(key))) {
  2865. value = true;
  2866. }
  2867. }
  2868. }
  2869. return value;
  2870. }
  2871. function normalizePropsOptions(comp, appContext, asMixin = false) {
  2872. if (!appContext.deopt && comp.__props) {
  2873. return comp.__props;
  2874. }
  2875. const raw = comp.props;
  2876. const normalized = {};
  2877. const needCastKeys = [];
  2878. // apply mixin/extends props
  2879. let hasExtends = false;
  2880. if (!isFunction(comp)) {
  2881. const extendProps = (raw) => {
  2882. hasExtends = true;
  2883. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  2884. extend(normalized, props);
  2885. if (keys)
  2886. needCastKeys.push(...keys);
  2887. };
  2888. if (!asMixin && appContext.mixins.length) {
  2889. appContext.mixins.forEach(extendProps);
  2890. }
  2891. if (comp.extends) {
  2892. extendProps(comp.extends);
  2893. }
  2894. if (comp.mixins) {
  2895. comp.mixins.forEach(extendProps);
  2896. }
  2897. }
  2898. if (!raw && !hasExtends) {
  2899. return (comp.__props = EMPTY_ARR);
  2900. }
  2901. if (isArray(raw)) {
  2902. for (let i = 0; i < raw.length; i++) {
  2903. if (!isString(raw[i])) {
  2904. warn(`props must be strings when using array syntax.`, raw[i]);
  2905. }
  2906. const normalizedKey = camelize(raw[i]);
  2907. if (validatePropName(normalizedKey)) {
  2908. normalized[normalizedKey] = EMPTY_OBJ;
  2909. }
  2910. }
  2911. }
  2912. else if (raw) {
  2913. if (!isObject(raw)) {
  2914. warn(`invalid props options`, raw);
  2915. }
  2916. for (const key in raw) {
  2917. const normalizedKey = camelize(key);
  2918. if (validatePropName(normalizedKey)) {
  2919. const opt = raw[key];
  2920. const prop = (normalized[normalizedKey] =
  2921. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  2922. if (prop) {
  2923. const booleanIndex = getTypeIndex(Boolean, prop.type);
  2924. const stringIndex = getTypeIndex(String, prop.type);
  2925. prop[0 /* shouldCast */] = booleanIndex > -1;
  2926. prop[1 /* shouldCastTrue */] =
  2927. stringIndex < 0 || booleanIndex < stringIndex;
  2928. // if the prop needs boolean casting or default value
  2929. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  2930. needCastKeys.push(normalizedKey);
  2931. }
  2932. }
  2933. }
  2934. }
  2935. }
  2936. return (comp.__props = [normalized, needCastKeys]);
  2937. }
  2938. function validatePropName(key) {
  2939. if (key[0] !== '$') {
  2940. return true;
  2941. }
  2942. else {
  2943. warn(`Invalid prop name: "${key}" is a reserved property.`);
  2944. }
  2945. return false;
  2946. }
  2947. // use function string name to check type constructors
  2948. // so that it works across vms / iframes.
  2949. function getType(ctor) {
  2950. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  2951. return match ? match[1] : '';
  2952. }
  2953. function isSameType(a, b) {
  2954. return getType(a) === getType(b);
  2955. }
  2956. function getTypeIndex(type, expectedTypes) {
  2957. if (isArray(expectedTypes)) {
  2958. for (let i = 0, len = expectedTypes.length; i < len; i++) {
  2959. if (isSameType(expectedTypes[i], type)) {
  2960. return i;
  2961. }
  2962. }
  2963. }
  2964. else if (isFunction(expectedTypes)) {
  2965. return isSameType(expectedTypes, type) ? 0 : -1;
  2966. }
  2967. return -1;
  2968. }
  2969. /**
  2970. * dev only
  2971. */
  2972. function validateProps(props, instance) {
  2973. const rawValues = toRaw(props);
  2974. const options = instance.propsOptions[0];
  2975. for (const key in options) {
  2976. let opt = options[key];
  2977. if (opt == null)
  2978. continue;
  2979. validateProp(key, rawValues[key], opt, !hasOwn(rawValues, key));
  2980. }
  2981. }
  2982. /**
  2983. * dev only
  2984. */
  2985. function validateProp(name, value, prop, isAbsent) {
  2986. const { type, required, validator } = prop;
  2987. // required!
  2988. if (required && isAbsent) {
  2989. warn('Missing required prop: "' + name + '"');
  2990. return;
  2991. }
  2992. // missing but optional
  2993. if (value == null && !prop.required) {
  2994. return;
  2995. }
  2996. // type check
  2997. if (type != null && type !== true) {
  2998. let isValid = false;
  2999. const types = isArray(type) ? type : [type];
  3000. const expectedTypes = [];
  3001. // value is valid as long as one of the specified types match
  3002. for (let i = 0; i < types.length && !isValid; i++) {
  3003. const { valid, expectedType } = assertType(value, types[i]);
  3004. expectedTypes.push(expectedType || '');
  3005. isValid = valid;
  3006. }
  3007. if (!isValid) {
  3008. warn(getInvalidTypeMessage(name, value, expectedTypes));
  3009. return;
  3010. }
  3011. }
  3012. // custom validator
  3013. if (validator && !validator(value)) {
  3014. warn('Invalid prop: custom validator check failed for prop "' + name + '".');
  3015. }
  3016. }
  3017. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  3018. /**
  3019. * dev only
  3020. */
  3021. function assertType(value, type) {
  3022. let valid;
  3023. const expectedType = getType(type);
  3024. if (isSimpleType(expectedType)) {
  3025. const t = typeof value;
  3026. valid = t === expectedType.toLowerCase();
  3027. // for primitive wrapper objects
  3028. if (!valid && t === 'object') {
  3029. valid = value instanceof type;
  3030. }
  3031. }
  3032. else if (expectedType === 'Object') {
  3033. valid = isObject(value);
  3034. }
  3035. else if (expectedType === 'Array') {
  3036. valid = isArray(value);
  3037. }
  3038. else {
  3039. valid = value instanceof type;
  3040. }
  3041. return {
  3042. valid,
  3043. expectedType
  3044. };
  3045. }
  3046. /**
  3047. * dev only
  3048. */
  3049. function getInvalidTypeMessage(name, value, expectedTypes) {
  3050. let message = `Invalid prop: type check failed for prop "${name}".` +
  3051. ` Expected ${expectedTypes.map(capitalize).join(', ')}`;
  3052. const expectedType = expectedTypes[0];
  3053. const receivedType = toRawType(value);
  3054. const expectedValue = styleValue(value, expectedType);
  3055. const receivedValue = styleValue(value, receivedType);
  3056. // check if we need to specify expected value
  3057. if (expectedTypes.length === 1 &&
  3058. isExplicable(expectedType) &&
  3059. !isBoolean(expectedType, receivedType)) {
  3060. message += ` with value ${expectedValue}`;
  3061. }
  3062. message += `, got ${receivedType} `;
  3063. // check if we need to specify received value
  3064. if (isExplicable(receivedType)) {
  3065. message += `with value ${receivedValue}.`;
  3066. }
  3067. return message;
  3068. }
  3069. /**
  3070. * dev only
  3071. */
  3072. function styleValue(value, type) {
  3073. if (type === 'String') {
  3074. return `"${value}"`;
  3075. }
  3076. else if (type === 'Number') {
  3077. return `${Number(value)}`;
  3078. }
  3079. else {
  3080. return `${value}`;
  3081. }
  3082. }
  3083. /**
  3084. * dev only
  3085. */
  3086. function isExplicable(type) {
  3087. const explicitTypes = ['string', 'number', 'boolean'];
  3088. return explicitTypes.some(elem => type.toLowerCase() === elem);
  3089. }
  3090. /**
  3091. * dev only
  3092. */
  3093. function isBoolean(...args) {
  3094. return args.some(elem => elem.toLowerCase() === 'boolean');
  3095. }
  3096. function injectHook(type, hook, target = currentInstance, prepend = false) {
  3097. if (target) {
  3098. const hooks = target[type] || (target[type] = []);
  3099. // cache the error handling wrapper for injected hooks so the same hook
  3100. // can be properly deduped by the scheduler. "__weh" stands for "with error
  3101. // handling".
  3102. const wrappedHook = hook.__weh ||
  3103. (hook.__weh = (...args) => {
  3104. if (target.isUnmounted) {
  3105. return;
  3106. }
  3107. // disable tracking inside all lifecycle hooks
  3108. // since they can potentially be called inside effects.
  3109. pauseTracking();
  3110. // Set currentInstance during hook invocation.
  3111. // This assumes the hook does not synchronously trigger other hooks, which
  3112. // can only be false when the user does something really funky.
  3113. setCurrentInstance(target);
  3114. const res = callWithAsyncErrorHandling(hook, target, type, args);
  3115. setCurrentInstance(null);
  3116. resetTracking();
  3117. return res;
  3118. });
  3119. if (prepend) {
  3120. hooks.unshift(wrappedHook);
  3121. }
  3122. else {
  3123. hooks.push(wrappedHook);
  3124. }
  3125. return wrappedHook;
  3126. }
  3127. else {
  3128. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  3129. warn(`${apiName} is called when there is no active component instance to be ` +
  3130. `associated with. ` +
  3131. `Lifecycle injection APIs can only be used during execution of setup().` +
  3132. (` If you are using async setup(), make sure to register lifecycle ` +
  3133. `hooks before the first await statement.`
  3134. ));
  3135. }
  3136. }
  3137. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  3138. // post-create lifecycle registrations are noops during SSR
  3139. !isInSSRComponentSetup && injectHook(lifecycle, hook, target);
  3140. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  3141. const onMounted = createHook("m" /* MOUNTED */);
  3142. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  3143. const onUpdated = createHook("u" /* UPDATED */);
  3144. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  3145. const onUnmounted = createHook("um" /* UNMOUNTED */);
  3146. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  3147. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  3148. const onErrorCaptured = (hook, target = currentInstance) => {
  3149. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  3150. };
  3151. // Simple effect.
  3152. function watchEffect(effect, options) {
  3153. return doWatch(effect, null, options);
  3154. }
  3155. // initial value for watchers to trigger on undefined initial values
  3156. const INITIAL_WATCHER_VALUE = {};
  3157. // implementation
  3158. function watch(source, cb, options) {
  3159. if (!isFunction(cb)) {
  3160. warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3161. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3162. `supports \`watch(source, cb, options?) signature.`);
  3163. }
  3164. return doWatch(source, cb, options);
  3165. }
  3166. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ, instance = currentInstance) {
  3167. if (!cb) {
  3168. if (immediate !== undefined) {
  3169. warn(`watch() "immediate" option is only respected when using the ` +
  3170. `watch(source, callback, options?) signature.`);
  3171. }
  3172. if (deep !== undefined) {
  3173. warn(`watch() "deep" option is only respected when using the ` +
  3174. `watch(source, callback, options?) signature.`);
  3175. }
  3176. }
  3177. const warnInvalidSource = (s) => {
  3178. warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3179. `a reactive object, or an array of these types.`);
  3180. };
  3181. let getter;
  3182. let forceTrigger = false;
  3183. if (isRef(source)) {
  3184. getter = () => source.value;
  3185. forceTrigger = !!source._shallow;
  3186. }
  3187. else if (isReactive(source)) {
  3188. getter = () => source;
  3189. deep = true;
  3190. }
  3191. else if (isArray(source)) {
  3192. getter = () => source.map(s => {
  3193. if (isRef(s)) {
  3194. return s.value;
  3195. }
  3196. else if (isReactive(s)) {
  3197. return traverse(s);
  3198. }
  3199. else if (isFunction(s)) {
  3200. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */, [
  3201. instance && instance.proxy
  3202. ]);
  3203. }
  3204. else {
  3205. warnInvalidSource(s);
  3206. }
  3207. });
  3208. }
  3209. else if (isFunction(source)) {
  3210. if (cb) {
  3211. // getter with cb
  3212. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */, [
  3213. instance && instance.proxy
  3214. ]);
  3215. }
  3216. else {
  3217. // no cb -> simple effect
  3218. getter = () => {
  3219. if (instance && instance.isUnmounted) {
  3220. return;
  3221. }
  3222. if (cleanup) {
  3223. cleanup();
  3224. }
  3225. return callWithErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
  3226. };
  3227. }
  3228. }
  3229. else {
  3230. getter = NOOP;
  3231. warnInvalidSource(source);
  3232. }
  3233. if (cb && deep) {
  3234. const baseGetter = getter;
  3235. getter = () => traverse(baseGetter());
  3236. }
  3237. let cleanup;
  3238. const onInvalidate = (fn) => {
  3239. cleanup = runner.options.onStop = () => {
  3240. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  3241. };
  3242. };
  3243. let oldValue = isArray(source) ? [] : INITIAL_WATCHER_VALUE;
  3244. const job = () => {
  3245. if (!runner.active) {
  3246. return;
  3247. }
  3248. if (cb) {
  3249. // watch(source, cb)
  3250. const newValue = runner();
  3251. if (deep || forceTrigger || hasChanged(newValue, oldValue)) {
  3252. // cleanup before running cb again
  3253. if (cleanup) {
  3254. cleanup();
  3255. }
  3256. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  3257. newValue,
  3258. // pass undefined as the old value when it's changed for the first time
  3259. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  3260. onInvalidate
  3261. ]);
  3262. oldValue = newValue;
  3263. }
  3264. }
  3265. else {
  3266. // watchEffect
  3267. runner();
  3268. }
  3269. };
  3270. // important: mark the job as a watcher callback so that scheduler knows
  3271. // it is allowed to self-trigger (#1727)
  3272. job.allowRecurse = !!cb;
  3273. let scheduler;
  3274. if (flush === 'sync') {
  3275. scheduler = job;
  3276. }
  3277. else if (flush === 'post') {
  3278. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3279. }
  3280. else {
  3281. // default: 'pre'
  3282. scheduler = () => {
  3283. if (!instance || instance.isMounted) {
  3284. queuePreFlushCb(job);
  3285. }
  3286. else {
  3287. // with 'pre' option, the first call must happen before
  3288. // the component is mounted so it is called synchronously.
  3289. job();
  3290. }
  3291. };
  3292. }
  3293. const runner = effect(getter, {
  3294. lazy: true,
  3295. onTrack,
  3296. onTrigger,
  3297. scheduler
  3298. });
  3299. recordInstanceBoundEffect(runner, instance);
  3300. // initial run
  3301. if (cb) {
  3302. if (immediate) {
  3303. job();
  3304. }
  3305. else {
  3306. oldValue = runner();
  3307. }
  3308. }
  3309. else if (flush === 'post') {
  3310. queuePostRenderEffect(runner, instance && instance.suspense);
  3311. }
  3312. else {
  3313. runner();
  3314. }
  3315. return () => {
  3316. stop(runner);
  3317. if (instance) {
  3318. remove(instance.effects, runner);
  3319. }
  3320. };
  3321. }
  3322. // this.$watch
  3323. function instanceWatch(source, cb, options) {
  3324. const publicThis = this.proxy;
  3325. const getter = isString(source)
  3326. ? () => publicThis[source]
  3327. : source.bind(publicThis);
  3328. return doWatch(getter, cb.bind(publicThis), options, this);
  3329. }
  3330. function traverse(value, seen = new Set()) {
  3331. if (!isObject(value) || seen.has(value)) {
  3332. return value;
  3333. }
  3334. seen.add(value);
  3335. if (isRef(value)) {
  3336. traverse(value.value, seen);
  3337. }
  3338. else if (isArray(value)) {
  3339. for (let i = 0; i < value.length; i++) {
  3340. traverse(value[i], seen);
  3341. }
  3342. }
  3343. else if (isSet(value) || isMap(value)) {
  3344. value.forEach((v) => {
  3345. traverse(v, seen);
  3346. });
  3347. }
  3348. else {
  3349. for (const key in value) {
  3350. traverse(value[key], seen);
  3351. }
  3352. }
  3353. return value;
  3354. }
  3355. function useTransitionState() {
  3356. const state = {
  3357. isMounted: false,
  3358. isLeaving: false,
  3359. isUnmounting: false,
  3360. leavingVNodes: new Map()
  3361. };
  3362. onMounted(() => {
  3363. state.isMounted = true;
  3364. });
  3365. onBeforeUnmount(() => {
  3366. state.isUnmounting = true;
  3367. });
  3368. return state;
  3369. }
  3370. const TransitionHookValidator = [Function, Array];
  3371. const BaseTransitionImpl = {
  3372. name: `BaseTransition`,
  3373. props: {
  3374. mode: String,
  3375. appear: Boolean,
  3376. persisted: Boolean,
  3377. // enter
  3378. onBeforeEnter: TransitionHookValidator,
  3379. onEnter: TransitionHookValidator,
  3380. onAfterEnter: TransitionHookValidator,
  3381. onEnterCancelled: TransitionHookValidator,
  3382. // leave
  3383. onBeforeLeave: TransitionHookValidator,
  3384. onLeave: TransitionHookValidator,
  3385. onAfterLeave: TransitionHookValidator,
  3386. onLeaveCancelled: TransitionHookValidator,
  3387. // appear
  3388. onBeforeAppear: TransitionHookValidator,
  3389. onAppear: TransitionHookValidator,
  3390. onAfterAppear: TransitionHookValidator,
  3391. onAppearCancelled: TransitionHookValidator
  3392. },
  3393. setup(props, { slots }) {
  3394. const instance = getCurrentInstance();
  3395. const state = useTransitionState();
  3396. let prevTransitionKey;
  3397. return () => {
  3398. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3399. if (!children || !children.length) {
  3400. return;
  3401. }
  3402. // warn multiple elements
  3403. if (children.length > 1) {
  3404. warn('<transition> can only be used on a single element or component. Use ' +
  3405. '<transition-group> for lists.');
  3406. }
  3407. // there's no need to track reactivity for these props so use the raw
  3408. // props for a bit better perf
  3409. const rawProps = toRaw(props);
  3410. const { mode } = rawProps;
  3411. // check mode
  3412. if (mode && !['in-out', 'out-in', 'default'].includes(mode)) {
  3413. warn(`invalid <transition> mode: ${mode}`);
  3414. }
  3415. // at this point children has a guaranteed length of 1.
  3416. const child = children[0];
  3417. if (state.isLeaving) {
  3418. return emptyPlaceholder(child);
  3419. }
  3420. // in the case of <transition><keep-alive/></transition>, we need to
  3421. // compare the type of the kept-alive children.
  3422. const innerChild = getKeepAliveChild(child);
  3423. if (!innerChild) {
  3424. return emptyPlaceholder(child);
  3425. }
  3426. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3427. setTransitionHooks(innerChild, enterHooks);
  3428. const oldChild = instance.subTree;
  3429. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3430. let transitionKeyChanged = false;
  3431. const { getTransitionKey } = innerChild.type;
  3432. if (getTransitionKey) {
  3433. const key = getTransitionKey();
  3434. if (prevTransitionKey === undefined) {
  3435. prevTransitionKey = key;
  3436. }
  3437. else if (key !== prevTransitionKey) {
  3438. prevTransitionKey = key;
  3439. transitionKeyChanged = true;
  3440. }
  3441. }
  3442. // handle mode
  3443. if (oldInnerChild &&
  3444. oldInnerChild.type !== Comment &&
  3445. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3446. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3447. // update old tree's hooks in case of dynamic transition
  3448. setTransitionHooks(oldInnerChild, leavingHooks);
  3449. // switching between different views
  3450. if (mode === 'out-in') {
  3451. state.isLeaving = true;
  3452. // return placeholder node and queue update when leave finishes
  3453. leavingHooks.afterLeave = () => {
  3454. state.isLeaving = false;
  3455. instance.update();
  3456. };
  3457. return emptyPlaceholder(child);
  3458. }
  3459. else if (mode === 'in-out') {
  3460. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3461. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3462. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3463. // early removal callback
  3464. el._leaveCb = () => {
  3465. earlyRemove();
  3466. el._leaveCb = undefined;
  3467. delete enterHooks.delayedLeave;
  3468. };
  3469. enterHooks.delayedLeave = delayedLeave;
  3470. };
  3471. }
  3472. }
  3473. return child;
  3474. };
  3475. }
  3476. };
  3477. // export the public type for h/tsx inference
  3478. // also to avoid inline import() in generated d.ts files
  3479. const BaseTransition = BaseTransitionImpl;
  3480. function getLeavingNodesForType(state, vnode) {
  3481. const { leavingVNodes } = state;
  3482. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3483. if (!leavingVNodesCache) {
  3484. leavingVNodesCache = Object.create(null);
  3485. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3486. }
  3487. return leavingVNodesCache;
  3488. }
  3489. // The transition hooks are attached to the vnode as vnode.transition
  3490. // and will be called at appropriate timing in the renderer.
  3491. function resolveTransitionHooks(vnode, props, state, instance) {
  3492. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3493. const key = String(vnode.key);
  3494. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3495. const callHook = (hook, args) => {
  3496. hook &&
  3497. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  3498. };
  3499. const hooks = {
  3500. mode,
  3501. persisted,
  3502. beforeEnter(el) {
  3503. let hook = onBeforeEnter;
  3504. if (!state.isMounted) {
  3505. if (appear) {
  3506. hook = onBeforeAppear || onBeforeEnter;
  3507. }
  3508. else {
  3509. return;
  3510. }
  3511. }
  3512. // for same element (v-show)
  3513. if (el._leaveCb) {
  3514. el._leaveCb(true /* cancelled */);
  3515. }
  3516. // for toggled element with same key (v-if)
  3517. const leavingVNode = leavingVNodesCache[key];
  3518. if (leavingVNode &&
  3519. isSameVNodeType(vnode, leavingVNode) &&
  3520. leavingVNode.el._leaveCb) {
  3521. // force early removal (not cancelled)
  3522. leavingVNode.el._leaveCb();
  3523. }
  3524. callHook(hook, [el]);
  3525. },
  3526. enter(el) {
  3527. let hook = onEnter;
  3528. let afterHook = onAfterEnter;
  3529. let cancelHook = onEnterCancelled;
  3530. if (!state.isMounted) {
  3531. if (appear) {
  3532. hook = onAppear || onEnter;
  3533. afterHook = onAfterAppear || onAfterEnter;
  3534. cancelHook = onAppearCancelled || onEnterCancelled;
  3535. }
  3536. else {
  3537. return;
  3538. }
  3539. }
  3540. let called = false;
  3541. const done = (el._enterCb = (cancelled) => {
  3542. if (called)
  3543. return;
  3544. called = true;
  3545. if (cancelled) {
  3546. callHook(cancelHook, [el]);
  3547. }
  3548. else {
  3549. callHook(afterHook, [el]);
  3550. }
  3551. if (hooks.delayedLeave) {
  3552. hooks.delayedLeave();
  3553. }
  3554. el._enterCb = undefined;
  3555. });
  3556. if (hook) {
  3557. hook(el, done);
  3558. if (hook.length <= 1) {
  3559. done();
  3560. }
  3561. }
  3562. else {
  3563. done();
  3564. }
  3565. },
  3566. leave(el, remove) {
  3567. const key = String(vnode.key);
  3568. if (el._enterCb) {
  3569. el._enterCb(true /* cancelled */);
  3570. }
  3571. if (state.isUnmounting) {
  3572. return remove();
  3573. }
  3574. callHook(onBeforeLeave, [el]);
  3575. let called = false;
  3576. const done = (el._leaveCb = (cancelled) => {
  3577. if (called)
  3578. return;
  3579. called = true;
  3580. remove();
  3581. if (cancelled) {
  3582. callHook(onLeaveCancelled, [el]);
  3583. }
  3584. else {
  3585. callHook(onAfterLeave, [el]);
  3586. }
  3587. el._leaveCb = undefined;
  3588. if (leavingVNodesCache[key] === vnode) {
  3589. delete leavingVNodesCache[key];
  3590. }
  3591. });
  3592. leavingVNodesCache[key] = vnode;
  3593. if (onLeave) {
  3594. onLeave(el, done);
  3595. if (onLeave.length <= 1) {
  3596. done();
  3597. }
  3598. }
  3599. else {
  3600. done();
  3601. }
  3602. },
  3603. clone(vnode) {
  3604. return resolveTransitionHooks(vnode, props, state, instance);
  3605. }
  3606. };
  3607. return hooks;
  3608. }
  3609. // the placeholder really only handles one special case: KeepAlive
  3610. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3611. // placeholder with empty content to avoid the KeepAlive instance from being
  3612. // unmounted.
  3613. function emptyPlaceholder(vnode) {
  3614. if (isKeepAlive(vnode)) {
  3615. vnode = cloneVNode(vnode);
  3616. vnode.children = null;
  3617. return vnode;
  3618. }
  3619. }
  3620. function getKeepAliveChild(vnode) {
  3621. return isKeepAlive(vnode)
  3622. ? vnode.children
  3623. ? vnode.children[0]
  3624. : undefined
  3625. : vnode;
  3626. }
  3627. function setTransitionHooks(vnode, hooks) {
  3628. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  3629. setTransitionHooks(vnode.component.subTree, hooks);
  3630. }
  3631. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  3632. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3633. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3634. }
  3635. else {
  3636. vnode.transition = hooks;
  3637. }
  3638. }
  3639. function getTransitionRawChildren(children, keepComment = false) {
  3640. let ret = [];
  3641. let keyedFragmentCount = 0;
  3642. for (let i = 0; i < children.length; i++) {
  3643. const child = children[i];
  3644. // handle fragment children case, e.g. v-for
  3645. if (child.type === Fragment) {
  3646. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  3647. keyedFragmentCount++;
  3648. ret = ret.concat(getTransitionRawChildren(child.children, keepComment));
  3649. }
  3650. // comment placeholders should be skipped, e.g. v-if
  3651. else if (keepComment || child.type !== Comment) {
  3652. ret.push(child);
  3653. }
  3654. }
  3655. // #1126 if a transition children list contains multiple sub fragments, these
  3656. // fragments will be merged into a flat children array. Since each v-for
  3657. // fragment may contain different static bindings inside, we need to de-op
  3658. // these children to force full diffs to ensure correct behavior.
  3659. if (keyedFragmentCount > 1) {
  3660. for (let i = 0; i < ret.length; i++) {
  3661. ret[i].patchFlag = -2 /* BAIL */;
  3662. }
  3663. }
  3664. return ret;
  3665. }
  3666. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3667. const KeepAliveImpl = {
  3668. name: `KeepAlive`,
  3669. // Marker for special handling inside the renderer. We are not using a ===
  3670. // check directly on KeepAlive in the renderer, because importing it directly
  3671. // would prevent it from being tree-shaken.
  3672. __isKeepAlive: true,
  3673. props: {
  3674. include: [String, RegExp, Array],
  3675. exclude: [String, RegExp, Array],
  3676. max: [String, Number]
  3677. },
  3678. setup(props, { slots }) {
  3679. const cache = new Map();
  3680. const keys = new Set();
  3681. let current = null;
  3682. const instance = getCurrentInstance();
  3683. const parentSuspense = instance.suspense;
  3684. // KeepAlive communicates with the instantiated renderer via the
  3685. // ctx where the renderer passes in its internals,
  3686. // and the KeepAlive instance exposes activate/deactivate implementations.
  3687. // The whole point of this is to avoid importing KeepAlive directly in the
  3688. // renderer to facilitate tree-shaking.
  3689. const sharedContext = instance.ctx;
  3690. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3691. const storageContainer = createElement('div');
  3692. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3693. const instance = vnode.component;
  3694. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  3695. // in case props have changed
  3696. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, optimized);
  3697. queuePostRenderEffect(() => {
  3698. instance.isDeactivated = false;
  3699. if (instance.a) {
  3700. invokeArrayFns(instance.a);
  3701. }
  3702. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3703. if (vnodeHook) {
  3704. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3705. }
  3706. }, parentSuspense);
  3707. };
  3708. sharedContext.deactivate = (vnode) => {
  3709. const instance = vnode.component;
  3710. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  3711. queuePostRenderEffect(() => {
  3712. if (instance.da) {
  3713. invokeArrayFns(instance.da);
  3714. }
  3715. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3716. if (vnodeHook) {
  3717. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3718. }
  3719. instance.isDeactivated = true;
  3720. }, parentSuspense);
  3721. };
  3722. function unmount(vnode) {
  3723. // reset the shapeFlag so it can be properly unmounted
  3724. resetShapeFlag(vnode);
  3725. _unmount(vnode, instance, parentSuspense);
  3726. }
  3727. function pruneCache(filter) {
  3728. cache.forEach((vnode, key) => {
  3729. const name = getComponentName(vnode.type);
  3730. if (name && (!filter || !filter(name))) {
  3731. pruneCacheEntry(key);
  3732. }
  3733. });
  3734. }
  3735. function pruneCacheEntry(key) {
  3736. const cached = cache.get(key);
  3737. if (!current || cached.type !== current.type) {
  3738. unmount(cached);
  3739. }
  3740. else if (current) {
  3741. // current active instance should no longer be kept-alive.
  3742. // we can't unmount it now but it might be later, so reset its flag now.
  3743. resetShapeFlag(current);
  3744. }
  3745. cache.delete(key);
  3746. keys.delete(key);
  3747. }
  3748. // prune cache on include/exclude prop change
  3749. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3750. include && pruneCache(name => matches(include, name));
  3751. exclude && pruneCache(name => !matches(exclude, name));
  3752. },
  3753. // prune post-render after `current` has been updated
  3754. { flush: 'post', deep: true });
  3755. // cache sub tree after render
  3756. let pendingCacheKey = null;
  3757. const cacheSubtree = () => {
  3758. // fix #1621, the pendingCacheKey could be 0
  3759. if (pendingCacheKey != null) {
  3760. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  3761. }
  3762. };
  3763. onMounted(cacheSubtree);
  3764. onUpdated(cacheSubtree);
  3765. onBeforeUnmount(() => {
  3766. cache.forEach(cached => {
  3767. const { subTree, suspense } = instance;
  3768. const vnode = getInnerChild(subTree);
  3769. if (cached.type === vnode.type) {
  3770. // current instance will be unmounted as part of keep-alive's unmount
  3771. resetShapeFlag(vnode);
  3772. // but invoke its deactivated hook here
  3773. const da = vnode.component.da;
  3774. da && queuePostRenderEffect(da, suspense);
  3775. return;
  3776. }
  3777. unmount(cached);
  3778. });
  3779. });
  3780. return () => {
  3781. pendingCacheKey = null;
  3782. if (!slots.default) {
  3783. return null;
  3784. }
  3785. const children = slots.default();
  3786. const rawVNode = children[0];
  3787. if (children.length > 1) {
  3788. {
  3789. warn(`KeepAlive should contain exactly one component child.`);
  3790. }
  3791. current = null;
  3792. return children;
  3793. }
  3794. else if (!isVNode(rawVNode) ||
  3795. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  3796. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  3797. current = null;
  3798. return rawVNode;
  3799. }
  3800. let vnode = getInnerChild(rawVNode);
  3801. const comp = vnode.type;
  3802. const name = getComponentName(comp);
  3803. const { include, exclude, max } = props;
  3804. if ((include && (!name || !matches(include, name))) ||
  3805. (exclude && name && matches(exclude, name))) {
  3806. current = vnode;
  3807. return rawVNode;
  3808. }
  3809. const key = vnode.key == null ? comp : vnode.key;
  3810. const cachedVNode = cache.get(key);
  3811. // clone vnode if it's reused because we are going to mutate it
  3812. if (vnode.el) {
  3813. vnode = cloneVNode(vnode);
  3814. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  3815. rawVNode.ssContent = vnode;
  3816. }
  3817. }
  3818. // #1513 it's possible for the returned vnode to be cloned due to attr
  3819. // fallthrough or scopeId, so the vnode here may not be the final vnode
  3820. // that is mounted. Instead of caching it directly, we store the pending
  3821. // key and cache `instance.subTree` (the normalized vnode) in
  3822. // beforeMount/beforeUpdate hooks.
  3823. pendingCacheKey = key;
  3824. if (cachedVNode) {
  3825. // copy over mounted state
  3826. vnode.el = cachedVNode.el;
  3827. vnode.component = cachedVNode.component;
  3828. if (vnode.transition) {
  3829. // recursively update transition hooks on subTree
  3830. setTransitionHooks(vnode, vnode.transition);
  3831. }
  3832. // avoid vnode being mounted as fresh
  3833. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  3834. // make this key the freshest
  3835. keys.delete(key);
  3836. keys.add(key);
  3837. }
  3838. else {
  3839. keys.add(key);
  3840. // prune oldest entry
  3841. if (max && keys.size > parseInt(max, 10)) {
  3842. pruneCacheEntry(keys.values().next().value);
  3843. }
  3844. }
  3845. // avoid vnode being unmounted
  3846. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  3847. current = vnode;
  3848. return rawVNode;
  3849. };
  3850. }
  3851. };
  3852. // export the public type for h/tsx inference
  3853. // also to avoid inline import() in generated d.ts files
  3854. const KeepAlive = KeepAliveImpl;
  3855. function matches(pattern, name) {
  3856. if (isArray(pattern)) {
  3857. return pattern.some((p) => matches(p, name));
  3858. }
  3859. else if (isString(pattern)) {
  3860. return pattern.split(',').indexOf(name) > -1;
  3861. }
  3862. else if (pattern.test) {
  3863. return pattern.test(name);
  3864. }
  3865. /* istanbul ignore next */
  3866. return false;
  3867. }
  3868. function onActivated(hook, target) {
  3869. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  3870. }
  3871. function onDeactivated(hook, target) {
  3872. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  3873. }
  3874. function registerKeepAliveHook(hook, type, target = currentInstance) {
  3875. // cache the deactivate branch check wrapper for injected hooks so the same
  3876. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  3877. // deactivation check".
  3878. const wrappedHook = hook.__wdc ||
  3879. (hook.__wdc = () => {
  3880. // only fire the hook if the target instance is NOT in a deactivated branch.
  3881. let current = target;
  3882. while (current) {
  3883. if (current.isDeactivated) {
  3884. return;
  3885. }
  3886. current = current.parent;
  3887. }
  3888. hook();
  3889. });
  3890. injectHook(type, wrappedHook, target);
  3891. // In addition to registering it on the target instance, we walk up the parent
  3892. // chain and register it on all ancestor instances that are keep-alive roots.
  3893. // This avoids the need to walk the entire component tree when invoking these
  3894. // hooks, and more importantly, avoids the need to track child components in
  3895. // arrays.
  3896. if (target) {
  3897. let current = target.parent;
  3898. while (current && current.parent) {
  3899. if (isKeepAlive(current.parent.vnode)) {
  3900. injectToKeepAliveRoot(wrappedHook, type, target, current);
  3901. }
  3902. current = current.parent;
  3903. }
  3904. }
  3905. }
  3906. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  3907. // injectHook wraps the original for error handling, so make sure to remove
  3908. // the wrapped version.
  3909. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  3910. onUnmounted(() => {
  3911. remove(keepAliveRoot[type], injected);
  3912. }, target);
  3913. }
  3914. function resetShapeFlag(vnode) {
  3915. let shapeFlag = vnode.shapeFlag;
  3916. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  3917. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  3918. }
  3919. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  3920. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  3921. }
  3922. vnode.shapeFlag = shapeFlag;
  3923. }
  3924. function getInnerChild(vnode) {
  3925. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  3926. }
  3927. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  3928. const normalizeSlotValue = (value) => isArray(value)
  3929. ? value.map(normalizeVNode)
  3930. : [normalizeVNode(value)];
  3931. const normalizeSlot = (key, rawSlot, ctx) => withCtx((props) => {
  3932. if (currentInstance) {
  3933. warn(`Slot "${key}" invoked outside of the render function: ` +
  3934. `this will not track dependencies used in the slot. ` +
  3935. `Invoke the slot function inside the render function instead.`);
  3936. }
  3937. return normalizeSlotValue(rawSlot(props));
  3938. }, ctx);
  3939. const normalizeObjectSlots = (rawSlots, slots) => {
  3940. const ctx = rawSlots._ctx;
  3941. for (const key in rawSlots) {
  3942. if (isInternalKey(key))
  3943. continue;
  3944. const value = rawSlots[key];
  3945. if (isFunction(value)) {
  3946. slots[key] = normalizeSlot(key, value, ctx);
  3947. }
  3948. else if (value != null) {
  3949. {
  3950. warn(`Non-function value encountered for slot "${key}". ` +
  3951. `Prefer function slots for better performance.`);
  3952. }
  3953. const normalized = normalizeSlotValue(value);
  3954. slots[key] = () => normalized;
  3955. }
  3956. }
  3957. };
  3958. const normalizeVNodeSlots = (instance, children) => {
  3959. if (!isKeepAlive(instance.vnode)) {
  3960. warn(`Non-function value encountered for default slot. ` +
  3961. `Prefer function slots for better performance.`);
  3962. }
  3963. const normalized = normalizeSlotValue(children);
  3964. instance.slots.default = () => normalized;
  3965. };
  3966. const initSlots = (instance, children) => {
  3967. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  3968. const type = children._;
  3969. if (type) {
  3970. instance.slots = children;
  3971. // make compiler marker non-enumerable
  3972. def(children, '_', type);
  3973. }
  3974. else {
  3975. normalizeObjectSlots(children, (instance.slots = {}));
  3976. }
  3977. }
  3978. else {
  3979. instance.slots = {};
  3980. if (children) {
  3981. normalizeVNodeSlots(instance, children);
  3982. }
  3983. }
  3984. def(instance.slots, InternalObjectKey, 1);
  3985. };
  3986. const updateSlots = (instance, children) => {
  3987. const { vnode, slots } = instance;
  3988. let needDeletionCheck = true;
  3989. let deletionComparisonTarget = EMPTY_OBJ;
  3990. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  3991. const type = children._;
  3992. if (type) {
  3993. // compiled slots.
  3994. if (isHmrUpdating) {
  3995. // Parent was HMR updated so slot content may have changed.
  3996. // force update slots and mark instance for hmr as well
  3997. extend(slots, children);
  3998. }
  3999. else if (type === 1 /* STABLE */) {
  4000. // compiled AND stable.
  4001. // no need to update, and skip stale slots removal.
  4002. needDeletionCheck = false;
  4003. }
  4004. else {
  4005. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  4006. // normalization.
  4007. extend(slots, children);
  4008. }
  4009. }
  4010. else {
  4011. needDeletionCheck = !children.$stable;
  4012. normalizeObjectSlots(children, slots);
  4013. }
  4014. deletionComparisonTarget = children;
  4015. }
  4016. else if (children) {
  4017. // non slot object children (direct value) passed to a component
  4018. normalizeVNodeSlots(instance, children);
  4019. deletionComparisonTarget = { default: 1 };
  4020. }
  4021. // delete stale slots
  4022. if (needDeletionCheck) {
  4023. for (const key in slots) {
  4024. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  4025. delete slots[key];
  4026. }
  4027. }
  4028. }
  4029. };
  4030. /**
  4031. Runtime helper for applying directives to a vnode. Example usage:
  4032. const comp = resolveComponent('comp')
  4033. const foo = resolveDirective('foo')
  4034. const bar = resolveDirective('bar')
  4035. return withDirectives(h(comp), [
  4036. [foo, this.x],
  4037. [bar, this.y]
  4038. ])
  4039. */
  4040. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text');
  4041. function validateDirectiveName(name) {
  4042. if (isBuiltInDirective(name)) {
  4043. warn('Do not use built-in directive ids as custom directive id: ' + name);
  4044. }
  4045. }
  4046. /**
  4047. * Adds directives to a VNode.
  4048. */
  4049. function withDirectives(vnode, directives) {
  4050. const internalInstance = currentRenderingInstance;
  4051. if (internalInstance === null) {
  4052. warn(`withDirectives can only be used inside render functions.`);
  4053. return vnode;
  4054. }
  4055. const instance = internalInstance.proxy;
  4056. const bindings = vnode.dirs || (vnode.dirs = []);
  4057. for (let i = 0; i < directives.length; i++) {
  4058. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4059. if (isFunction(dir)) {
  4060. dir = {
  4061. mounted: dir,
  4062. updated: dir
  4063. };
  4064. }
  4065. bindings.push({
  4066. dir,
  4067. instance,
  4068. value,
  4069. oldValue: void 0,
  4070. arg,
  4071. modifiers
  4072. });
  4073. }
  4074. return vnode;
  4075. }
  4076. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4077. const bindings = vnode.dirs;
  4078. const oldBindings = prevVNode && prevVNode.dirs;
  4079. for (let i = 0; i < bindings.length; i++) {
  4080. const binding = bindings[i];
  4081. if (oldBindings) {
  4082. binding.oldValue = oldBindings[i].value;
  4083. }
  4084. const hook = binding.dir[name];
  4085. if (hook) {
  4086. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  4087. vnode.el,
  4088. binding,
  4089. vnode,
  4090. prevVNode
  4091. ]);
  4092. }
  4093. }
  4094. }
  4095. function createAppContext() {
  4096. return {
  4097. app: null,
  4098. config: {
  4099. isNativeTag: NO,
  4100. performance: false,
  4101. globalProperties: {},
  4102. optionMergeStrategies: {},
  4103. isCustomElement: NO,
  4104. errorHandler: undefined,
  4105. warnHandler: undefined
  4106. },
  4107. mixins: [],
  4108. components: {},
  4109. directives: {},
  4110. provides: Object.create(null)
  4111. };
  4112. }
  4113. let uid$1 = 0;
  4114. function createAppAPI(render, hydrate) {
  4115. return function createApp(rootComponent, rootProps = null) {
  4116. if (rootProps != null && !isObject(rootProps)) {
  4117. warn(`root props passed to app.mount() must be an object.`);
  4118. rootProps = null;
  4119. }
  4120. const context = createAppContext();
  4121. const installedPlugins = new Set();
  4122. let isMounted = false;
  4123. const app = (context.app = {
  4124. _uid: uid$1++,
  4125. _component: rootComponent,
  4126. _props: rootProps,
  4127. _container: null,
  4128. _context: context,
  4129. version,
  4130. get config() {
  4131. return context.config;
  4132. },
  4133. set config(v) {
  4134. {
  4135. warn(`app.config cannot be replaced. Modify individual options instead.`);
  4136. }
  4137. },
  4138. use(plugin, ...options) {
  4139. if (installedPlugins.has(plugin)) {
  4140. warn(`Plugin has already been applied to target app.`);
  4141. }
  4142. else if (plugin && isFunction(plugin.install)) {
  4143. installedPlugins.add(plugin);
  4144. plugin.install(app, ...options);
  4145. }
  4146. else if (isFunction(plugin)) {
  4147. installedPlugins.add(plugin);
  4148. plugin(app, ...options);
  4149. }
  4150. else {
  4151. warn(`A plugin must either be a function or an object with an "install" ` +
  4152. `function.`);
  4153. }
  4154. return app;
  4155. },
  4156. mixin(mixin) {
  4157. {
  4158. if (!context.mixins.includes(mixin)) {
  4159. context.mixins.push(mixin);
  4160. // global mixin with props/emits de-optimizes props/emits
  4161. // normalization caching.
  4162. if (mixin.props || mixin.emits) {
  4163. context.deopt = true;
  4164. }
  4165. }
  4166. else {
  4167. warn('Mixin has already been applied to target app' +
  4168. (mixin.name ? `: ${mixin.name}` : ''));
  4169. }
  4170. }
  4171. return app;
  4172. },
  4173. component(name, component) {
  4174. {
  4175. validateComponentName(name, context.config);
  4176. }
  4177. if (!component) {
  4178. return context.components[name];
  4179. }
  4180. if (context.components[name]) {
  4181. warn(`Component "${name}" has already been registered in target app.`);
  4182. }
  4183. context.components[name] = component;
  4184. return app;
  4185. },
  4186. directive(name, directive) {
  4187. {
  4188. validateDirectiveName(name);
  4189. }
  4190. if (!directive) {
  4191. return context.directives[name];
  4192. }
  4193. if (context.directives[name]) {
  4194. warn(`Directive "${name}" has already been registered in target app.`);
  4195. }
  4196. context.directives[name] = directive;
  4197. return app;
  4198. },
  4199. mount(rootContainer, isHydrate) {
  4200. if (!isMounted) {
  4201. const vnode = createVNode(rootComponent, rootProps);
  4202. // store app context on the root VNode.
  4203. // this will be set on the root instance on initial mount.
  4204. vnode.appContext = context;
  4205. // HMR root reload
  4206. {
  4207. context.reload = () => {
  4208. render(cloneVNode(vnode), rootContainer);
  4209. };
  4210. }
  4211. if (isHydrate && hydrate) {
  4212. hydrate(vnode, rootContainer);
  4213. }
  4214. else {
  4215. render(vnode, rootContainer);
  4216. }
  4217. isMounted = true;
  4218. app._container = rootContainer;
  4219. rootContainer.__vue_app__ = app;
  4220. {
  4221. devtoolsInitApp(app, version);
  4222. }
  4223. return vnode.component.proxy;
  4224. }
  4225. else {
  4226. warn(`App has already been mounted.\n` +
  4227. `If you want to remount the same app, move your app creation logic ` +
  4228. `into a factory function and create fresh app instances for each ` +
  4229. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  4230. }
  4231. },
  4232. unmount() {
  4233. if (isMounted) {
  4234. render(null, app._container);
  4235. {
  4236. devtoolsUnmountApp(app);
  4237. }
  4238. delete app._container.__vue_app__;
  4239. }
  4240. else {
  4241. warn(`Cannot unmount an app that is not mounted.`);
  4242. }
  4243. },
  4244. provide(key, value) {
  4245. if (key in context.provides) {
  4246. warn(`App already provides property with key "${String(key)}". ` +
  4247. `It will be overwritten with the new value.`);
  4248. }
  4249. // TypeScript doesn't allow symbols as index type
  4250. // https://github.com/Microsoft/TypeScript/issues/24587
  4251. context.provides[key] = value;
  4252. return app;
  4253. }
  4254. });
  4255. return app;
  4256. };
  4257. }
  4258. let hasMismatch = false;
  4259. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  4260. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  4261. // Note: hydration is DOM-specific
  4262. // But we have to place it in core due to tight coupling with core - splitting
  4263. // it out creates a ton of unnecessary complexity.
  4264. // Hydration also depends on some renderer internal logic which needs to be
  4265. // passed in via arguments.
  4266. function createHydrationFunctions(rendererInternals) {
  4267. const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  4268. const hydrate = (vnode, container) => {
  4269. if (!container.hasChildNodes()) {
  4270. warn(`Attempting to hydrate existing markup but container is empty. ` +
  4271. `Performing full mount instead.`);
  4272. patch(null, vnode, container);
  4273. return;
  4274. }
  4275. hasMismatch = false;
  4276. hydrateNode(container.firstChild, vnode, null, null);
  4277. flushPostFlushCbs();
  4278. if (hasMismatch && !false) {
  4279. // this error should show up in production
  4280. console.error(`Hydration completed but contains mismatches.`);
  4281. }
  4282. };
  4283. const hydrateNode = (node, vnode, parentComponent, parentSuspense, optimized = false) => {
  4284. const isFragmentStart = isComment(node) && node.data === '[';
  4285. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, isFragmentStart);
  4286. const { type, ref, shapeFlag } = vnode;
  4287. const domType = node.nodeType;
  4288. vnode.el = node;
  4289. let nextNode = null;
  4290. switch (type) {
  4291. case Text:
  4292. if (domType !== 3 /* TEXT */) {
  4293. nextNode = onMismatch();
  4294. }
  4295. else {
  4296. if (node.data !== vnode.children) {
  4297. hasMismatch = true;
  4298. warn(`Hydration text mismatch:` +
  4299. `\n- Client: ${JSON.stringify(node.data)}` +
  4300. `\n- Server: ${JSON.stringify(vnode.children)}`);
  4301. node.data = vnode.children;
  4302. }
  4303. nextNode = nextSibling(node);
  4304. }
  4305. break;
  4306. case Comment:
  4307. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  4308. nextNode = onMismatch();
  4309. }
  4310. else {
  4311. nextNode = nextSibling(node);
  4312. }
  4313. break;
  4314. case Static:
  4315. if (domType !== 1 /* ELEMENT */) {
  4316. nextNode = onMismatch();
  4317. }
  4318. else {
  4319. // determine anchor, adopt content
  4320. nextNode = node;
  4321. // if the static vnode has its content stripped during build,
  4322. // adopt it from the server-rendered HTML.
  4323. const needToAdoptContent = !vnode.children.length;
  4324. for (let i = 0; i < vnode.staticCount; i++) {
  4325. if (needToAdoptContent)
  4326. vnode.children += nextNode.outerHTML;
  4327. if (i === vnode.staticCount - 1) {
  4328. vnode.anchor = nextNode;
  4329. }
  4330. nextNode = nextSibling(nextNode);
  4331. }
  4332. return nextNode;
  4333. }
  4334. break;
  4335. case Fragment:
  4336. if (!isFragmentStart) {
  4337. nextNode = onMismatch();
  4338. }
  4339. else {
  4340. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, optimized);
  4341. }
  4342. break;
  4343. default:
  4344. if (shapeFlag & 1 /* ELEMENT */) {
  4345. if (domType !== 1 /* ELEMENT */ ||
  4346. vnode.type !== node.tagName.toLowerCase()) {
  4347. nextNode = onMismatch();
  4348. }
  4349. else {
  4350. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, optimized);
  4351. }
  4352. }
  4353. else if (shapeFlag & 6 /* COMPONENT */) {
  4354. // when setting up the render effect, if the initial vnode already
  4355. // has .el set, the component will perform hydration instead of mount
  4356. // on its sub-tree.
  4357. const container = parentNode(node);
  4358. const hydrateComponent = () => {
  4359. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  4360. };
  4361. // async component
  4362. const loadAsync = vnode.type.__asyncLoader;
  4363. if (loadAsync) {
  4364. loadAsync().then(hydrateComponent);
  4365. }
  4366. else {
  4367. hydrateComponent();
  4368. }
  4369. // component may be async, so in the case of fragments we cannot rely
  4370. // on component's rendered output to determine the end of the fragment
  4371. // instead, we do a lookahead to find the end anchor node.
  4372. nextNode = isFragmentStart
  4373. ? locateClosingAsyncAnchor(node)
  4374. : nextSibling(node);
  4375. }
  4376. else if (shapeFlag & 64 /* TELEPORT */) {
  4377. if (domType !== 8 /* COMMENT */) {
  4378. nextNode = onMismatch();
  4379. }
  4380. else {
  4381. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, optimized, rendererInternals, hydrateChildren);
  4382. }
  4383. }
  4384. else if (shapeFlag & 128 /* SUSPENSE */) {
  4385. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), optimized, rendererInternals, hydrateNode);
  4386. }
  4387. else {
  4388. warn('Invalid HostVNode type:', type, `(${typeof type})`);
  4389. }
  4390. }
  4391. if (ref != null) {
  4392. setRef(ref, null, parentSuspense, vnode);
  4393. }
  4394. return nextNode;
  4395. };
  4396. const hydrateElement = (el, vnode, parentComponent, parentSuspense, optimized) => {
  4397. optimized = optimized || !!vnode.dynamicChildren;
  4398. const { props, patchFlag, shapeFlag, dirs } = vnode;
  4399. // skip props & children if this is hoisted static nodes
  4400. if (patchFlag !== -1 /* HOISTED */) {
  4401. if (dirs) {
  4402. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  4403. }
  4404. // props
  4405. if (props) {
  4406. if (!optimized ||
  4407. (patchFlag & 16 /* FULL_PROPS */ ||
  4408. patchFlag & 32 /* HYDRATE_EVENTS */)) {
  4409. for (const key in props) {
  4410. if (!isReservedProp(key) && isOn(key)) {
  4411. patchProp(el, key, null, props[key]);
  4412. }
  4413. }
  4414. }
  4415. else if (props.onClick) {
  4416. // Fast path for click listeners (which is most often) to avoid
  4417. // iterating through props.
  4418. patchProp(el, 'onClick', null, props.onClick);
  4419. }
  4420. }
  4421. // vnode / directive hooks
  4422. let vnodeHooks;
  4423. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  4424. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4425. }
  4426. if (dirs) {
  4427. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  4428. }
  4429. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  4430. queueEffectWithSuspense(() => {
  4431. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4432. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  4433. }, parentSuspense);
  4434. }
  4435. // children
  4436. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  4437. // skip if element has innerHTML / textContent
  4438. !(props && (props.innerHTML || props.textContent))) {
  4439. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, optimized);
  4440. let hasWarned = false;
  4441. while (next) {
  4442. hasMismatch = true;
  4443. if (!hasWarned) {
  4444. warn(`Hydration children mismatch in <${vnode.type}>: ` +
  4445. `server rendered element contains more child nodes than client vdom.`);
  4446. hasWarned = true;
  4447. }
  4448. // The SSRed DOM contains more nodes than it should. Remove them.
  4449. const cur = next;
  4450. next = next.nextSibling;
  4451. remove(cur);
  4452. }
  4453. }
  4454. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  4455. if (el.textContent !== vnode.children) {
  4456. hasMismatch = true;
  4457. warn(`Hydration text content mismatch in <${vnode.type}>:\n` +
  4458. `- Client: ${el.textContent}\n` +
  4459. `- Server: ${vnode.children}`);
  4460. el.textContent = vnode.children;
  4461. }
  4462. }
  4463. }
  4464. return el.nextSibling;
  4465. };
  4466. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, optimized) => {
  4467. optimized = optimized || !!parentVNode.dynamicChildren;
  4468. const children = parentVNode.children;
  4469. const l = children.length;
  4470. let hasWarned = false;
  4471. for (let i = 0; i < l; i++) {
  4472. const vnode = optimized
  4473. ? children[i]
  4474. : (children[i] = normalizeVNode(children[i]));
  4475. if (node) {
  4476. node = hydrateNode(node, vnode, parentComponent, parentSuspense, optimized);
  4477. }
  4478. else {
  4479. hasMismatch = true;
  4480. if (!hasWarned) {
  4481. warn(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  4482. `server rendered element contains fewer child nodes than client vdom.`);
  4483. hasWarned = true;
  4484. }
  4485. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  4486. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container));
  4487. }
  4488. }
  4489. return node;
  4490. };
  4491. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, optimized) => {
  4492. const container = parentNode(node);
  4493. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, optimized);
  4494. if (next && isComment(next) && next.data === ']') {
  4495. return nextSibling((vnode.anchor = next));
  4496. }
  4497. else {
  4498. // fragment didn't hydrate successfully, since we didn't get a end anchor
  4499. // back. This should have led to node/children mismatch warnings.
  4500. hasMismatch = true;
  4501. // since the anchor is missing, we need to create one and insert it
  4502. insert((vnode.anchor = createComment(`]`)), container, next);
  4503. return next;
  4504. }
  4505. };
  4506. const handleMismatch = (node, vnode, parentComponent, parentSuspense, isFragment) => {
  4507. hasMismatch = true;
  4508. warn(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  4509. ? `(text)`
  4510. : isComment(node) && node.data === '['
  4511. ? `(start of fragment)`
  4512. : ``);
  4513. vnode.el = null;
  4514. if (isFragment) {
  4515. // remove excessive fragment nodes
  4516. const end = locateClosingAsyncAnchor(node);
  4517. while (true) {
  4518. const next = nextSibling(node);
  4519. if (next && next !== end) {
  4520. remove(next);
  4521. }
  4522. else {
  4523. break;
  4524. }
  4525. }
  4526. }
  4527. const next = nextSibling(node);
  4528. const container = parentNode(node);
  4529. remove(node);
  4530. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container));
  4531. return next;
  4532. };
  4533. const locateClosingAsyncAnchor = (node) => {
  4534. let match = 0;
  4535. while (node) {
  4536. node = nextSibling(node);
  4537. if (node && isComment(node)) {
  4538. if (node.data === '[')
  4539. match++;
  4540. if (node.data === ']') {
  4541. if (match === 0) {
  4542. return nextSibling(node);
  4543. }
  4544. else {
  4545. match--;
  4546. }
  4547. }
  4548. }
  4549. }
  4550. return node;
  4551. };
  4552. return [hydrate, hydrateNode];
  4553. }
  4554. let supported;
  4555. let perf;
  4556. function startMeasure(instance, type) {
  4557. if (instance.appContext.config.performance && isSupported()) {
  4558. perf.mark(`vue-${type}-${instance.uid}`);
  4559. }
  4560. }
  4561. function endMeasure(instance, type) {
  4562. if (instance.appContext.config.performance && isSupported()) {
  4563. const startTag = `vue-${type}-${instance.uid}`;
  4564. const endTag = startTag + `:end`;
  4565. perf.mark(endTag);
  4566. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  4567. perf.clearMarks(startTag);
  4568. perf.clearMarks(endTag);
  4569. }
  4570. }
  4571. function isSupported() {
  4572. if (supported !== undefined) {
  4573. return supported;
  4574. }
  4575. /* eslint-disable no-restricted-globals */
  4576. if (typeof window !== 'undefined' && window.performance) {
  4577. supported = true;
  4578. perf = window.performance;
  4579. }
  4580. else {
  4581. supported = false;
  4582. }
  4583. /* eslint-enable no-restricted-globals */
  4584. return supported;
  4585. }
  4586. // implementation, close to no-op
  4587. function defineComponent(options) {
  4588. return isFunction(options) ? { setup: options, name: options.name } : options;
  4589. }
  4590. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  4591. function defineAsyncComponent(source) {
  4592. if (isFunction(source)) {
  4593. source = { loader: source };
  4594. }
  4595. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  4596. suspensible = true, onError: userOnError } = source;
  4597. let pendingRequest = null;
  4598. let resolvedComp;
  4599. let retries = 0;
  4600. const retry = () => {
  4601. retries++;
  4602. pendingRequest = null;
  4603. return load();
  4604. };
  4605. const load = () => {
  4606. let thisRequest;
  4607. return (pendingRequest ||
  4608. (thisRequest = pendingRequest = loader()
  4609. .catch(err => {
  4610. err = err instanceof Error ? err : new Error(String(err));
  4611. if (userOnError) {
  4612. return new Promise((resolve, reject) => {
  4613. const userRetry = () => resolve(retry());
  4614. const userFail = () => reject(err);
  4615. userOnError(err, userRetry, userFail, retries + 1);
  4616. });
  4617. }
  4618. else {
  4619. throw err;
  4620. }
  4621. })
  4622. .then((comp) => {
  4623. if (thisRequest !== pendingRequest && pendingRequest) {
  4624. return pendingRequest;
  4625. }
  4626. if (!comp) {
  4627. warn(`Async component loader resolved to undefined. ` +
  4628. `If you are using retry(), make sure to return its return value.`);
  4629. }
  4630. // interop module default
  4631. if (comp &&
  4632. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  4633. comp = comp.default;
  4634. }
  4635. if (comp && !isObject(comp) && !isFunction(comp)) {
  4636. throw new Error(`Invalid async component load result: ${comp}`);
  4637. }
  4638. resolvedComp = comp;
  4639. return comp;
  4640. })));
  4641. };
  4642. return defineComponent({
  4643. __asyncLoader: load,
  4644. name: 'AsyncComponentWrapper',
  4645. setup() {
  4646. const instance = currentInstance;
  4647. // already resolved
  4648. if (resolvedComp) {
  4649. return () => createInnerComp(resolvedComp, instance);
  4650. }
  4651. const onError = (err) => {
  4652. pendingRequest = null;
  4653. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  4654. };
  4655. // suspense-controlled or SSR.
  4656. if ((suspensible && instance.suspense) ||
  4657. (false )) {
  4658. return load()
  4659. .then(comp => {
  4660. return () => createInnerComp(comp, instance);
  4661. })
  4662. .catch(err => {
  4663. onError(err);
  4664. return () => errorComponent
  4665. ? createVNode(errorComponent, {
  4666. error: err
  4667. })
  4668. : null;
  4669. });
  4670. }
  4671. const loaded = ref(false);
  4672. const error = ref();
  4673. const delayed = ref(!!delay);
  4674. if (delay) {
  4675. setTimeout(() => {
  4676. delayed.value = false;
  4677. }, delay);
  4678. }
  4679. if (timeout != null) {
  4680. setTimeout(() => {
  4681. if (!loaded.value && !error.value) {
  4682. const err = new Error(`Async component timed out after ${timeout}ms.`);
  4683. onError(err);
  4684. error.value = err;
  4685. }
  4686. }, timeout);
  4687. }
  4688. load()
  4689. .then(() => {
  4690. loaded.value = true;
  4691. })
  4692. .catch(err => {
  4693. onError(err);
  4694. error.value = err;
  4695. });
  4696. return () => {
  4697. if (loaded.value && resolvedComp) {
  4698. return createInnerComp(resolvedComp, instance);
  4699. }
  4700. else if (error.value && errorComponent) {
  4701. return createVNode(errorComponent, {
  4702. error: error.value
  4703. });
  4704. }
  4705. else if (loadingComponent && !delayed.value) {
  4706. return createVNode(loadingComponent);
  4707. }
  4708. };
  4709. }
  4710. });
  4711. }
  4712. function createInnerComp(comp, { vnode: { ref, props, children } }) {
  4713. const vnode = createVNode(comp, props, children);
  4714. // ensure inner component inherits the async wrapper's ref owner
  4715. vnode.ref = ref;
  4716. return vnode;
  4717. }
  4718. function createDevEffectOptions(instance) {
  4719. return {
  4720. scheduler: queueJob,
  4721. allowRecurse: true,
  4722. onTrack: instance.rtc ? e => invokeArrayFns(instance.rtc, e) : void 0,
  4723. onTrigger: instance.rtg ? e => invokeArrayFns(instance.rtg, e) : void 0
  4724. };
  4725. }
  4726. const queuePostRenderEffect = queueEffectWithSuspense
  4727. ;
  4728. const setRef = (rawRef, oldRawRef, parentSuspense, vnode) => {
  4729. if (isArray(rawRef)) {
  4730. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode));
  4731. return;
  4732. }
  4733. let value;
  4734. if (!vnode || isAsyncWrapper(vnode)) {
  4735. value = null;
  4736. }
  4737. else {
  4738. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  4739. value = vnode.component.exposed || vnode.component.proxy;
  4740. }
  4741. else {
  4742. value = vnode.el;
  4743. }
  4744. }
  4745. const { i: owner, r: ref } = rawRef;
  4746. if (!owner) {
  4747. warn(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  4748. `A vnode with ref must be created inside the render function.`);
  4749. return;
  4750. }
  4751. const oldRef = oldRawRef && oldRawRef.r;
  4752. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  4753. const setupState = owner.setupState;
  4754. // unset old ref
  4755. if (oldRef != null && oldRef !== ref) {
  4756. if (isString(oldRef)) {
  4757. refs[oldRef] = null;
  4758. if (hasOwn(setupState, oldRef)) {
  4759. setupState[oldRef] = null;
  4760. }
  4761. }
  4762. else if (isRef(oldRef)) {
  4763. oldRef.value = null;
  4764. }
  4765. }
  4766. if (isString(ref)) {
  4767. const doSet = () => {
  4768. refs[ref] = value;
  4769. if (hasOwn(setupState, ref)) {
  4770. setupState[ref] = value;
  4771. }
  4772. };
  4773. // #1789: for non-null values, set them after render
  4774. // null values means this is unmount and it should not overwrite another
  4775. // ref with the same key
  4776. if (value) {
  4777. doSet.id = -1;
  4778. queuePostRenderEffect(doSet, parentSuspense);
  4779. }
  4780. else {
  4781. doSet();
  4782. }
  4783. }
  4784. else if (isRef(ref)) {
  4785. const doSet = () => {
  4786. ref.value = value;
  4787. };
  4788. if (value) {
  4789. doSet.id = -1;
  4790. queuePostRenderEffect(doSet, parentSuspense);
  4791. }
  4792. else {
  4793. doSet();
  4794. }
  4795. }
  4796. else if (isFunction(ref)) {
  4797. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  4798. }
  4799. else {
  4800. warn('Invalid template ref type:', value, `(${typeof value})`);
  4801. }
  4802. };
  4803. /**
  4804. * The createRenderer function accepts two generic arguments:
  4805. * HostNode and HostElement, corresponding to Node and Element types in the
  4806. * host environment. For example, for runtime-dom, HostNode would be the DOM
  4807. * `Node` interface and HostElement would be the DOM `Element` interface.
  4808. *
  4809. * Custom renderers can pass in the platform specific types like this:
  4810. *
  4811. * ``` js
  4812. * const { render, createApp } = createRenderer<Node, Element>({
  4813. * patchProp,
  4814. * ...nodeOps
  4815. * })
  4816. * ```
  4817. */
  4818. function createRenderer(options) {
  4819. return baseCreateRenderer(options);
  4820. }
  4821. // Separate API for creating hydration-enabled renderer.
  4822. // Hydration logic is only used when calling this function, making it
  4823. // tree-shakable.
  4824. function createHydrationRenderer(options) {
  4825. return baseCreateRenderer(options, createHydrationFunctions);
  4826. }
  4827. // implementation
  4828. function baseCreateRenderer(options, createHydrationFns) {
  4829. {
  4830. const target = getGlobalThis();
  4831. target.__VUE__ = true;
  4832. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__);
  4833. }
  4834. const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, forcePatchProp: hostForcePatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
  4835. // Note: functions inside this closure should use `const xxx = () => {}`
  4836. // style in order to prevent being inlined by minifiers.
  4837. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, optimized = false) => {
  4838. // patching & not same type, unmount old tree
  4839. if (n1 && !isSameVNodeType(n1, n2)) {
  4840. anchor = getNextHostNode(n1);
  4841. unmount(n1, parentComponent, parentSuspense, true);
  4842. n1 = null;
  4843. }
  4844. if (n2.patchFlag === -2 /* BAIL */) {
  4845. optimized = false;
  4846. n2.dynamicChildren = null;
  4847. }
  4848. const { type, ref, shapeFlag } = n2;
  4849. switch (type) {
  4850. case Text:
  4851. processText(n1, n2, container, anchor);
  4852. break;
  4853. case Comment:
  4854. processCommentNode(n1, n2, container, anchor);
  4855. break;
  4856. case Static:
  4857. if (n1 == null) {
  4858. mountStaticNode(n2, container, anchor, isSVG);
  4859. }
  4860. else {
  4861. patchStaticNode(n1, n2, container, isSVG);
  4862. }
  4863. break;
  4864. case Fragment:
  4865. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  4866. break;
  4867. default:
  4868. if (shapeFlag & 1 /* ELEMENT */) {
  4869. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  4870. }
  4871. else if (shapeFlag & 6 /* COMPONENT */) {
  4872. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  4873. }
  4874. else if (shapeFlag & 64 /* TELEPORT */) {
  4875. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals);
  4876. }
  4877. else if (shapeFlag & 128 /* SUSPENSE */) {
  4878. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals);
  4879. }
  4880. else {
  4881. warn('Invalid VNode type:', type, `(${typeof type})`);
  4882. }
  4883. }
  4884. // set ref
  4885. if (ref != null && parentComponent) {
  4886. setRef(ref, n1 && n1.ref, parentSuspense, n2);
  4887. }
  4888. };
  4889. const processText = (n1, n2, container, anchor) => {
  4890. if (n1 == null) {
  4891. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  4892. }
  4893. else {
  4894. const el = (n2.el = n1.el);
  4895. if (n2.children !== n1.children) {
  4896. hostSetText(el, n2.children);
  4897. }
  4898. }
  4899. };
  4900. const processCommentNode = (n1, n2, container, anchor) => {
  4901. if (n1 == null) {
  4902. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  4903. }
  4904. else {
  4905. // there's no support for dynamic comments
  4906. n2.el = n1.el;
  4907. }
  4908. };
  4909. const mountStaticNode = (n2, container, anchor, isSVG) => {
  4910. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  4911. };
  4912. /**
  4913. * Dev / HMR only
  4914. */
  4915. const patchStaticNode = (n1, n2, container, isSVG) => {
  4916. // static nodes are only patched during dev for HMR
  4917. if (n2.children !== n1.children) {
  4918. const anchor = hostNextSibling(n1.anchor);
  4919. // remove existing
  4920. removeStaticNode(n1);
  4921. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  4922. }
  4923. else {
  4924. n2.el = n1.el;
  4925. n2.anchor = n1.anchor;
  4926. }
  4927. };
  4928. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  4929. let next;
  4930. while (el && el !== anchor) {
  4931. next = hostNextSibling(el);
  4932. hostInsert(el, container, nextSibling);
  4933. el = next;
  4934. }
  4935. hostInsert(anchor, container, nextSibling);
  4936. };
  4937. const removeStaticNode = ({ el, anchor }) => {
  4938. let next;
  4939. while (el && el !== anchor) {
  4940. next = hostNextSibling(el);
  4941. hostRemove(el);
  4942. el = next;
  4943. }
  4944. hostRemove(anchor);
  4945. };
  4946. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  4947. isSVG = isSVG || n2.type === 'svg';
  4948. if (n1 == null) {
  4949. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  4950. }
  4951. else {
  4952. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, optimized);
  4953. }
  4954. };
  4955. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  4956. let el;
  4957. let vnodeHook;
  4958. const { type, props, shapeFlag, transition, scopeId, patchFlag, dirs } = vnode;
  4959. {
  4960. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is);
  4961. // mount children first, since some props may rely on child content
  4962. // being already rendered, e.g. `<select value>`
  4963. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  4964. hostSetElementText(el, vnode.children);
  4965. }
  4966. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  4967. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', optimized || !!vnode.dynamicChildren);
  4968. }
  4969. if (dirs) {
  4970. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  4971. }
  4972. // props
  4973. if (props) {
  4974. for (const key in props) {
  4975. if (!isReservedProp(key)) {
  4976. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  4977. }
  4978. }
  4979. if ((vnodeHook = props.onVnodeBeforeMount)) {
  4980. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  4981. }
  4982. }
  4983. // scopeId
  4984. setScopeId(el, scopeId, vnode, parentComponent);
  4985. }
  4986. {
  4987. Object.defineProperty(el, '__vnode', {
  4988. value: vnode,
  4989. enumerable: false
  4990. });
  4991. Object.defineProperty(el, '__vueParentComponent', {
  4992. value: parentComponent,
  4993. enumerable: false
  4994. });
  4995. }
  4996. if (dirs) {
  4997. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  4998. }
  4999. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  5000. // #1689 For inside suspense + suspense resolved case, just call it
  5001. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  5002. transition &&
  5003. !transition.persisted;
  5004. if (needCallTransitionHooks) {
  5005. transition.beforeEnter(el);
  5006. }
  5007. hostInsert(el, container, anchor);
  5008. if ((vnodeHook = props && props.onVnodeMounted) ||
  5009. needCallTransitionHooks ||
  5010. dirs) {
  5011. queuePostRenderEffect(() => {
  5012. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5013. needCallTransitionHooks && transition.enter(el);
  5014. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  5015. }, parentSuspense);
  5016. }
  5017. };
  5018. const setScopeId = (el, scopeId, vnode, parentComponent) => {
  5019. if (scopeId) {
  5020. hostSetScopeId(el, scopeId);
  5021. }
  5022. if (parentComponent) {
  5023. const treeOwnerId = parentComponent.type.__scopeId;
  5024. // vnode's own scopeId and the current patched component's scopeId is
  5025. // different - this is a slot content node.
  5026. if (treeOwnerId && treeOwnerId !== scopeId) {
  5027. hostSetScopeId(el, treeOwnerId + '-s');
  5028. }
  5029. let subTree = parentComponent.subTree;
  5030. if (subTree.type === Fragment) {
  5031. subTree =
  5032. filterSingleRoot(subTree.children) || subTree;
  5033. }
  5034. if (vnode === subTree) {
  5035. setScopeId(el, parentComponent.vnode.scopeId, parentComponent.vnode, parentComponent.parent);
  5036. }
  5037. }
  5038. };
  5039. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, optimized, start = 0) => {
  5040. for (let i = start; i < children.length; i++) {
  5041. const child = (children[i] = optimized
  5042. ? cloneIfMounted(children[i])
  5043. : normalizeVNode(children[i]));
  5044. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5045. }
  5046. };
  5047. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, optimized) => {
  5048. const el = (n2.el = n1.el);
  5049. let { patchFlag, dynamicChildren, dirs } = n2;
  5050. // #1426 take the old vnode's patch flag into account since user may clone a
  5051. // compiler-generated vnode, which de-opts to FULL_PROPS
  5052. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  5053. const oldProps = n1.props || EMPTY_OBJ;
  5054. const newProps = n2.props || EMPTY_OBJ;
  5055. let vnodeHook;
  5056. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  5057. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5058. }
  5059. if (dirs) {
  5060. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  5061. }
  5062. if (isHmrUpdating) {
  5063. // HMR updated, force full diff
  5064. patchFlag = 0;
  5065. optimized = false;
  5066. dynamicChildren = null;
  5067. }
  5068. if (patchFlag > 0) {
  5069. // the presence of a patchFlag means this element's render code was
  5070. // generated by the compiler and can take the fast path.
  5071. // in this path old node and new node are guaranteed to have the same shape
  5072. // (i.e. at the exact same position in the source template)
  5073. if (patchFlag & 16 /* FULL_PROPS */) {
  5074. // element props contain dynamic keys, full diff needed
  5075. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5076. }
  5077. else {
  5078. // class
  5079. // this flag is matched when the element has dynamic class bindings.
  5080. if (patchFlag & 2 /* CLASS */) {
  5081. if (oldProps.class !== newProps.class) {
  5082. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  5083. }
  5084. }
  5085. // style
  5086. // this flag is matched when the element has dynamic style bindings
  5087. if (patchFlag & 4 /* STYLE */) {
  5088. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  5089. }
  5090. // props
  5091. // This flag is matched when the element has dynamic prop/attr bindings
  5092. // other than class and style. The keys of dynamic prop/attrs are saved for
  5093. // faster iteration.
  5094. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  5095. // bail out and go through a full diff because we need to unset the old key
  5096. if (patchFlag & 8 /* PROPS */) {
  5097. // if the flag is present then dynamicProps must be non-null
  5098. const propsToUpdate = n2.dynamicProps;
  5099. for (let i = 0; i < propsToUpdate.length; i++) {
  5100. const key = propsToUpdate[i];
  5101. const prev = oldProps[key];
  5102. const next = newProps[key];
  5103. if (next !== prev ||
  5104. (hostForcePatchProp && hostForcePatchProp(el, key))) {
  5105. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  5106. }
  5107. }
  5108. }
  5109. }
  5110. // text
  5111. // This flag is matched when the element has only dynamic text children.
  5112. if (patchFlag & 1 /* TEXT */) {
  5113. if (n1.children !== n2.children) {
  5114. hostSetElementText(el, n2.children);
  5115. }
  5116. }
  5117. }
  5118. else if (!optimized && dynamicChildren == null) {
  5119. // unoptimized, full diff
  5120. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5121. }
  5122. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  5123. if (dynamicChildren) {
  5124. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG);
  5125. if (parentComponent && parentComponent.type.__hmrId) {
  5126. traverseStaticChildren(n1, n2);
  5127. }
  5128. }
  5129. else if (!optimized) {
  5130. // full diff
  5131. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG);
  5132. }
  5133. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  5134. queuePostRenderEffect(() => {
  5135. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5136. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  5137. }, parentSuspense);
  5138. }
  5139. };
  5140. // The fast path for blocks.
  5141. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG) => {
  5142. for (let i = 0; i < newChildren.length; i++) {
  5143. const oldVNode = oldChildren[i];
  5144. const newVNode = newChildren[i];
  5145. // Determine the container (parent element) for the patch.
  5146. const container =
  5147. // - In the case of a Fragment, we need to provide the actual parent
  5148. // of the Fragment itself so it can move its children.
  5149. oldVNode.type === Fragment ||
  5150. // - In the case of different nodes, there is going to be a replacement
  5151. // which also requires the correct parent container
  5152. !isSameVNodeType(oldVNode, newVNode) ||
  5153. // - In the case of a component, it could contain anything.
  5154. oldVNode.shapeFlag & 6 /* COMPONENT */ ||
  5155. oldVNode.shapeFlag & 64 /* TELEPORT */
  5156. ? hostParentNode(oldVNode.el)
  5157. : // In other cases, the parent container is not actually used so we
  5158. // just pass the block element here to avoid a DOM parentNode call.
  5159. fallbackContainer;
  5160. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, true);
  5161. }
  5162. };
  5163. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  5164. if (oldProps !== newProps) {
  5165. for (const key in newProps) {
  5166. // empty string is not valid prop
  5167. if (isReservedProp(key))
  5168. continue;
  5169. const next = newProps[key];
  5170. const prev = oldProps[key];
  5171. if (next !== prev ||
  5172. (hostForcePatchProp && hostForcePatchProp(el, key))) {
  5173. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5174. }
  5175. }
  5176. if (oldProps !== EMPTY_OBJ) {
  5177. for (const key in oldProps) {
  5178. if (!isReservedProp(key) && !(key in newProps)) {
  5179. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5180. }
  5181. }
  5182. }
  5183. }
  5184. };
  5185. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5186. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  5187. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  5188. let { patchFlag, dynamicChildren } = n2;
  5189. if (patchFlag > 0) {
  5190. optimized = true;
  5191. }
  5192. if (isHmrUpdating) {
  5193. // HMR updated, force full diff
  5194. patchFlag = 0;
  5195. optimized = false;
  5196. dynamicChildren = null;
  5197. }
  5198. if (n1 == null) {
  5199. hostInsert(fragmentStartAnchor, container, anchor);
  5200. hostInsert(fragmentEndAnchor, container, anchor);
  5201. // a fragment can only have array children
  5202. // since they are either generated by the compiler, or implicitly created
  5203. // from arrays.
  5204. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, optimized);
  5205. }
  5206. else {
  5207. if (patchFlag > 0 &&
  5208. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  5209. dynamicChildren &&
  5210. // #2715 the previous fragment could've been a BAILed one as a result
  5211. // of renderSlot() with no valid children
  5212. n1.dynamicChildren) {
  5213. // a stable fragment (template root or <template v-for>) doesn't need to
  5214. // patch children order, but it may contain dynamicChildren.
  5215. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG);
  5216. if (parentComponent && parentComponent.type.__hmrId) {
  5217. traverseStaticChildren(n1, n2);
  5218. }
  5219. else if (
  5220. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  5221. // get moved around. Make sure all root level vnodes inherit el.
  5222. // #2134 or if it's a component root, it may also get moved around
  5223. // as the component is being moved.
  5224. n2.key != null ||
  5225. (parentComponent && n2 === parentComponent.subTree)) {
  5226. traverseStaticChildren(n1, n2, true /* shallow */);
  5227. }
  5228. }
  5229. else {
  5230. // keyed / unkeyed, or manual fragments.
  5231. // for keyed & unkeyed, since they are compiler generated from v-for,
  5232. // each child is guaranteed to be a block so the fragment will never
  5233. // have dynamicChildren.
  5234. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, optimized);
  5235. }
  5236. }
  5237. };
  5238. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5239. if (n1 == null) {
  5240. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  5241. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  5242. }
  5243. else {
  5244. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5245. }
  5246. }
  5247. else {
  5248. updateComponent(n1, n2, optimized);
  5249. }
  5250. };
  5251. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5252. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  5253. if (instance.type.__hmrId) {
  5254. registerHMR(instance);
  5255. }
  5256. {
  5257. pushWarningContext(initialVNode);
  5258. startMeasure(instance, `mount`);
  5259. }
  5260. // inject renderer internals for keepAlive
  5261. if (isKeepAlive(initialVNode)) {
  5262. instance.ctx.renderer = internals;
  5263. }
  5264. // resolve props and slots for setup context
  5265. {
  5266. startMeasure(instance, `init`);
  5267. }
  5268. setupComponent(instance);
  5269. {
  5270. endMeasure(instance, `init`);
  5271. }
  5272. // setup() is async. This component relies on async logic to be resolved
  5273. // before proceeding
  5274. if (instance.asyncDep) {
  5275. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  5276. // Give it a placeholder if this is not hydration
  5277. // TODO handle self-defined fallback
  5278. if (!initialVNode.el) {
  5279. const placeholder = (instance.subTree = createVNode(Comment));
  5280. processCommentNode(null, placeholder, container, anchor);
  5281. }
  5282. return;
  5283. }
  5284. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  5285. {
  5286. popWarningContext();
  5287. endMeasure(instance, `mount`);
  5288. }
  5289. };
  5290. const updateComponent = (n1, n2, optimized) => {
  5291. const instance = (n2.component = n1.component);
  5292. if (shouldUpdateComponent(n1, n2, optimized)) {
  5293. if (instance.asyncDep &&
  5294. !instance.asyncResolved) {
  5295. // async & still pending - just update props and slots
  5296. // since the component's reactive effect for render isn't set-up yet
  5297. {
  5298. pushWarningContext(n2);
  5299. }
  5300. updateComponentPreRender(instance, n2, optimized);
  5301. {
  5302. popWarningContext();
  5303. }
  5304. return;
  5305. }
  5306. else {
  5307. // normal update
  5308. instance.next = n2;
  5309. // in case the child component is also queued, remove it to avoid
  5310. // double updating the same child component in the same flush.
  5311. invalidateJob(instance.update);
  5312. // instance.update is the reactive effect runner.
  5313. instance.update();
  5314. }
  5315. }
  5316. else {
  5317. // no update needed. just copy over properties
  5318. n2.component = n1.component;
  5319. n2.el = n1.el;
  5320. instance.vnode = n2;
  5321. }
  5322. };
  5323. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  5324. // create reactive effect for rendering
  5325. instance.update = effect(function componentEffect() {
  5326. if (!instance.isMounted) {
  5327. let vnodeHook;
  5328. const { el, props } = initialVNode;
  5329. const { bm, m, parent } = instance;
  5330. // beforeMount hook
  5331. if (bm) {
  5332. invokeArrayFns(bm);
  5333. }
  5334. // onVnodeBeforeMount
  5335. if ((vnodeHook = props && props.onVnodeBeforeMount)) {
  5336. invokeVNodeHook(vnodeHook, parent, initialVNode);
  5337. }
  5338. // render
  5339. {
  5340. startMeasure(instance, `render`);
  5341. }
  5342. const subTree = (instance.subTree = renderComponentRoot(instance));
  5343. {
  5344. endMeasure(instance, `render`);
  5345. }
  5346. if (el && hydrateNode) {
  5347. {
  5348. startMeasure(instance, `hydrate`);
  5349. }
  5350. // vnode has adopted host node - perform hydration instead of mount.
  5351. hydrateNode(initialVNode.el, subTree, instance, parentSuspense);
  5352. {
  5353. endMeasure(instance, `hydrate`);
  5354. }
  5355. }
  5356. else {
  5357. {
  5358. startMeasure(instance, `patch`);
  5359. }
  5360. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  5361. {
  5362. endMeasure(instance, `patch`);
  5363. }
  5364. initialVNode.el = subTree.el;
  5365. }
  5366. // mounted hook
  5367. if (m) {
  5368. queuePostRenderEffect(m, parentSuspense);
  5369. }
  5370. // onVnodeMounted
  5371. if ((vnodeHook = props && props.onVnodeMounted)) {
  5372. const scopedInitialVNode = initialVNode;
  5373. queuePostRenderEffect(() => {
  5374. invokeVNodeHook(vnodeHook, parent, scopedInitialVNode);
  5375. }, parentSuspense);
  5376. }
  5377. // activated hook for keep-alive roots.
  5378. // #1742 activated hook must be accessed after first render
  5379. // since the hook may be injected by a child keep-alive
  5380. const { a } = instance;
  5381. if (a &&
  5382. initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  5383. queuePostRenderEffect(a, parentSuspense);
  5384. }
  5385. instance.isMounted = true;
  5386. {
  5387. devtoolsComponentAdded(instance);
  5388. }
  5389. // #2458: deference mount-only object parameters to prevent memleaks
  5390. initialVNode = container = anchor = null;
  5391. }
  5392. else {
  5393. // updateComponent
  5394. // This is triggered by mutation of component's own state (next: null)
  5395. // OR parent calling processComponent (next: VNode)
  5396. let { next, bu, u, parent, vnode } = instance;
  5397. let originNext = next;
  5398. let vnodeHook;
  5399. {
  5400. pushWarningContext(next || instance.vnode);
  5401. }
  5402. if (next) {
  5403. next.el = vnode.el;
  5404. updateComponentPreRender(instance, next, optimized);
  5405. }
  5406. else {
  5407. next = vnode;
  5408. }
  5409. // beforeUpdate hook
  5410. if (bu) {
  5411. invokeArrayFns(bu);
  5412. }
  5413. // onVnodeBeforeUpdate
  5414. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  5415. invokeVNodeHook(vnodeHook, parent, next, vnode);
  5416. }
  5417. // render
  5418. {
  5419. startMeasure(instance, `render`);
  5420. }
  5421. const nextTree = renderComponentRoot(instance);
  5422. {
  5423. endMeasure(instance, `render`);
  5424. }
  5425. const prevTree = instance.subTree;
  5426. instance.subTree = nextTree;
  5427. {
  5428. startMeasure(instance, `patch`);
  5429. }
  5430. patch(prevTree, nextTree,
  5431. // parent may have changed if it's in a teleport
  5432. hostParentNode(prevTree.el),
  5433. // anchor may have changed if it's in a fragment
  5434. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  5435. {
  5436. endMeasure(instance, `patch`);
  5437. }
  5438. next.el = nextTree.el;
  5439. if (originNext === null) {
  5440. // self-triggered update. In case of HOC, update parent component
  5441. // vnode el. HOC is indicated by parent instance's subTree pointing
  5442. // to child component's vnode
  5443. updateHOCHostEl(instance, nextTree.el);
  5444. }
  5445. // updated hook
  5446. if (u) {
  5447. queuePostRenderEffect(u, parentSuspense);
  5448. }
  5449. // onVnodeUpdated
  5450. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  5451. queuePostRenderEffect(() => {
  5452. invokeVNodeHook(vnodeHook, parent, next, vnode);
  5453. }, parentSuspense);
  5454. }
  5455. {
  5456. devtoolsComponentUpdated(instance);
  5457. }
  5458. {
  5459. popWarningContext();
  5460. }
  5461. }
  5462. }, createDevEffectOptions(instance) );
  5463. };
  5464. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  5465. nextVNode.component = instance;
  5466. const prevProps = instance.vnode.props;
  5467. instance.vnode = nextVNode;
  5468. instance.next = null;
  5469. updateProps(instance, nextVNode.props, prevProps, optimized);
  5470. updateSlots(instance, nextVNode.children);
  5471. // props update may have triggered pre-flush watchers.
  5472. // flush them before the render update.
  5473. flushPreFlushCbs(undefined, instance.update);
  5474. };
  5475. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized = false) => {
  5476. const c1 = n1 && n1.children;
  5477. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  5478. const c2 = n2.children;
  5479. const { patchFlag, shapeFlag } = n2;
  5480. // fast path
  5481. if (patchFlag > 0) {
  5482. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  5483. // this could be either fully-keyed or mixed (some keyed some not)
  5484. // presence of patchFlag means children are guaranteed to be arrays
  5485. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5486. return;
  5487. }
  5488. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  5489. // unkeyed
  5490. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5491. return;
  5492. }
  5493. }
  5494. // children has 3 possibilities: text, array or no children.
  5495. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5496. // text children fast path
  5497. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  5498. unmountChildren(c1, parentComponent, parentSuspense);
  5499. }
  5500. if (c2 !== c1) {
  5501. hostSetElementText(container, c2);
  5502. }
  5503. }
  5504. else {
  5505. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  5506. // prev children was array
  5507. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5508. // two arrays, cannot assume anything, do full diff
  5509. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5510. }
  5511. else {
  5512. // no new children, just unmount old
  5513. unmountChildren(c1, parentComponent, parentSuspense, true);
  5514. }
  5515. }
  5516. else {
  5517. // prev children was text OR null
  5518. // new children is array OR null
  5519. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  5520. hostSetElementText(container, '');
  5521. }
  5522. // mount new if array
  5523. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5524. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5525. }
  5526. }
  5527. }
  5528. };
  5529. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5530. c1 = c1 || EMPTY_ARR;
  5531. c2 = c2 || EMPTY_ARR;
  5532. const oldLength = c1.length;
  5533. const newLength = c2.length;
  5534. const commonLength = Math.min(oldLength, newLength);
  5535. let i;
  5536. for (i = 0; i < commonLength; i++) {
  5537. const nextChild = (c2[i] = optimized
  5538. ? cloneIfMounted(c2[i])
  5539. : normalizeVNode(c2[i]));
  5540. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, optimized);
  5541. }
  5542. if (oldLength > newLength) {
  5543. // remove old
  5544. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  5545. }
  5546. else {
  5547. // mount new
  5548. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, commonLength);
  5549. }
  5550. };
  5551. // can be all-keyed or mixed
  5552. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5553. let i = 0;
  5554. const l2 = c2.length;
  5555. let e1 = c1.length - 1; // prev ending index
  5556. let e2 = l2 - 1; // next ending index
  5557. // 1. sync from start
  5558. // (a b) c
  5559. // (a b) d e
  5560. while (i <= e1 && i <= e2) {
  5561. const n1 = c1[i];
  5562. const n2 = (c2[i] = optimized
  5563. ? cloneIfMounted(c2[i])
  5564. : normalizeVNode(c2[i]));
  5565. if (isSameVNodeType(n1, n2)) {
  5566. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, optimized);
  5567. }
  5568. else {
  5569. break;
  5570. }
  5571. i++;
  5572. }
  5573. // 2. sync from end
  5574. // a (b c)
  5575. // d e (b c)
  5576. while (i <= e1 && i <= e2) {
  5577. const n1 = c1[e1];
  5578. const n2 = (c2[e2] = optimized
  5579. ? cloneIfMounted(c2[e2])
  5580. : normalizeVNode(c2[e2]));
  5581. if (isSameVNodeType(n1, n2)) {
  5582. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, optimized);
  5583. }
  5584. else {
  5585. break;
  5586. }
  5587. e1--;
  5588. e2--;
  5589. }
  5590. // 3. common sequence + mount
  5591. // (a b)
  5592. // (a b) c
  5593. // i = 2, e1 = 1, e2 = 2
  5594. // (a b)
  5595. // c (a b)
  5596. // i = 0, e1 = -1, e2 = 0
  5597. if (i > e1) {
  5598. if (i <= e2) {
  5599. const nextPos = e2 + 1;
  5600. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  5601. while (i <= e2) {
  5602. patch(null, (c2[i] = optimized
  5603. ? cloneIfMounted(c2[i])
  5604. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG);
  5605. i++;
  5606. }
  5607. }
  5608. }
  5609. // 4. common sequence + unmount
  5610. // (a b) c
  5611. // (a b)
  5612. // i = 2, e1 = 2, e2 = 1
  5613. // a (b c)
  5614. // (b c)
  5615. // i = 0, e1 = 0, e2 = -1
  5616. else if (i > e2) {
  5617. while (i <= e1) {
  5618. unmount(c1[i], parentComponent, parentSuspense, true);
  5619. i++;
  5620. }
  5621. }
  5622. // 5. unknown sequence
  5623. // [i ... e1 + 1]: a b [c d e] f g
  5624. // [i ... e2 + 1]: a b [e d c h] f g
  5625. // i = 2, e1 = 4, e2 = 5
  5626. else {
  5627. const s1 = i; // prev starting index
  5628. const s2 = i; // next starting index
  5629. // 5.1 build key:index map for newChildren
  5630. const keyToNewIndexMap = new Map();
  5631. for (i = s2; i <= e2; i++) {
  5632. const nextChild = (c2[i] = optimized
  5633. ? cloneIfMounted(c2[i])
  5634. : normalizeVNode(c2[i]));
  5635. if (nextChild.key != null) {
  5636. if (keyToNewIndexMap.has(nextChild.key)) {
  5637. warn(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  5638. }
  5639. keyToNewIndexMap.set(nextChild.key, i);
  5640. }
  5641. }
  5642. // 5.2 loop through old children left to be patched and try to patch
  5643. // matching nodes & remove nodes that are no longer present
  5644. let j;
  5645. let patched = 0;
  5646. const toBePatched = e2 - s2 + 1;
  5647. let moved = false;
  5648. // used to track whether any node has moved
  5649. let maxNewIndexSoFar = 0;
  5650. // works as Map<newIndex, oldIndex>
  5651. // Note that oldIndex is offset by +1
  5652. // and oldIndex = 0 is a special value indicating the new node has
  5653. // no corresponding old node.
  5654. // used for determining longest stable subsequence
  5655. const newIndexToOldIndexMap = new Array(toBePatched);
  5656. for (i = 0; i < toBePatched; i++)
  5657. newIndexToOldIndexMap[i] = 0;
  5658. for (i = s1; i <= e1; i++) {
  5659. const prevChild = c1[i];
  5660. if (patched >= toBePatched) {
  5661. // all new children have been patched so this can only be a removal
  5662. unmount(prevChild, parentComponent, parentSuspense, true);
  5663. continue;
  5664. }
  5665. let newIndex;
  5666. if (prevChild.key != null) {
  5667. newIndex = keyToNewIndexMap.get(prevChild.key);
  5668. }
  5669. else {
  5670. // key-less node, try to locate a key-less node of the same type
  5671. for (j = s2; j <= e2; j++) {
  5672. if (newIndexToOldIndexMap[j - s2] === 0 &&
  5673. isSameVNodeType(prevChild, c2[j])) {
  5674. newIndex = j;
  5675. break;
  5676. }
  5677. }
  5678. }
  5679. if (newIndex === undefined) {
  5680. unmount(prevChild, parentComponent, parentSuspense, true);
  5681. }
  5682. else {
  5683. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  5684. if (newIndex >= maxNewIndexSoFar) {
  5685. maxNewIndexSoFar = newIndex;
  5686. }
  5687. else {
  5688. moved = true;
  5689. }
  5690. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, optimized);
  5691. patched++;
  5692. }
  5693. }
  5694. // 5.3 move and mount
  5695. // generate longest stable subsequence only when nodes have moved
  5696. const increasingNewIndexSequence = moved
  5697. ? getSequence(newIndexToOldIndexMap)
  5698. : EMPTY_ARR;
  5699. j = increasingNewIndexSequence.length - 1;
  5700. // looping backwards so that we can use last patched node as anchor
  5701. for (i = toBePatched - 1; i >= 0; i--) {
  5702. const nextIndex = s2 + i;
  5703. const nextChild = c2[nextIndex];
  5704. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  5705. if (newIndexToOldIndexMap[i] === 0) {
  5706. // mount new
  5707. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG);
  5708. }
  5709. else if (moved) {
  5710. // move if:
  5711. // There is no stable subsequence (e.g. a reverse)
  5712. // OR current node is not among the stable sequence
  5713. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  5714. move(nextChild, container, anchor, 2 /* REORDER */);
  5715. }
  5716. else {
  5717. j--;
  5718. }
  5719. }
  5720. }
  5721. }
  5722. };
  5723. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  5724. const { el, type, transition, children, shapeFlag } = vnode;
  5725. if (shapeFlag & 6 /* COMPONENT */) {
  5726. move(vnode.component.subTree, container, anchor, moveType);
  5727. return;
  5728. }
  5729. if (shapeFlag & 128 /* SUSPENSE */) {
  5730. vnode.suspense.move(container, anchor, moveType);
  5731. return;
  5732. }
  5733. if (shapeFlag & 64 /* TELEPORT */) {
  5734. type.move(vnode, container, anchor, internals);
  5735. return;
  5736. }
  5737. if (type === Fragment) {
  5738. hostInsert(el, container, anchor);
  5739. for (let i = 0; i < children.length; i++) {
  5740. move(children[i], container, anchor, moveType);
  5741. }
  5742. hostInsert(vnode.anchor, container, anchor);
  5743. return;
  5744. }
  5745. if (type === Static) {
  5746. moveStaticNode(vnode, container, anchor);
  5747. return;
  5748. }
  5749. // single nodes
  5750. const needTransition = moveType !== 2 /* REORDER */ &&
  5751. shapeFlag & 1 /* ELEMENT */ &&
  5752. transition;
  5753. if (needTransition) {
  5754. if (moveType === 0 /* ENTER */) {
  5755. transition.beforeEnter(el);
  5756. hostInsert(el, container, anchor);
  5757. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  5758. }
  5759. else {
  5760. const { leave, delayLeave, afterLeave } = transition;
  5761. const remove = () => hostInsert(el, container, anchor);
  5762. const performLeave = () => {
  5763. leave(el, () => {
  5764. remove();
  5765. afterLeave && afterLeave();
  5766. });
  5767. };
  5768. if (delayLeave) {
  5769. delayLeave(el, remove, performLeave);
  5770. }
  5771. else {
  5772. performLeave();
  5773. }
  5774. }
  5775. }
  5776. else {
  5777. hostInsert(el, container, anchor);
  5778. }
  5779. };
  5780. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  5781. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  5782. // unset ref
  5783. if (ref != null) {
  5784. setRef(ref, null, parentSuspense, null);
  5785. }
  5786. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  5787. parentComponent.ctx.deactivate(vnode);
  5788. return;
  5789. }
  5790. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  5791. let vnodeHook;
  5792. if ((vnodeHook = props && props.onVnodeBeforeUnmount)) {
  5793. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5794. }
  5795. if (shapeFlag & 6 /* COMPONENT */) {
  5796. unmountComponent(vnode.component, parentSuspense, doRemove);
  5797. }
  5798. else {
  5799. if (shapeFlag & 128 /* SUSPENSE */) {
  5800. vnode.suspense.unmount(parentSuspense, doRemove);
  5801. return;
  5802. }
  5803. if (shouldInvokeDirs) {
  5804. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  5805. }
  5806. if (dynamicChildren &&
  5807. // #1153: fast path should not be taken for non-stable (v-for) fragments
  5808. (type !== Fragment ||
  5809. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  5810. // fast path for block nodes: only need to unmount dynamic children.
  5811. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  5812. }
  5813. else if ((type === Fragment &&
  5814. (patchFlag & 128 /* KEYED_FRAGMENT */ ||
  5815. patchFlag & 256 /* UNKEYED_FRAGMENT */)) ||
  5816. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  5817. unmountChildren(children, parentComponent, parentSuspense);
  5818. }
  5819. // an unmounted teleport should always remove its children if not disabled
  5820. if (shapeFlag & 64 /* TELEPORT */ &&
  5821. (doRemove || !isTeleportDisabled(vnode.props))) {
  5822. vnode.type.remove(vnode, internals);
  5823. }
  5824. if (doRemove) {
  5825. remove(vnode);
  5826. }
  5827. }
  5828. if ((vnodeHook = props && props.onVnodeUnmounted) || shouldInvokeDirs) {
  5829. queuePostRenderEffect(() => {
  5830. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5831. shouldInvokeDirs &&
  5832. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  5833. }, parentSuspense);
  5834. }
  5835. };
  5836. const remove = vnode => {
  5837. const { type, el, anchor, transition } = vnode;
  5838. if (type === Fragment) {
  5839. removeFragment(el, anchor);
  5840. return;
  5841. }
  5842. if (type === Static) {
  5843. removeStaticNode(vnode);
  5844. return;
  5845. }
  5846. const performRemove = () => {
  5847. hostRemove(el);
  5848. if (transition && !transition.persisted && transition.afterLeave) {
  5849. transition.afterLeave();
  5850. }
  5851. };
  5852. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  5853. transition &&
  5854. !transition.persisted) {
  5855. const { leave, delayLeave } = transition;
  5856. const performLeave = () => leave(el, performRemove);
  5857. if (delayLeave) {
  5858. delayLeave(vnode.el, performRemove, performLeave);
  5859. }
  5860. else {
  5861. performLeave();
  5862. }
  5863. }
  5864. else {
  5865. performRemove();
  5866. }
  5867. };
  5868. const removeFragment = (cur, end) => {
  5869. // For fragments, directly remove all contained DOM nodes.
  5870. // (fragment child nodes cannot have transition)
  5871. let next;
  5872. while (cur !== end) {
  5873. next = hostNextSibling(cur);
  5874. hostRemove(cur);
  5875. cur = next;
  5876. }
  5877. hostRemove(end);
  5878. };
  5879. const unmountComponent = (instance, parentSuspense, doRemove) => {
  5880. if (instance.type.__hmrId) {
  5881. unregisterHMR(instance);
  5882. }
  5883. const { bum, effects, update, subTree, um } = instance;
  5884. // beforeUnmount hook
  5885. if (bum) {
  5886. invokeArrayFns(bum);
  5887. }
  5888. if (effects) {
  5889. for (let i = 0; i < effects.length; i++) {
  5890. stop(effects[i]);
  5891. }
  5892. }
  5893. // update may be null if a component is unmounted before its async
  5894. // setup has resolved.
  5895. if (update) {
  5896. stop(update);
  5897. unmount(subTree, instance, parentSuspense, doRemove);
  5898. }
  5899. // unmounted hook
  5900. if (um) {
  5901. queuePostRenderEffect(um, parentSuspense);
  5902. }
  5903. queuePostRenderEffect(() => {
  5904. instance.isUnmounted = true;
  5905. }, parentSuspense);
  5906. // A component with async dep inside a pending suspense is unmounted before
  5907. // its async dep resolves. This should remove the dep from the suspense, and
  5908. // cause the suspense to resolve immediately if that was the last dep.
  5909. if (parentSuspense &&
  5910. parentSuspense.pendingBranch &&
  5911. !parentSuspense.isUnmounted &&
  5912. instance.asyncDep &&
  5913. !instance.asyncResolved &&
  5914. instance.suspenseId === parentSuspense.pendingId) {
  5915. parentSuspense.deps--;
  5916. if (parentSuspense.deps === 0) {
  5917. parentSuspense.resolve();
  5918. }
  5919. }
  5920. {
  5921. devtoolsComponentRemoved(instance);
  5922. }
  5923. };
  5924. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  5925. for (let i = start; i < children.length; i++) {
  5926. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  5927. }
  5928. };
  5929. const getNextHostNode = vnode => {
  5930. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  5931. return getNextHostNode(vnode.component.subTree);
  5932. }
  5933. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  5934. return vnode.suspense.next();
  5935. }
  5936. return hostNextSibling((vnode.anchor || vnode.el));
  5937. };
  5938. const render = (vnode, container) => {
  5939. if (vnode == null) {
  5940. if (container._vnode) {
  5941. unmount(container._vnode, null, null, true);
  5942. }
  5943. }
  5944. else {
  5945. patch(container._vnode || null, vnode, container);
  5946. }
  5947. flushPostFlushCbs();
  5948. container._vnode = vnode;
  5949. };
  5950. const internals = {
  5951. p: patch,
  5952. um: unmount,
  5953. m: move,
  5954. r: remove,
  5955. mt: mountComponent,
  5956. mc: mountChildren,
  5957. pc: patchChildren,
  5958. pbc: patchBlockChildren,
  5959. n: getNextHostNode,
  5960. o: options
  5961. };
  5962. let hydrate;
  5963. let hydrateNode;
  5964. if (createHydrationFns) {
  5965. [hydrate, hydrateNode] = createHydrationFns(internals);
  5966. }
  5967. return {
  5968. render,
  5969. hydrate,
  5970. createApp: createAppAPI(render, hydrate)
  5971. };
  5972. }
  5973. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  5974. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  5975. vnode,
  5976. prevVNode
  5977. ]);
  5978. }
  5979. /**
  5980. * #1156
  5981. * When a component is HMR-enabled, we need to make sure that all static nodes
  5982. * inside a block also inherit the DOM element from the previous tree so that
  5983. * HMR updates (which are full updates) can retrieve the element for patching.
  5984. *
  5985. * #2080
  5986. * Inside keyed `template` fragment static children, if a fragment is moved,
  5987. * the children will always moved so that need inherit el form previous nodes
  5988. * to ensure correct moved position.
  5989. */
  5990. function traverseStaticChildren(n1, n2, shallow = false) {
  5991. const ch1 = n1.children;
  5992. const ch2 = n2.children;
  5993. if (isArray(ch1) && isArray(ch2)) {
  5994. for (let i = 0; i < ch1.length; i++) {
  5995. // this is only called in the optimized path so array children are
  5996. // guaranteed to be vnodes
  5997. const c1 = ch1[i];
  5998. let c2 = ch2[i];
  5999. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  6000. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  6001. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  6002. c2.el = c1.el;
  6003. }
  6004. if (!shallow)
  6005. traverseStaticChildren(c1, c2);
  6006. }
  6007. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  6008. // would have received .el during block patch)
  6009. if (c2.type === Comment && !c2.el) {
  6010. c2.el = c1.el;
  6011. }
  6012. }
  6013. }
  6014. }
  6015. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  6016. function getSequence(arr) {
  6017. const p = arr.slice();
  6018. const result = [0];
  6019. let i, j, u, v, c;
  6020. const len = arr.length;
  6021. for (i = 0; i < len; i++) {
  6022. const arrI = arr[i];
  6023. if (arrI !== 0) {
  6024. j = result[result.length - 1];
  6025. if (arr[j] < arrI) {
  6026. p[i] = j;
  6027. result.push(i);
  6028. continue;
  6029. }
  6030. u = 0;
  6031. v = result.length - 1;
  6032. while (u < v) {
  6033. c = ((u + v) / 2) | 0;
  6034. if (arr[result[c]] < arrI) {
  6035. u = c + 1;
  6036. }
  6037. else {
  6038. v = c;
  6039. }
  6040. }
  6041. if (arrI < arr[result[u]]) {
  6042. if (u > 0) {
  6043. p[i] = result[u - 1];
  6044. }
  6045. result[u] = i;
  6046. }
  6047. }
  6048. }
  6049. u = result.length;
  6050. v = result[u - 1];
  6051. while (u-- > 0) {
  6052. result[u] = v;
  6053. v = p[v];
  6054. }
  6055. return result;
  6056. }
  6057. const isTeleport = (type) => type.__isTeleport;
  6058. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  6059. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  6060. const resolveTarget = (props, select) => {
  6061. const targetSelector = props && props.to;
  6062. if (isString(targetSelector)) {
  6063. if (!select) {
  6064. warn(`Current renderer does not support string target for Teleports. ` +
  6065. `(missing querySelector renderer option)`);
  6066. return null;
  6067. }
  6068. else {
  6069. const target = select(targetSelector);
  6070. if (!target) {
  6071. warn(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  6072. `Note the target element must exist before the component is mounted - ` +
  6073. `i.e. the target cannot be rendered by the component itself, and ` +
  6074. `ideally should be outside of the entire Vue component tree.`);
  6075. }
  6076. return target;
  6077. }
  6078. }
  6079. else {
  6080. if (!targetSelector && !isTeleportDisabled(props)) {
  6081. warn(`Invalid Teleport target: ${targetSelector}`);
  6082. }
  6083. return targetSelector;
  6084. }
  6085. };
  6086. const TeleportImpl = {
  6087. __isTeleport: true,
  6088. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals) {
  6089. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  6090. const disabled = isTeleportDisabled(n2.props);
  6091. const { shapeFlag, children } = n2;
  6092. if (n1 == null) {
  6093. // insert anchors in the main view
  6094. const placeholder = (n2.el = createComment('teleport start')
  6095. );
  6096. const mainAnchor = (n2.anchor = createComment('teleport end')
  6097. );
  6098. insert(placeholder, container, anchor);
  6099. insert(mainAnchor, container, anchor);
  6100. const target = (n2.target = resolveTarget(n2.props, querySelector));
  6101. const targetAnchor = (n2.targetAnchor = createText(''));
  6102. if (target) {
  6103. insert(targetAnchor, target);
  6104. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  6105. isSVG = isSVG || isTargetSVG(target);
  6106. }
  6107. else if (!disabled) {
  6108. warn('Invalid Teleport target on mount:', target, `(${typeof target})`);
  6109. }
  6110. const mount = (container, anchor) => {
  6111. // Teleport *always* has Array children. This is enforced in both the
  6112. // compiler and vnode children normalization.
  6113. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6114. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6115. }
  6116. };
  6117. if (disabled) {
  6118. mount(container, mainAnchor);
  6119. }
  6120. else if (target) {
  6121. mount(target, targetAnchor);
  6122. }
  6123. }
  6124. else {
  6125. // update content
  6126. n2.el = n1.el;
  6127. const mainAnchor = (n2.anchor = n1.anchor);
  6128. const target = (n2.target = n1.target);
  6129. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  6130. const wasDisabled = isTeleportDisabled(n1.props);
  6131. const currentContainer = wasDisabled ? container : target;
  6132. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  6133. isSVG = isSVG || isTargetSVG(target);
  6134. if (n2.dynamicChildren) {
  6135. // fast path when the teleport happens to be a block root
  6136. patchBlockChildren(n1.dynamicChildren, n2.dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG);
  6137. // even in block tree mode we need to make sure all root-level nodes
  6138. // in the teleport inherit previous DOM references so that they can
  6139. // be moved in future patches.
  6140. traverseStaticChildren(n1, n2, true);
  6141. }
  6142. else if (!optimized) {
  6143. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG);
  6144. }
  6145. if (disabled) {
  6146. if (!wasDisabled) {
  6147. // enabled -> disabled
  6148. // move into main container
  6149. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  6150. }
  6151. }
  6152. else {
  6153. // target changed
  6154. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  6155. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  6156. if (nextTarget) {
  6157. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  6158. }
  6159. else {
  6160. warn('Invalid Teleport target on update:', target, `(${typeof target})`);
  6161. }
  6162. }
  6163. else if (wasDisabled) {
  6164. // disabled -> enabled
  6165. // move into teleport target
  6166. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  6167. }
  6168. }
  6169. }
  6170. },
  6171. remove(vnode, { r: remove, o: { remove: hostRemove } }) {
  6172. const { shapeFlag, children, anchor } = vnode;
  6173. hostRemove(anchor);
  6174. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6175. for (let i = 0; i < children.length; i++) {
  6176. remove(children[i]);
  6177. }
  6178. }
  6179. },
  6180. move: moveTeleport,
  6181. hydrate: hydrateTeleport
  6182. };
  6183. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  6184. // move target anchor if this is a target change.
  6185. if (moveType === 0 /* TARGET_CHANGE */) {
  6186. insert(vnode.targetAnchor, container, parentAnchor);
  6187. }
  6188. const { el, anchor, shapeFlag, children, props } = vnode;
  6189. const isReorder = moveType === 2 /* REORDER */;
  6190. // move main view anchor if this is a re-order.
  6191. if (isReorder) {
  6192. insert(el, container, parentAnchor);
  6193. }
  6194. // if this is a re-order and teleport is enabled (content is in target)
  6195. // do not move children. So the opposite is: only move children if this
  6196. // is not a reorder, or the teleport is disabled
  6197. if (!isReorder || isTeleportDisabled(props)) {
  6198. // Teleport has either Array children or no children.
  6199. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6200. for (let i = 0; i < children.length; i++) {
  6201. move(children[i], container, parentAnchor, 2 /* REORDER */);
  6202. }
  6203. }
  6204. }
  6205. // move main view anchor if this is a re-order.
  6206. if (isReorder) {
  6207. insert(anchor, container, parentAnchor);
  6208. }
  6209. }
  6210. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  6211. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  6212. if (target) {
  6213. // if multiple teleports rendered to the same target element, we need to
  6214. // pick up from where the last teleport finished instead of the first node
  6215. const targetNode = target._lpa || target.firstChild;
  6216. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6217. if (isTeleportDisabled(vnode.props)) {
  6218. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, optimized);
  6219. vnode.targetAnchor = targetNode;
  6220. }
  6221. else {
  6222. vnode.anchor = nextSibling(node);
  6223. vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, optimized);
  6224. }
  6225. target._lpa =
  6226. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  6227. }
  6228. }
  6229. return vnode.anchor && nextSibling(vnode.anchor);
  6230. }
  6231. // Force-casted public typing for h and TSX props inference
  6232. const Teleport = TeleportImpl;
  6233. const COMPONENTS = 'components';
  6234. const DIRECTIVES = 'directives';
  6235. /**
  6236. * @private
  6237. */
  6238. function resolveComponent(name) {
  6239. return resolveAsset(COMPONENTS, name) || name;
  6240. }
  6241. const NULL_DYNAMIC_COMPONENT = Symbol();
  6242. /**
  6243. * @private
  6244. */
  6245. function resolveDynamicComponent(component) {
  6246. if (isString(component)) {
  6247. return resolveAsset(COMPONENTS, component, false) || component;
  6248. }
  6249. else {
  6250. // invalid types will fallthrough to createVNode and raise warning
  6251. return (component || NULL_DYNAMIC_COMPONENT);
  6252. }
  6253. }
  6254. /**
  6255. * @private
  6256. */
  6257. function resolveDirective(name) {
  6258. return resolveAsset(DIRECTIVES, name);
  6259. }
  6260. // implementation
  6261. function resolveAsset(type, name, warnMissing = true) {
  6262. const instance = currentRenderingInstance || currentInstance;
  6263. if (instance) {
  6264. const Component = instance.type;
  6265. // self name has highest priority
  6266. if (type === COMPONENTS) {
  6267. // special self referencing call generated by compiler
  6268. // inferred from SFC filename
  6269. if (name === `_self`) {
  6270. return Component;
  6271. }
  6272. const selfName = getComponentName(Component);
  6273. if (selfName &&
  6274. (selfName === name ||
  6275. selfName === camelize(name) ||
  6276. selfName === capitalize(camelize(name)))) {
  6277. return Component;
  6278. }
  6279. }
  6280. const res =
  6281. // local registration
  6282. // check instance[type] first for components with mixin or extends.
  6283. resolve(instance[type] || Component[type], name) ||
  6284. // global registration
  6285. resolve(instance.appContext[type], name);
  6286. if (warnMissing && !res) {
  6287. warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`);
  6288. }
  6289. return res;
  6290. }
  6291. else {
  6292. warn(`resolve${capitalize(type.slice(0, -1))} ` +
  6293. `can only be used in render() or setup().`);
  6294. }
  6295. }
  6296. function resolve(registry, name) {
  6297. return (registry &&
  6298. (registry[name] ||
  6299. registry[camelize(name)] ||
  6300. registry[capitalize(camelize(name))]));
  6301. }
  6302. const Fragment = Symbol('Fragment' );
  6303. const Text = Symbol('Text' );
  6304. const Comment = Symbol('Comment' );
  6305. const Static = Symbol('Static' );
  6306. // Since v-if and v-for are the two possible ways node structure can dynamically
  6307. // change, once we consider v-if branches and each v-for fragment a block, we
  6308. // can divide a template into nested blocks, and within each block the node
  6309. // structure would be stable. This allows us to skip most children diffing
  6310. // and only worry about the dynamic nodes (indicated by patch flags).
  6311. const blockStack = [];
  6312. let currentBlock = null;
  6313. /**
  6314. * Open a block.
  6315. * This must be called before `createBlock`. It cannot be part of `createBlock`
  6316. * because the children of the block are evaluated before `createBlock` itself
  6317. * is called. The generated code typically looks like this:
  6318. *
  6319. * ```js
  6320. * function render() {
  6321. * return (openBlock(),createBlock('div', null, [...]))
  6322. * }
  6323. * ```
  6324. * disableTracking is true when creating a v-for fragment block, since a v-for
  6325. * fragment always diffs its children.
  6326. *
  6327. * @private
  6328. */
  6329. function openBlock(disableTracking = false) {
  6330. blockStack.push((currentBlock = disableTracking ? null : []));
  6331. }
  6332. function closeBlock() {
  6333. blockStack.pop();
  6334. currentBlock = blockStack[blockStack.length - 1] || null;
  6335. }
  6336. // Whether we should be tracking dynamic child nodes inside a block.
  6337. // Only tracks when this value is > 0
  6338. // We are not using a simple boolean because this value may need to be
  6339. // incremented/decremented by nested usage of v-once (see below)
  6340. let shouldTrack$1 = 1;
  6341. /**
  6342. * Block tracking sometimes needs to be disabled, for example during the
  6343. * creation of a tree that needs to be cached by v-once. The compiler generates
  6344. * code like this:
  6345. *
  6346. * ``` js
  6347. * _cache[1] || (
  6348. * setBlockTracking(-1),
  6349. * _cache[1] = createVNode(...),
  6350. * setBlockTracking(1),
  6351. * _cache[1]
  6352. * )
  6353. * ```
  6354. *
  6355. * @private
  6356. */
  6357. function setBlockTracking(value) {
  6358. shouldTrack$1 += value;
  6359. }
  6360. /**
  6361. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  6362. * A block root keeps track of dynamic nodes within the block in the
  6363. * `dynamicChildren` array.
  6364. *
  6365. * @private
  6366. */
  6367. function createBlock(type, props, children, patchFlag, dynamicProps) {
  6368. const vnode = createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */);
  6369. // save current block children on the block vnode
  6370. vnode.dynamicChildren = currentBlock || EMPTY_ARR;
  6371. // close block
  6372. closeBlock();
  6373. // a block is always going to be patched, so track it as a child of its
  6374. // parent block
  6375. if (shouldTrack$1 > 0 && currentBlock) {
  6376. currentBlock.push(vnode);
  6377. }
  6378. return vnode;
  6379. }
  6380. function isVNode(value) {
  6381. return value ? value.__v_isVNode === true : false;
  6382. }
  6383. function isSameVNodeType(n1, n2) {
  6384. if (n2.shapeFlag & 6 /* COMPONENT */ &&
  6385. hmrDirtyComponents.has(n2.type)) {
  6386. // HMR only: if the component has been hot-updated, force a reload.
  6387. return false;
  6388. }
  6389. return n1.type === n2.type && n1.key === n2.key;
  6390. }
  6391. let vnodeArgsTransformer;
  6392. /**
  6393. * Internal API for registering an arguments transform for createVNode
  6394. * used for creating stubs in the test-utils
  6395. * It is *internal* but needs to be exposed for test-utils to pick up proper
  6396. * typings
  6397. */
  6398. function transformVNodeArgs(transformer) {
  6399. vnodeArgsTransformer = transformer;
  6400. }
  6401. const createVNodeWithArgsTransform = (...args) => {
  6402. return _createVNode(...(vnodeArgsTransformer
  6403. ? vnodeArgsTransformer(args, currentRenderingInstance)
  6404. : args));
  6405. };
  6406. const InternalObjectKey = `__vInternal`;
  6407. const normalizeKey = ({ key }) => key != null ? key : null;
  6408. const normalizeRef = ({ ref }) => {
  6409. return (ref != null
  6410. ? isString(ref) || isRef(ref) || isFunction(ref)
  6411. ? { i: currentRenderingInstance, r: ref }
  6412. : ref
  6413. : null);
  6414. };
  6415. const createVNode = (createVNodeWithArgsTransform
  6416. );
  6417. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  6418. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  6419. if (!type) {
  6420. warn(`Invalid vnode type when creating vnode: ${type}.`);
  6421. }
  6422. type = Comment;
  6423. }
  6424. if (isVNode(type)) {
  6425. // createVNode receiving an existing vnode. This happens in cases like
  6426. // <component :is="vnode"/>
  6427. // #2078 make sure to merge refs during the clone instead of overwriting it
  6428. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  6429. if (children) {
  6430. normalizeChildren(cloned, children);
  6431. }
  6432. return cloned;
  6433. }
  6434. // class component normalization.
  6435. if (isClassComponent(type)) {
  6436. type = type.__vccOpts;
  6437. }
  6438. // class & style normalization.
  6439. if (props) {
  6440. // for reactive or proxy objects, we need to clone it to enable mutation.
  6441. if (isProxy(props) || InternalObjectKey in props) {
  6442. props = extend({}, props);
  6443. }
  6444. let { class: klass, style } = props;
  6445. if (klass && !isString(klass)) {
  6446. props.class = normalizeClass(klass);
  6447. }
  6448. if (isObject(style)) {
  6449. // reactive state objects need to be cloned since they are likely to be
  6450. // mutated
  6451. if (isProxy(style) && !isArray(style)) {
  6452. style = extend({}, style);
  6453. }
  6454. props.style = normalizeStyle(style);
  6455. }
  6456. }
  6457. // encode the vnode type information into a bitmap
  6458. const shapeFlag = isString(type)
  6459. ? 1 /* ELEMENT */
  6460. : isSuspense(type)
  6461. ? 128 /* SUSPENSE */
  6462. : isTeleport(type)
  6463. ? 64 /* TELEPORT */
  6464. : isObject(type)
  6465. ? 4 /* STATEFUL_COMPONENT */
  6466. : isFunction(type)
  6467. ? 2 /* FUNCTIONAL_COMPONENT */
  6468. : 0;
  6469. if (shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  6470. type = toRaw(type);
  6471. warn(`Vue received a Component which was made a reactive object. This can ` +
  6472. `lead to unnecessary performance overhead, and should be avoided by ` +
  6473. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  6474. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  6475. }
  6476. const vnode = {
  6477. __v_isVNode: true,
  6478. ["__v_skip" /* SKIP */]: true,
  6479. type,
  6480. props,
  6481. key: props && normalizeKey(props),
  6482. ref: props && normalizeRef(props),
  6483. scopeId: currentScopeId,
  6484. children: null,
  6485. component: null,
  6486. suspense: null,
  6487. ssContent: null,
  6488. ssFallback: null,
  6489. dirs: null,
  6490. transition: null,
  6491. el: null,
  6492. anchor: null,
  6493. target: null,
  6494. targetAnchor: null,
  6495. staticCount: 0,
  6496. shapeFlag,
  6497. patchFlag,
  6498. dynamicProps,
  6499. dynamicChildren: null,
  6500. appContext: null
  6501. };
  6502. // validate key
  6503. if (vnode.key !== vnode.key) {
  6504. warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  6505. }
  6506. normalizeChildren(vnode, children);
  6507. // normalize suspense children
  6508. if (shapeFlag & 128 /* SUSPENSE */) {
  6509. const { content, fallback } = normalizeSuspenseChildren(vnode);
  6510. vnode.ssContent = content;
  6511. vnode.ssFallback = fallback;
  6512. }
  6513. if (shouldTrack$1 > 0 &&
  6514. // avoid a block node from tracking itself
  6515. !isBlockNode &&
  6516. // has current parent block
  6517. currentBlock &&
  6518. // presence of a patch flag indicates this node needs patching on updates.
  6519. // component nodes also should always be patched, because even if the
  6520. // component doesn't need to update, it needs to persist the instance on to
  6521. // the next vnode so that it can be properly unmounted later.
  6522. (patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  6523. // the EVENTS flag is only for hydration and if it is the only flag, the
  6524. // vnode should not be considered dynamic due to handler caching.
  6525. patchFlag !== 32 /* HYDRATE_EVENTS */) {
  6526. currentBlock.push(vnode);
  6527. }
  6528. return vnode;
  6529. }
  6530. function cloneVNode(vnode, extraProps, mergeRef = false) {
  6531. // This is intentionally NOT using spread or extend to avoid the runtime
  6532. // key enumeration cost.
  6533. const { props, ref, patchFlag, children } = vnode;
  6534. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  6535. return {
  6536. __v_isVNode: true,
  6537. ["__v_skip" /* SKIP */]: true,
  6538. type: vnode.type,
  6539. props: mergedProps,
  6540. key: mergedProps && normalizeKey(mergedProps),
  6541. ref: extraProps && extraProps.ref
  6542. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  6543. // if the vnode itself already has a ref, cloneVNode will need to merge
  6544. // the refs so the single vnode can be set on multiple refs
  6545. mergeRef && ref
  6546. ? isArray(ref)
  6547. ? ref.concat(normalizeRef(extraProps))
  6548. : [ref, normalizeRef(extraProps)]
  6549. : normalizeRef(extraProps)
  6550. : ref,
  6551. scopeId: vnode.scopeId,
  6552. children: patchFlag === -1 /* HOISTED */ && isArray(children)
  6553. ? children.map(deepCloneVNode)
  6554. : children,
  6555. target: vnode.target,
  6556. targetAnchor: vnode.targetAnchor,
  6557. staticCount: vnode.staticCount,
  6558. shapeFlag: vnode.shapeFlag,
  6559. // if the vnode is cloned with extra props, we can no longer assume its
  6560. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  6561. // note: perserve flag for fragments since they use the flag for children
  6562. // fast paths only.
  6563. patchFlag: extraProps && vnode.type !== Fragment
  6564. ? patchFlag === -1 // hoisted node
  6565. ? 16 /* FULL_PROPS */
  6566. : patchFlag | 16 /* FULL_PROPS */
  6567. : patchFlag,
  6568. dynamicProps: vnode.dynamicProps,
  6569. dynamicChildren: vnode.dynamicChildren,
  6570. appContext: vnode.appContext,
  6571. dirs: vnode.dirs,
  6572. transition: vnode.transition,
  6573. // These should technically only be non-null on mounted VNodes. However,
  6574. // they *should* be copied for kept-alive vnodes. So we just always copy
  6575. // them since them being non-null during a mount doesn't affect the logic as
  6576. // they will simply be overwritten.
  6577. component: vnode.component,
  6578. suspense: vnode.suspense,
  6579. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  6580. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  6581. el: vnode.el,
  6582. anchor: vnode.anchor
  6583. };
  6584. }
  6585. /**
  6586. * Dev only, for HMR of hoisted vnodes reused in v-for
  6587. * https://github.com/vitejs/vite/issues/2022
  6588. */
  6589. function deepCloneVNode(vnode) {
  6590. const cloned = cloneVNode(vnode);
  6591. if (isArray(vnode.children)) {
  6592. cloned.children = vnode.children.map(deepCloneVNode);
  6593. }
  6594. return cloned;
  6595. }
  6596. /**
  6597. * @private
  6598. */
  6599. function createTextVNode(text = ' ', flag = 0) {
  6600. return createVNode(Text, null, text, flag);
  6601. }
  6602. /**
  6603. * @private
  6604. */
  6605. function createStaticVNode(content, numberOfNodes) {
  6606. // A static vnode can contain multiple stringified elements, and the number
  6607. // of elements is necessary for hydration.
  6608. const vnode = createVNode(Static, null, content);
  6609. vnode.staticCount = numberOfNodes;
  6610. return vnode;
  6611. }
  6612. /**
  6613. * @private
  6614. */
  6615. function createCommentVNode(text = '',
  6616. // when used as the v-else branch, the comment node must be created as a
  6617. // block to ensure correct updates.
  6618. asBlock = false) {
  6619. return asBlock
  6620. ? (openBlock(), createBlock(Comment, null, text))
  6621. : createVNode(Comment, null, text);
  6622. }
  6623. function normalizeVNode(child) {
  6624. if (child == null || typeof child === 'boolean') {
  6625. // empty placeholder
  6626. return createVNode(Comment);
  6627. }
  6628. else if (isArray(child)) {
  6629. // fragment
  6630. return createVNode(Fragment, null, child);
  6631. }
  6632. else if (typeof child === 'object') {
  6633. // already vnode, this should be the most common since compiled templates
  6634. // always produce all-vnode children arrays
  6635. return child.el === null ? child : cloneVNode(child);
  6636. }
  6637. else {
  6638. // strings and numbers
  6639. return createVNode(Text, null, String(child));
  6640. }
  6641. }
  6642. // optimized normalization for template-compiled render fns
  6643. function cloneIfMounted(child) {
  6644. return child.el === null ? child : cloneVNode(child);
  6645. }
  6646. function normalizeChildren(vnode, children) {
  6647. let type = 0;
  6648. const { shapeFlag } = vnode;
  6649. if (children == null) {
  6650. children = null;
  6651. }
  6652. else if (isArray(children)) {
  6653. type = 16 /* ARRAY_CHILDREN */;
  6654. }
  6655. else if (typeof children === 'object') {
  6656. if (shapeFlag & 1 /* ELEMENT */ || shapeFlag & 64 /* TELEPORT */) {
  6657. // Normalize slot to plain children for plain element and Teleport
  6658. const slot = children.default;
  6659. if (slot) {
  6660. // _c marker is added by withCtx() indicating this is a compiled slot
  6661. slot._c && setCompiledSlotRendering(1);
  6662. normalizeChildren(vnode, slot());
  6663. slot._c && setCompiledSlotRendering(-1);
  6664. }
  6665. return;
  6666. }
  6667. else {
  6668. type = 32 /* SLOTS_CHILDREN */;
  6669. const slotFlag = children._;
  6670. if (!slotFlag && !(InternalObjectKey in children)) {
  6671. children._ctx = currentRenderingInstance;
  6672. }
  6673. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  6674. // a child component receives forwarded slots from the parent.
  6675. // its slot type is determined by its parent's slot type.
  6676. if (currentRenderingInstance.vnode.patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  6677. children._ = 2 /* DYNAMIC */;
  6678. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  6679. }
  6680. else {
  6681. children._ = 1 /* STABLE */;
  6682. }
  6683. }
  6684. }
  6685. }
  6686. else if (isFunction(children)) {
  6687. children = { default: children, _ctx: currentRenderingInstance };
  6688. type = 32 /* SLOTS_CHILDREN */;
  6689. }
  6690. else {
  6691. children = String(children);
  6692. // force teleport children to array so it can be moved around
  6693. if (shapeFlag & 64 /* TELEPORT */) {
  6694. type = 16 /* ARRAY_CHILDREN */;
  6695. children = [createTextVNode(children)];
  6696. }
  6697. else {
  6698. type = 8 /* TEXT_CHILDREN */;
  6699. }
  6700. }
  6701. vnode.children = children;
  6702. vnode.shapeFlag |= type;
  6703. }
  6704. function mergeProps(...args) {
  6705. const ret = extend({}, args[0]);
  6706. for (let i = 1; i < args.length; i++) {
  6707. const toMerge = args[i];
  6708. for (const key in toMerge) {
  6709. if (key === 'class') {
  6710. if (ret.class !== toMerge.class) {
  6711. ret.class = normalizeClass([ret.class, toMerge.class]);
  6712. }
  6713. }
  6714. else if (key === 'style') {
  6715. ret.style = normalizeStyle([ret.style, toMerge.style]);
  6716. }
  6717. else if (isOn(key)) {
  6718. const existing = ret[key];
  6719. const incoming = toMerge[key];
  6720. if (existing !== incoming) {
  6721. ret[key] = existing
  6722. ? [].concat(existing, toMerge[key])
  6723. : incoming;
  6724. }
  6725. }
  6726. else if (key !== '') {
  6727. ret[key] = toMerge[key];
  6728. }
  6729. }
  6730. }
  6731. return ret;
  6732. }
  6733. function provide(key, value) {
  6734. if (!currentInstance) {
  6735. {
  6736. warn(`provide() can only be used inside setup().`);
  6737. }
  6738. }
  6739. else {
  6740. let provides = currentInstance.provides;
  6741. // by default an instance inherits its parent's provides object
  6742. // but when it needs to provide values of its own, it creates its
  6743. // own provides object using parent provides object as prototype.
  6744. // this way in `inject` we can simply look up injections from direct
  6745. // parent and let the prototype chain do the work.
  6746. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  6747. if (parentProvides === provides) {
  6748. provides = currentInstance.provides = Object.create(parentProvides);
  6749. }
  6750. // TS doesn't allow symbol as index type
  6751. provides[key] = value;
  6752. }
  6753. }
  6754. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  6755. // fallback to `currentRenderingInstance` so that this can be called in
  6756. // a functional component
  6757. const instance = currentInstance || currentRenderingInstance;
  6758. if (instance) {
  6759. // #2400
  6760. // to support `app.use` plugins,
  6761. // fallback to appContext's `provides` if the intance is at root
  6762. const provides = instance.parent == null
  6763. ? instance.vnode.appContext && instance.vnode.appContext.provides
  6764. : instance.parent.provides;
  6765. if (provides && key in provides) {
  6766. // TS doesn't allow symbol as index type
  6767. return provides[key];
  6768. }
  6769. else if (arguments.length > 1) {
  6770. return treatDefaultAsFactory && isFunction(defaultValue)
  6771. ? defaultValue()
  6772. : defaultValue;
  6773. }
  6774. else {
  6775. warn(`injection "${String(key)}" not found.`);
  6776. }
  6777. }
  6778. else {
  6779. warn(`inject() can only be used inside setup() or functional components.`);
  6780. }
  6781. }
  6782. function createDuplicateChecker() {
  6783. const cache = Object.create(null);
  6784. return (type, key) => {
  6785. if (cache[key]) {
  6786. warn(`${type} property "${key}" is already defined in ${cache[key]}.`);
  6787. }
  6788. else {
  6789. cache[key] = type;
  6790. }
  6791. };
  6792. }
  6793. let isInBeforeCreate = false;
  6794. function applyOptions(instance, options, deferredData = [], deferredWatch = [], deferredProvide = [], asMixin = false) {
  6795. const {
  6796. // composition
  6797. mixins, extends: extendsOptions,
  6798. // state
  6799. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  6800. // assets
  6801. components, directives,
  6802. // lifecycle
  6803. beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured,
  6804. // public API
  6805. expose } = options;
  6806. const publicThis = instance.proxy;
  6807. const ctx = instance.ctx;
  6808. const globalMixins = instance.appContext.mixins;
  6809. if (asMixin && render && instance.render === NOOP) {
  6810. instance.render = render;
  6811. }
  6812. // applyOptions is called non-as-mixin once per instance
  6813. if (!asMixin) {
  6814. isInBeforeCreate = true;
  6815. callSyncHook('beforeCreate', "bc" /* BEFORE_CREATE */, options, instance, globalMixins);
  6816. isInBeforeCreate = false;
  6817. // global mixins are applied first
  6818. applyMixins(instance, globalMixins, deferredData, deferredWatch, deferredProvide);
  6819. }
  6820. // extending a base component...
  6821. if (extendsOptions) {
  6822. applyOptions(instance, extendsOptions, deferredData, deferredWatch, deferredProvide, true);
  6823. }
  6824. // local mixins
  6825. if (mixins) {
  6826. applyMixins(instance, mixins, deferredData, deferredWatch, deferredProvide);
  6827. }
  6828. const checkDuplicateProperties = createDuplicateChecker() ;
  6829. {
  6830. const [propsOptions] = instance.propsOptions;
  6831. if (propsOptions) {
  6832. for (const key in propsOptions) {
  6833. checkDuplicateProperties("Props" /* PROPS */, key);
  6834. }
  6835. }
  6836. }
  6837. // options initialization order (to be consistent with Vue 2):
  6838. // - props (already done outside of this function)
  6839. // - inject
  6840. // - methods
  6841. // - data (deferred since it relies on `this` access)
  6842. // - computed
  6843. // - watch (deferred since it relies on `this` access)
  6844. if (injectOptions) {
  6845. if (isArray(injectOptions)) {
  6846. for (let i = 0; i < injectOptions.length; i++) {
  6847. const key = injectOptions[i];
  6848. ctx[key] = inject(key);
  6849. {
  6850. checkDuplicateProperties("Inject" /* INJECT */, key);
  6851. }
  6852. }
  6853. }
  6854. else {
  6855. for (const key in injectOptions) {
  6856. const opt = injectOptions[key];
  6857. if (isObject(opt)) {
  6858. ctx[key] = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  6859. }
  6860. else {
  6861. ctx[key] = inject(opt);
  6862. }
  6863. {
  6864. checkDuplicateProperties("Inject" /* INJECT */, key);
  6865. }
  6866. }
  6867. }
  6868. }
  6869. if (methods) {
  6870. for (const key in methods) {
  6871. const methodHandler = methods[key];
  6872. if (isFunction(methodHandler)) {
  6873. // In dev mode, we use the `createRenderContext` function to define methods to the proxy target,
  6874. // and those are read-only but reconfigurable, so it needs to be redefined here
  6875. {
  6876. Object.defineProperty(ctx, key, {
  6877. value: methodHandler.bind(publicThis),
  6878. configurable: true,
  6879. enumerable: true,
  6880. writable: true
  6881. });
  6882. }
  6883. {
  6884. checkDuplicateProperties("Methods" /* METHODS */, key);
  6885. }
  6886. }
  6887. else {
  6888. warn(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  6889. `Did you reference the function correctly?`);
  6890. }
  6891. }
  6892. }
  6893. if (!asMixin) {
  6894. if (deferredData.length) {
  6895. deferredData.forEach(dataFn => resolveData(instance, dataFn, publicThis));
  6896. }
  6897. if (dataOptions) {
  6898. // @ts-ignore dataOptions is not fully type safe
  6899. resolveData(instance, dataOptions, publicThis);
  6900. }
  6901. {
  6902. const rawData = toRaw(instance.data);
  6903. for (const key in rawData) {
  6904. checkDuplicateProperties("Data" /* DATA */, key);
  6905. // expose data on ctx during dev
  6906. if (key[0] !== '$' && key[0] !== '_') {
  6907. Object.defineProperty(ctx, key, {
  6908. configurable: true,
  6909. enumerable: true,
  6910. get: () => rawData[key],
  6911. set: NOOP
  6912. });
  6913. }
  6914. }
  6915. }
  6916. }
  6917. else if (dataOptions) {
  6918. deferredData.push(dataOptions);
  6919. }
  6920. if (computedOptions) {
  6921. for (const key in computedOptions) {
  6922. const opt = computedOptions[key];
  6923. const get = isFunction(opt)
  6924. ? opt.bind(publicThis, publicThis)
  6925. : isFunction(opt.get)
  6926. ? opt.get.bind(publicThis, publicThis)
  6927. : NOOP;
  6928. if (get === NOOP) {
  6929. warn(`Computed property "${key}" has no getter.`);
  6930. }
  6931. const set = !isFunction(opt) && isFunction(opt.set)
  6932. ? opt.set.bind(publicThis)
  6933. : () => {
  6934. warn(`Write operation failed: computed property "${key}" is readonly.`);
  6935. }
  6936. ;
  6937. const c = computed$1({
  6938. get,
  6939. set
  6940. });
  6941. Object.defineProperty(ctx, key, {
  6942. enumerable: true,
  6943. configurable: true,
  6944. get: () => c.value,
  6945. set: v => (c.value = v)
  6946. });
  6947. {
  6948. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  6949. }
  6950. }
  6951. }
  6952. if (watchOptions) {
  6953. deferredWatch.push(watchOptions);
  6954. }
  6955. if (!asMixin && deferredWatch.length) {
  6956. deferredWatch.forEach(watchOptions => {
  6957. for (const key in watchOptions) {
  6958. createWatcher(watchOptions[key], ctx, publicThis, key);
  6959. }
  6960. });
  6961. }
  6962. if (provideOptions) {
  6963. deferredProvide.push(provideOptions);
  6964. }
  6965. if (!asMixin && deferredProvide.length) {
  6966. deferredProvide.forEach(provideOptions => {
  6967. const provides = isFunction(provideOptions)
  6968. ? provideOptions.call(publicThis)
  6969. : provideOptions;
  6970. Reflect.ownKeys(provides).forEach(key => {
  6971. provide(key, provides[key]);
  6972. });
  6973. });
  6974. }
  6975. // asset options.
  6976. // To reduce memory usage, only components with mixins or extends will have
  6977. // resolved asset registry attached to instance.
  6978. if (asMixin) {
  6979. if (components) {
  6980. extend(instance.components ||
  6981. (instance.components = extend({}, instance.type.components)), components);
  6982. }
  6983. if (directives) {
  6984. extend(instance.directives ||
  6985. (instance.directives = extend({}, instance.type.directives)), directives);
  6986. }
  6987. }
  6988. // lifecycle options
  6989. if (!asMixin) {
  6990. callSyncHook('created', "c" /* CREATED */, options, instance, globalMixins);
  6991. }
  6992. if (beforeMount) {
  6993. onBeforeMount(beforeMount.bind(publicThis));
  6994. }
  6995. if (mounted) {
  6996. onMounted(mounted.bind(publicThis));
  6997. }
  6998. if (beforeUpdate) {
  6999. onBeforeUpdate(beforeUpdate.bind(publicThis));
  7000. }
  7001. if (updated) {
  7002. onUpdated(updated.bind(publicThis));
  7003. }
  7004. if (activated) {
  7005. onActivated(activated.bind(publicThis));
  7006. }
  7007. if (deactivated) {
  7008. onDeactivated(deactivated.bind(publicThis));
  7009. }
  7010. if (errorCaptured) {
  7011. onErrorCaptured(errorCaptured.bind(publicThis));
  7012. }
  7013. if (renderTracked) {
  7014. onRenderTracked(renderTracked.bind(publicThis));
  7015. }
  7016. if (renderTriggered) {
  7017. onRenderTriggered(renderTriggered.bind(publicThis));
  7018. }
  7019. if (beforeDestroy) {
  7020. warn(`\`beforeDestroy\` has been renamed to \`beforeUnmount\`.`);
  7021. }
  7022. if (beforeUnmount) {
  7023. onBeforeUnmount(beforeUnmount.bind(publicThis));
  7024. }
  7025. if (destroyed) {
  7026. warn(`\`destroyed\` has been renamed to \`unmounted\`.`);
  7027. }
  7028. if (unmounted) {
  7029. onUnmounted(unmounted.bind(publicThis));
  7030. }
  7031. if (isArray(expose)) {
  7032. if (!asMixin) {
  7033. if (expose.length) {
  7034. const exposed = instance.exposed || (instance.exposed = proxyRefs({}));
  7035. expose.forEach(key => {
  7036. exposed[key] = toRef(publicThis, key);
  7037. });
  7038. }
  7039. else if (!instance.exposed) {
  7040. instance.exposed = EMPTY_OBJ;
  7041. }
  7042. }
  7043. else {
  7044. warn(`The \`expose\` option is ignored when used in mixins.`);
  7045. }
  7046. }
  7047. }
  7048. function callSyncHook(name, type, options, instance, globalMixins) {
  7049. callHookFromMixins(name, type, globalMixins, instance);
  7050. const { extends: base, mixins } = options;
  7051. if (base) {
  7052. callHookFromExtends(name, type, base, instance);
  7053. }
  7054. if (mixins) {
  7055. callHookFromMixins(name, type, mixins, instance);
  7056. }
  7057. const selfHook = options[name];
  7058. if (selfHook) {
  7059. callWithAsyncErrorHandling(selfHook.bind(instance.proxy), instance, type);
  7060. }
  7061. }
  7062. function callHookFromExtends(name, type, base, instance) {
  7063. if (base.extends) {
  7064. callHookFromExtends(name, type, base.extends, instance);
  7065. }
  7066. const baseHook = base[name];
  7067. if (baseHook) {
  7068. callWithAsyncErrorHandling(baseHook.bind(instance.proxy), instance, type);
  7069. }
  7070. }
  7071. function callHookFromMixins(name, type, mixins, instance) {
  7072. for (let i = 0; i < mixins.length; i++) {
  7073. const chainedMixins = mixins[i].mixins;
  7074. if (chainedMixins) {
  7075. callHookFromMixins(name, type, chainedMixins, instance);
  7076. }
  7077. const fn = mixins[i][name];
  7078. if (fn) {
  7079. callWithAsyncErrorHandling(fn.bind(instance.proxy), instance, type);
  7080. }
  7081. }
  7082. }
  7083. function applyMixins(instance, mixins, deferredData, deferredWatch, deferredProvide) {
  7084. for (let i = 0; i < mixins.length; i++) {
  7085. applyOptions(instance, mixins[i], deferredData, deferredWatch, deferredProvide, true);
  7086. }
  7087. }
  7088. function resolveData(instance, dataFn, publicThis) {
  7089. if (!isFunction(dataFn)) {
  7090. warn(`The data option must be a function. ` +
  7091. `Plain object usage is no longer supported.`);
  7092. }
  7093. const data = dataFn.call(publicThis, publicThis);
  7094. if (isPromise(data)) {
  7095. warn(`data() returned a Promise - note data() cannot be async; If you ` +
  7096. `intend to perform data fetching before component renders, use ` +
  7097. `async setup() + <Suspense>.`);
  7098. }
  7099. if (!isObject(data)) {
  7100. warn(`data() should return an object.`);
  7101. }
  7102. else if (instance.data === EMPTY_OBJ) {
  7103. instance.data = reactive(data);
  7104. }
  7105. else {
  7106. // existing data: this is a mixin or extends.
  7107. extend(instance.data, data);
  7108. }
  7109. }
  7110. function createWatcher(raw, ctx, publicThis, key) {
  7111. const getter = key.includes('.')
  7112. ? createPathGetter(publicThis, key)
  7113. : () => publicThis[key];
  7114. if (isString(raw)) {
  7115. const handler = ctx[raw];
  7116. if (isFunction(handler)) {
  7117. watch(getter, handler);
  7118. }
  7119. else {
  7120. warn(`Invalid watch handler specified by key "${raw}"`, handler);
  7121. }
  7122. }
  7123. else if (isFunction(raw)) {
  7124. watch(getter, raw.bind(publicThis));
  7125. }
  7126. else if (isObject(raw)) {
  7127. if (isArray(raw)) {
  7128. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  7129. }
  7130. else {
  7131. const handler = isFunction(raw.handler)
  7132. ? raw.handler.bind(publicThis)
  7133. : ctx[raw.handler];
  7134. if (isFunction(handler)) {
  7135. watch(getter, handler, raw);
  7136. }
  7137. else {
  7138. warn(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  7139. }
  7140. }
  7141. }
  7142. else {
  7143. warn(`Invalid watch option: "${key}"`, raw);
  7144. }
  7145. }
  7146. function createPathGetter(ctx, path) {
  7147. const segments = path.split('.');
  7148. return () => {
  7149. let cur = ctx;
  7150. for (let i = 0; i < segments.length && cur; i++) {
  7151. cur = cur[segments[i]];
  7152. }
  7153. return cur;
  7154. };
  7155. }
  7156. function resolveMergedOptions(instance) {
  7157. const raw = instance.type;
  7158. const { __merged, mixins, extends: extendsOptions } = raw;
  7159. if (__merged)
  7160. return __merged;
  7161. const globalMixins = instance.appContext.mixins;
  7162. if (!globalMixins.length && !mixins && !extendsOptions)
  7163. return raw;
  7164. const options = {};
  7165. globalMixins.forEach(m => mergeOptions(options, m, instance));
  7166. mergeOptions(options, raw, instance);
  7167. return (raw.__merged = options);
  7168. }
  7169. function mergeOptions(to, from, instance) {
  7170. const strats = instance.appContext.config.optionMergeStrategies;
  7171. const { mixins, extends: extendsOptions } = from;
  7172. extendsOptions && mergeOptions(to, extendsOptions, instance);
  7173. mixins &&
  7174. mixins.forEach((m) => mergeOptions(to, m, instance));
  7175. for (const key in from) {
  7176. if (strats && hasOwn(strats, key)) {
  7177. to[key] = strats[key](to[key], from[key], instance.proxy, key);
  7178. }
  7179. else {
  7180. to[key] = from[key];
  7181. }
  7182. }
  7183. }
  7184. /**
  7185. * #2437 In Vue 3, functional components do not have a public instance proxy but
  7186. * they exist in the internal parent chain. For code that relies on traversing
  7187. * public $parent chains, skip functional ones and go to the parent instead.
  7188. */
  7189. const getPublicInstance = (i) => {
  7190. if (!i)
  7191. return null;
  7192. if (isStatefulComponent(i))
  7193. return i.exposed ? i.exposed : i.proxy;
  7194. return getPublicInstance(i.parent);
  7195. };
  7196. const publicPropertiesMap = extend(Object.create(null), {
  7197. $: i => i,
  7198. $el: i => i.vnode.el,
  7199. $data: i => i.data,
  7200. $props: i => (shallowReadonly(i.props) ),
  7201. $attrs: i => (shallowReadonly(i.attrs) ),
  7202. $slots: i => (shallowReadonly(i.slots) ),
  7203. $refs: i => (shallowReadonly(i.refs) ),
  7204. $parent: i => getPublicInstance(i.parent),
  7205. $root: i => getPublicInstance(i.root),
  7206. $emit: i => i.emit,
  7207. $options: i => (resolveMergedOptions(i) ),
  7208. $forceUpdate: i => () => queueJob(i.update),
  7209. $nextTick: i => nextTick.bind(i.proxy),
  7210. $watch: i => (instanceWatch.bind(i) )
  7211. });
  7212. const PublicInstanceProxyHandlers = {
  7213. get({ _: instance }, key) {
  7214. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  7215. // let @vue/reactivity know it should never observe Vue public instances.
  7216. if (key === "__v_skip" /* SKIP */) {
  7217. return true;
  7218. }
  7219. // for internal formatters to know that this is a Vue instance
  7220. if (key === '__isVue') {
  7221. return true;
  7222. }
  7223. // data / props / ctx
  7224. // This getter gets called for every property access on the render context
  7225. // during render and is a major hotspot. The most expensive part of this
  7226. // is the multiple hasOwn() calls. It's much faster to do a simple property
  7227. // access on a plain object, so we use an accessCache object (with null
  7228. // prototype) to memoize what access type a key corresponds to.
  7229. let normalizedProps;
  7230. if (key[0] !== '$') {
  7231. const n = accessCache[key];
  7232. if (n !== undefined) {
  7233. switch (n) {
  7234. case 0 /* SETUP */:
  7235. return setupState[key];
  7236. case 1 /* DATA */:
  7237. return data[key];
  7238. case 3 /* CONTEXT */:
  7239. return ctx[key];
  7240. case 2 /* PROPS */:
  7241. return props[key];
  7242. // default: just fallthrough
  7243. }
  7244. }
  7245. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  7246. accessCache[key] = 0 /* SETUP */;
  7247. return setupState[key];
  7248. }
  7249. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  7250. accessCache[key] = 1 /* DATA */;
  7251. return data[key];
  7252. }
  7253. else if (
  7254. // only cache other properties when instance has declared (thus stable)
  7255. // props
  7256. (normalizedProps = instance.propsOptions[0]) &&
  7257. hasOwn(normalizedProps, key)) {
  7258. accessCache[key] = 2 /* PROPS */;
  7259. return props[key];
  7260. }
  7261. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  7262. accessCache[key] = 3 /* CONTEXT */;
  7263. return ctx[key];
  7264. }
  7265. else if (!isInBeforeCreate) {
  7266. accessCache[key] = 4 /* OTHER */;
  7267. }
  7268. }
  7269. const publicGetter = publicPropertiesMap[key];
  7270. let cssModule, globalProperties;
  7271. // public $xxx properties
  7272. if (publicGetter) {
  7273. if (key === '$attrs') {
  7274. track(instance, "get" /* GET */, key);
  7275. markAttrsAccessed();
  7276. }
  7277. return publicGetter(instance);
  7278. }
  7279. else if (
  7280. // css module (injected by vue-loader)
  7281. (cssModule = type.__cssModules) &&
  7282. (cssModule = cssModule[key])) {
  7283. return cssModule;
  7284. }
  7285. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  7286. // user may set custom properties to `this` that start with `$`
  7287. accessCache[key] = 3 /* CONTEXT */;
  7288. return ctx[key];
  7289. }
  7290. else if (
  7291. // global properties
  7292. ((globalProperties = appContext.config.globalProperties),
  7293. hasOwn(globalProperties, key))) {
  7294. return globalProperties[key];
  7295. }
  7296. else if (currentRenderingInstance &&
  7297. (!isString(key) ||
  7298. // #1091 avoid internal isRef/isVNode checks on component instance leading
  7299. // to infinite warning loop
  7300. key.indexOf('__v') !== 0)) {
  7301. if (data !== EMPTY_OBJ &&
  7302. (key[0] === '$' || key[0] === '_') &&
  7303. hasOwn(data, key)) {
  7304. warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  7305. `character ("$" or "_") and is not proxied on the render context.`);
  7306. }
  7307. else if (instance === currentRenderingInstance) {
  7308. warn(`Property ${JSON.stringify(key)} was accessed during render ` +
  7309. `but is not defined on instance.`);
  7310. }
  7311. }
  7312. },
  7313. set({ _: instance }, key, value) {
  7314. const { data, setupState, ctx } = instance;
  7315. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  7316. setupState[key] = value;
  7317. }
  7318. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  7319. data[key] = value;
  7320. }
  7321. else if (hasOwn(instance.props, key)) {
  7322. warn(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  7323. return false;
  7324. }
  7325. if (key[0] === '$' && key.slice(1) in instance) {
  7326. warn(`Attempting to mutate public property "${key}". ` +
  7327. `Properties starting with $ are reserved and readonly.`, instance);
  7328. return false;
  7329. }
  7330. else {
  7331. if (key in instance.appContext.config.globalProperties) {
  7332. Object.defineProperty(ctx, key, {
  7333. enumerable: true,
  7334. configurable: true,
  7335. value
  7336. });
  7337. }
  7338. else {
  7339. ctx[key] = value;
  7340. }
  7341. }
  7342. return true;
  7343. },
  7344. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  7345. let normalizedProps;
  7346. return (accessCache[key] !== undefined ||
  7347. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  7348. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  7349. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  7350. hasOwn(ctx, key) ||
  7351. hasOwn(publicPropertiesMap, key) ||
  7352. hasOwn(appContext.config.globalProperties, key));
  7353. }
  7354. };
  7355. {
  7356. PublicInstanceProxyHandlers.ownKeys = (target) => {
  7357. warn(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  7358. `The keys will be empty in production mode to avoid performance overhead.`);
  7359. return Reflect.ownKeys(target);
  7360. };
  7361. }
  7362. const RuntimeCompiledPublicInstanceProxyHandlers = extend({}, PublicInstanceProxyHandlers, {
  7363. get(target, key) {
  7364. // fast path for unscopables when using `with` block
  7365. if (key === Symbol.unscopables) {
  7366. return;
  7367. }
  7368. return PublicInstanceProxyHandlers.get(target, key, target);
  7369. },
  7370. has(_, key) {
  7371. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  7372. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  7373. warn(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  7374. }
  7375. return has;
  7376. }
  7377. });
  7378. // In dev mode, the proxy target exposes the same properties as seen on `this`
  7379. // for easier console inspection. In prod mode it will be an empty object so
  7380. // these properties definitions can be skipped.
  7381. function createRenderContext(instance) {
  7382. const target = {};
  7383. // expose internal instance for proxy handlers
  7384. Object.defineProperty(target, `_`, {
  7385. configurable: true,
  7386. enumerable: false,
  7387. get: () => instance
  7388. });
  7389. // expose public properties
  7390. Object.keys(publicPropertiesMap).forEach(key => {
  7391. Object.defineProperty(target, key, {
  7392. configurable: true,
  7393. enumerable: false,
  7394. get: () => publicPropertiesMap[key](instance),
  7395. // intercepted by the proxy so no need for implementation,
  7396. // but needed to prevent set errors
  7397. set: NOOP
  7398. });
  7399. });
  7400. // expose global properties
  7401. const { globalProperties } = instance.appContext.config;
  7402. Object.keys(globalProperties).forEach(key => {
  7403. Object.defineProperty(target, key, {
  7404. configurable: true,
  7405. enumerable: false,
  7406. get: () => globalProperties[key],
  7407. set: NOOP
  7408. });
  7409. });
  7410. return target;
  7411. }
  7412. // dev only
  7413. function exposePropsOnRenderContext(instance) {
  7414. const { ctx, propsOptions: [propsOptions] } = instance;
  7415. if (propsOptions) {
  7416. Object.keys(propsOptions).forEach(key => {
  7417. Object.defineProperty(ctx, key, {
  7418. enumerable: true,
  7419. configurable: true,
  7420. get: () => instance.props[key],
  7421. set: NOOP
  7422. });
  7423. });
  7424. }
  7425. }
  7426. // dev only
  7427. function exposeSetupStateOnRenderContext(instance) {
  7428. const { ctx, setupState } = instance;
  7429. Object.keys(toRaw(setupState)).forEach(key => {
  7430. if (key[0] === '$' || key[0] === '_') {
  7431. warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  7432. `which are reserved prefixes for Vue internals.`);
  7433. return;
  7434. }
  7435. Object.defineProperty(ctx, key, {
  7436. enumerable: true,
  7437. configurable: true,
  7438. get: () => setupState[key],
  7439. set: NOOP
  7440. });
  7441. });
  7442. }
  7443. const emptyAppContext = createAppContext();
  7444. let uid$2 = 0;
  7445. function createComponentInstance(vnode, parent, suspense) {
  7446. const type = vnode.type;
  7447. // inherit parent app context - or - if root, adopt from root vnode
  7448. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  7449. const instance = {
  7450. uid: uid$2++,
  7451. vnode,
  7452. type,
  7453. parent,
  7454. appContext,
  7455. root: null,
  7456. next: null,
  7457. subTree: null,
  7458. update: null,
  7459. render: null,
  7460. proxy: null,
  7461. exposed: null,
  7462. withProxy: null,
  7463. effects: null,
  7464. provides: parent ? parent.provides : Object.create(appContext.provides),
  7465. accessCache: null,
  7466. renderCache: [],
  7467. // local resovled assets
  7468. components: null,
  7469. directives: null,
  7470. // resolved props and emits options
  7471. propsOptions: normalizePropsOptions(type, appContext),
  7472. emitsOptions: normalizeEmitsOptions(type, appContext),
  7473. // emit
  7474. emit: null,
  7475. emitted: null,
  7476. // state
  7477. ctx: EMPTY_OBJ,
  7478. data: EMPTY_OBJ,
  7479. props: EMPTY_OBJ,
  7480. attrs: EMPTY_OBJ,
  7481. slots: EMPTY_OBJ,
  7482. refs: EMPTY_OBJ,
  7483. setupState: EMPTY_OBJ,
  7484. setupContext: null,
  7485. // suspense related
  7486. suspense,
  7487. suspenseId: suspense ? suspense.pendingId : 0,
  7488. asyncDep: null,
  7489. asyncResolved: false,
  7490. // lifecycle hooks
  7491. // not using enums here because it results in computed properties
  7492. isMounted: false,
  7493. isUnmounted: false,
  7494. isDeactivated: false,
  7495. bc: null,
  7496. c: null,
  7497. bm: null,
  7498. m: null,
  7499. bu: null,
  7500. u: null,
  7501. um: null,
  7502. bum: null,
  7503. da: null,
  7504. a: null,
  7505. rtg: null,
  7506. rtc: null,
  7507. ec: null
  7508. };
  7509. {
  7510. instance.ctx = createRenderContext(instance);
  7511. }
  7512. instance.root = parent ? parent.root : instance;
  7513. instance.emit = emit.bind(null, instance);
  7514. return instance;
  7515. }
  7516. let currentInstance = null;
  7517. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  7518. const setCurrentInstance = (instance) => {
  7519. currentInstance = instance;
  7520. };
  7521. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  7522. function validateComponentName(name, config) {
  7523. const appIsNativeTag = config.isNativeTag || NO;
  7524. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  7525. warn('Do not use built-in or reserved HTML elements as component id: ' + name);
  7526. }
  7527. }
  7528. function isStatefulComponent(instance) {
  7529. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  7530. }
  7531. let isInSSRComponentSetup = false;
  7532. function setupComponent(instance, isSSR = false) {
  7533. isInSSRComponentSetup = isSSR;
  7534. const { props, children } = instance.vnode;
  7535. const isStateful = isStatefulComponent(instance);
  7536. initProps(instance, props, isStateful, isSSR);
  7537. initSlots(instance, children);
  7538. const setupResult = isStateful
  7539. ? setupStatefulComponent(instance, isSSR)
  7540. : undefined;
  7541. isInSSRComponentSetup = false;
  7542. return setupResult;
  7543. }
  7544. function setupStatefulComponent(instance, isSSR) {
  7545. const Component = instance.type;
  7546. {
  7547. if (Component.name) {
  7548. validateComponentName(Component.name, instance.appContext.config);
  7549. }
  7550. if (Component.components) {
  7551. const names = Object.keys(Component.components);
  7552. for (let i = 0; i < names.length; i++) {
  7553. validateComponentName(names[i], instance.appContext.config);
  7554. }
  7555. }
  7556. if (Component.directives) {
  7557. const names = Object.keys(Component.directives);
  7558. for (let i = 0; i < names.length; i++) {
  7559. validateDirectiveName(names[i]);
  7560. }
  7561. }
  7562. }
  7563. // 0. create render proxy property access cache
  7564. instance.accessCache = Object.create(null);
  7565. // 1. create public instance / render proxy
  7566. // also mark it raw so it's never observed
  7567. instance.proxy = new Proxy(instance.ctx, PublicInstanceProxyHandlers);
  7568. {
  7569. exposePropsOnRenderContext(instance);
  7570. }
  7571. // 2. call setup()
  7572. const { setup } = Component;
  7573. if (setup) {
  7574. const setupContext = (instance.setupContext =
  7575. setup.length > 1 ? createSetupContext(instance) : null);
  7576. currentInstance = instance;
  7577. pauseTracking();
  7578. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  7579. resetTracking();
  7580. currentInstance = null;
  7581. if (isPromise(setupResult)) {
  7582. if (isSSR) {
  7583. // return the promise so server-renderer can wait on it
  7584. return setupResult.then((resolvedResult) => {
  7585. handleSetupResult(instance, resolvedResult);
  7586. });
  7587. }
  7588. else {
  7589. // async setup returned Promise.
  7590. // bail here and wait for re-entry.
  7591. instance.asyncDep = setupResult;
  7592. }
  7593. }
  7594. else {
  7595. handleSetupResult(instance, setupResult);
  7596. }
  7597. }
  7598. else {
  7599. finishComponentSetup(instance);
  7600. }
  7601. }
  7602. function handleSetupResult(instance, setupResult, isSSR) {
  7603. if (isFunction(setupResult)) {
  7604. // setup returned an inline render function
  7605. {
  7606. instance.render = setupResult;
  7607. }
  7608. }
  7609. else if (isObject(setupResult)) {
  7610. if (isVNode(setupResult)) {
  7611. warn(`setup() should not return VNodes directly - ` +
  7612. `return a render function instead.`);
  7613. }
  7614. // setup returned bindings.
  7615. // assuming a render function compiled from template is present.
  7616. {
  7617. instance.devtoolsRawSetupState = setupResult;
  7618. }
  7619. instance.setupState = proxyRefs(setupResult);
  7620. {
  7621. exposeSetupStateOnRenderContext(instance);
  7622. }
  7623. }
  7624. else if (setupResult !== undefined) {
  7625. warn(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  7626. }
  7627. finishComponentSetup(instance);
  7628. }
  7629. let compile;
  7630. // dev only
  7631. const isRuntimeOnly = () => !compile;
  7632. /**
  7633. * For runtime-dom to register the compiler.
  7634. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  7635. */
  7636. function registerRuntimeCompiler(_compile) {
  7637. compile = _compile;
  7638. }
  7639. function finishComponentSetup(instance, isSSR) {
  7640. const Component = instance.type;
  7641. // template / render function normalization
  7642. if (!instance.render) {
  7643. // could be set from setup()
  7644. if (compile && Component.template && !Component.render) {
  7645. {
  7646. startMeasure(instance, `compile`);
  7647. }
  7648. Component.render = compile(Component.template, {
  7649. isCustomElement: instance.appContext.config.isCustomElement,
  7650. delimiters: Component.delimiters
  7651. });
  7652. {
  7653. endMeasure(instance, `compile`);
  7654. }
  7655. }
  7656. instance.render = (Component.render || NOOP);
  7657. // for runtime-compiled render functions using `with` blocks, the render
  7658. // proxy used needs a different `has` handler which is more performant and
  7659. // also only allows a whitelist of globals to fallthrough.
  7660. if (instance.render._rc) {
  7661. instance.withProxy = new Proxy(instance.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  7662. }
  7663. }
  7664. // support for 2.x options
  7665. {
  7666. currentInstance = instance;
  7667. pauseTracking();
  7668. applyOptions(instance, Component);
  7669. resetTracking();
  7670. currentInstance = null;
  7671. }
  7672. // warn missing template/render
  7673. if (!Component.render && instance.render === NOOP) {
  7674. /* istanbul ignore if */
  7675. if (!compile && Component.template) {
  7676. warn(`Component provided template option but ` +
  7677. `runtime compilation is not supported in this build of Vue.` +
  7678. (` Use "vue.global.js" instead.`
  7679. ) /* should not happen */);
  7680. }
  7681. else {
  7682. warn(`Component is missing template or render function.`);
  7683. }
  7684. }
  7685. }
  7686. const attrHandlers = {
  7687. get: (target, key) => {
  7688. {
  7689. markAttrsAccessed();
  7690. }
  7691. return target[key];
  7692. },
  7693. set: () => {
  7694. warn(`setupContext.attrs is readonly.`);
  7695. return false;
  7696. },
  7697. deleteProperty: () => {
  7698. warn(`setupContext.attrs is readonly.`);
  7699. return false;
  7700. }
  7701. };
  7702. function createSetupContext(instance) {
  7703. const expose = exposed => {
  7704. if (instance.exposed) {
  7705. warn(`expose() should be called only once per setup().`);
  7706. }
  7707. instance.exposed = proxyRefs(exposed);
  7708. };
  7709. {
  7710. // We use getters in dev in case libs like test-utils overwrite instance
  7711. // properties (overwrites should not be done in prod)
  7712. return Object.freeze({
  7713. get props() {
  7714. return instance.props;
  7715. },
  7716. get attrs() {
  7717. return new Proxy(instance.attrs, attrHandlers);
  7718. },
  7719. get slots() {
  7720. return shallowReadonly(instance.slots);
  7721. },
  7722. get emit() {
  7723. return (event, ...args) => instance.emit(event, ...args);
  7724. },
  7725. expose
  7726. });
  7727. }
  7728. }
  7729. // record effects created during a component's setup() so that they can be
  7730. // stopped when the component unmounts
  7731. function recordInstanceBoundEffect(effect, instance = currentInstance) {
  7732. if (instance) {
  7733. (instance.effects || (instance.effects = [])).push(effect);
  7734. }
  7735. }
  7736. const classifyRE = /(?:^|[-_])(\w)/g;
  7737. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  7738. function getComponentName(Component) {
  7739. return isFunction(Component)
  7740. ? Component.displayName || Component.name
  7741. : Component.name;
  7742. }
  7743. /* istanbul ignore next */
  7744. function formatComponentName(instance, Component, isRoot = false) {
  7745. let name = getComponentName(Component);
  7746. if (!name && Component.__file) {
  7747. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  7748. if (match) {
  7749. name = match[1];
  7750. }
  7751. }
  7752. if (!name && instance && instance.parent) {
  7753. // try to infer the name based on reverse resolution
  7754. const inferFromRegistry = (registry) => {
  7755. for (const key in registry) {
  7756. if (registry[key] === Component) {
  7757. return key;
  7758. }
  7759. }
  7760. };
  7761. name =
  7762. inferFromRegistry(instance.components ||
  7763. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  7764. }
  7765. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  7766. }
  7767. function isClassComponent(value) {
  7768. return isFunction(value) && '__vccOpts' in value;
  7769. }
  7770. function computed$1(getterOrOptions) {
  7771. const c = computed(getterOrOptions);
  7772. recordInstanceBoundEffect(c.effect);
  7773. return c;
  7774. }
  7775. // implementation
  7776. function defineProps() {
  7777. {
  7778. warn(`defineProps() is a compiler-hint helper that is only usable inside ` +
  7779. `<script setup> of a single file component. Its arguments should be ` +
  7780. `compiled away and passing it at runtime has no effect.`);
  7781. }
  7782. return null;
  7783. }
  7784. // implementation
  7785. function defineEmit() {
  7786. {
  7787. warn(`defineEmit() is a compiler-hint helper that is only usable inside ` +
  7788. `<script setup> of a single file component. Its arguments should be ` +
  7789. `compiled away and passing it at runtime has no effect.`);
  7790. }
  7791. return null;
  7792. }
  7793. function useContext() {
  7794. const i = getCurrentInstance();
  7795. if (!i) {
  7796. warn(`useContext() called without active instance.`);
  7797. }
  7798. return i.setupContext || (i.setupContext = createSetupContext(i));
  7799. }
  7800. // Actual implementation
  7801. function h(type, propsOrChildren, children) {
  7802. const l = arguments.length;
  7803. if (l === 2) {
  7804. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  7805. // single vnode without props
  7806. if (isVNode(propsOrChildren)) {
  7807. return createVNode(type, null, [propsOrChildren]);
  7808. }
  7809. // props without children
  7810. return createVNode(type, propsOrChildren);
  7811. }
  7812. else {
  7813. // omit props
  7814. return createVNode(type, null, propsOrChildren);
  7815. }
  7816. }
  7817. else {
  7818. if (l > 3) {
  7819. children = Array.prototype.slice.call(arguments, 2);
  7820. }
  7821. else if (l === 3 && isVNode(children)) {
  7822. children = [children];
  7823. }
  7824. return createVNode(type, propsOrChildren, children);
  7825. }
  7826. }
  7827. const ssrContextKey = Symbol(`ssrContext` );
  7828. const useSSRContext = () => {
  7829. {
  7830. warn(`useSSRContext() is not supported in the global build.`);
  7831. }
  7832. };
  7833. function initCustomFormatter() {
  7834. /* eslint-disable no-restricted-globals */
  7835. if (typeof window === 'undefined') {
  7836. return;
  7837. }
  7838. const vueStyle = { style: 'color:#3ba776' };
  7839. const numberStyle = { style: 'color:#0b1bc9' };
  7840. const stringStyle = { style: 'color:#b62e24' };
  7841. const keywordStyle = { style: 'color:#9d288c' };
  7842. // custom formatter for Chrome
  7843. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  7844. const formatter = {
  7845. header(obj) {
  7846. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  7847. if (!isObject(obj)) {
  7848. return null;
  7849. }
  7850. if (obj.__isVue) {
  7851. return ['div', vueStyle, `VueInstance`];
  7852. }
  7853. else if (isRef(obj)) {
  7854. return [
  7855. 'div',
  7856. {},
  7857. ['span', vueStyle, genRefFlag(obj)],
  7858. '<',
  7859. formatValue(obj.value),
  7860. `>`
  7861. ];
  7862. }
  7863. else if (isReactive(obj)) {
  7864. return [
  7865. 'div',
  7866. {},
  7867. ['span', vueStyle, 'Reactive'],
  7868. '<',
  7869. formatValue(obj),
  7870. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  7871. ];
  7872. }
  7873. else if (isReadonly(obj)) {
  7874. return [
  7875. 'div',
  7876. {},
  7877. ['span', vueStyle, 'Readonly'],
  7878. '<',
  7879. formatValue(obj),
  7880. '>'
  7881. ];
  7882. }
  7883. return null;
  7884. },
  7885. hasBody(obj) {
  7886. return obj && obj.__isVue;
  7887. },
  7888. body(obj) {
  7889. if (obj && obj.__isVue) {
  7890. return [
  7891. 'div',
  7892. {},
  7893. ...formatInstance(obj.$)
  7894. ];
  7895. }
  7896. }
  7897. };
  7898. function formatInstance(instance) {
  7899. const blocks = [];
  7900. if (instance.type.props && instance.props) {
  7901. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  7902. }
  7903. if (instance.setupState !== EMPTY_OBJ) {
  7904. blocks.push(createInstanceBlock('setup', instance.setupState));
  7905. }
  7906. if (instance.data !== EMPTY_OBJ) {
  7907. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  7908. }
  7909. const computed = extractKeys(instance, 'computed');
  7910. if (computed) {
  7911. blocks.push(createInstanceBlock('computed', computed));
  7912. }
  7913. const injected = extractKeys(instance, 'inject');
  7914. if (injected) {
  7915. blocks.push(createInstanceBlock('injected', injected));
  7916. }
  7917. blocks.push([
  7918. 'div',
  7919. {},
  7920. [
  7921. 'span',
  7922. {
  7923. style: keywordStyle.style + ';opacity:0.66'
  7924. },
  7925. '$ (internal): '
  7926. ],
  7927. ['object', { object: instance }]
  7928. ]);
  7929. return blocks;
  7930. }
  7931. function createInstanceBlock(type, target) {
  7932. target = extend({}, target);
  7933. if (!Object.keys(target).length) {
  7934. return ['span', {}];
  7935. }
  7936. return [
  7937. 'div',
  7938. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  7939. [
  7940. 'div',
  7941. {
  7942. style: 'color:#476582'
  7943. },
  7944. type
  7945. ],
  7946. [
  7947. 'div',
  7948. {
  7949. style: 'padding-left:1.25em'
  7950. },
  7951. ...Object.keys(target).map(key => {
  7952. return [
  7953. 'div',
  7954. {},
  7955. ['span', keywordStyle, key + ': '],
  7956. formatValue(target[key], false)
  7957. ];
  7958. })
  7959. ]
  7960. ];
  7961. }
  7962. function formatValue(v, asRaw = true) {
  7963. if (typeof v === 'number') {
  7964. return ['span', numberStyle, v];
  7965. }
  7966. else if (typeof v === 'string') {
  7967. return ['span', stringStyle, JSON.stringify(v)];
  7968. }
  7969. else if (typeof v === 'boolean') {
  7970. return ['span', keywordStyle, v];
  7971. }
  7972. else if (isObject(v)) {
  7973. return ['object', { object: asRaw ? toRaw(v) : v }];
  7974. }
  7975. else {
  7976. return ['span', stringStyle, String(v)];
  7977. }
  7978. }
  7979. function extractKeys(instance, type) {
  7980. const Comp = instance.type;
  7981. if (isFunction(Comp)) {
  7982. return;
  7983. }
  7984. const extracted = {};
  7985. for (const key in instance.ctx) {
  7986. if (isKeyOfType(Comp, key, type)) {
  7987. extracted[key] = instance.ctx[key];
  7988. }
  7989. }
  7990. return extracted;
  7991. }
  7992. function isKeyOfType(Comp, key, type) {
  7993. const opts = Comp[type];
  7994. if ((isArray(opts) && opts.includes(key)) ||
  7995. (isObject(opts) && key in opts)) {
  7996. return true;
  7997. }
  7998. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  7999. return true;
  8000. }
  8001. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  8002. return true;
  8003. }
  8004. }
  8005. function genRefFlag(v) {
  8006. if (v._shallow) {
  8007. return `ShallowRef`;
  8008. }
  8009. if (v.effect) {
  8010. return `ComputedRef`;
  8011. }
  8012. return `Ref`;
  8013. }
  8014. if (window.devtoolsFormatters) {
  8015. window.devtoolsFormatters.push(formatter);
  8016. }
  8017. else {
  8018. window.devtoolsFormatters = [formatter];
  8019. }
  8020. }
  8021. /**
  8022. * Actual implementation
  8023. */
  8024. function renderList(source, renderItem) {
  8025. let ret;
  8026. if (isArray(source) || isString(source)) {
  8027. ret = new Array(source.length);
  8028. for (let i = 0, l = source.length; i < l; i++) {
  8029. ret[i] = renderItem(source[i], i);
  8030. }
  8031. }
  8032. else if (typeof source === 'number') {
  8033. if (!Number.isInteger(source)) {
  8034. warn(`The v-for range expect an integer value but got ${source}.`);
  8035. return [];
  8036. }
  8037. ret = new Array(source);
  8038. for (let i = 0; i < source; i++) {
  8039. ret[i] = renderItem(i + 1, i);
  8040. }
  8041. }
  8042. else if (isObject(source)) {
  8043. if (source[Symbol.iterator]) {
  8044. ret = Array.from(source, renderItem);
  8045. }
  8046. else {
  8047. const keys = Object.keys(source);
  8048. ret = new Array(keys.length);
  8049. for (let i = 0, l = keys.length; i < l; i++) {
  8050. const key = keys[i];
  8051. ret[i] = renderItem(source[key], key, i);
  8052. }
  8053. }
  8054. }
  8055. else {
  8056. ret = [];
  8057. }
  8058. return ret;
  8059. }
  8060. /**
  8061. * For prefixing keys in v-on="obj" with "on"
  8062. * @private
  8063. */
  8064. function toHandlers(obj) {
  8065. const ret = {};
  8066. if (!isObject(obj)) {
  8067. warn(`v-on with no argument expects an object value.`);
  8068. return ret;
  8069. }
  8070. for (const key in obj) {
  8071. ret[toHandlerKey(key)] = obj[key];
  8072. }
  8073. return ret;
  8074. }
  8075. /**
  8076. * Compiler runtime helper for creating dynamic slots object
  8077. * @private
  8078. */
  8079. function createSlots(slots, dynamicSlots) {
  8080. for (let i = 0; i < dynamicSlots.length; i++) {
  8081. const slot = dynamicSlots[i];
  8082. // array of dynamic slot generated by <template v-for="..." #[...]>
  8083. if (isArray(slot)) {
  8084. for (let j = 0; j < slot.length; j++) {
  8085. slots[slot[j].name] = slot[j].fn;
  8086. }
  8087. }
  8088. else if (slot) {
  8089. // conditional single slot generated by <template v-if="..." #foo>
  8090. slots[slot.name] = slot.fn;
  8091. }
  8092. }
  8093. return slots;
  8094. }
  8095. // Core API ------------------------------------------------------------------
  8096. const version = "3.0.7";
  8097. /**
  8098. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  8099. * @internal
  8100. */
  8101. const ssrUtils = (null);
  8102. const svgNS = 'http://www.w3.org/2000/svg';
  8103. const doc = (typeof document !== 'undefined' ? document : null);
  8104. let tempContainer;
  8105. let tempSVGContainer;
  8106. const nodeOps = {
  8107. insert: (child, parent, anchor) => {
  8108. parent.insertBefore(child, anchor || null);
  8109. },
  8110. remove: child => {
  8111. const parent = child.parentNode;
  8112. if (parent) {
  8113. parent.removeChild(child);
  8114. }
  8115. },
  8116. createElement: (tag, isSVG, is) => isSVG
  8117. ? doc.createElementNS(svgNS, tag)
  8118. : doc.createElement(tag, is ? { is } : undefined),
  8119. createText: text => doc.createTextNode(text),
  8120. createComment: text => doc.createComment(text),
  8121. setText: (node, text) => {
  8122. node.nodeValue = text;
  8123. },
  8124. setElementText: (el, text) => {
  8125. el.textContent = text;
  8126. },
  8127. parentNode: node => node.parentNode,
  8128. nextSibling: node => node.nextSibling,
  8129. querySelector: selector => doc.querySelector(selector),
  8130. setScopeId(el, id) {
  8131. el.setAttribute(id, '');
  8132. },
  8133. cloneNode(el) {
  8134. return el.cloneNode(true);
  8135. },
  8136. // __UNSAFE__
  8137. // Reason: innerHTML.
  8138. // Static content here can only come from compiled templates.
  8139. // As long as the user only uses trusted templates, this is safe.
  8140. insertStaticContent(content, parent, anchor, isSVG) {
  8141. const temp = isSVG
  8142. ? tempSVGContainer ||
  8143. (tempSVGContainer = doc.createElementNS(svgNS, 'svg'))
  8144. : tempContainer || (tempContainer = doc.createElement('div'));
  8145. temp.innerHTML = content;
  8146. const first = temp.firstChild;
  8147. let node = first;
  8148. let last = node;
  8149. while (node) {
  8150. last = node;
  8151. nodeOps.insert(node, parent, anchor);
  8152. node = temp.firstChild;
  8153. }
  8154. return [first, last];
  8155. }
  8156. };
  8157. // compiler should normalize class + :class bindings on the same element
  8158. // into a single binding ['staticClass', dynamic]
  8159. function patchClass(el, value, isSVG) {
  8160. if (value == null) {
  8161. value = '';
  8162. }
  8163. if (isSVG) {
  8164. el.setAttribute('class', value);
  8165. }
  8166. else {
  8167. // directly setting className should be faster than setAttribute in theory
  8168. // if this is an element during a transition, take the temporary transition
  8169. // classes into account.
  8170. const transitionClasses = el._vtc;
  8171. if (transitionClasses) {
  8172. value = (value
  8173. ? [value, ...transitionClasses]
  8174. : [...transitionClasses]).join(' ');
  8175. }
  8176. el.className = value;
  8177. }
  8178. }
  8179. function patchStyle(el, prev, next) {
  8180. const style = el.style;
  8181. if (!next) {
  8182. el.removeAttribute('style');
  8183. }
  8184. else if (isString(next)) {
  8185. if (prev !== next) {
  8186. const current = style.display;
  8187. style.cssText = next;
  8188. // indicates that the `display` of the element is controlled by `v-show`,
  8189. // so we always keep the current `display` value regardless of the `style` value,
  8190. // thus handing over control to `v-show`.
  8191. if ('_vod' in el) {
  8192. style.display = current;
  8193. }
  8194. }
  8195. }
  8196. else {
  8197. for (const key in next) {
  8198. setStyle(style, key, next[key]);
  8199. }
  8200. if (prev && !isString(prev)) {
  8201. for (const key in prev) {
  8202. if (next[key] == null) {
  8203. setStyle(style, key, '');
  8204. }
  8205. }
  8206. }
  8207. }
  8208. }
  8209. const importantRE = /\s*!important$/;
  8210. function setStyle(style, name, val) {
  8211. if (isArray(val)) {
  8212. val.forEach(v => setStyle(style, name, v));
  8213. }
  8214. else {
  8215. if (name.startsWith('--')) {
  8216. // custom property definition
  8217. style.setProperty(name, val);
  8218. }
  8219. else {
  8220. const prefixed = autoPrefix(style, name);
  8221. if (importantRE.test(val)) {
  8222. // !important
  8223. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  8224. }
  8225. else {
  8226. style[prefixed] = val;
  8227. }
  8228. }
  8229. }
  8230. }
  8231. const prefixes = ['Webkit', 'Moz', 'ms'];
  8232. const prefixCache = {};
  8233. function autoPrefix(style, rawName) {
  8234. const cached = prefixCache[rawName];
  8235. if (cached) {
  8236. return cached;
  8237. }
  8238. let name = camelize(rawName);
  8239. if (name !== 'filter' && name in style) {
  8240. return (prefixCache[rawName] = name);
  8241. }
  8242. name = capitalize(name);
  8243. for (let i = 0; i < prefixes.length; i++) {
  8244. const prefixed = prefixes[i] + name;
  8245. if (prefixed in style) {
  8246. return (prefixCache[rawName] = prefixed);
  8247. }
  8248. }
  8249. return rawName;
  8250. }
  8251. const xlinkNS = 'http://www.w3.org/1999/xlink';
  8252. function patchAttr(el, key, value, isSVG) {
  8253. if (isSVG && key.startsWith('xlink:')) {
  8254. if (value == null) {
  8255. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  8256. }
  8257. else {
  8258. el.setAttributeNS(xlinkNS, key, value);
  8259. }
  8260. }
  8261. else {
  8262. // note we are only checking boolean attributes that don't have a
  8263. // corresponding dom prop of the same name here.
  8264. const isBoolean = isSpecialBooleanAttr(key);
  8265. if (value == null || (isBoolean && value === false)) {
  8266. el.removeAttribute(key);
  8267. }
  8268. else {
  8269. el.setAttribute(key, isBoolean ? '' : value);
  8270. }
  8271. }
  8272. }
  8273. // __UNSAFE__
  8274. // functions. The user is responsible for using them with only trusted content.
  8275. function patchDOMProp(el, key, value,
  8276. // the following args are passed only due to potential innerHTML/textContent
  8277. // overriding existing VNodes, in which case the old tree must be properly
  8278. // unmounted.
  8279. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  8280. if (key === 'innerHTML' || key === 'textContent') {
  8281. if (prevChildren) {
  8282. unmountChildren(prevChildren, parentComponent, parentSuspense);
  8283. }
  8284. el[key] = value == null ? '' : value;
  8285. return;
  8286. }
  8287. if (key === 'value' && el.tagName !== 'PROGRESS') {
  8288. // store value as _value as well since
  8289. // non-string values will be stringified.
  8290. el._value = value;
  8291. const newValue = value == null ? '' : value;
  8292. if (el.value !== newValue) {
  8293. el.value = newValue;
  8294. }
  8295. return;
  8296. }
  8297. if (value === '' || value == null) {
  8298. const type = typeof el[key];
  8299. if (value === '' && type === 'boolean') {
  8300. // e.g. <select multiple> compiles to { multiple: '' }
  8301. el[key] = true;
  8302. return;
  8303. }
  8304. else if (value == null && type === 'string') {
  8305. // e.g. <div :id="null">
  8306. el[key] = '';
  8307. el.removeAttribute(key);
  8308. return;
  8309. }
  8310. else if (type === 'number') {
  8311. // e.g. <img :width="null">
  8312. el[key] = 0;
  8313. el.removeAttribute(key);
  8314. return;
  8315. }
  8316. }
  8317. // some properties perform value validation and throw
  8318. try {
  8319. el[key] = value;
  8320. }
  8321. catch (e) {
  8322. {
  8323. warn(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  8324. `value ${value} is invalid.`, e);
  8325. }
  8326. }
  8327. }
  8328. // Async edge case fix requires storing an event listener's attach timestamp.
  8329. let _getNow = Date.now;
  8330. // Determine what event timestamp the browser is using. Annoyingly, the
  8331. // timestamp can either be hi-res (relative to page load) or low-res
  8332. // (relative to UNIX epoch), so in order to compare time we have to use the
  8333. // same timestamp type when saving the flush timestamp.
  8334. if (typeof document !== 'undefined' &&
  8335. _getNow() > document.createEvent('Event').timeStamp) {
  8336. // if the low-res timestamp which is bigger than the event timestamp
  8337. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  8338. // and we need to use the hi-res version for event listeners as well.
  8339. _getNow = () => performance.now();
  8340. }
  8341. // To avoid the overhead of repeatedly calling performance.now(), we cache
  8342. // and use the same timestamp for all event listeners attached in the same tick.
  8343. let cachedNow = 0;
  8344. const p = Promise.resolve();
  8345. const reset = () => {
  8346. cachedNow = 0;
  8347. };
  8348. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  8349. function addEventListener(el, event, handler, options) {
  8350. el.addEventListener(event, handler, options);
  8351. }
  8352. function removeEventListener(el, event, handler, options) {
  8353. el.removeEventListener(event, handler, options);
  8354. }
  8355. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  8356. // vei = vue event invokers
  8357. const invokers = el._vei || (el._vei = {});
  8358. const existingInvoker = invokers[rawName];
  8359. if (nextValue && existingInvoker) {
  8360. // patch
  8361. existingInvoker.value = nextValue;
  8362. }
  8363. else {
  8364. const [name, options] = parseName(rawName);
  8365. if (nextValue) {
  8366. // add
  8367. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  8368. addEventListener(el, name, invoker, options);
  8369. }
  8370. else if (existingInvoker) {
  8371. // remove
  8372. removeEventListener(el, name, existingInvoker, options);
  8373. invokers[rawName] = undefined;
  8374. }
  8375. }
  8376. }
  8377. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  8378. function parseName(name) {
  8379. let options;
  8380. if (optionsModifierRE.test(name)) {
  8381. options = {};
  8382. let m;
  8383. while ((m = name.match(optionsModifierRE))) {
  8384. name = name.slice(0, name.length - m[0].length);
  8385. options[m[0].toLowerCase()] = true;
  8386. }
  8387. }
  8388. return [hyphenate(name.slice(2)), options];
  8389. }
  8390. function createInvoker(initialValue, instance) {
  8391. const invoker = (e) => {
  8392. // async edge case #6566: inner click event triggers patch, event handler
  8393. // attached to outer element during patch, and triggered again. This
  8394. // happens because browsers fire microtask ticks between event propagation.
  8395. // the solution is simple: we save the timestamp when a handler is attached,
  8396. // and the handler would only fire if the event passed to it was fired
  8397. // AFTER it was attached.
  8398. const timeStamp = e.timeStamp || _getNow();
  8399. if (timeStamp >= invoker.attached - 1) {
  8400. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  8401. }
  8402. };
  8403. invoker.value = initialValue;
  8404. invoker.attached = getNow();
  8405. return invoker;
  8406. }
  8407. function patchStopImmediatePropagation(e, value) {
  8408. if (isArray(value)) {
  8409. const originalStop = e.stopImmediatePropagation;
  8410. e.stopImmediatePropagation = () => {
  8411. originalStop.call(e);
  8412. e._stopped = true;
  8413. };
  8414. return value.map(fn => (e) => !e._stopped && fn(e));
  8415. }
  8416. else {
  8417. return value;
  8418. }
  8419. }
  8420. const nativeOnRE = /^on[a-z]/;
  8421. const forcePatchProp = (_, key) => key === 'value';
  8422. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  8423. switch (key) {
  8424. // special
  8425. case 'class':
  8426. patchClass(el, nextValue, isSVG);
  8427. break;
  8428. case 'style':
  8429. patchStyle(el, prevValue, nextValue);
  8430. break;
  8431. default:
  8432. if (isOn(key)) {
  8433. // ignore v-model listeners
  8434. if (!isModelListener(key)) {
  8435. patchEvent(el, key, prevValue, nextValue, parentComponent);
  8436. }
  8437. }
  8438. else if (shouldSetAsProp(el, key, nextValue, isSVG)) {
  8439. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  8440. }
  8441. else {
  8442. // special case for <input v-model type="checkbox"> with
  8443. // :true-value & :false-value
  8444. // store value as dom properties since non-string values will be
  8445. // stringified.
  8446. if (key === 'true-value') {
  8447. el._trueValue = nextValue;
  8448. }
  8449. else if (key === 'false-value') {
  8450. el._falseValue = nextValue;
  8451. }
  8452. patchAttr(el, key, nextValue, isSVG);
  8453. }
  8454. break;
  8455. }
  8456. };
  8457. function shouldSetAsProp(el, key, value, isSVG) {
  8458. if (isSVG) {
  8459. // most keys must be set as attribute on svg elements to work
  8460. // ...except innerHTML
  8461. if (key === 'innerHTML') {
  8462. return true;
  8463. }
  8464. // or native onclick with function values
  8465. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  8466. return true;
  8467. }
  8468. return false;
  8469. }
  8470. // spellcheck and draggable are numerated attrs, however their
  8471. // corresponding DOM properties are actually booleans - this leads to
  8472. // setting it with a string "false" value leading it to be coerced to
  8473. // `true`, so we need to always treat them as attributes.
  8474. // Note that `contentEditable` doesn't have this problem: its DOM
  8475. // property is also enumerated string values.
  8476. if (key === 'spellcheck' || key === 'draggable') {
  8477. return false;
  8478. }
  8479. // #1787, #2840 form property on form elements is readonly and must be set as
  8480. // attribute.
  8481. if (key === 'form') {
  8482. return false;
  8483. }
  8484. // #1526 <input list> must be set as attribute
  8485. if (key === 'list' && el.tagName === 'INPUT') {
  8486. return false;
  8487. }
  8488. // #2766 <textarea type> must be set as attribute
  8489. if (key === 'type' && el.tagName === 'TEXTAREA') {
  8490. return false;
  8491. }
  8492. // native onclick with string value, must be set as attribute
  8493. if (nativeOnRE.test(key) && isString(value)) {
  8494. return false;
  8495. }
  8496. return key in el;
  8497. }
  8498. function useCssModule(name = '$style') {
  8499. /* istanbul ignore else */
  8500. {
  8501. {
  8502. warn(`useCssModule() is not supported in the global build.`);
  8503. }
  8504. return EMPTY_OBJ;
  8505. }
  8506. }
  8507. /**
  8508. * Runtime helper for SFC's CSS variable injection feature.
  8509. * @private
  8510. */
  8511. function useCssVars(getter) {
  8512. const instance = getCurrentInstance();
  8513. /* istanbul ignore next */
  8514. if (!instance) {
  8515. warn(`useCssVars is called without current active component instance.`);
  8516. return;
  8517. }
  8518. const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
  8519. onMounted(() => watchEffect(setVars, { flush: 'post' }));
  8520. onUpdated(setVars);
  8521. }
  8522. function setVarsOnVNode(vnode, vars) {
  8523. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  8524. const suspense = vnode.suspense;
  8525. vnode = suspense.activeBranch;
  8526. if (suspense.pendingBranch && !suspense.isHydrating) {
  8527. suspense.effects.push(() => {
  8528. setVarsOnVNode(suspense.activeBranch, vars);
  8529. });
  8530. }
  8531. }
  8532. // drill down HOCs until it's a non-component vnode
  8533. while (vnode.component) {
  8534. vnode = vnode.component.subTree;
  8535. }
  8536. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  8537. const style = vnode.el.style;
  8538. for (const key in vars) {
  8539. style.setProperty(`--${key}`, vars[key]);
  8540. }
  8541. }
  8542. else if (vnode.type === Fragment) {
  8543. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  8544. }
  8545. }
  8546. const TRANSITION = 'transition';
  8547. const ANIMATION = 'animation';
  8548. // DOM Transition is a higher-order-component based on the platform-agnostic
  8549. // base Transition component, with DOM-specific logic.
  8550. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  8551. Transition.displayName = 'Transition';
  8552. const DOMTransitionPropsValidators = {
  8553. name: String,
  8554. type: String,
  8555. css: {
  8556. type: Boolean,
  8557. default: true
  8558. },
  8559. duration: [String, Number, Object],
  8560. enterFromClass: String,
  8561. enterActiveClass: String,
  8562. enterToClass: String,
  8563. appearFromClass: String,
  8564. appearActiveClass: String,
  8565. appearToClass: String,
  8566. leaveFromClass: String,
  8567. leaveActiveClass: String,
  8568. leaveToClass: String
  8569. };
  8570. const TransitionPropsValidators = (Transition.props = /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  8571. function resolveTransitionProps(rawProps) {
  8572. let { name = 'v', type, css = true, duration, enterFromClass = `${name}-enter-from`, enterActiveClass = `${name}-enter-active`, enterToClass = `${name}-enter-to`, appearFromClass = enterFromClass, appearActiveClass = enterActiveClass, appearToClass = enterToClass, leaveFromClass = `${name}-leave-from`, leaveActiveClass = `${name}-leave-active`, leaveToClass = `${name}-leave-to` } = rawProps;
  8573. const baseProps = {};
  8574. for (const key in rawProps) {
  8575. if (!(key in DOMTransitionPropsValidators)) {
  8576. baseProps[key] = rawProps[key];
  8577. }
  8578. }
  8579. if (!css) {
  8580. return baseProps;
  8581. }
  8582. const durations = normalizeDuration(duration);
  8583. const enterDuration = durations && durations[0];
  8584. const leaveDuration = durations && durations[1];
  8585. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  8586. const finishEnter = (el, isAppear, done) => {
  8587. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  8588. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  8589. done && done();
  8590. };
  8591. const finishLeave = (el, done) => {
  8592. removeTransitionClass(el, leaveToClass);
  8593. removeTransitionClass(el, leaveActiveClass);
  8594. done && done();
  8595. };
  8596. const makeEnterHook = (isAppear) => {
  8597. return (el, done) => {
  8598. const hook = isAppear ? onAppear : onEnter;
  8599. const resolve = () => finishEnter(el, isAppear, done);
  8600. hook && hook(el, resolve);
  8601. nextFrame(() => {
  8602. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  8603. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  8604. if (!(hook && hook.length > 1)) {
  8605. whenTransitionEnds(el, type, enterDuration, resolve);
  8606. }
  8607. });
  8608. };
  8609. };
  8610. return extend(baseProps, {
  8611. onBeforeEnter(el) {
  8612. onBeforeEnter && onBeforeEnter(el);
  8613. addTransitionClass(el, enterFromClass);
  8614. addTransitionClass(el, enterActiveClass);
  8615. },
  8616. onBeforeAppear(el) {
  8617. onBeforeAppear && onBeforeAppear(el);
  8618. addTransitionClass(el, appearFromClass);
  8619. addTransitionClass(el, appearActiveClass);
  8620. },
  8621. onEnter: makeEnterHook(false),
  8622. onAppear: makeEnterHook(true),
  8623. onLeave(el, done) {
  8624. const resolve = () => finishLeave(el, done);
  8625. addTransitionClass(el, leaveFromClass);
  8626. // force reflow so *-leave-from classes immediately take effect (#2593)
  8627. forceReflow();
  8628. addTransitionClass(el, leaveActiveClass);
  8629. nextFrame(() => {
  8630. removeTransitionClass(el, leaveFromClass);
  8631. addTransitionClass(el, leaveToClass);
  8632. if (!(onLeave && onLeave.length > 1)) {
  8633. whenTransitionEnds(el, type, leaveDuration, resolve);
  8634. }
  8635. });
  8636. onLeave && onLeave(el, resolve);
  8637. },
  8638. onEnterCancelled(el) {
  8639. finishEnter(el, false);
  8640. onEnterCancelled && onEnterCancelled(el);
  8641. },
  8642. onAppearCancelled(el) {
  8643. finishEnter(el, true);
  8644. onAppearCancelled && onAppearCancelled(el);
  8645. },
  8646. onLeaveCancelled(el) {
  8647. finishLeave(el);
  8648. onLeaveCancelled && onLeaveCancelled(el);
  8649. }
  8650. });
  8651. }
  8652. function normalizeDuration(duration) {
  8653. if (duration == null) {
  8654. return null;
  8655. }
  8656. else if (isObject(duration)) {
  8657. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  8658. }
  8659. else {
  8660. const n = NumberOf(duration);
  8661. return [n, n];
  8662. }
  8663. }
  8664. function NumberOf(val) {
  8665. const res = toNumber(val);
  8666. validateDuration(res);
  8667. return res;
  8668. }
  8669. function validateDuration(val) {
  8670. if (typeof val !== 'number') {
  8671. warn(`<transition> explicit duration is not a valid number - ` +
  8672. `got ${JSON.stringify(val)}.`);
  8673. }
  8674. else if (isNaN(val)) {
  8675. warn(`<transition> explicit duration is NaN - ` +
  8676. 'the duration expression might be incorrect.');
  8677. }
  8678. }
  8679. function addTransitionClass(el, cls) {
  8680. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  8681. (el._vtc ||
  8682. (el._vtc = new Set())).add(cls);
  8683. }
  8684. function removeTransitionClass(el, cls) {
  8685. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  8686. const { _vtc } = el;
  8687. if (_vtc) {
  8688. _vtc.delete(cls);
  8689. if (!_vtc.size) {
  8690. el._vtc = undefined;
  8691. }
  8692. }
  8693. }
  8694. function nextFrame(cb) {
  8695. requestAnimationFrame(() => {
  8696. requestAnimationFrame(cb);
  8697. });
  8698. }
  8699. let endId = 0;
  8700. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  8701. const id = (el._endId = ++endId);
  8702. const resolveIfNotStale = () => {
  8703. if (id === el._endId) {
  8704. resolve();
  8705. }
  8706. };
  8707. if (explicitTimeout) {
  8708. return setTimeout(resolveIfNotStale, explicitTimeout);
  8709. }
  8710. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  8711. if (!type) {
  8712. return resolve();
  8713. }
  8714. const endEvent = type + 'end';
  8715. let ended = 0;
  8716. const end = () => {
  8717. el.removeEventListener(endEvent, onEnd);
  8718. resolveIfNotStale();
  8719. };
  8720. const onEnd = (e) => {
  8721. if (e.target === el && ++ended >= propCount) {
  8722. end();
  8723. }
  8724. };
  8725. setTimeout(() => {
  8726. if (ended < propCount) {
  8727. end();
  8728. }
  8729. }, timeout + 1);
  8730. el.addEventListener(endEvent, onEnd);
  8731. }
  8732. function getTransitionInfo(el, expectedType) {
  8733. const styles = window.getComputedStyle(el);
  8734. // JSDOM may return undefined for transition properties
  8735. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  8736. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  8737. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  8738. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  8739. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  8740. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  8741. const animationTimeout = getTimeout(animationDelays, animationDurations);
  8742. let type = null;
  8743. let timeout = 0;
  8744. let propCount = 0;
  8745. /* istanbul ignore if */
  8746. if (expectedType === TRANSITION) {
  8747. if (transitionTimeout > 0) {
  8748. type = TRANSITION;
  8749. timeout = transitionTimeout;
  8750. propCount = transitionDurations.length;
  8751. }
  8752. }
  8753. else if (expectedType === ANIMATION) {
  8754. if (animationTimeout > 0) {
  8755. type = ANIMATION;
  8756. timeout = animationTimeout;
  8757. propCount = animationDurations.length;
  8758. }
  8759. }
  8760. else {
  8761. timeout = Math.max(transitionTimeout, animationTimeout);
  8762. type =
  8763. timeout > 0
  8764. ? transitionTimeout > animationTimeout
  8765. ? TRANSITION
  8766. : ANIMATION
  8767. : null;
  8768. propCount = type
  8769. ? type === TRANSITION
  8770. ? transitionDurations.length
  8771. : animationDurations.length
  8772. : 0;
  8773. }
  8774. const hasTransform = type === TRANSITION &&
  8775. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  8776. return {
  8777. type,
  8778. timeout,
  8779. propCount,
  8780. hasTransform
  8781. };
  8782. }
  8783. function getTimeout(delays, durations) {
  8784. while (delays.length < durations.length) {
  8785. delays = delays.concat(delays);
  8786. }
  8787. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  8788. }
  8789. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  8790. // numbers in a locale-dependent way, using a comma instead of a dot.
  8791. // If comma is not replaced with a dot, the input will be rounded down
  8792. // (i.e. acting as a floor function) causing unexpected behaviors
  8793. function toMs(s) {
  8794. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  8795. }
  8796. // synchronously force layout to put elements into a certain state
  8797. function forceReflow() {
  8798. return document.body.offsetHeight;
  8799. }
  8800. const positionMap = new WeakMap();
  8801. const newPositionMap = new WeakMap();
  8802. const TransitionGroupImpl = {
  8803. name: 'TransitionGroup',
  8804. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  8805. tag: String,
  8806. moveClass: String
  8807. }),
  8808. setup(props, { slots }) {
  8809. const instance = getCurrentInstance();
  8810. const state = useTransitionState();
  8811. let prevChildren;
  8812. let children;
  8813. onUpdated(() => {
  8814. // children is guaranteed to exist after initial render
  8815. if (!prevChildren.length) {
  8816. return;
  8817. }
  8818. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  8819. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  8820. return;
  8821. }
  8822. // we divide the work into three loops to avoid mixing DOM reads and writes
  8823. // in each iteration - which helps prevent layout thrashing.
  8824. prevChildren.forEach(callPendingCbs);
  8825. prevChildren.forEach(recordPosition);
  8826. const movedChildren = prevChildren.filter(applyTranslation);
  8827. // force reflow to put everything in position
  8828. forceReflow();
  8829. movedChildren.forEach(c => {
  8830. const el = c.el;
  8831. const style = el.style;
  8832. addTransitionClass(el, moveClass);
  8833. style.transform = style.webkitTransform = style.transitionDuration = '';
  8834. const cb = (el._moveCb = (e) => {
  8835. if (e && e.target !== el) {
  8836. return;
  8837. }
  8838. if (!e || /transform$/.test(e.propertyName)) {
  8839. el.removeEventListener('transitionend', cb);
  8840. el._moveCb = null;
  8841. removeTransitionClass(el, moveClass);
  8842. }
  8843. });
  8844. el.addEventListener('transitionend', cb);
  8845. });
  8846. });
  8847. return () => {
  8848. const rawProps = toRaw(props);
  8849. const cssTransitionProps = resolveTransitionProps(rawProps);
  8850. const tag = rawProps.tag || Fragment;
  8851. prevChildren = children;
  8852. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  8853. for (let i = 0; i < children.length; i++) {
  8854. const child = children[i];
  8855. if (child.key != null) {
  8856. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  8857. }
  8858. else {
  8859. warn(`<TransitionGroup> children must be keyed.`);
  8860. }
  8861. }
  8862. if (prevChildren) {
  8863. for (let i = 0; i < prevChildren.length; i++) {
  8864. const child = prevChildren[i];
  8865. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  8866. positionMap.set(child, child.el.getBoundingClientRect());
  8867. }
  8868. }
  8869. return createVNode(tag, null, children);
  8870. };
  8871. }
  8872. };
  8873. const TransitionGroup = TransitionGroupImpl;
  8874. function callPendingCbs(c) {
  8875. const el = c.el;
  8876. if (el._moveCb) {
  8877. el._moveCb();
  8878. }
  8879. if (el._enterCb) {
  8880. el._enterCb();
  8881. }
  8882. }
  8883. function recordPosition(c) {
  8884. newPositionMap.set(c, c.el.getBoundingClientRect());
  8885. }
  8886. function applyTranslation(c) {
  8887. const oldPos = positionMap.get(c);
  8888. const newPos = newPositionMap.get(c);
  8889. const dx = oldPos.left - newPos.left;
  8890. const dy = oldPos.top - newPos.top;
  8891. if (dx || dy) {
  8892. const s = c.el.style;
  8893. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  8894. s.transitionDuration = '0s';
  8895. return c;
  8896. }
  8897. }
  8898. function hasCSSTransform(el, root, moveClass) {
  8899. // Detect whether an element with the move class applied has
  8900. // CSS transitions. Since the element may be inside an entering
  8901. // transition at this very moment, we make a clone of it and remove
  8902. // all other transition classes applied to ensure only the move class
  8903. // is applied.
  8904. const clone = el.cloneNode();
  8905. if (el._vtc) {
  8906. el._vtc.forEach(cls => {
  8907. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  8908. });
  8909. }
  8910. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  8911. clone.style.display = 'none';
  8912. const container = (root.nodeType === 1
  8913. ? root
  8914. : root.parentNode);
  8915. container.appendChild(clone);
  8916. const { hasTransform } = getTransitionInfo(clone);
  8917. container.removeChild(clone);
  8918. return hasTransform;
  8919. }
  8920. const getModelAssigner = (vnode) => {
  8921. const fn = vnode.props['onUpdate:modelValue'];
  8922. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  8923. };
  8924. function onCompositionStart(e) {
  8925. e.target.composing = true;
  8926. }
  8927. function onCompositionEnd(e) {
  8928. const target = e.target;
  8929. if (target.composing) {
  8930. target.composing = false;
  8931. trigger$1(target, 'input');
  8932. }
  8933. }
  8934. function trigger$1(el, type) {
  8935. const e = document.createEvent('HTMLEvents');
  8936. e.initEvent(type, true, true);
  8937. el.dispatchEvent(e);
  8938. }
  8939. // We are exporting the v-model runtime directly as vnode hooks so that it can
  8940. // be tree-shaken in case v-model is never used.
  8941. const vModelText = {
  8942. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  8943. el._assign = getModelAssigner(vnode);
  8944. const castToNumber = number || el.type === 'number';
  8945. addEventListener(el, lazy ? 'change' : 'input', e => {
  8946. if (e.target.composing)
  8947. return;
  8948. let domValue = el.value;
  8949. if (trim) {
  8950. domValue = domValue.trim();
  8951. }
  8952. else if (castToNumber) {
  8953. domValue = toNumber(domValue);
  8954. }
  8955. el._assign(domValue);
  8956. });
  8957. if (trim) {
  8958. addEventListener(el, 'change', () => {
  8959. el.value = el.value.trim();
  8960. });
  8961. }
  8962. if (!lazy) {
  8963. addEventListener(el, 'compositionstart', onCompositionStart);
  8964. addEventListener(el, 'compositionend', onCompositionEnd);
  8965. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  8966. // switching focus before confirming composition choice
  8967. // this also fixes the issue where some browsers e.g. iOS Chrome
  8968. // fires "change" instead of "input" on autocomplete.
  8969. addEventListener(el, 'change', onCompositionEnd);
  8970. }
  8971. },
  8972. // set value on mounted so it's after min/max for type="range"
  8973. mounted(el, { value }) {
  8974. el.value = value == null ? '' : value;
  8975. },
  8976. beforeUpdate(el, { value, modifiers: { trim, number } }, vnode) {
  8977. el._assign = getModelAssigner(vnode);
  8978. // avoid clearing unresolved text. #2302
  8979. if (el.composing)
  8980. return;
  8981. if (document.activeElement === el) {
  8982. if (trim && el.value.trim() === value) {
  8983. return;
  8984. }
  8985. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  8986. return;
  8987. }
  8988. }
  8989. const newValue = value == null ? '' : value;
  8990. if (el.value !== newValue) {
  8991. el.value = newValue;
  8992. }
  8993. }
  8994. };
  8995. const vModelCheckbox = {
  8996. created(el, _, vnode) {
  8997. el._assign = getModelAssigner(vnode);
  8998. addEventListener(el, 'change', () => {
  8999. const modelValue = el._modelValue;
  9000. const elementValue = getValue(el);
  9001. const checked = el.checked;
  9002. const assign = el._assign;
  9003. if (isArray(modelValue)) {
  9004. const index = looseIndexOf(modelValue, elementValue);
  9005. const found = index !== -1;
  9006. if (checked && !found) {
  9007. assign(modelValue.concat(elementValue));
  9008. }
  9009. else if (!checked && found) {
  9010. const filtered = [...modelValue];
  9011. filtered.splice(index, 1);
  9012. assign(filtered);
  9013. }
  9014. }
  9015. else if (isSet(modelValue)) {
  9016. const cloned = new Set(modelValue);
  9017. if (checked) {
  9018. cloned.add(elementValue);
  9019. }
  9020. else {
  9021. cloned.delete(elementValue);
  9022. }
  9023. assign(cloned);
  9024. }
  9025. else {
  9026. assign(getCheckboxValue(el, checked));
  9027. }
  9028. });
  9029. },
  9030. // set initial checked on mount to wait for true-value/false-value
  9031. mounted: setChecked,
  9032. beforeUpdate(el, binding, vnode) {
  9033. el._assign = getModelAssigner(vnode);
  9034. setChecked(el, binding, vnode);
  9035. }
  9036. };
  9037. function setChecked(el, { value, oldValue }, vnode) {
  9038. el._modelValue = value;
  9039. if (isArray(value)) {
  9040. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  9041. }
  9042. else if (isSet(value)) {
  9043. el.checked = value.has(vnode.props.value);
  9044. }
  9045. else if (value !== oldValue) {
  9046. el.checked = looseEqual(value, getCheckboxValue(el, true));
  9047. }
  9048. }
  9049. const vModelRadio = {
  9050. created(el, { value }, vnode) {
  9051. el.checked = looseEqual(value, vnode.props.value);
  9052. el._assign = getModelAssigner(vnode);
  9053. addEventListener(el, 'change', () => {
  9054. el._assign(getValue(el));
  9055. });
  9056. },
  9057. beforeUpdate(el, { value, oldValue }, vnode) {
  9058. el._assign = getModelAssigner(vnode);
  9059. if (value !== oldValue) {
  9060. el.checked = looseEqual(value, vnode.props.value);
  9061. }
  9062. }
  9063. };
  9064. const vModelSelect = {
  9065. created(el, { value, modifiers: { number } }, vnode) {
  9066. const isSetModel = isSet(value);
  9067. addEventListener(el, 'change', () => {
  9068. const selectedVal = Array.prototype.filter
  9069. .call(el.options, (o) => o.selected)
  9070. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  9071. el._assign(el.multiple
  9072. ? isSetModel
  9073. ? new Set(selectedVal)
  9074. : selectedVal
  9075. : selectedVal[0]);
  9076. });
  9077. el._assign = getModelAssigner(vnode);
  9078. },
  9079. // set value in mounted & updated because <select> relies on its children
  9080. // <option>s.
  9081. mounted(el, { value }) {
  9082. setSelected(el, value);
  9083. },
  9084. beforeUpdate(el, _binding, vnode) {
  9085. el._assign = getModelAssigner(vnode);
  9086. },
  9087. updated(el, { value }) {
  9088. setSelected(el, value);
  9089. }
  9090. };
  9091. function setSelected(el, value) {
  9092. const isMultiple = el.multiple;
  9093. if (isMultiple && !isArray(value) && !isSet(value)) {
  9094. warn(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  9095. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  9096. return;
  9097. }
  9098. for (let i = 0, l = el.options.length; i < l; i++) {
  9099. const option = el.options[i];
  9100. const optionValue = getValue(option);
  9101. if (isMultiple) {
  9102. if (isArray(value)) {
  9103. option.selected = looseIndexOf(value, optionValue) > -1;
  9104. }
  9105. else {
  9106. option.selected = value.has(optionValue);
  9107. }
  9108. }
  9109. else {
  9110. if (looseEqual(getValue(option), value)) {
  9111. el.selectedIndex = i;
  9112. return;
  9113. }
  9114. }
  9115. }
  9116. if (!isMultiple) {
  9117. el.selectedIndex = -1;
  9118. }
  9119. }
  9120. // retrieve raw value set via :value bindings
  9121. function getValue(el) {
  9122. return '_value' in el ? el._value : el.value;
  9123. }
  9124. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  9125. function getCheckboxValue(el, checked) {
  9126. const key = checked ? '_trueValue' : '_falseValue';
  9127. return key in el ? el[key] : checked;
  9128. }
  9129. const vModelDynamic = {
  9130. created(el, binding, vnode) {
  9131. callModelHook(el, binding, vnode, null, 'created');
  9132. },
  9133. mounted(el, binding, vnode) {
  9134. callModelHook(el, binding, vnode, null, 'mounted');
  9135. },
  9136. beforeUpdate(el, binding, vnode, prevVNode) {
  9137. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  9138. },
  9139. updated(el, binding, vnode, prevVNode) {
  9140. callModelHook(el, binding, vnode, prevVNode, 'updated');
  9141. }
  9142. };
  9143. function callModelHook(el, binding, vnode, prevVNode, hook) {
  9144. let modelToUse;
  9145. switch (el.tagName) {
  9146. case 'SELECT':
  9147. modelToUse = vModelSelect;
  9148. break;
  9149. case 'TEXTAREA':
  9150. modelToUse = vModelText;
  9151. break;
  9152. default:
  9153. switch (vnode.props && vnode.props.type) {
  9154. case 'checkbox':
  9155. modelToUse = vModelCheckbox;
  9156. break;
  9157. case 'radio':
  9158. modelToUse = vModelRadio;
  9159. break;
  9160. default:
  9161. modelToUse = vModelText;
  9162. }
  9163. }
  9164. const fn = modelToUse[hook];
  9165. fn && fn(el, binding, vnode, prevVNode);
  9166. }
  9167. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  9168. const modifierGuards = {
  9169. stop: e => e.stopPropagation(),
  9170. prevent: e => e.preventDefault(),
  9171. self: e => e.target !== e.currentTarget,
  9172. ctrl: e => !e.ctrlKey,
  9173. shift: e => !e.shiftKey,
  9174. alt: e => !e.altKey,
  9175. meta: e => !e.metaKey,
  9176. left: e => 'button' in e && e.button !== 0,
  9177. middle: e => 'button' in e && e.button !== 1,
  9178. right: e => 'button' in e && e.button !== 2,
  9179. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  9180. };
  9181. /**
  9182. * @private
  9183. */
  9184. const withModifiers = (fn, modifiers) => {
  9185. return (event, ...args) => {
  9186. for (let i = 0; i < modifiers.length; i++) {
  9187. const guard = modifierGuards[modifiers[i]];
  9188. if (guard && guard(event, modifiers))
  9189. return;
  9190. }
  9191. return fn(event, ...args);
  9192. };
  9193. };
  9194. // Kept for 2.x compat.
  9195. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  9196. const keyNames = {
  9197. esc: 'escape',
  9198. space: ' ',
  9199. up: 'arrow-up',
  9200. left: 'arrow-left',
  9201. right: 'arrow-right',
  9202. down: 'arrow-down',
  9203. delete: 'backspace'
  9204. };
  9205. /**
  9206. * @private
  9207. */
  9208. const withKeys = (fn, modifiers) => {
  9209. return (event) => {
  9210. if (!('key' in event))
  9211. return;
  9212. const eventKey = hyphenate(event.key);
  9213. if (
  9214. // None of the provided key modifiers match the current event key
  9215. !modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  9216. return;
  9217. }
  9218. return fn(event);
  9219. };
  9220. };
  9221. const vShow = {
  9222. beforeMount(el, { value }, { transition }) {
  9223. el._vod = el.style.display === 'none' ? '' : el.style.display;
  9224. if (transition && value) {
  9225. transition.beforeEnter(el);
  9226. }
  9227. else {
  9228. setDisplay(el, value);
  9229. }
  9230. },
  9231. mounted(el, { value }, { transition }) {
  9232. if (transition && value) {
  9233. transition.enter(el);
  9234. }
  9235. },
  9236. updated(el, { value, oldValue }, { transition }) {
  9237. if (!value === !oldValue)
  9238. return;
  9239. if (transition) {
  9240. if (value) {
  9241. transition.beforeEnter(el);
  9242. setDisplay(el, true);
  9243. transition.enter(el);
  9244. }
  9245. else {
  9246. transition.leave(el, () => {
  9247. setDisplay(el, false);
  9248. });
  9249. }
  9250. }
  9251. else {
  9252. setDisplay(el, value);
  9253. }
  9254. },
  9255. beforeUnmount(el, { value }) {
  9256. setDisplay(el, value);
  9257. }
  9258. };
  9259. function setDisplay(el, value) {
  9260. el.style.display = value ? el._vod : 'none';
  9261. }
  9262. const rendererOptions = extend({ patchProp, forcePatchProp }, nodeOps);
  9263. // lazy create the renderer - this makes core renderer logic tree-shakable
  9264. // in case the user only imports reactivity utilities from Vue.
  9265. let renderer;
  9266. let enabledHydration = false;
  9267. function ensureRenderer() {
  9268. return renderer || (renderer = createRenderer(rendererOptions));
  9269. }
  9270. function ensureHydrationRenderer() {
  9271. renderer = enabledHydration
  9272. ? renderer
  9273. : createHydrationRenderer(rendererOptions);
  9274. enabledHydration = true;
  9275. return renderer;
  9276. }
  9277. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  9278. const render = ((...args) => {
  9279. ensureRenderer().render(...args);
  9280. });
  9281. const hydrate = ((...args) => {
  9282. ensureHydrationRenderer().hydrate(...args);
  9283. });
  9284. const createApp = ((...args) => {
  9285. const app = ensureRenderer().createApp(...args);
  9286. {
  9287. injectNativeTagCheck(app);
  9288. injectCustomElementCheck(app);
  9289. }
  9290. const { mount } = app;
  9291. app.mount = (containerOrSelector) => {
  9292. const container = normalizeContainer(containerOrSelector);
  9293. if (!container)
  9294. return;
  9295. const component = app._component;
  9296. if (!isFunction(component) && !component.render && !component.template) {
  9297. component.template = container.innerHTML;
  9298. }
  9299. // clear content before mounting
  9300. container.innerHTML = '';
  9301. const proxy = mount(container);
  9302. if (container instanceof Element) {
  9303. container.removeAttribute('v-cloak');
  9304. container.setAttribute('data-v-app', '');
  9305. }
  9306. return proxy;
  9307. };
  9308. return app;
  9309. });
  9310. const createSSRApp = ((...args) => {
  9311. const app = ensureHydrationRenderer().createApp(...args);
  9312. {
  9313. injectNativeTagCheck(app);
  9314. injectCustomElementCheck(app);
  9315. }
  9316. const { mount } = app;
  9317. app.mount = (containerOrSelector) => {
  9318. const container = normalizeContainer(containerOrSelector);
  9319. if (container) {
  9320. return mount(container, true);
  9321. }
  9322. };
  9323. return app;
  9324. });
  9325. function injectNativeTagCheck(app) {
  9326. // Inject `isNativeTag`
  9327. // this is used for component name validation (dev only)
  9328. Object.defineProperty(app.config, 'isNativeTag', {
  9329. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  9330. writable: false
  9331. });
  9332. }
  9333. // dev only
  9334. function injectCustomElementCheck(app) {
  9335. if (isRuntimeOnly()) {
  9336. const value = app.config.isCustomElement;
  9337. Object.defineProperty(app.config, 'isCustomElement', {
  9338. get() {
  9339. return value;
  9340. },
  9341. set() {
  9342. warn(`The \`isCustomElement\` config option is only respected when using the runtime compiler.` +
  9343. `If you are using the runtime-only build, \`isCustomElement\` must be passed to \`@vue/compiler-dom\` in the build setup instead` +
  9344. `- for example, via the \`compilerOptions\` option in vue-loader: https://vue-loader.vuejs.org/options.html#compileroptions.`);
  9345. }
  9346. });
  9347. }
  9348. }
  9349. function normalizeContainer(container) {
  9350. if (isString(container)) {
  9351. const res = document.querySelector(container);
  9352. if (!res) {
  9353. warn(`Failed to mount app: mount target selector "${container}" returned null.`);
  9354. }
  9355. return res;
  9356. }
  9357. if (container instanceof window.ShadowRoot &&
  9358. container.mode === 'closed') {
  9359. warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  9360. }
  9361. return container;
  9362. }
  9363. function initDev() {
  9364. {
  9365. {
  9366. console.info(`You are running a development build of Vue.\n` +
  9367. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  9368. }
  9369. initCustomFormatter();
  9370. }
  9371. }
  9372. function defaultOnError(error) {
  9373. throw error;
  9374. }
  9375. function createCompilerError(code, loc, messages, additionalMessage) {
  9376. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  9377. ;
  9378. const error = new SyntaxError(String(msg));
  9379. error.code = code;
  9380. error.loc = loc;
  9381. return error;
  9382. }
  9383. const errorMessages = {
  9384. // parse errors
  9385. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  9386. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  9387. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  9388. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  9389. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  9390. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  9391. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  9392. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  9393. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  9394. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  9395. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  9396. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  9397. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  9398. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  9399. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  9400. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  9401. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  9402. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  9403. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  9404. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  9405. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  9406. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  9407. // Vue-specific parse errors
  9408. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  9409. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  9410. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  9411. [26 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  9412. 'Note that dynamic directive argument cannot contain spaces.',
  9413. // transform errors
  9414. [27 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  9415. [28 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  9416. [29 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if.`,
  9417. [30 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  9418. [31 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  9419. [32 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  9420. [33 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  9421. [34 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  9422. [35 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  9423. [36 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  9424. `When there are multiple named slots, all slots should use <template> ` +
  9425. `syntax to avoid scope ambiguity.`,
  9426. [37 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  9427. [38 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  9428. `default slot. These children will be ignored.`,
  9429. [39 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  9430. [40 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  9431. [41 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  9432. [42 /* X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  9433. [43 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  9434. [44 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  9435. // generic errors
  9436. [45 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  9437. [46 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  9438. [47 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  9439. [48 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`
  9440. };
  9441. const FRAGMENT = Symbol(`Fragment` );
  9442. const TELEPORT = Symbol(`Teleport` );
  9443. const SUSPENSE = Symbol(`Suspense` );
  9444. const KEEP_ALIVE = Symbol(`KeepAlive` );
  9445. const BASE_TRANSITION = Symbol(`BaseTransition` );
  9446. const OPEN_BLOCK = Symbol(`openBlock` );
  9447. const CREATE_BLOCK = Symbol(`createBlock` );
  9448. const CREATE_VNODE = Symbol(`createVNode` );
  9449. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  9450. const CREATE_TEXT = Symbol(`createTextVNode` );
  9451. const CREATE_STATIC = Symbol(`createStaticVNode` );
  9452. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  9453. const RESOLVE_DYNAMIC_COMPONENT = Symbol(`resolveDynamicComponent` );
  9454. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  9455. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  9456. const RENDER_LIST = Symbol(`renderList` );
  9457. const RENDER_SLOT = Symbol(`renderSlot` );
  9458. const CREATE_SLOTS = Symbol(`createSlots` );
  9459. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  9460. const MERGE_PROPS = Symbol(`mergeProps` );
  9461. const TO_HANDLERS = Symbol(`toHandlers` );
  9462. const CAMELIZE = Symbol(`camelize` );
  9463. const CAPITALIZE = Symbol(`capitalize` );
  9464. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  9465. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  9466. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  9467. const POP_SCOPE_ID = Symbol(`popScopeId` );
  9468. const WITH_SCOPE_ID = Symbol(`withScopeId` );
  9469. const WITH_CTX = Symbol(`withCtx` );
  9470. const UNREF = Symbol(`unref` );
  9471. const IS_REF = Symbol(`isRef` );
  9472. // Name mapping for runtime helpers that need to be imported from 'vue' in
  9473. // generated code. Make sure these are correctly exported in the runtime!
  9474. // Using `any` here because TS doesn't allow symbols as index type.
  9475. const helperNameMap = {
  9476. [FRAGMENT]: `Fragment`,
  9477. [TELEPORT]: `Teleport`,
  9478. [SUSPENSE]: `Suspense`,
  9479. [KEEP_ALIVE]: `KeepAlive`,
  9480. [BASE_TRANSITION]: `BaseTransition`,
  9481. [OPEN_BLOCK]: `openBlock`,
  9482. [CREATE_BLOCK]: `createBlock`,
  9483. [CREATE_VNODE]: `createVNode`,
  9484. [CREATE_COMMENT]: `createCommentVNode`,
  9485. [CREATE_TEXT]: `createTextVNode`,
  9486. [CREATE_STATIC]: `createStaticVNode`,
  9487. [RESOLVE_COMPONENT]: `resolveComponent`,
  9488. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  9489. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  9490. [WITH_DIRECTIVES]: `withDirectives`,
  9491. [RENDER_LIST]: `renderList`,
  9492. [RENDER_SLOT]: `renderSlot`,
  9493. [CREATE_SLOTS]: `createSlots`,
  9494. [TO_DISPLAY_STRING]: `toDisplayString`,
  9495. [MERGE_PROPS]: `mergeProps`,
  9496. [TO_HANDLERS]: `toHandlers`,
  9497. [CAMELIZE]: `camelize`,
  9498. [CAPITALIZE]: `capitalize`,
  9499. [TO_HANDLER_KEY]: `toHandlerKey`,
  9500. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  9501. [PUSH_SCOPE_ID]: `pushScopeId`,
  9502. [POP_SCOPE_ID]: `popScopeId`,
  9503. [WITH_SCOPE_ID]: `withScopeId`,
  9504. [WITH_CTX]: `withCtx`,
  9505. [UNREF]: `unref`,
  9506. [IS_REF]: `isRef`
  9507. };
  9508. function registerRuntimeHelpers(helpers) {
  9509. Object.getOwnPropertySymbols(helpers).forEach(s => {
  9510. helperNameMap[s] = helpers[s];
  9511. });
  9512. }
  9513. // AST Utilities ---------------------------------------------------------------
  9514. // Some expressions, e.g. sequence and conditional expressions, are never
  9515. // associated with template nodes, so their source locations are just a stub.
  9516. // Container types like CompoundExpression also don't need a real location.
  9517. const locStub = {
  9518. source: '',
  9519. start: { line: 1, column: 1, offset: 0 },
  9520. end: { line: 1, column: 1, offset: 0 }
  9521. };
  9522. function createRoot(children, loc = locStub) {
  9523. return {
  9524. type: 0 /* ROOT */,
  9525. children,
  9526. helpers: [],
  9527. components: [],
  9528. directives: [],
  9529. hoists: [],
  9530. imports: [],
  9531. cached: 0,
  9532. temps: 0,
  9533. codegenNode: undefined,
  9534. loc
  9535. };
  9536. }
  9537. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, loc = locStub) {
  9538. if (context) {
  9539. if (isBlock) {
  9540. context.helper(OPEN_BLOCK);
  9541. context.helper(CREATE_BLOCK);
  9542. }
  9543. else {
  9544. context.helper(CREATE_VNODE);
  9545. }
  9546. if (directives) {
  9547. context.helper(WITH_DIRECTIVES);
  9548. }
  9549. }
  9550. return {
  9551. type: 13 /* VNODE_CALL */,
  9552. tag,
  9553. props,
  9554. children,
  9555. patchFlag,
  9556. dynamicProps,
  9557. directives,
  9558. isBlock,
  9559. disableTracking,
  9560. loc
  9561. };
  9562. }
  9563. function createArrayExpression(elements, loc = locStub) {
  9564. return {
  9565. type: 17 /* JS_ARRAY_EXPRESSION */,
  9566. loc,
  9567. elements
  9568. };
  9569. }
  9570. function createObjectExpression(properties, loc = locStub) {
  9571. return {
  9572. type: 15 /* JS_OBJECT_EXPRESSION */,
  9573. loc,
  9574. properties
  9575. };
  9576. }
  9577. function createObjectProperty(key, value) {
  9578. return {
  9579. type: 16 /* JS_PROPERTY */,
  9580. loc: locStub,
  9581. key: isString(key) ? createSimpleExpression(key, true) : key,
  9582. value
  9583. };
  9584. }
  9585. function createSimpleExpression(content, isStatic, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
  9586. return {
  9587. type: 4 /* SIMPLE_EXPRESSION */,
  9588. loc,
  9589. content,
  9590. isStatic,
  9591. constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
  9592. };
  9593. }
  9594. function createCompoundExpression(children, loc = locStub) {
  9595. return {
  9596. type: 8 /* COMPOUND_EXPRESSION */,
  9597. loc,
  9598. children
  9599. };
  9600. }
  9601. function createCallExpression(callee, args = [], loc = locStub) {
  9602. return {
  9603. type: 14 /* JS_CALL_EXPRESSION */,
  9604. loc,
  9605. callee,
  9606. arguments: args
  9607. };
  9608. }
  9609. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  9610. return {
  9611. type: 18 /* JS_FUNCTION_EXPRESSION */,
  9612. params,
  9613. returns,
  9614. newline,
  9615. isSlot,
  9616. loc
  9617. };
  9618. }
  9619. function createConditionalExpression(test, consequent, alternate, newline = true) {
  9620. return {
  9621. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  9622. test,
  9623. consequent,
  9624. alternate,
  9625. newline,
  9626. loc: locStub
  9627. };
  9628. }
  9629. function createCacheExpression(index, value, isVNode = false) {
  9630. return {
  9631. type: 20 /* JS_CACHE_EXPRESSION */,
  9632. index,
  9633. value,
  9634. isVNode,
  9635. loc: locStub
  9636. };
  9637. }
  9638. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  9639. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  9640. function isCoreComponent(tag) {
  9641. if (isBuiltInType(tag, 'Teleport')) {
  9642. return TELEPORT;
  9643. }
  9644. else if (isBuiltInType(tag, 'Suspense')) {
  9645. return SUSPENSE;
  9646. }
  9647. else if (isBuiltInType(tag, 'KeepAlive')) {
  9648. return KEEP_ALIVE;
  9649. }
  9650. else if (isBuiltInType(tag, 'BaseTransition')) {
  9651. return BASE_TRANSITION;
  9652. }
  9653. }
  9654. const nonIdentifierRE = /^\d|[^\$\w]/;
  9655. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  9656. const memberExpRE = /^[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*|\[[^\]]+\])*$/;
  9657. const isMemberExpression = (path) => {
  9658. if (!path)
  9659. return false;
  9660. return memberExpRE.test(path.trim());
  9661. };
  9662. function getInnerRange(loc, offset, length) {
  9663. const source = loc.source.substr(offset, length);
  9664. const newLoc = {
  9665. source,
  9666. start: advancePositionWithClone(loc.start, loc.source, offset),
  9667. end: loc.end
  9668. };
  9669. if (length != null) {
  9670. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  9671. }
  9672. return newLoc;
  9673. }
  9674. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  9675. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  9676. }
  9677. // advance by mutation without cloning (for performance reasons), since this
  9678. // gets called a lot in the parser
  9679. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  9680. let linesCount = 0;
  9681. let lastNewLinePos = -1;
  9682. for (let i = 0; i < numberOfCharacters; i++) {
  9683. if (source.charCodeAt(i) === 10 /* newline char code */) {
  9684. linesCount++;
  9685. lastNewLinePos = i;
  9686. }
  9687. }
  9688. pos.offset += numberOfCharacters;
  9689. pos.line += linesCount;
  9690. pos.column =
  9691. lastNewLinePos === -1
  9692. ? pos.column + numberOfCharacters
  9693. : numberOfCharacters - lastNewLinePos;
  9694. return pos;
  9695. }
  9696. function assert(condition, msg) {
  9697. /* istanbul ignore if */
  9698. if (!condition) {
  9699. throw new Error(msg || `unexpected compiler condition`);
  9700. }
  9701. }
  9702. function findDir(node, name, allowEmpty = false) {
  9703. for (let i = 0; i < node.props.length; i++) {
  9704. const p = node.props[i];
  9705. if (p.type === 7 /* DIRECTIVE */ &&
  9706. (allowEmpty || p.exp) &&
  9707. (isString(name) ? p.name === name : name.test(p.name))) {
  9708. return p;
  9709. }
  9710. }
  9711. }
  9712. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  9713. for (let i = 0; i < node.props.length; i++) {
  9714. const p = node.props[i];
  9715. if (p.type === 6 /* ATTRIBUTE */) {
  9716. if (dynamicOnly)
  9717. continue;
  9718. if (p.name === name && (p.value || allowEmpty)) {
  9719. return p;
  9720. }
  9721. }
  9722. else if (p.name === 'bind' &&
  9723. (p.exp || allowEmpty) &&
  9724. isBindKey(p.arg, name)) {
  9725. return p;
  9726. }
  9727. }
  9728. }
  9729. function isBindKey(arg, name) {
  9730. return !!(arg && isStaticExp(arg) && arg.content === name);
  9731. }
  9732. function hasDynamicKeyVBind(node) {
  9733. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  9734. p.name === 'bind' &&
  9735. (!p.arg || // v-bind="obj"
  9736. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  9737. !p.arg.isStatic) // v-bind:[foo]
  9738. );
  9739. }
  9740. function isText(node) {
  9741. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  9742. }
  9743. function isVSlot(p) {
  9744. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  9745. }
  9746. function isTemplateNode(node) {
  9747. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  9748. }
  9749. function isSlotOutlet(node) {
  9750. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  9751. }
  9752. function injectProp(node, prop, context) {
  9753. let propsWithInjection;
  9754. const props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  9755. if (props == null || isString(props)) {
  9756. propsWithInjection = createObjectExpression([prop]);
  9757. }
  9758. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  9759. // merged props... add ours
  9760. // only inject key to object literal if it's the first argument so that
  9761. // if doesn't override user provided keys
  9762. const first = props.arguments[0];
  9763. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  9764. first.properties.unshift(prop);
  9765. }
  9766. else {
  9767. if (props.callee === TO_HANDLERS) {
  9768. // #2366
  9769. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  9770. createObjectExpression([prop]),
  9771. props
  9772. ]);
  9773. }
  9774. else {
  9775. props.arguments.unshift(createObjectExpression([prop]));
  9776. }
  9777. }
  9778. !propsWithInjection && (propsWithInjection = props);
  9779. }
  9780. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  9781. let alreadyExists = false;
  9782. // check existing key to avoid overriding user provided keys
  9783. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  9784. const propKeyName = prop.key.content;
  9785. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  9786. p.key.content === propKeyName);
  9787. }
  9788. if (!alreadyExists) {
  9789. props.properties.unshift(prop);
  9790. }
  9791. propsWithInjection = props;
  9792. }
  9793. else {
  9794. // single v-bind with expression, return a merged replacement
  9795. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  9796. createObjectExpression([prop]),
  9797. props
  9798. ]);
  9799. }
  9800. if (node.type === 13 /* VNODE_CALL */) {
  9801. node.props = propsWithInjection;
  9802. }
  9803. else {
  9804. node.arguments[2] = propsWithInjection;
  9805. }
  9806. }
  9807. function toValidAssetId(name, type) {
  9808. return `_${type}_${name.replace(/[^\w]/g, '_')}`;
  9809. }
  9810. // The default decoder only provides escapes for characters reserved as part of
  9811. // the template syntax, and is only used if the custom renderer did not provide
  9812. // a platform-specific decoder.
  9813. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  9814. const decodeMap = {
  9815. gt: '>',
  9816. lt: '<',
  9817. amp: '&',
  9818. apos: "'",
  9819. quot: '"'
  9820. };
  9821. const defaultParserOptions = {
  9822. delimiters: [`{{`, `}}`],
  9823. getNamespace: () => 0 /* HTML */,
  9824. getTextMode: () => 0 /* DATA */,
  9825. isVoidTag: NO,
  9826. isPreTag: NO,
  9827. isCustomElement: NO,
  9828. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  9829. onError: defaultOnError,
  9830. comments: false
  9831. };
  9832. function baseParse(content, options = {}) {
  9833. const context = createParserContext(content, options);
  9834. const start = getCursor(context);
  9835. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  9836. }
  9837. function createParserContext(content, rawOptions) {
  9838. const options = extend({}, defaultParserOptions);
  9839. for (const key in rawOptions) {
  9840. // @ts-ignore
  9841. options[key] = rawOptions[key] || defaultParserOptions[key];
  9842. }
  9843. return {
  9844. options,
  9845. column: 1,
  9846. line: 1,
  9847. offset: 0,
  9848. originalSource: content,
  9849. source: content,
  9850. inPre: false,
  9851. inVPre: false
  9852. };
  9853. }
  9854. function parseChildren(context, mode, ancestors) {
  9855. const parent = last(ancestors);
  9856. const ns = parent ? parent.ns : 0 /* HTML */;
  9857. const nodes = [];
  9858. while (!isEnd(context, mode, ancestors)) {
  9859. const s = context.source;
  9860. let node = undefined;
  9861. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  9862. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  9863. // '{{'
  9864. node = parseInterpolation(context, mode);
  9865. }
  9866. else if (mode === 0 /* DATA */ && s[0] === '<') {
  9867. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  9868. if (s.length === 1) {
  9869. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  9870. }
  9871. else if (s[1] === '!') {
  9872. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  9873. if (startsWith(s, '<!--')) {
  9874. node = parseComment(context);
  9875. }
  9876. else if (startsWith(s, '<!DOCTYPE')) {
  9877. // Ignore DOCTYPE by a limitation.
  9878. node = parseBogusComment(context);
  9879. }
  9880. else if (startsWith(s, '<![CDATA[')) {
  9881. if (ns !== 0 /* HTML */) {
  9882. node = parseCDATA(context, ancestors);
  9883. }
  9884. else {
  9885. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  9886. node = parseBogusComment(context);
  9887. }
  9888. }
  9889. else {
  9890. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  9891. node = parseBogusComment(context);
  9892. }
  9893. }
  9894. else if (s[1] === '/') {
  9895. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  9896. if (s.length === 2) {
  9897. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  9898. }
  9899. else if (s[2] === '>') {
  9900. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  9901. advanceBy(context, 3);
  9902. continue;
  9903. }
  9904. else if (/[a-z]/i.test(s[2])) {
  9905. emitError(context, 23 /* X_INVALID_END_TAG */);
  9906. parseTag(context, 1 /* End */, parent);
  9907. continue;
  9908. }
  9909. else {
  9910. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  9911. node = parseBogusComment(context);
  9912. }
  9913. }
  9914. else if (/[a-z]/i.test(s[1])) {
  9915. node = parseElement(context, ancestors);
  9916. }
  9917. else if (s[1] === '?') {
  9918. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  9919. node = parseBogusComment(context);
  9920. }
  9921. else {
  9922. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  9923. }
  9924. }
  9925. }
  9926. if (!node) {
  9927. node = parseText(context, mode);
  9928. }
  9929. if (isArray(node)) {
  9930. for (let i = 0; i < node.length; i++) {
  9931. pushNode(nodes, node[i]);
  9932. }
  9933. }
  9934. else {
  9935. pushNode(nodes, node);
  9936. }
  9937. }
  9938. // Whitespace management for more efficient output
  9939. // (same as v2 whitespace: 'condense')
  9940. let removedWhitespace = false;
  9941. if (mode !== 2 /* RAWTEXT */) {
  9942. for (let i = 0; i < nodes.length; i++) {
  9943. const node = nodes[i];
  9944. if (!context.inPre && node.type === 2 /* TEXT */) {
  9945. if (!/[^\t\r\n\f ]/.test(node.content)) {
  9946. const prev = nodes[i - 1];
  9947. const next = nodes[i + 1];
  9948. // If:
  9949. // - the whitespace is the first or last node, or:
  9950. // - the whitespace is adjacent to a comment, or:
  9951. // - the whitespace is between two elements AND contains newline
  9952. // Then the whitespace is ignored.
  9953. if (!prev ||
  9954. !next ||
  9955. prev.type === 3 /* COMMENT */ ||
  9956. next.type === 3 /* COMMENT */ ||
  9957. (prev.type === 1 /* ELEMENT */ &&
  9958. next.type === 1 /* ELEMENT */ &&
  9959. /[\r\n]/.test(node.content))) {
  9960. removedWhitespace = true;
  9961. nodes[i] = null;
  9962. }
  9963. else {
  9964. // Otherwise, condensed consecutive whitespace inside the text
  9965. // down to a single space
  9966. node.content = ' ';
  9967. }
  9968. }
  9969. else {
  9970. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  9971. }
  9972. }
  9973. }
  9974. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  9975. // remove leading newline per html spec
  9976. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  9977. const first = nodes[0];
  9978. if (first && first.type === 2 /* TEXT */) {
  9979. first.content = first.content.replace(/^\r?\n/, '');
  9980. }
  9981. }
  9982. }
  9983. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  9984. }
  9985. function pushNode(nodes, node) {
  9986. if (node.type === 2 /* TEXT */) {
  9987. const prev = last(nodes);
  9988. // Merge if both this and the previous node are text and those are
  9989. // consecutive. This happens for cases like "a < b".
  9990. if (prev &&
  9991. prev.type === 2 /* TEXT */ &&
  9992. prev.loc.end.offset === node.loc.start.offset) {
  9993. prev.content += node.content;
  9994. prev.loc.end = node.loc.end;
  9995. prev.loc.source += node.loc.source;
  9996. return;
  9997. }
  9998. }
  9999. nodes.push(node);
  10000. }
  10001. function parseCDATA(context, ancestors) {
  10002. advanceBy(context, 9);
  10003. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  10004. if (context.source.length === 0) {
  10005. emitError(context, 6 /* EOF_IN_CDATA */);
  10006. }
  10007. else {
  10008. advanceBy(context, 3);
  10009. }
  10010. return nodes;
  10011. }
  10012. function parseComment(context) {
  10013. const start = getCursor(context);
  10014. let content;
  10015. // Regular comment.
  10016. const match = /--(\!)?>/.exec(context.source);
  10017. if (!match) {
  10018. content = context.source.slice(4);
  10019. advanceBy(context, context.source.length);
  10020. emitError(context, 7 /* EOF_IN_COMMENT */);
  10021. }
  10022. else {
  10023. if (match.index <= 3) {
  10024. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  10025. }
  10026. if (match[1]) {
  10027. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  10028. }
  10029. content = context.source.slice(4, match.index);
  10030. // Advancing with reporting nested comments.
  10031. const s = context.source.slice(0, match.index);
  10032. let prevIndex = 1, nestedIndex = 0;
  10033. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  10034. advanceBy(context, nestedIndex - prevIndex + 1);
  10035. if (nestedIndex + 4 < s.length) {
  10036. emitError(context, 16 /* NESTED_COMMENT */);
  10037. }
  10038. prevIndex = nestedIndex + 1;
  10039. }
  10040. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  10041. }
  10042. return {
  10043. type: 3 /* COMMENT */,
  10044. content,
  10045. loc: getSelection(context, start)
  10046. };
  10047. }
  10048. function parseBogusComment(context) {
  10049. const start = getCursor(context);
  10050. const contentStart = context.source[1] === '?' ? 1 : 2;
  10051. let content;
  10052. const closeIndex = context.source.indexOf('>');
  10053. if (closeIndex === -1) {
  10054. content = context.source.slice(contentStart);
  10055. advanceBy(context, context.source.length);
  10056. }
  10057. else {
  10058. content = context.source.slice(contentStart, closeIndex);
  10059. advanceBy(context, closeIndex + 1);
  10060. }
  10061. return {
  10062. type: 3 /* COMMENT */,
  10063. content,
  10064. loc: getSelection(context, start)
  10065. };
  10066. }
  10067. function parseElement(context, ancestors) {
  10068. // Start tag.
  10069. const wasInPre = context.inPre;
  10070. const wasInVPre = context.inVPre;
  10071. const parent = last(ancestors);
  10072. const element = parseTag(context, 0 /* Start */, parent);
  10073. const isPreBoundary = context.inPre && !wasInPre;
  10074. const isVPreBoundary = context.inVPre && !wasInVPre;
  10075. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  10076. return element;
  10077. }
  10078. // Children.
  10079. ancestors.push(element);
  10080. const mode = context.options.getTextMode(element, parent);
  10081. const children = parseChildren(context, mode, ancestors);
  10082. ancestors.pop();
  10083. element.children = children;
  10084. // End tag.
  10085. if (startsWithEndTagOpen(context.source, element.tag)) {
  10086. parseTag(context, 1 /* End */, parent);
  10087. }
  10088. else {
  10089. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  10090. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  10091. const first = children[0];
  10092. if (first && startsWith(first.loc.source, '<!--')) {
  10093. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  10094. }
  10095. }
  10096. }
  10097. element.loc = getSelection(context, element.loc.start);
  10098. if (isPreBoundary) {
  10099. context.inPre = false;
  10100. }
  10101. if (isVPreBoundary) {
  10102. context.inVPre = false;
  10103. }
  10104. return element;
  10105. }
  10106. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  10107. /**
  10108. * Parse a tag (E.g. `<div id=a>`) with that type (start tag or end tag).
  10109. */
  10110. function parseTag(context, type, parent) {
  10111. // Tag open.
  10112. const start = getCursor(context);
  10113. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  10114. const tag = match[1];
  10115. const ns = context.options.getNamespace(tag, parent);
  10116. advanceBy(context, match[0].length);
  10117. advanceSpaces(context);
  10118. // save current state in case we need to re-parse attributes with v-pre
  10119. const cursor = getCursor(context);
  10120. const currentSource = context.source;
  10121. // Attributes.
  10122. let props = parseAttributes(context, type);
  10123. // check <pre> tag
  10124. if (context.options.isPreTag(tag)) {
  10125. context.inPre = true;
  10126. }
  10127. // check v-pre
  10128. if (!context.inVPre &&
  10129. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  10130. context.inVPre = true;
  10131. // reset context
  10132. extend(context, cursor);
  10133. context.source = currentSource;
  10134. // re-parse attrs and filter out v-pre itself
  10135. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  10136. }
  10137. // Tag close.
  10138. let isSelfClosing = false;
  10139. if (context.source.length === 0) {
  10140. emitError(context, 9 /* EOF_IN_TAG */);
  10141. }
  10142. else {
  10143. isSelfClosing = startsWith(context.source, '/>');
  10144. if (type === 1 /* End */ && isSelfClosing) {
  10145. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  10146. }
  10147. advanceBy(context, isSelfClosing ? 2 : 1);
  10148. }
  10149. let tagType = 0 /* ELEMENT */;
  10150. const options = context.options;
  10151. if (!context.inVPre && !options.isCustomElement(tag)) {
  10152. const hasVIs = props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'is');
  10153. if (options.isNativeTag && !hasVIs) {
  10154. if (!options.isNativeTag(tag))
  10155. tagType = 1 /* COMPONENT */;
  10156. }
  10157. else if (hasVIs ||
  10158. isCoreComponent(tag) ||
  10159. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  10160. /^[A-Z]/.test(tag) ||
  10161. tag === 'component') {
  10162. tagType = 1 /* COMPONENT */;
  10163. }
  10164. if (tag === 'slot') {
  10165. tagType = 2 /* SLOT */;
  10166. }
  10167. else if (tag === 'template' &&
  10168. props.some(p => {
  10169. return (p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name));
  10170. })) {
  10171. tagType = 3 /* TEMPLATE */;
  10172. }
  10173. }
  10174. return {
  10175. type: 1 /* ELEMENT */,
  10176. ns,
  10177. tag,
  10178. tagType,
  10179. props,
  10180. isSelfClosing,
  10181. children: [],
  10182. loc: getSelection(context, start),
  10183. codegenNode: undefined // to be created during transform phase
  10184. };
  10185. }
  10186. function parseAttributes(context, type) {
  10187. const props = [];
  10188. const attributeNames = new Set();
  10189. while (context.source.length > 0 &&
  10190. !startsWith(context.source, '>') &&
  10191. !startsWith(context.source, '/>')) {
  10192. if (startsWith(context.source, '/')) {
  10193. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  10194. advanceBy(context, 1);
  10195. advanceSpaces(context);
  10196. continue;
  10197. }
  10198. if (type === 1 /* End */) {
  10199. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  10200. }
  10201. const attr = parseAttribute(context, attributeNames);
  10202. if (type === 0 /* Start */) {
  10203. props.push(attr);
  10204. }
  10205. if (/^[^\t\r\n\f />]/.test(context.source)) {
  10206. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  10207. }
  10208. advanceSpaces(context);
  10209. }
  10210. return props;
  10211. }
  10212. function parseAttribute(context, nameSet) {
  10213. // Name.
  10214. const start = getCursor(context);
  10215. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  10216. const name = match[0];
  10217. if (nameSet.has(name)) {
  10218. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  10219. }
  10220. nameSet.add(name);
  10221. if (name[0] === '=') {
  10222. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  10223. }
  10224. {
  10225. const pattern = /["'<]/g;
  10226. let m;
  10227. while ((m = pattern.exec(name))) {
  10228. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  10229. }
  10230. }
  10231. advanceBy(context, name.length);
  10232. // Value
  10233. let value = undefined;
  10234. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  10235. advanceSpaces(context);
  10236. advanceBy(context, 1);
  10237. advanceSpaces(context);
  10238. value = parseAttributeValue(context);
  10239. if (!value) {
  10240. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  10241. }
  10242. }
  10243. const loc = getSelection(context, start);
  10244. if (!context.inVPre && /^(v-|:|@|#)/.test(name)) {
  10245. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  10246. const dirName = match[1] ||
  10247. (startsWith(name, ':') ? 'bind' : startsWith(name, '@') ? 'on' : 'slot');
  10248. let arg;
  10249. if (match[2]) {
  10250. const isSlot = dirName === 'slot';
  10251. const startOffset = name.indexOf(match[2]);
  10252. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  10253. let content = match[2];
  10254. let isStatic = true;
  10255. if (content.startsWith('[')) {
  10256. isStatic = false;
  10257. if (!content.endsWith(']')) {
  10258. emitError(context, 26 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  10259. }
  10260. content = content.substr(1, content.length - 2);
  10261. }
  10262. else if (isSlot) {
  10263. // #1241 special case for v-slot: vuetify relies extensively on slot
  10264. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  10265. // supports such usage so we are keeping it consistent with 2.x.
  10266. content += match[3] || '';
  10267. }
  10268. arg = {
  10269. type: 4 /* SIMPLE_EXPRESSION */,
  10270. content,
  10271. isStatic,
  10272. constType: isStatic
  10273. ? 3 /* CAN_STRINGIFY */
  10274. : 0 /* NOT_CONSTANT */,
  10275. loc
  10276. };
  10277. }
  10278. if (value && value.isQuoted) {
  10279. const valueLoc = value.loc;
  10280. valueLoc.start.offset++;
  10281. valueLoc.start.column++;
  10282. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  10283. valueLoc.source = valueLoc.source.slice(1, -1);
  10284. }
  10285. return {
  10286. type: 7 /* DIRECTIVE */,
  10287. name: dirName,
  10288. exp: value && {
  10289. type: 4 /* SIMPLE_EXPRESSION */,
  10290. content: value.content,
  10291. isStatic: false,
  10292. // Treat as non-constant by default. This can be potentially set to
  10293. // other values by `transformExpression` to make it eligible for hoisting.
  10294. constType: 0 /* NOT_CONSTANT */,
  10295. loc: value.loc
  10296. },
  10297. arg,
  10298. modifiers: match[3] ? match[3].substr(1).split('.') : [],
  10299. loc
  10300. };
  10301. }
  10302. return {
  10303. type: 6 /* ATTRIBUTE */,
  10304. name,
  10305. value: value && {
  10306. type: 2 /* TEXT */,
  10307. content: value.content,
  10308. loc: value.loc
  10309. },
  10310. loc
  10311. };
  10312. }
  10313. function parseAttributeValue(context) {
  10314. const start = getCursor(context);
  10315. let content;
  10316. const quote = context.source[0];
  10317. const isQuoted = quote === `"` || quote === `'`;
  10318. if (isQuoted) {
  10319. // Quoted value.
  10320. advanceBy(context, 1);
  10321. const endIndex = context.source.indexOf(quote);
  10322. if (endIndex === -1) {
  10323. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  10324. }
  10325. else {
  10326. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  10327. advanceBy(context, 1);
  10328. }
  10329. }
  10330. else {
  10331. // Unquoted
  10332. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  10333. if (!match) {
  10334. return undefined;
  10335. }
  10336. const unexpectedChars = /["'<=`]/g;
  10337. let m;
  10338. while ((m = unexpectedChars.exec(match[0]))) {
  10339. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  10340. }
  10341. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  10342. }
  10343. return { content, isQuoted, loc: getSelection(context, start) };
  10344. }
  10345. function parseInterpolation(context, mode) {
  10346. const [open, close] = context.options.delimiters;
  10347. const closeIndex = context.source.indexOf(close, open.length);
  10348. if (closeIndex === -1) {
  10349. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  10350. return undefined;
  10351. }
  10352. const start = getCursor(context);
  10353. advanceBy(context, open.length);
  10354. const innerStart = getCursor(context);
  10355. const innerEnd = getCursor(context);
  10356. const rawContentLength = closeIndex - open.length;
  10357. const rawContent = context.source.slice(0, rawContentLength);
  10358. const preTrimContent = parseTextData(context, rawContentLength, mode);
  10359. const content = preTrimContent.trim();
  10360. const startOffset = preTrimContent.indexOf(content);
  10361. if (startOffset > 0) {
  10362. advancePositionWithMutation(innerStart, rawContent, startOffset);
  10363. }
  10364. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  10365. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  10366. advanceBy(context, close.length);
  10367. return {
  10368. type: 5 /* INTERPOLATION */,
  10369. content: {
  10370. type: 4 /* SIMPLE_EXPRESSION */,
  10371. isStatic: false,
  10372. // Set `isConstant` to false by default and will decide in transformExpression
  10373. constType: 0 /* NOT_CONSTANT */,
  10374. content,
  10375. loc: getSelection(context, innerStart, innerEnd)
  10376. },
  10377. loc: getSelection(context, start)
  10378. };
  10379. }
  10380. function parseText(context, mode) {
  10381. const endTokens = ['<', context.options.delimiters[0]];
  10382. if (mode === 3 /* CDATA */) {
  10383. endTokens.push(']]>');
  10384. }
  10385. let endIndex = context.source.length;
  10386. for (let i = 0; i < endTokens.length; i++) {
  10387. const index = context.source.indexOf(endTokens[i], 1);
  10388. if (index !== -1 && endIndex > index) {
  10389. endIndex = index;
  10390. }
  10391. }
  10392. const start = getCursor(context);
  10393. const content = parseTextData(context, endIndex, mode);
  10394. return {
  10395. type: 2 /* TEXT */,
  10396. content,
  10397. loc: getSelection(context, start)
  10398. };
  10399. }
  10400. /**
  10401. * Get text data with a given length from the current location.
  10402. * This translates HTML entities in the text data.
  10403. */
  10404. function parseTextData(context, length, mode) {
  10405. const rawText = context.source.slice(0, length);
  10406. advanceBy(context, length);
  10407. if (mode === 2 /* RAWTEXT */ ||
  10408. mode === 3 /* CDATA */ ||
  10409. rawText.indexOf('&') === -1) {
  10410. return rawText;
  10411. }
  10412. else {
  10413. // DATA or RCDATA containing "&"". Entity decoding required.
  10414. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  10415. }
  10416. }
  10417. function getCursor(context) {
  10418. const { column, line, offset } = context;
  10419. return { column, line, offset };
  10420. }
  10421. function getSelection(context, start, end) {
  10422. end = end || getCursor(context);
  10423. return {
  10424. start,
  10425. end,
  10426. source: context.originalSource.slice(start.offset, end.offset)
  10427. };
  10428. }
  10429. function last(xs) {
  10430. return xs[xs.length - 1];
  10431. }
  10432. function startsWith(source, searchString) {
  10433. return source.startsWith(searchString);
  10434. }
  10435. function advanceBy(context, numberOfCharacters) {
  10436. const { source } = context;
  10437. advancePositionWithMutation(context, source, numberOfCharacters);
  10438. context.source = source.slice(numberOfCharacters);
  10439. }
  10440. function advanceSpaces(context) {
  10441. const match = /^[\t\r\n\f ]+/.exec(context.source);
  10442. if (match) {
  10443. advanceBy(context, match[0].length);
  10444. }
  10445. }
  10446. function getNewPosition(context, start, numberOfCharacters) {
  10447. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  10448. }
  10449. function emitError(context, code, offset, loc = getCursor(context)) {
  10450. if (offset) {
  10451. loc.offset += offset;
  10452. loc.column += offset;
  10453. }
  10454. context.options.onError(createCompilerError(code, {
  10455. start: loc,
  10456. end: loc,
  10457. source: ''
  10458. }));
  10459. }
  10460. function isEnd(context, mode, ancestors) {
  10461. const s = context.source;
  10462. switch (mode) {
  10463. case 0 /* DATA */:
  10464. if (startsWith(s, '</')) {
  10465. // TODO: probably bad performance
  10466. for (let i = ancestors.length - 1; i >= 0; --i) {
  10467. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  10468. return true;
  10469. }
  10470. }
  10471. }
  10472. break;
  10473. case 1 /* RCDATA */:
  10474. case 2 /* RAWTEXT */: {
  10475. const parent = last(ancestors);
  10476. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  10477. return true;
  10478. }
  10479. break;
  10480. }
  10481. case 3 /* CDATA */:
  10482. if (startsWith(s, ']]>')) {
  10483. return true;
  10484. }
  10485. break;
  10486. }
  10487. return !s;
  10488. }
  10489. function startsWithEndTagOpen(source, tag) {
  10490. return (startsWith(source, '</') &&
  10491. source.substr(2, tag.length).toLowerCase() === tag.toLowerCase() &&
  10492. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  10493. }
  10494. function hoistStatic(root, context) {
  10495. walk(root, context,
  10496. // Root node is unfortunately non-hoistable due to potential parent
  10497. // fallthrough attributes.
  10498. isSingleElementRoot(root, root.children[0]));
  10499. }
  10500. function isSingleElementRoot(root, child) {
  10501. const { children } = root;
  10502. return (children.length === 1 &&
  10503. child.type === 1 /* ELEMENT */ &&
  10504. !isSlotOutlet(child));
  10505. }
  10506. function walk(node, context, doNotHoistNode = false) {
  10507. let hasHoistedNode = false;
  10508. // Some transforms, e.g. transformAssetUrls from @vue/compiler-sfc, replaces
  10509. // static bindings with expressions. These expressions are guaranteed to be
  10510. // constant so they are still eligible for hoisting, but they are only
  10511. // available at runtime and therefore cannot be evaluated ahead of time.
  10512. // This is only a concern for pre-stringification (via transformHoist by
  10513. // @vue/compiler-dom), but doing it here allows us to perform only one full
  10514. // walk of the AST and allow `stringifyStatic` to stop walking as soon as its
  10515. // stringficiation threshold is met.
  10516. let canStringify = true;
  10517. const { children } = node;
  10518. for (let i = 0; i < children.length; i++) {
  10519. const child = children[i];
  10520. // only plain elements & text calls are eligible for hoisting.
  10521. if (child.type === 1 /* ELEMENT */ &&
  10522. child.tagType === 0 /* ELEMENT */) {
  10523. const constantType = doNotHoistNode
  10524. ? 0 /* NOT_CONSTANT */
  10525. : getConstantType(child, context);
  10526. if (constantType > 0 /* NOT_CONSTANT */) {
  10527. if (constantType < 3 /* CAN_STRINGIFY */) {
  10528. canStringify = false;
  10529. }
  10530. if (constantType >= 2 /* CAN_HOIST */) {
  10531. child.codegenNode.patchFlag =
  10532. -1 /* HOISTED */ + (` /* HOISTED */` );
  10533. child.codegenNode = context.hoist(child.codegenNode);
  10534. hasHoistedNode = true;
  10535. continue;
  10536. }
  10537. }
  10538. else {
  10539. // node may contain dynamic children, but its props may be eligible for
  10540. // hoisting.
  10541. const codegenNode = child.codegenNode;
  10542. if (codegenNode.type === 13 /* VNODE_CALL */) {
  10543. const flag = getPatchFlag(codegenNode);
  10544. if ((!flag ||
  10545. flag === 512 /* NEED_PATCH */ ||
  10546. flag === 1 /* TEXT */) &&
  10547. getGeneratedPropsConstantType(child, context) >=
  10548. 2 /* CAN_HOIST */) {
  10549. const props = getNodeProps(child);
  10550. if (props) {
  10551. codegenNode.props = context.hoist(props);
  10552. }
  10553. }
  10554. }
  10555. }
  10556. }
  10557. else if (child.type === 12 /* TEXT_CALL */) {
  10558. const contentType = getConstantType(child.content, context);
  10559. if (contentType > 0) {
  10560. if (contentType < 3 /* CAN_STRINGIFY */) {
  10561. canStringify = false;
  10562. }
  10563. if (contentType >= 2 /* CAN_HOIST */) {
  10564. child.codegenNode = context.hoist(child.codegenNode);
  10565. hasHoistedNode = true;
  10566. }
  10567. }
  10568. }
  10569. // walk further
  10570. if (child.type === 1 /* ELEMENT */) {
  10571. walk(child, context);
  10572. }
  10573. else if (child.type === 11 /* FOR */) {
  10574. // Do not hoist v-for single child because it has to be a block
  10575. walk(child, context, child.children.length === 1);
  10576. }
  10577. else if (child.type === 9 /* IF */) {
  10578. for (let i = 0; i < child.branches.length; i++) {
  10579. // Do not hoist v-if single child because it has to be a block
  10580. walk(child.branches[i], context, child.branches[i].children.length === 1);
  10581. }
  10582. }
  10583. }
  10584. if (canStringify && hasHoistedNode && context.transformHoist) {
  10585. context.transformHoist(children, context, node);
  10586. }
  10587. }
  10588. function getConstantType(node, context) {
  10589. const { constantCache } = context;
  10590. switch (node.type) {
  10591. case 1 /* ELEMENT */:
  10592. if (node.tagType !== 0 /* ELEMENT */) {
  10593. return 0 /* NOT_CONSTANT */;
  10594. }
  10595. const cached = constantCache.get(node);
  10596. if (cached !== undefined) {
  10597. return cached;
  10598. }
  10599. const codegenNode = node.codegenNode;
  10600. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  10601. return 0 /* NOT_CONSTANT */;
  10602. }
  10603. const flag = getPatchFlag(codegenNode);
  10604. if (!flag) {
  10605. let returnType = 3 /* CAN_STRINGIFY */;
  10606. // Element itself has no patch flag. However we still need to check:
  10607. // 1. Even for a node with no patch flag, it is possible for it to contain
  10608. // non-hoistable expressions that refers to scope variables, e.g. compiler
  10609. // injected keys or cached event handlers. Therefore we need to always
  10610. // check the codegenNode's props to be sure.
  10611. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  10612. if (generatedPropsType === 0 /* NOT_CONSTANT */) {
  10613. constantCache.set(node, 0 /* NOT_CONSTANT */);
  10614. return 0 /* NOT_CONSTANT */;
  10615. }
  10616. if (generatedPropsType < returnType) {
  10617. returnType = generatedPropsType;
  10618. }
  10619. // 2. its children.
  10620. for (let i = 0; i < node.children.length; i++) {
  10621. const childType = getConstantType(node.children[i], context);
  10622. if (childType === 0 /* NOT_CONSTANT */) {
  10623. constantCache.set(node, 0 /* NOT_CONSTANT */);
  10624. return 0 /* NOT_CONSTANT */;
  10625. }
  10626. if (childType < returnType) {
  10627. returnType = childType;
  10628. }
  10629. }
  10630. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  10631. // type, check if any of the props can cause the type to be lowered
  10632. // we can skip can_patch because it's guaranteed by the absence of a
  10633. // patchFlag.
  10634. if (returnType > 1 /* CAN_SKIP_PATCH */) {
  10635. for (let i = 0; i < node.props.length; i++) {
  10636. const p = node.props[i];
  10637. if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
  10638. const expType = getConstantType(p.exp, context);
  10639. if (expType === 0 /* NOT_CONSTANT */) {
  10640. constantCache.set(node, 0 /* NOT_CONSTANT */);
  10641. return 0 /* NOT_CONSTANT */;
  10642. }
  10643. if (expType < returnType) {
  10644. returnType = expType;
  10645. }
  10646. }
  10647. }
  10648. }
  10649. // only svg/foreignObject could be block here, however if they are
  10650. // static then they don't need to be blocks since there will be no
  10651. // nested updates.
  10652. if (codegenNode.isBlock) {
  10653. codegenNode.isBlock = false;
  10654. context.helper(CREATE_VNODE);
  10655. }
  10656. constantCache.set(node, returnType);
  10657. return returnType;
  10658. }
  10659. else {
  10660. constantCache.set(node, 0 /* NOT_CONSTANT */);
  10661. return 0 /* NOT_CONSTANT */;
  10662. }
  10663. case 2 /* TEXT */:
  10664. case 3 /* COMMENT */:
  10665. return 3 /* CAN_STRINGIFY */;
  10666. case 9 /* IF */:
  10667. case 11 /* FOR */:
  10668. case 10 /* IF_BRANCH */:
  10669. return 0 /* NOT_CONSTANT */;
  10670. case 5 /* INTERPOLATION */:
  10671. case 12 /* TEXT_CALL */:
  10672. return getConstantType(node.content, context);
  10673. case 4 /* SIMPLE_EXPRESSION */:
  10674. return node.constType;
  10675. case 8 /* COMPOUND_EXPRESSION */:
  10676. let returnType = 3 /* CAN_STRINGIFY */;
  10677. for (let i = 0; i < node.children.length; i++) {
  10678. const child = node.children[i];
  10679. if (isString(child) || isSymbol(child)) {
  10680. continue;
  10681. }
  10682. const childType = getConstantType(child, context);
  10683. if (childType === 0 /* NOT_CONSTANT */) {
  10684. return 0 /* NOT_CONSTANT */;
  10685. }
  10686. else if (childType < returnType) {
  10687. returnType = childType;
  10688. }
  10689. }
  10690. return returnType;
  10691. default:
  10692. return 0 /* NOT_CONSTANT */;
  10693. }
  10694. }
  10695. function getGeneratedPropsConstantType(node, context) {
  10696. let returnType = 3 /* CAN_STRINGIFY */;
  10697. const props = getNodeProps(node);
  10698. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  10699. const { properties } = props;
  10700. for (let i = 0; i < properties.length; i++) {
  10701. const { key, value } = properties[i];
  10702. const keyType = getConstantType(key, context);
  10703. if (keyType === 0 /* NOT_CONSTANT */) {
  10704. return keyType;
  10705. }
  10706. if (keyType < returnType) {
  10707. returnType = keyType;
  10708. }
  10709. if (value.type !== 4 /* SIMPLE_EXPRESSION */) {
  10710. return 0 /* NOT_CONSTANT */;
  10711. }
  10712. const valueType = getConstantType(value, context);
  10713. if (valueType === 0 /* NOT_CONSTANT */) {
  10714. return valueType;
  10715. }
  10716. if (valueType < returnType) {
  10717. returnType = valueType;
  10718. }
  10719. }
  10720. }
  10721. return returnType;
  10722. }
  10723. function getNodeProps(node) {
  10724. const codegenNode = node.codegenNode;
  10725. if (codegenNode.type === 13 /* VNODE_CALL */) {
  10726. return codegenNode.props;
  10727. }
  10728. }
  10729. function getPatchFlag(node) {
  10730. const flag = node.patchFlag;
  10731. return flag ? parseInt(flag, 10) : undefined;
  10732. }
  10733. function createTransformContext(root, { filename = '', prefixIdentifiers = false, hoistStatic = false, cacheHandlers = false, nodeTransforms = [], directiveTransforms = {}, transformHoist = null, isBuiltInComponent = NOOP, isCustomElement = NOOP, expressionPlugins = [], scopeId = null, ssr = false, ssrCssVars = ``, bindingMetadata = EMPTY_OBJ, inline = false, isTS = false, onError = defaultOnError }) {
  10734. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  10735. const context = {
  10736. // options
  10737. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  10738. prefixIdentifiers,
  10739. hoistStatic,
  10740. cacheHandlers,
  10741. nodeTransforms,
  10742. directiveTransforms,
  10743. transformHoist,
  10744. isBuiltInComponent,
  10745. isCustomElement,
  10746. expressionPlugins,
  10747. scopeId,
  10748. ssr,
  10749. ssrCssVars,
  10750. bindingMetadata,
  10751. inline,
  10752. isTS,
  10753. onError,
  10754. // state
  10755. root,
  10756. helpers: new Set(),
  10757. components: new Set(),
  10758. directives: new Set(),
  10759. hoists: [],
  10760. imports: [],
  10761. constantCache: new Map(),
  10762. temps: 0,
  10763. cached: 0,
  10764. identifiers: Object.create(null),
  10765. scopes: {
  10766. vFor: 0,
  10767. vSlot: 0,
  10768. vPre: 0,
  10769. vOnce: 0
  10770. },
  10771. parent: null,
  10772. currentNode: root,
  10773. childIndex: 0,
  10774. // methods
  10775. helper(name) {
  10776. context.helpers.add(name);
  10777. return name;
  10778. },
  10779. helperString(name) {
  10780. return `_${helperNameMap[context.helper(name)]}`;
  10781. },
  10782. replaceNode(node) {
  10783. /* istanbul ignore if */
  10784. {
  10785. if (!context.currentNode) {
  10786. throw new Error(`Node being replaced is already removed.`);
  10787. }
  10788. if (!context.parent) {
  10789. throw new Error(`Cannot replace root node.`);
  10790. }
  10791. }
  10792. context.parent.children[context.childIndex] = context.currentNode = node;
  10793. },
  10794. removeNode(node) {
  10795. if (!context.parent) {
  10796. throw new Error(`Cannot remove root node.`);
  10797. }
  10798. const list = context.parent.children;
  10799. const removalIndex = node
  10800. ? list.indexOf(node)
  10801. : context.currentNode
  10802. ? context.childIndex
  10803. : -1;
  10804. /* istanbul ignore if */
  10805. if (removalIndex < 0) {
  10806. throw new Error(`node being removed is not a child of current parent`);
  10807. }
  10808. if (!node || node === context.currentNode) {
  10809. // current node removed
  10810. context.currentNode = null;
  10811. context.onNodeRemoved();
  10812. }
  10813. else {
  10814. // sibling node removed
  10815. if (context.childIndex > removalIndex) {
  10816. context.childIndex--;
  10817. context.onNodeRemoved();
  10818. }
  10819. }
  10820. context.parent.children.splice(removalIndex, 1);
  10821. },
  10822. onNodeRemoved: () => { },
  10823. addIdentifiers(exp) {
  10824. },
  10825. removeIdentifiers(exp) {
  10826. },
  10827. hoist(exp) {
  10828. context.hoists.push(exp);
  10829. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
  10830. identifier.hoisted = exp;
  10831. return identifier;
  10832. },
  10833. cache(exp, isVNode = false) {
  10834. return createCacheExpression(++context.cached, exp, isVNode);
  10835. }
  10836. };
  10837. return context;
  10838. }
  10839. function transform(root, options) {
  10840. const context = createTransformContext(root, options);
  10841. traverseNode(root, context);
  10842. if (options.hoistStatic) {
  10843. hoistStatic(root, context);
  10844. }
  10845. if (!options.ssr) {
  10846. createRootCodegen(root, context);
  10847. }
  10848. // finalize meta information
  10849. root.helpers = [...context.helpers];
  10850. root.components = [...context.components];
  10851. root.directives = [...context.directives];
  10852. root.imports = context.imports;
  10853. root.hoists = context.hoists;
  10854. root.temps = context.temps;
  10855. root.cached = context.cached;
  10856. }
  10857. function createRootCodegen(root, context) {
  10858. const { helper } = context;
  10859. const { children } = root;
  10860. if (children.length === 1) {
  10861. const child = children[0];
  10862. // if the single child is an element, turn it into a block.
  10863. if (isSingleElementRoot(root, child) && child.codegenNode) {
  10864. // single element root is never hoisted so codegenNode will never be
  10865. // SimpleExpressionNode
  10866. const codegenNode = child.codegenNode;
  10867. if (codegenNode.type === 13 /* VNODE_CALL */) {
  10868. codegenNode.isBlock = true;
  10869. helper(OPEN_BLOCK);
  10870. helper(CREATE_BLOCK);
  10871. }
  10872. root.codegenNode = codegenNode;
  10873. }
  10874. else {
  10875. // - single <slot/>, IfNode, ForNode: already blocks.
  10876. // - single text node: always patched.
  10877. // root codegen falls through via genNode()
  10878. root.codegenNode = child;
  10879. }
  10880. }
  10881. else if (children.length > 1) {
  10882. // root has multiple nodes - return a fragment block.
  10883. let patchFlag = 64 /* STABLE_FRAGMENT */;
  10884. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  10885. // check if the fragment actually contains a single valid child with
  10886. // the rest being comments
  10887. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  10888. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  10889. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  10890. }
  10891. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true);
  10892. }
  10893. else ;
  10894. }
  10895. function traverseChildren(parent, context) {
  10896. let i = 0;
  10897. const nodeRemoved = () => {
  10898. i--;
  10899. };
  10900. for (; i < parent.children.length; i++) {
  10901. const child = parent.children[i];
  10902. if (isString(child))
  10903. continue;
  10904. context.parent = parent;
  10905. context.childIndex = i;
  10906. context.onNodeRemoved = nodeRemoved;
  10907. traverseNode(child, context);
  10908. }
  10909. }
  10910. function traverseNode(node, context) {
  10911. context.currentNode = node;
  10912. // apply transform plugins
  10913. const { nodeTransforms } = context;
  10914. const exitFns = [];
  10915. for (let i = 0; i < nodeTransforms.length; i++) {
  10916. const onExit = nodeTransforms[i](node, context);
  10917. if (onExit) {
  10918. if (isArray(onExit)) {
  10919. exitFns.push(...onExit);
  10920. }
  10921. else {
  10922. exitFns.push(onExit);
  10923. }
  10924. }
  10925. if (!context.currentNode) {
  10926. // node was removed
  10927. return;
  10928. }
  10929. else {
  10930. // node may have been replaced
  10931. node = context.currentNode;
  10932. }
  10933. }
  10934. switch (node.type) {
  10935. case 3 /* COMMENT */:
  10936. if (!context.ssr) {
  10937. // inject import for the Comment symbol, which is needed for creating
  10938. // comment nodes with `createVNode`
  10939. context.helper(CREATE_COMMENT);
  10940. }
  10941. break;
  10942. case 5 /* INTERPOLATION */:
  10943. // no need to traverse, but we need to inject toString helper
  10944. if (!context.ssr) {
  10945. context.helper(TO_DISPLAY_STRING);
  10946. }
  10947. break;
  10948. // for container types, further traverse downwards
  10949. case 9 /* IF */:
  10950. for (let i = 0; i < node.branches.length; i++) {
  10951. traverseNode(node.branches[i], context);
  10952. }
  10953. break;
  10954. case 10 /* IF_BRANCH */:
  10955. case 11 /* FOR */:
  10956. case 1 /* ELEMENT */:
  10957. case 0 /* ROOT */:
  10958. traverseChildren(node, context);
  10959. break;
  10960. }
  10961. // exit transforms
  10962. context.currentNode = node;
  10963. let i = exitFns.length;
  10964. while (i--) {
  10965. exitFns[i]();
  10966. }
  10967. }
  10968. function createStructuralDirectiveTransform(name, fn) {
  10969. const matches = isString(name)
  10970. ? (n) => n === name
  10971. : (n) => name.test(n);
  10972. return (node, context) => {
  10973. if (node.type === 1 /* ELEMENT */) {
  10974. const { props } = node;
  10975. // structural directive transforms are not concerned with slots
  10976. // as they are handled separately in vSlot.ts
  10977. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  10978. return;
  10979. }
  10980. const exitFns = [];
  10981. for (let i = 0; i < props.length; i++) {
  10982. const prop = props[i];
  10983. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  10984. // structural directives are removed to avoid infinite recursion
  10985. // also we remove them *before* applying so that it can further
  10986. // traverse itself in case it moves the node around
  10987. props.splice(i, 1);
  10988. i--;
  10989. const onExit = fn(node, prop, context);
  10990. if (onExit)
  10991. exitFns.push(onExit);
  10992. }
  10993. }
  10994. return exitFns;
  10995. }
  10996. };
  10997. }
  10998. const PURE_ANNOTATION = `/*#__PURE__*/`;
  10999. function createCodegenContext(ast, { mode = 'function', prefixIdentifiers = mode === 'module', sourceMap = false, filename = `template.vue.html`, scopeId = null, optimizeImports = false, runtimeGlobalName = `Vue`, runtimeModuleName = `vue`, ssr = false }) {
  11000. const context = {
  11001. mode,
  11002. prefixIdentifiers,
  11003. sourceMap,
  11004. filename,
  11005. scopeId,
  11006. optimizeImports,
  11007. runtimeGlobalName,
  11008. runtimeModuleName,
  11009. ssr,
  11010. source: ast.loc.source,
  11011. code: ``,
  11012. column: 1,
  11013. line: 1,
  11014. offset: 0,
  11015. indentLevel: 0,
  11016. pure: false,
  11017. map: undefined,
  11018. helper(key) {
  11019. return `_${helperNameMap[key]}`;
  11020. },
  11021. push(code, node) {
  11022. context.code += code;
  11023. },
  11024. indent() {
  11025. newline(++context.indentLevel);
  11026. },
  11027. deindent(withoutNewLine = false) {
  11028. if (withoutNewLine) {
  11029. --context.indentLevel;
  11030. }
  11031. else {
  11032. newline(--context.indentLevel);
  11033. }
  11034. },
  11035. newline() {
  11036. newline(context.indentLevel);
  11037. }
  11038. };
  11039. function newline(n) {
  11040. context.push('\n' + ` `.repeat(n));
  11041. }
  11042. return context;
  11043. }
  11044. function generate(ast, options = {}) {
  11045. const context = createCodegenContext(ast, options);
  11046. if (options.onContextCreated)
  11047. options.onContextCreated(context);
  11048. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  11049. const hasHelpers = ast.helpers.length > 0;
  11050. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  11051. // preambles
  11052. // in setup() inline mode, the preamble is generated in a sub context
  11053. // and returned separately.
  11054. const preambleContext = context;
  11055. {
  11056. genFunctionPreamble(ast, preambleContext);
  11057. }
  11058. // enter render function
  11059. const functionName = ssr ? `ssrRender` : `render`;
  11060. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  11061. const signature = args.join(', ');
  11062. {
  11063. push(`function ${functionName}(${signature}) {`);
  11064. }
  11065. indent();
  11066. if (useWithBlock) {
  11067. push(`with (_ctx) {`);
  11068. indent();
  11069. // function mode const declarations should be inside with block
  11070. // also they should be renamed to avoid collision with user properties
  11071. if (hasHelpers) {
  11072. push(`const { ${ast.helpers
  11073. .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
  11074. .join(', ')} } = _Vue`);
  11075. push(`\n`);
  11076. newline();
  11077. }
  11078. }
  11079. // generate asset resolution statements
  11080. if (ast.components.length) {
  11081. genAssets(ast.components, 'component', context);
  11082. if (ast.directives.length || ast.temps > 0) {
  11083. newline();
  11084. }
  11085. }
  11086. if (ast.directives.length) {
  11087. genAssets(ast.directives, 'directive', context);
  11088. if (ast.temps > 0) {
  11089. newline();
  11090. }
  11091. }
  11092. if (ast.temps > 0) {
  11093. push(`let `);
  11094. for (let i = 0; i < ast.temps; i++) {
  11095. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  11096. }
  11097. }
  11098. if (ast.components.length || ast.directives.length || ast.temps) {
  11099. push(`\n`);
  11100. newline();
  11101. }
  11102. // generate the VNode tree expression
  11103. if (!ssr) {
  11104. push(`return `);
  11105. }
  11106. if (ast.codegenNode) {
  11107. genNode(ast.codegenNode, context);
  11108. }
  11109. else {
  11110. push(`null`);
  11111. }
  11112. if (useWithBlock) {
  11113. deindent();
  11114. push(`}`);
  11115. }
  11116. deindent();
  11117. push(`}`);
  11118. return {
  11119. ast,
  11120. code: context.code,
  11121. preamble: ``,
  11122. // SourceMapGenerator does have toJSON() method but it's not in the types
  11123. map: context.map ? context.map.toJSON() : undefined
  11124. };
  11125. }
  11126. function genFunctionPreamble(ast, context) {
  11127. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName } = context;
  11128. const VueBinding = runtimeGlobalName;
  11129. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  11130. // Generate const declaration for helpers
  11131. // In prefix mode, we place the const declaration at top so it's done
  11132. // only once; But if we not prefixing, we place the declaration inside the
  11133. // with block so it doesn't incur the `in` check cost for every helper access.
  11134. if (ast.helpers.length > 0) {
  11135. {
  11136. // "with" mode.
  11137. // save Vue in a separate variable to avoid collision
  11138. push(`const _Vue = ${VueBinding}\n`);
  11139. // in "with" mode, helpers are declared inside the with block to avoid
  11140. // has check cost, but hoists are lifted out of the function - we need
  11141. // to provide the helper here.
  11142. if (ast.hoists.length) {
  11143. const staticHelpers = [
  11144. CREATE_VNODE,
  11145. CREATE_COMMENT,
  11146. CREATE_TEXT,
  11147. CREATE_STATIC
  11148. ]
  11149. .filter(helper => ast.helpers.includes(helper))
  11150. .map(aliasHelper)
  11151. .join(', ');
  11152. push(`const { ${staticHelpers} } = _Vue\n`);
  11153. }
  11154. }
  11155. }
  11156. genHoists(ast.hoists, context);
  11157. newline();
  11158. push(`return `);
  11159. }
  11160. function genAssets(assets, type, { helper, push, newline }) {
  11161. const resolver = helper(type === 'component' ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE);
  11162. for (let i = 0; i < assets.length; i++) {
  11163. const id = assets[i];
  11164. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)})`);
  11165. if (i < assets.length - 1) {
  11166. newline();
  11167. }
  11168. }
  11169. }
  11170. function genHoists(hoists, context) {
  11171. if (!hoists.length) {
  11172. return;
  11173. }
  11174. context.pure = true;
  11175. const { push, newline, helper, scopeId, mode } = context;
  11176. newline();
  11177. hoists.forEach((exp, i) => {
  11178. if (exp) {
  11179. push(`const _hoisted_${i + 1} = `);
  11180. genNode(exp, context);
  11181. newline();
  11182. }
  11183. });
  11184. context.pure = false;
  11185. }
  11186. function isText$1(n) {
  11187. return (isString(n) ||
  11188. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  11189. n.type === 2 /* TEXT */ ||
  11190. n.type === 5 /* INTERPOLATION */ ||
  11191. n.type === 8 /* COMPOUND_EXPRESSION */);
  11192. }
  11193. function genNodeListAsArray(nodes, context) {
  11194. const multilines = nodes.length > 3 ||
  11195. (nodes.some(n => isArray(n) || !isText$1(n)));
  11196. context.push(`[`);
  11197. multilines && context.indent();
  11198. genNodeList(nodes, context, multilines);
  11199. multilines && context.deindent();
  11200. context.push(`]`);
  11201. }
  11202. function genNodeList(nodes, context, multilines = false, comma = true) {
  11203. const { push, newline } = context;
  11204. for (let i = 0; i < nodes.length; i++) {
  11205. const node = nodes[i];
  11206. if (isString(node)) {
  11207. push(node);
  11208. }
  11209. else if (isArray(node)) {
  11210. genNodeListAsArray(node, context);
  11211. }
  11212. else {
  11213. genNode(node, context);
  11214. }
  11215. if (i < nodes.length - 1) {
  11216. if (multilines) {
  11217. comma && push(',');
  11218. newline();
  11219. }
  11220. else {
  11221. comma && push(', ');
  11222. }
  11223. }
  11224. }
  11225. }
  11226. function genNode(node, context) {
  11227. if (isString(node)) {
  11228. context.push(node);
  11229. return;
  11230. }
  11231. if (isSymbol(node)) {
  11232. context.push(context.helper(node));
  11233. return;
  11234. }
  11235. switch (node.type) {
  11236. case 1 /* ELEMENT */:
  11237. case 9 /* IF */:
  11238. case 11 /* FOR */:
  11239. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  11240. `Apply appropriate transforms first.`);
  11241. genNode(node.codegenNode, context);
  11242. break;
  11243. case 2 /* TEXT */:
  11244. genText(node, context);
  11245. break;
  11246. case 4 /* SIMPLE_EXPRESSION */:
  11247. genExpression(node, context);
  11248. break;
  11249. case 5 /* INTERPOLATION */:
  11250. genInterpolation(node, context);
  11251. break;
  11252. case 12 /* TEXT_CALL */:
  11253. genNode(node.codegenNode, context);
  11254. break;
  11255. case 8 /* COMPOUND_EXPRESSION */:
  11256. genCompoundExpression(node, context);
  11257. break;
  11258. case 3 /* COMMENT */:
  11259. genComment(node, context);
  11260. break;
  11261. case 13 /* VNODE_CALL */:
  11262. genVNodeCall(node, context);
  11263. break;
  11264. case 14 /* JS_CALL_EXPRESSION */:
  11265. genCallExpression(node, context);
  11266. break;
  11267. case 15 /* JS_OBJECT_EXPRESSION */:
  11268. genObjectExpression(node, context);
  11269. break;
  11270. case 17 /* JS_ARRAY_EXPRESSION */:
  11271. genArrayExpression(node, context);
  11272. break;
  11273. case 18 /* JS_FUNCTION_EXPRESSION */:
  11274. genFunctionExpression(node, context);
  11275. break;
  11276. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  11277. genConditionalExpression(node, context);
  11278. break;
  11279. case 20 /* JS_CACHE_EXPRESSION */:
  11280. genCacheExpression(node, context);
  11281. break;
  11282. // SSR only types
  11283. case 21 /* JS_BLOCK_STATEMENT */:
  11284. break;
  11285. case 22 /* JS_TEMPLATE_LITERAL */:
  11286. break;
  11287. case 23 /* JS_IF_STATEMENT */:
  11288. break;
  11289. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  11290. break;
  11291. case 25 /* JS_SEQUENCE_EXPRESSION */:
  11292. break;
  11293. case 26 /* JS_RETURN_STATEMENT */:
  11294. break;
  11295. /* istanbul ignore next */
  11296. case 10 /* IF_BRANCH */:
  11297. // noop
  11298. break;
  11299. default:
  11300. {
  11301. assert(false, `unhandled codegen node type: ${node.type}`);
  11302. // make sure we exhaust all possible types
  11303. const exhaustiveCheck = node;
  11304. return exhaustiveCheck;
  11305. }
  11306. }
  11307. }
  11308. function genText(node, context) {
  11309. context.push(JSON.stringify(node.content), node);
  11310. }
  11311. function genExpression(node, context) {
  11312. const { content, isStatic } = node;
  11313. context.push(isStatic ? JSON.stringify(content) : content, node);
  11314. }
  11315. function genInterpolation(node, context) {
  11316. const { push, helper, pure } = context;
  11317. if (pure)
  11318. push(PURE_ANNOTATION);
  11319. push(`${helper(TO_DISPLAY_STRING)}(`);
  11320. genNode(node.content, context);
  11321. push(`)`);
  11322. }
  11323. function genCompoundExpression(node, context) {
  11324. for (let i = 0; i < node.children.length; i++) {
  11325. const child = node.children[i];
  11326. if (isString(child)) {
  11327. context.push(child);
  11328. }
  11329. else {
  11330. genNode(child, context);
  11331. }
  11332. }
  11333. }
  11334. function genExpressionAsPropertyKey(node, context) {
  11335. const { push } = context;
  11336. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  11337. push(`[`);
  11338. genCompoundExpression(node, context);
  11339. push(`]`);
  11340. }
  11341. else if (node.isStatic) {
  11342. // only quote keys if necessary
  11343. const text = isSimpleIdentifier(node.content)
  11344. ? node.content
  11345. : JSON.stringify(node.content);
  11346. push(text, node);
  11347. }
  11348. else {
  11349. push(`[${node.content}]`, node);
  11350. }
  11351. }
  11352. function genComment(node, context) {
  11353. {
  11354. const { push, helper, pure } = context;
  11355. if (pure) {
  11356. push(PURE_ANNOTATION);
  11357. }
  11358. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  11359. }
  11360. }
  11361. function genVNodeCall(node, context) {
  11362. const { push, helper, pure } = context;
  11363. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking } = node;
  11364. if (directives) {
  11365. push(helper(WITH_DIRECTIVES) + `(`);
  11366. }
  11367. if (isBlock) {
  11368. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  11369. }
  11370. if (pure) {
  11371. push(PURE_ANNOTATION);
  11372. }
  11373. push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node);
  11374. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  11375. push(`)`);
  11376. if (isBlock) {
  11377. push(`)`);
  11378. }
  11379. if (directives) {
  11380. push(`, `);
  11381. genNode(directives, context);
  11382. push(`)`);
  11383. }
  11384. }
  11385. function genNullableArgs(args) {
  11386. let i = args.length;
  11387. while (i--) {
  11388. if (args[i] != null)
  11389. break;
  11390. }
  11391. return args.slice(0, i + 1).map(arg => arg || `null`);
  11392. }
  11393. // JavaScript
  11394. function genCallExpression(node, context) {
  11395. const { push, helper, pure } = context;
  11396. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  11397. if (pure) {
  11398. push(PURE_ANNOTATION);
  11399. }
  11400. push(callee + `(`, node);
  11401. genNodeList(node.arguments, context);
  11402. push(`)`);
  11403. }
  11404. function genObjectExpression(node, context) {
  11405. const { push, indent, deindent, newline } = context;
  11406. const { properties } = node;
  11407. if (!properties.length) {
  11408. push(`{}`, node);
  11409. return;
  11410. }
  11411. const multilines = properties.length > 1 ||
  11412. (properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  11413. push(multilines ? `{` : `{ `);
  11414. multilines && indent();
  11415. for (let i = 0; i < properties.length; i++) {
  11416. const { key, value } = properties[i];
  11417. // key
  11418. genExpressionAsPropertyKey(key, context);
  11419. push(`: `);
  11420. // value
  11421. genNode(value, context);
  11422. if (i < properties.length - 1) {
  11423. // will only reach this if it's multilines
  11424. push(`,`);
  11425. newline();
  11426. }
  11427. }
  11428. multilines && deindent();
  11429. push(multilines ? `}` : ` }`);
  11430. }
  11431. function genArrayExpression(node, context) {
  11432. genNodeListAsArray(node.elements, context);
  11433. }
  11434. function genFunctionExpression(node, context) {
  11435. const { push, indent, deindent, scopeId, mode } = context;
  11436. const { params, returns, body, newline, isSlot } = node;
  11437. if (isSlot) {
  11438. push(`_${helperNameMap[WITH_CTX]}(`);
  11439. }
  11440. push(`(`, node);
  11441. if (isArray(params)) {
  11442. genNodeList(params, context);
  11443. }
  11444. else if (params) {
  11445. genNode(params, context);
  11446. }
  11447. push(`) => `);
  11448. if (newline || body) {
  11449. push(`{`);
  11450. indent();
  11451. }
  11452. if (returns) {
  11453. if (newline) {
  11454. push(`return `);
  11455. }
  11456. if (isArray(returns)) {
  11457. genNodeListAsArray(returns, context);
  11458. }
  11459. else {
  11460. genNode(returns, context);
  11461. }
  11462. }
  11463. else if (body) {
  11464. genNode(body, context);
  11465. }
  11466. if (newline || body) {
  11467. deindent();
  11468. push(`}`);
  11469. }
  11470. if (isSlot) {
  11471. push(`)`);
  11472. }
  11473. }
  11474. function genConditionalExpression(node, context) {
  11475. const { test, consequent, alternate, newline: needNewline } = node;
  11476. const { push, indent, deindent, newline } = context;
  11477. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  11478. const needsParens = !isSimpleIdentifier(test.content);
  11479. needsParens && push(`(`);
  11480. genExpression(test, context);
  11481. needsParens && push(`)`);
  11482. }
  11483. else {
  11484. push(`(`);
  11485. genNode(test, context);
  11486. push(`)`);
  11487. }
  11488. needNewline && indent();
  11489. context.indentLevel++;
  11490. needNewline || push(` `);
  11491. push(`? `);
  11492. genNode(consequent, context);
  11493. context.indentLevel--;
  11494. needNewline && newline();
  11495. needNewline || push(` `);
  11496. push(`: `);
  11497. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  11498. if (!isNested) {
  11499. context.indentLevel++;
  11500. }
  11501. genNode(alternate, context);
  11502. if (!isNested) {
  11503. context.indentLevel--;
  11504. }
  11505. needNewline && deindent(true /* without newline */);
  11506. }
  11507. function genCacheExpression(node, context) {
  11508. const { push, helper, indent, deindent, newline } = context;
  11509. push(`_cache[${node.index}] || (`);
  11510. if (node.isVNode) {
  11511. indent();
  11512. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  11513. newline();
  11514. }
  11515. push(`_cache[${node.index}] = `);
  11516. genNode(node.value, context);
  11517. if (node.isVNode) {
  11518. push(`,`);
  11519. newline();
  11520. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  11521. newline();
  11522. push(`_cache[${node.index}]`);
  11523. deindent();
  11524. }
  11525. push(`)`);
  11526. }
  11527. // these keywords should not appear inside expressions, but operators like
  11528. // typeof, instanceof and in are allowed
  11529. const prohibitedKeywordRE = new RegExp('\\b' +
  11530. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  11531. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  11532. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  11533. .split(',')
  11534. .join('\\b|\\b') +
  11535. '\\b');
  11536. // strip strings in expressions
  11537. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  11538. /**
  11539. * Validate a non-prefixed expression.
  11540. * This is only called when using the in-browser runtime compiler since it
  11541. * doesn't prefix expressions.
  11542. */
  11543. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  11544. const exp = node.content;
  11545. // empty expressions are validated per-directive since some directives
  11546. // do allow empty expressions.
  11547. if (!exp.trim()) {
  11548. return;
  11549. }
  11550. try {
  11551. new Function(asRawStatements
  11552. ? ` ${exp} `
  11553. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  11554. }
  11555. catch (e) {
  11556. let message = e.message;
  11557. const keywordMatch = exp
  11558. .replace(stripStringRE, '')
  11559. .match(prohibitedKeywordRE);
  11560. if (keywordMatch) {
  11561. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  11562. }
  11563. context.onError(createCompilerError(43 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  11564. }
  11565. }
  11566. const transformExpression = (node, context) => {
  11567. if (node.type === 5 /* INTERPOLATION */) {
  11568. node.content = processExpression(node.content, context);
  11569. }
  11570. else if (node.type === 1 /* ELEMENT */) {
  11571. // handle directives on element
  11572. for (let i = 0; i < node.props.length; i++) {
  11573. const dir = node.props[i];
  11574. // do not process for v-on & v-for since they are special handled
  11575. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  11576. const exp = dir.exp;
  11577. const arg = dir.arg;
  11578. // do not process exp if this is v-on:arg - we need special handling
  11579. // for wrapping inline statements.
  11580. if (exp &&
  11581. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  11582. !(dir.name === 'on' && arg)) {
  11583. dir.exp = processExpression(exp, context,
  11584. // slot args must be processed as function params
  11585. dir.name === 'slot');
  11586. }
  11587. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  11588. dir.arg = processExpression(arg, context);
  11589. }
  11590. }
  11591. }
  11592. }
  11593. };
  11594. // Important: since this function uses Node.js only dependencies, it should
  11595. // always be used with a leading !true check so that it can be
  11596. // tree-shaken from the browser build.
  11597. function processExpression(node, context,
  11598. // some expressions like v-slot props & v-for aliases should be parsed as
  11599. // function params
  11600. asParams = false,
  11601. // v-on handler values may contain multiple statements
  11602. asRawStatements = false) {
  11603. {
  11604. {
  11605. // simple in-browser validation (same logic in 2.x)
  11606. validateBrowserExpression(node, context, asParams, asRawStatements);
  11607. }
  11608. return node;
  11609. }
  11610. }
  11611. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  11612. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  11613. // #1587: We need to dynamically increment the key based on the current
  11614. // node's sibling nodes, since chained v-if/else branches are
  11615. // rendered at the same depth
  11616. const siblings = context.parent.children;
  11617. let i = siblings.indexOf(ifNode);
  11618. let key = 0;
  11619. while (i-- >= 0) {
  11620. const sibling = siblings[i];
  11621. if (sibling && sibling.type === 9 /* IF */) {
  11622. key += sibling.branches.length;
  11623. }
  11624. }
  11625. // Exit callback. Complete the codegenNode when all children have been
  11626. // transformed.
  11627. return () => {
  11628. if (isRoot) {
  11629. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  11630. }
  11631. else {
  11632. // attach this branch's codegen node to the v-if root.
  11633. const parentCondition = getParentCondition(ifNode.codegenNode);
  11634. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  11635. }
  11636. };
  11637. });
  11638. });
  11639. // target-agnostic transform used for both Client and SSR
  11640. function processIf(node, dir, context, processCodegen) {
  11641. if (dir.name !== 'else' &&
  11642. (!dir.exp || !dir.exp.content.trim())) {
  11643. const loc = dir.exp ? dir.exp.loc : node.loc;
  11644. context.onError(createCompilerError(27 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  11645. dir.exp = createSimpleExpression(`true`, false, loc);
  11646. }
  11647. if (dir.exp) {
  11648. validateBrowserExpression(dir.exp, context);
  11649. }
  11650. if (dir.name === 'if') {
  11651. const branch = createIfBranch(node, dir);
  11652. const ifNode = {
  11653. type: 9 /* IF */,
  11654. loc: node.loc,
  11655. branches: [branch]
  11656. };
  11657. context.replaceNode(ifNode);
  11658. if (processCodegen) {
  11659. return processCodegen(ifNode, branch, true);
  11660. }
  11661. }
  11662. else {
  11663. // locate the adjacent v-if
  11664. const siblings = context.parent.children;
  11665. const comments = [];
  11666. let i = siblings.indexOf(node);
  11667. while (i-- >= -1) {
  11668. const sibling = siblings[i];
  11669. if (sibling && sibling.type === 3 /* COMMENT */) {
  11670. context.removeNode(sibling);
  11671. comments.unshift(sibling);
  11672. continue;
  11673. }
  11674. if (sibling &&
  11675. sibling.type === 2 /* TEXT */ &&
  11676. !sibling.content.trim().length) {
  11677. context.removeNode(sibling);
  11678. continue;
  11679. }
  11680. if (sibling && sibling.type === 9 /* IF */) {
  11681. // move the node to the if node's branches
  11682. context.removeNode();
  11683. const branch = createIfBranch(node, dir);
  11684. if (comments.length) {
  11685. branch.children = [...comments, ...branch.children];
  11686. }
  11687. // check if user is forcing same key on different branches
  11688. {
  11689. const key = branch.userKey;
  11690. if (key) {
  11691. sibling.branches.forEach(({ userKey }) => {
  11692. if (isSameKey(userKey, key)) {
  11693. context.onError(createCompilerError(28 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  11694. }
  11695. });
  11696. }
  11697. }
  11698. sibling.branches.push(branch);
  11699. const onExit = processCodegen && processCodegen(sibling, branch, false);
  11700. // since the branch was removed, it will not be traversed.
  11701. // make sure to traverse here.
  11702. traverseNode(branch, context);
  11703. // call on exit
  11704. if (onExit)
  11705. onExit();
  11706. // make sure to reset currentNode after traversal to indicate this
  11707. // node has been removed.
  11708. context.currentNode = null;
  11709. }
  11710. else {
  11711. context.onError(createCompilerError(29 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  11712. }
  11713. break;
  11714. }
  11715. }
  11716. }
  11717. function createIfBranch(node, dir) {
  11718. return {
  11719. type: 10 /* IF_BRANCH */,
  11720. loc: node.loc,
  11721. condition: dir.name === 'else' ? undefined : dir.exp,
  11722. children: node.tagType === 3 /* TEMPLATE */ && !findDir(node, 'for')
  11723. ? node.children
  11724. : [node],
  11725. userKey: findProp(node, `key`)
  11726. };
  11727. }
  11728. function createCodegenNodeForBranch(branch, keyIndex, context) {
  11729. if (branch.condition) {
  11730. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  11731. // make sure to pass in asBlock: true so that the comment node call
  11732. // closes the current block.
  11733. createCallExpression(context.helper(CREATE_COMMENT), [
  11734. '"v-if"' ,
  11735. 'true'
  11736. ]));
  11737. }
  11738. else {
  11739. return createChildrenCodegenNode(branch, keyIndex, context);
  11740. }
  11741. }
  11742. function createChildrenCodegenNode(branch, keyIndex, context) {
  11743. const { helper } = context;
  11744. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
  11745. const { children } = branch;
  11746. const firstChild = children[0];
  11747. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  11748. if (needFragmentWrapper) {
  11749. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  11750. // optimize away nested fragments when child is a ForNode
  11751. const vnodeCall = firstChild.codegenNode;
  11752. injectProp(vnodeCall, keyProperty, context);
  11753. return vnodeCall;
  11754. }
  11755. else {
  11756. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, 64 /* STABLE_FRAGMENT */ +
  11757. (` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  11758. ), undefined, undefined, true, false, branch.loc);
  11759. }
  11760. }
  11761. else {
  11762. const vnodeCall = firstChild
  11763. .codegenNode;
  11764. // Change createVNode to createBlock.
  11765. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  11766. vnodeCall.isBlock = true;
  11767. helper(OPEN_BLOCK);
  11768. helper(CREATE_BLOCK);
  11769. }
  11770. // inject branch key
  11771. injectProp(vnodeCall, keyProperty, context);
  11772. return vnodeCall;
  11773. }
  11774. }
  11775. function isSameKey(a, b) {
  11776. if (!a || a.type !== b.type) {
  11777. return false;
  11778. }
  11779. if (a.type === 6 /* ATTRIBUTE */) {
  11780. if (a.value.content !== b.value.content) {
  11781. return false;
  11782. }
  11783. }
  11784. else {
  11785. // directive
  11786. const exp = a.exp;
  11787. const branchExp = b.exp;
  11788. if (exp.type !== branchExp.type) {
  11789. return false;
  11790. }
  11791. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  11792. (exp.isStatic !== branchExp.isStatic ||
  11793. exp.content !== branchExp.content)) {
  11794. return false;
  11795. }
  11796. }
  11797. return true;
  11798. }
  11799. function getParentCondition(node) {
  11800. while (true) {
  11801. if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  11802. if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  11803. node = node.alternate;
  11804. }
  11805. else {
  11806. return node;
  11807. }
  11808. }
  11809. else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
  11810. node = node.value;
  11811. }
  11812. }
  11813. }
  11814. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  11815. const { helper } = context;
  11816. return processFor(node, dir, context, forNode => {
  11817. // create the loop render function expression now, and add the
  11818. // iterator on exit after all children have been traversed
  11819. const renderExp = createCallExpression(helper(RENDER_LIST), [
  11820. forNode.source
  11821. ]);
  11822. const keyProp = findProp(node, `key`);
  11823. const keyProperty = keyProp
  11824. ? createObjectProperty(`key`, keyProp.type === 6 /* ATTRIBUTE */
  11825. ? createSimpleExpression(keyProp.value.content, true)
  11826. : keyProp.exp)
  11827. : null;
  11828. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  11829. forNode.source.constType > 0 /* NOT_CONSTANT */;
  11830. const fragmentFlag = isStableFragment
  11831. ? 64 /* STABLE_FRAGMENT */
  11832. : keyProp
  11833. ? 128 /* KEYED_FRAGMENT */
  11834. : 256 /* UNKEYED_FRAGMENT */;
  11835. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  11836. (` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, node.loc);
  11837. return () => {
  11838. // finish the codegen now that all children have been traversed
  11839. let childBlock;
  11840. const isTemplate = isTemplateNode(node);
  11841. const { children } = forNode;
  11842. // check <template v-for> key placement
  11843. if (isTemplate) {
  11844. node.children.some(c => {
  11845. if (c.type === 1 /* ELEMENT */) {
  11846. const key = findProp(c, 'key');
  11847. if (key) {
  11848. context.onError(createCompilerError(32 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  11849. return true;
  11850. }
  11851. }
  11852. });
  11853. }
  11854. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  11855. const slotOutlet = isSlotOutlet(node)
  11856. ? node
  11857. : isTemplate &&
  11858. node.children.length === 1 &&
  11859. isSlotOutlet(node.children[0])
  11860. ? node.children[0] // api-extractor somehow fails to infer this
  11861. : null;
  11862. if (slotOutlet) {
  11863. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  11864. childBlock = slotOutlet.codegenNode;
  11865. if (isTemplate && keyProperty) {
  11866. // <template v-for="..." :key="..."><slot/></template>
  11867. // we need to inject the key to the renderSlot() call.
  11868. // the props for renderSlot is passed as the 3rd argument.
  11869. injectProp(childBlock, keyProperty, context);
  11870. }
  11871. }
  11872. else if (needFragmentWrapper) {
  11873. // <template v-for="..."> with text or multi-elements
  11874. // should generate a fragment block for each loop
  11875. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
  11876. (` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  11877. ), undefined, undefined, true);
  11878. }
  11879. else {
  11880. // Normal element v-for. Directly use the child's codegenNode
  11881. // but mark it as a block.
  11882. childBlock = children[0]
  11883. .codegenNode;
  11884. if (isTemplate && keyProperty) {
  11885. injectProp(childBlock, keyProperty, context);
  11886. }
  11887. childBlock.isBlock = !isStableFragment;
  11888. if (childBlock.isBlock) {
  11889. helper(OPEN_BLOCK);
  11890. helper(CREATE_BLOCK);
  11891. }
  11892. else {
  11893. helper(CREATE_VNODE);
  11894. }
  11895. }
  11896. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  11897. };
  11898. });
  11899. });
  11900. // target-agnostic transform used for both Client and SSR
  11901. function processFor(node, dir, context, processCodegen) {
  11902. if (!dir.exp) {
  11903. context.onError(createCompilerError(30 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  11904. return;
  11905. }
  11906. const parseResult = parseForExpression(
  11907. // can only be simple expression because vFor transform is applied
  11908. // before expression transform.
  11909. dir.exp, context);
  11910. if (!parseResult) {
  11911. context.onError(createCompilerError(31 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  11912. return;
  11913. }
  11914. const { addIdentifiers, removeIdentifiers, scopes } = context;
  11915. const { source, value, key, index } = parseResult;
  11916. const forNode = {
  11917. type: 11 /* FOR */,
  11918. loc: dir.loc,
  11919. source,
  11920. valueAlias: value,
  11921. keyAlias: key,
  11922. objectIndexAlias: index,
  11923. parseResult,
  11924. children: isTemplateNode(node) ? node.children : [node]
  11925. };
  11926. context.replaceNode(forNode);
  11927. // bookkeeping
  11928. scopes.vFor++;
  11929. const onExit = processCodegen && processCodegen(forNode);
  11930. return () => {
  11931. scopes.vFor--;
  11932. if (onExit)
  11933. onExit();
  11934. };
  11935. }
  11936. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  11937. // This regex doesn't cover the case if key or index aliases have destructuring,
  11938. // but those do not make sense in the first place, so this works in practice.
  11939. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  11940. const stripParensRE = /^\(|\)$/g;
  11941. function parseForExpression(input, context) {
  11942. const loc = input.loc;
  11943. const exp = input.content;
  11944. const inMatch = exp.match(forAliasRE);
  11945. if (!inMatch)
  11946. return;
  11947. const [, LHS, RHS] = inMatch;
  11948. const result = {
  11949. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  11950. value: undefined,
  11951. key: undefined,
  11952. index: undefined
  11953. };
  11954. {
  11955. validateBrowserExpression(result.source, context);
  11956. }
  11957. let valueContent = LHS.trim()
  11958. .replace(stripParensRE, '')
  11959. .trim();
  11960. const trimmedOffset = LHS.indexOf(valueContent);
  11961. const iteratorMatch = valueContent.match(forIteratorRE);
  11962. if (iteratorMatch) {
  11963. valueContent = valueContent.replace(forIteratorRE, '').trim();
  11964. const keyContent = iteratorMatch[1].trim();
  11965. let keyOffset;
  11966. if (keyContent) {
  11967. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  11968. result.key = createAliasExpression(loc, keyContent, keyOffset);
  11969. {
  11970. validateBrowserExpression(result.key, context, true);
  11971. }
  11972. }
  11973. if (iteratorMatch[2]) {
  11974. const indexContent = iteratorMatch[2].trim();
  11975. if (indexContent) {
  11976. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  11977. ? keyOffset + keyContent.length
  11978. : trimmedOffset + valueContent.length));
  11979. {
  11980. validateBrowserExpression(result.index, context, true);
  11981. }
  11982. }
  11983. }
  11984. }
  11985. if (valueContent) {
  11986. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  11987. {
  11988. validateBrowserExpression(result.value, context, true);
  11989. }
  11990. }
  11991. return result;
  11992. }
  11993. function createAliasExpression(range, content, offset) {
  11994. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  11995. }
  11996. function createForLoopParams({ value, key, index }) {
  11997. const params = [];
  11998. if (value) {
  11999. params.push(value);
  12000. }
  12001. if (key) {
  12002. if (!value) {
  12003. params.push(createSimpleExpression(`_`, false));
  12004. }
  12005. params.push(key);
  12006. }
  12007. if (index) {
  12008. if (!key) {
  12009. if (!value) {
  12010. params.push(createSimpleExpression(`_`, false));
  12011. }
  12012. params.push(createSimpleExpression(`__`, false));
  12013. }
  12014. params.push(index);
  12015. }
  12016. return params;
  12017. }
  12018. const defaultFallback = createSimpleExpression(`undefined`, false);
  12019. // A NodeTransform that:
  12020. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  12021. // by transformExpression. This is only applied in non-browser builds with
  12022. // { prefixIdentifiers: true }.
  12023. // 2. Track v-slot depths so that we know a slot is inside another slot.
  12024. // Note the exit callback is executed before buildSlots() on the same node,
  12025. // so only nested slots see positive numbers.
  12026. const trackSlotScopes = (node, context) => {
  12027. if (node.type === 1 /* ELEMENT */ &&
  12028. (node.tagType === 1 /* COMPONENT */ ||
  12029. node.tagType === 3 /* TEMPLATE */)) {
  12030. // We are only checking non-empty v-slot here
  12031. // since we only care about slots that introduce scope variables.
  12032. const vSlot = findDir(node, 'slot');
  12033. if (vSlot) {
  12034. vSlot.exp;
  12035. context.scopes.vSlot++;
  12036. return () => {
  12037. context.scopes.vSlot--;
  12038. };
  12039. }
  12040. }
  12041. };
  12042. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  12043. // Instead of being a DirectiveTransform, v-slot processing is called during
  12044. // transformElement to build the slots object for a component.
  12045. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  12046. context.helper(WITH_CTX);
  12047. const { children, loc } = node;
  12048. const slotsProperties = [];
  12049. const dynamicSlots = [];
  12050. const buildDefaultSlotProperty = (props, children) => createObjectProperty(`default`, buildSlotFn(props, children, loc));
  12051. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  12052. // since it likely uses a scope variable.
  12053. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  12054. // 1. Check for slot with slotProps on component itself.
  12055. // <Comp v-slot="{ prop }"/>
  12056. const onComponentSlot = findDir(node, 'slot', true);
  12057. if (onComponentSlot) {
  12058. const { arg, exp } = onComponentSlot;
  12059. if (arg && !isStaticExp(arg)) {
  12060. hasDynamicSlots = true;
  12061. }
  12062. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  12063. }
  12064. // 2. Iterate through children and check for template slots
  12065. // <template v-slot:foo="{ prop }">
  12066. let hasTemplateSlots = false;
  12067. let hasNamedDefaultSlot = false;
  12068. const implicitDefaultChildren = [];
  12069. const seenSlotNames = new Set();
  12070. for (let i = 0; i < children.length; i++) {
  12071. const slotElement = children[i];
  12072. let slotDir;
  12073. if (!isTemplateNode(slotElement) ||
  12074. !(slotDir = findDir(slotElement, 'slot', true))) {
  12075. // not a <template v-slot>, skip.
  12076. if (slotElement.type !== 3 /* COMMENT */) {
  12077. implicitDefaultChildren.push(slotElement);
  12078. }
  12079. continue;
  12080. }
  12081. if (onComponentSlot) {
  12082. // already has on-component slot - this is incorrect usage.
  12083. context.onError(createCompilerError(36 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  12084. break;
  12085. }
  12086. hasTemplateSlots = true;
  12087. const { children: slotChildren, loc: slotLoc } = slotElement;
  12088. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  12089. // check if name is dynamic.
  12090. let staticSlotName;
  12091. if (isStaticExp(slotName)) {
  12092. staticSlotName = slotName ? slotName.content : `default`;
  12093. }
  12094. else {
  12095. hasDynamicSlots = true;
  12096. }
  12097. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  12098. // check if this slot is conditional (v-if/v-for)
  12099. let vIf;
  12100. let vElse;
  12101. let vFor;
  12102. if ((vIf = findDir(slotElement, 'if'))) {
  12103. hasDynamicSlots = true;
  12104. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  12105. }
  12106. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  12107. // find adjacent v-if
  12108. let j = i;
  12109. let prev;
  12110. while (j--) {
  12111. prev = children[j];
  12112. if (prev.type !== 3 /* COMMENT */) {
  12113. break;
  12114. }
  12115. }
  12116. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  12117. // remove node
  12118. children.splice(i, 1);
  12119. i--;
  12120. // attach this slot to previous conditional
  12121. let conditional = dynamicSlots[dynamicSlots.length - 1];
  12122. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  12123. conditional = conditional.alternate;
  12124. }
  12125. conditional.alternate = vElse.exp
  12126. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  12127. : buildDynamicSlot(slotName, slotFunction);
  12128. }
  12129. else {
  12130. context.onError(createCompilerError(29 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  12131. }
  12132. }
  12133. else if ((vFor = findDir(slotElement, 'for'))) {
  12134. hasDynamicSlots = true;
  12135. const parseResult = vFor.parseResult ||
  12136. parseForExpression(vFor.exp, context);
  12137. if (parseResult) {
  12138. // Render the dynamic slots as an array and add it to the createSlot()
  12139. // args. The runtime knows how to handle it appropriately.
  12140. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  12141. parseResult.source,
  12142. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  12143. ]));
  12144. }
  12145. else {
  12146. context.onError(createCompilerError(31 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  12147. }
  12148. }
  12149. else {
  12150. // check duplicate static names
  12151. if (staticSlotName) {
  12152. if (seenSlotNames.has(staticSlotName)) {
  12153. context.onError(createCompilerError(37 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  12154. continue;
  12155. }
  12156. seenSlotNames.add(staticSlotName);
  12157. if (staticSlotName === 'default') {
  12158. hasNamedDefaultSlot = true;
  12159. }
  12160. }
  12161. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  12162. }
  12163. }
  12164. if (!onComponentSlot) {
  12165. if (!hasTemplateSlots) {
  12166. // implicit default slot (on component)
  12167. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  12168. }
  12169. else if (implicitDefaultChildren.length) {
  12170. // implicit default slot (mixed with named slots)
  12171. if (hasNamedDefaultSlot) {
  12172. context.onError(createCompilerError(38 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  12173. }
  12174. else {
  12175. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  12176. }
  12177. }
  12178. }
  12179. const slotFlag = hasDynamicSlots
  12180. ? 2 /* DYNAMIC */
  12181. : hasForwardedSlots(node.children)
  12182. ? 3 /* FORWARDED */
  12183. : 1 /* STABLE */;
  12184. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  12185. // 2 = compiled but dynamic = can skip normalization, but must run diff
  12186. // 1 = compiled and static = can skip normalization AND diff as optimized
  12187. createSimpleExpression(slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ), false))), loc);
  12188. if (dynamicSlots.length) {
  12189. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  12190. slots,
  12191. createArrayExpression(dynamicSlots)
  12192. ]);
  12193. }
  12194. return {
  12195. slots,
  12196. hasDynamicSlots
  12197. };
  12198. }
  12199. function buildDynamicSlot(name, fn) {
  12200. return createObjectExpression([
  12201. createObjectProperty(`name`, name),
  12202. createObjectProperty(`fn`, fn)
  12203. ]);
  12204. }
  12205. function hasForwardedSlots(children) {
  12206. for (let i = 0; i < children.length; i++) {
  12207. const child = children[i];
  12208. if (child.type === 1 /* ELEMENT */) {
  12209. if (child.tagType === 2 /* SLOT */ ||
  12210. (child.tagType === 0 /* ELEMENT */ &&
  12211. hasForwardedSlots(child.children))) {
  12212. return true;
  12213. }
  12214. }
  12215. }
  12216. return false;
  12217. }
  12218. // some directive transforms (e.g. v-model) may return a symbol for runtime
  12219. // import, which should be used instead of a resolveDirective call.
  12220. const directiveImportMap = new WeakMap();
  12221. // generate a JavaScript AST for this element's codegen
  12222. const transformElement = (node, context) => {
  12223. if (!(node.type === 1 /* ELEMENT */ &&
  12224. (node.tagType === 0 /* ELEMENT */ ||
  12225. node.tagType === 1 /* COMPONENT */))) {
  12226. return;
  12227. }
  12228. // perform the work on exit, after all child expressions have been
  12229. // processed and merged.
  12230. return function postTransformElement() {
  12231. const { tag, props } = node;
  12232. const isComponent = node.tagType === 1 /* COMPONENT */;
  12233. // The goal of the transform is to create a codegenNode implementing the
  12234. // VNodeCall interface.
  12235. const vnodeTag = isComponent
  12236. ? resolveComponentType(node, context)
  12237. : `"${tag}"`;
  12238. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  12239. let vnodeProps;
  12240. let vnodeChildren;
  12241. let vnodePatchFlag;
  12242. let patchFlag = 0;
  12243. let vnodeDynamicProps;
  12244. let dynamicPropNames;
  12245. let vnodeDirectives;
  12246. let shouldUseBlock =
  12247. // dynamic component may resolve to plain elements
  12248. isDynamicComponent ||
  12249. vnodeTag === TELEPORT ||
  12250. vnodeTag === SUSPENSE ||
  12251. (!isComponent &&
  12252. // <svg> and <foreignObject> must be forced into blocks so that block
  12253. // updates inside get proper isSVG flag at runtime. (#639, #643)
  12254. // This is technically web-specific, but splitting the logic out of core
  12255. // leads to too much unnecessary complexity.
  12256. (tag === 'svg' ||
  12257. tag === 'foreignObject' ||
  12258. // #938: elements with dynamic keys should be forced into blocks
  12259. findProp(node, 'key', true)));
  12260. // props
  12261. if (props.length > 0) {
  12262. const propsBuildResult = buildProps(node, context);
  12263. vnodeProps = propsBuildResult.props;
  12264. patchFlag = propsBuildResult.patchFlag;
  12265. dynamicPropNames = propsBuildResult.dynamicPropNames;
  12266. const directives = propsBuildResult.directives;
  12267. vnodeDirectives =
  12268. directives && directives.length
  12269. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  12270. : undefined;
  12271. }
  12272. // children
  12273. if (node.children.length > 0) {
  12274. if (vnodeTag === KEEP_ALIVE) {
  12275. // Although a built-in component, we compile KeepAlive with raw children
  12276. // instead of slot functions so that it can be used inside Transition
  12277. // or other Transition-wrapping HOCs.
  12278. // To ensure correct updates with block optimizations, we need to:
  12279. // 1. Force keep-alive into a block. This avoids its children being
  12280. // collected by a parent block.
  12281. shouldUseBlock = true;
  12282. // 2. Force keep-alive to always be updated, since it uses raw children.
  12283. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  12284. if (node.children.length > 1) {
  12285. context.onError(createCompilerError(44 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  12286. start: node.children[0].loc.start,
  12287. end: node.children[node.children.length - 1].loc.end,
  12288. source: ''
  12289. }));
  12290. }
  12291. }
  12292. const shouldBuildAsSlots = isComponent &&
  12293. // Teleport is not a real component and has dedicated runtime handling
  12294. vnodeTag !== TELEPORT &&
  12295. // explained above.
  12296. vnodeTag !== KEEP_ALIVE;
  12297. if (shouldBuildAsSlots) {
  12298. const { slots, hasDynamicSlots } = buildSlots(node, context);
  12299. vnodeChildren = slots;
  12300. if (hasDynamicSlots) {
  12301. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  12302. }
  12303. }
  12304. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  12305. const child = node.children[0];
  12306. const type = child.type;
  12307. // check for dynamic text children
  12308. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  12309. type === 8 /* COMPOUND_EXPRESSION */;
  12310. if (hasDynamicTextChild &&
  12311. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  12312. patchFlag |= 1 /* TEXT */;
  12313. }
  12314. // pass directly if the only child is a text node
  12315. // (plain / interpolation / expression)
  12316. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  12317. vnodeChildren = child;
  12318. }
  12319. else {
  12320. vnodeChildren = node.children;
  12321. }
  12322. }
  12323. else {
  12324. vnodeChildren = node.children;
  12325. }
  12326. }
  12327. // patchFlag & dynamicPropNames
  12328. if (patchFlag !== 0) {
  12329. {
  12330. if (patchFlag < 0) {
  12331. // special flags (negative and mutually exclusive)
  12332. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  12333. }
  12334. else {
  12335. // bitwise flags
  12336. const flagNames = Object.keys(PatchFlagNames)
  12337. .map(Number)
  12338. .filter(n => n > 0 && patchFlag & n)
  12339. .map(n => PatchFlagNames[n])
  12340. .join(`, `);
  12341. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  12342. }
  12343. }
  12344. if (dynamicPropNames && dynamicPropNames.length) {
  12345. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  12346. }
  12347. }
  12348. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, node.loc);
  12349. };
  12350. };
  12351. function resolveComponentType(node, context, ssr = false) {
  12352. const { tag } = node;
  12353. // 1. dynamic component
  12354. const isProp = node.tag === 'component' ? findProp(node, 'is') : findDir(node, 'is');
  12355. if (isProp) {
  12356. const exp = isProp.type === 6 /* ATTRIBUTE */
  12357. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  12358. : isProp.exp;
  12359. if (exp) {
  12360. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  12361. exp
  12362. ]);
  12363. }
  12364. }
  12365. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  12366. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  12367. if (builtIn) {
  12368. // built-ins are simply fallthroughs / have special handling during ssr
  12369. // so we don't need to import their runtime equivalents
  12370. if (!ssr)
  12371. context.helper(builtIn);
  12372. return builtIn;
  12373. }
  12374. // 5. user component (resolve)
  12375. context.helper(RESOLVE_COMPONENT);
  12376. context.components.add(tag);
  12377. return toValidAssetId(tag, `component`);
  12378. }
  12379. function buildProps(node, context, props = node.props, ssr = false) {
  12380. const { tag, loc: elementLoc } = node;
  12381. const isComponent = node.tagType === 1 /* COMPONENT */;
  12382. let properties = [];
  12383. const mergeArgs = [];
  12384. const runtimeDirectives = [];
  12385. // patchFlag analysis
  12386. let patchFlag = 0;
  12387. let hasRef = false;
  12388. let hasClassBinding = false;
  12389. let hasStyleBinding = false;
  12390. let hasHydrationEventBinding = false;
  12391. let hasDynamicKeys = false;
  12392. let hasVnodeHook = false;
  12393. const dynamicPropNames = [];
  12394. const analyzePatchFlag = ({ key, value }) => {
  12395. if (isStaticExp(key)) {
  12396. const name = key.content;
  12397. const isEventHandler = isOn(name);
  12398. if (!isComponent &&
  12399. isEventHandler &&
  12400. // omit the flag for click handlers because hydration gives click
  12401. // dedicated fast path.
  12402. name.toLowerCase() !== 'onclick' &&
  12403. // omit v-model handlers
  12404. name !== 'onUpdate:modelValue' &&
  12405. // omit onVnodeXXX hooks
  12406. !isReservedProp(name)) {
  12407. hasHydrationEventBinding = true;
  12408. }
  12409. if (isEventHandler && isReservedProp(name)) {
  12410. hasVnodeHook = true;
  12411. }
  12412. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  12413. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  12414. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  12415. getConstantType(value, context) > 0)) {
  12416. // skip if the prop is a cached handler or has constant value
  12417. return;
  12418. }
  12419. if (name === 'ref') {
  12420. hasRef = true;
  12421. }
  12422. else if (name === 'class' && !isComponent) {
  12423. hasClassBinding = true;
  12424. }
  12425. else if (name === 'style' && !isComponent) {
  12426. hasStyleBinding = true;
  12427. }
  12428. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  12429. dynamicPropNames.push(name);
  12430. }
  12431. }
  12432. else {
  12433. hasDynamicKeys = true;
  12434. }
  12435. };
  12436. for (let i = 0; i < props.length; i++) {
  12437. // static attribute
  12438. const prop = props[i];
  12439. if (prop.type === 6 /* ATTRIBUTE */) {
  12440. const { loc, name, value } = prop;
  12441. let isStatic = true;
  12442. if (name === 'ref') {
  12443. hasRef = true;
  12444. }
  12445. // skip :is on <component>
  12446. if (name === 'is' && tag === 'component') {
  12447. continue;
  12448. }
  12449. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  12450. }
  12451. else {
  12452. // directives
  12453. const { name, arg, exp, loc } = prop;
  12454. const isBind = name === 'bind';
  12455. const isOn = name === 'on';
  12456. // skip v-slot - it is handled by its dedicated transform.
  12457. if (name === 'slot') {
  12458. if (!isComponent) {
  12459. context.onError(createCompilerError(39 /* X_V_SLOT_MISPLACED */, loc));
  12460. }
  12461. continue;
  12462. }
  12463. // skip v-once - it is handled by its dedicated transform.
  12464. if (name === 'once') {
  12465. continue;
  12466. }
  12467. // skip v-is and :is on <component>
  12468. if (name === 'is' ||
  12469. (isBind && tag === 'component' && isBindKey(arg, 'is'))) {
  12470. continue;
  12471. }
  12472. // skip v-on in SSR compilation
  12473. if (isOn && ssr) {
  12474. continue;
  12475. }
  12476. // special case for v-bind and v-on with no argument
  12477. if (!arg && (isBind || isOn)) {
  12478. hasDynamicKeys = true;
  12479. if (exp) {
  12480. if (properties.length) {
  12481. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  12482. properties = [];
  12483. }
  12484. if (isBind) {
  12485. mergeArgs.push(exp);
  12486. }
  12487. else {
  12488. // v-on="obj" -> toHandlers(obj)
  12489. mergeArgs.push({
  12490. type: 14 /* JS_CALL_EXPRESSION */,
  12491. loc,
  12492. callee: context.helper(TO_HANDLERS),
  12493. arguments: [exp]
  12494. });
  12495. }
  12496. }
  12497. else {
  12498. context.onError(createCompilerError(isBind
  12499. ? 33 /* X_V_BIND_NO_EXPRESSION */
  12500. : 34 /* X_V_ON_NO_EXPRESSION */, loc));
  12501. }
  12502. continue;
  12503. }
  12504. const directiveTransform = context.directiveTransforms[name];
  12505. if (directiveTransform) {
  12506. // has built-in directive transform.
  12507. const { props, needRuntime } = directiveTransform(prop, node, context);
  12508. !ssr && props.forEach(analyzePatchFlag);
  12509. properties.push(...props);
  12510. if (needRuntime) {
  12511. runtimeDirectives.push(prop);
  12512. if (isSymbol(needRuntime)) {
  12513. directiveImportMap.set(prop, needRuntime);
  12514. }
  12515. }
  12516. }
  12517. else {
  12518. // no built-in transform, this is a user custom directive.
  12519. runtimeDirectives.push(prop);
  12520. }
  12521. }
  12522. }
  12523. let propsExpression = undefined;
  12524. // has v-bind="object" or v-on="object", wrap with mergeProps
  12525. if (mergeArgs.length) {
  12526. if (properties.length) {
  12527. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  12528. }
  12529. if (mergeArgs.length > 1) {
  12530. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  12531. }
  12532. else {
  12533. // single v-bind with nothing else - no need for a mergeProps call
  12534. propsExpression = mergeArgs[0];
  12535. }
  12536. }
  12537. else if (properties.length) {
  12538. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  12539. }
  12540. // patchFlag analysis
  12541. if (hasDynamicKeys) {
  12542. patchFlag |= 16 /* FULL_PROPS */;
  12543. }
  12544. else {
  12545. if (hasClassBinding) {
  12546. patchFlag |= 2 /* CLASS */;
  12547. }
  12548. if (hasStyleBinding) {
  12549. patchFlag |= 4 /* STYLE */;
  12550. }
  12551. if (dynamicPropNames.length) {
  12552. patchFlag |= 8 /* PROPS */;
  12553. }
  12554. if (hasHydrationEventBinding) {
  12555. patchFlag |= 32 /* HYDRATE_EVENTS */;
  12556. }
  12557. }
  12558. if ((patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  12559. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  12560. patchFlag |= 512 /* NEED_PATCH */;
  12561. }
  12562. return {
  12563. props: propsExpression,
  12564. directives: runtimeDirectives,
  12565. patchFlag,
  12566. dynamicPropNames
  12567. };
  12568. }
  12569. // Dedupe props in an object literal.
  12570. // Literal duplicated attributes would have been warned during the parse phase,
  12571. // however, it's possible to encounter duplicated `onXXX` handlers with different
  12572. // modifiers. We also need to merge static and dynamic class / style attributes.
  12573. // - onXXX handlers / style: merge into array
  12574. // - class: merge into single expression with concatenation
  12575. function dedupeProperties(properties) {
  12576. const knownProps = new Map();
  12577. const deduped = [];
  12578. for (let i = 0; i < properties.length; i++) {
  12579. const prop = properties[i];
  12580. // dynamic keys are always allowed
  12581. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  12582. deduped.push(prop);
  12583. continue;
  12584. }
  12585. const name = prop.key.content;
  12586. const existing = knownProps.get(name);
  12587. if (existing) {
  12588. if (name === 'style' || name === 'class' || name.startsWith('on')) {
  12589. mergeAsArray(existing, prop);
  12590. }
  12591. // unexpected duplicate, should have emitted error during parse
  12592. }
  12593. else {
  12594. knownProps.set(name, prop);
  12595. deduped.push(prop);
  12596. }
  12597. }
  12598. return deduped;
  12599. }
  12600. function mergeAsArray(existing, incoming) {
  12601. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  12602. existing.value.elements.push(incoming.value);
  12603. }
  12604. else {
  12605. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  12606. }
  12607. }
  12608. function buildDirectiveArgs(dir, context) {
  12609. const dirArgs = [];
  12610. const runtime = directiveImportMap.get(dir);
  12611. if (runtime) {
  12612. // built-in directive with runtime
  12613. dirArgs.push(context.helperString(runtime));
  12614. }
  12615. else {
  12616. {
  12617. // inject statement for resolving directive
  12618. context.helper(RESOLVE_DIRECTIVE);
  12619. context.directives.add(dir.name);
  12620. dirArgs.push(toValidAssetId(dir.name, `directive`));
  12621. }
  12622. }
  12623. const { loc } = dir;
  12624. if (dir.exp)
  12625. dirArgs.push(dir.exp);
  12626. if (dir.arg) {
  12627. if (!dir.exp) {
  12628. dirArgs.push(`void 0`);
  12629. }
  12630. dirArgs.push(dir.arg);
  12631. }
  12632. if (Object.keys(dir.modifiers).length) {
  12633. if (!dir.arg) {
  12634. if (!dir.exp) {
  12635. dirArgs.push(`void 0`);
  12636. }
  12637. dirArgs.push(`void 0`);
  12638. }
  12639. const trueExpression = createSimpleExpression(`true`, false, loc);
  12640. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  12641. }
  12642. return createArrayExpression(dirArgs, dir.loc);
  12643. }
  12644. function stringifyDynamicPropNames(props) {
  12645. let propsNamesString = `[`;
  12646. for (let i = 0, l = props.length; i < l; i++) {
  12647. propsNamesString += JSON.stringify(props[i]);
  12648. if (i < l - 1)
  12649. propsNamesString += ', ';
  12650. }
  12651. return propsNamesString + `]`;
  12652. }
  12653. const transformSlotOutlet = (node, context) => {
  12654. if (isSlotOutlet(node)) {
  12655. const { children, loc } = node;
  12656. const { slotName, slotProps } = processSlotOutlet(node, context);
  12657. const slotArgs = [
  12658. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  12659. slotName
  12660. ];
  12661. if (slotProps) {
  12662. slotArgs.push(slotProps);
  12663. }
  12664. if (children.length) {
  12665. if (!slotProps) {
  12666. slotArgs.push(`{}`);
  12667. }
  12668. slotArgs.push(createFunctionExpression([], children, false, false, loc));
  12669. }
  12670. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  12671. }
  12672. };
  12673. function processSlotOutlet(node, context) {
  12674. let slotName = `"default"`;
  12675. let slotProps = undefined;
  12676. const nonNameProps = [];
  12677. for (let i = 0; i < node.props.length; i++) {
  12678. const p = node.props[i];
  12679. if (p.type === 6 /* ATTRIBUTE */) {
  12680. if (p.value) {
  12681. if (p.name === 'name') {
  12682. slotName = JSON.stringify(p.value.content);
  12683. }
  12684. else {
  12685. p.name = camelize(p.name);
  12686. nonNameProps.push(p);
  12687. }
  12688. }
  12689. }
  12690. else {
  12691. if (p.name === 'bind' && isBindKey(p.arg, 'name')) {
  12692. if (p.exp)
  12693. slotName = p.exp;
  12694. }
  12695. else {
  12696. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  12697. p.arg.content = camelize(p.arg.content);
  12698. }
  12699. nonNameProps.push(p);
  12700. }
  12701. }
  12702. }
  12703. if (nonNameProps.length > 0) {
  12704. const { props, directives } = buildProps(node, context, nonNameProps);
  12705. slotProps = props;
  12706. if (directives.length) {
  12707. context.onError(createCompilerError(35 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  12708. }
  12709. }
  12710. return {
  12711. slotName,
  12712. slotProps
  12713. };
  12714. }
  12715. const fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^\s*function(?:\s+[\w$]+)?\s*\(/;
  12716. const transformOn = (dir, node, context, augmentor) => {
  12717. const { loc, modifiers, arg } = dir;
  12718. if (!dir.exp && !modifiers.length) {
  12719. context.onError(createCompilerError(34 /* X_V_ON_NO_EXPRESSION */, loc));
  12720. }
  12721. let eventName;
  12722. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12723. if (arg.isStatic) {
  12724. const rawName = arg.content;
  12725. // for all event listeners, auto convert it to camelCase. See issue #2249
  12726. eventName = createSimpleExpression(toHandlerKey(camelize(rawName)), true, arg.loc);
  12727. }
  12728. else {
  12729. // #2388
  12730. eventName = createCompoundExpression([
  12731. `${context.helperString(TO_HANDLER_KEY)}(`,
  12732. arg,
  12733. `)`
  12734. ]);
  12735. }
  12736. }
  12737. else {
  12738. // already a compound expression.
  12739. eventName = arg;
  12740. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  12741. eventName.children.push(`)`);
  12742. }
  12743. // handler processing
  12744. let exp = dir.exp;
  12745. if (exp && !exp.content.trim()) {
  12746. exp = undefined;
  12747. }
  12748. let shouldCache = context.cacheHandlers && !exp;
  12749. if (exp) {
  12750. const isMemberExp = isMemberExpression(exp.content);
  12751. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  12752. const hasMultipleStatements = exp.content.includes(`;`);
  12753. {
  12754. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  12755. }
  12756. if (isInlineStatement || (shouldCache && isMemberExp)) {
  12757. // wrap inline statement in a function expression
  12758. exp = createCompoundExpression([
  12759. `${isInlineStatement
  12760. ? `$event`
  12761. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  12762. exp,
  12763. hasMultipleStatements ? `}` : `)`
  12764. ]);
  12765. }
  12766. }
  12767. let ret = {
  12768. props: [
  12769. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  12770. ]
  12771. };
  12772. // apply extended compiler augmentor
  12773. if (augmentor) {
  12774. ret = augmentor(ret);
  12775. }
  12776. if (shouldCache) {
  12777. // cache handlers so that it's always the same handler being passed down.
  12778. // this avoids unnecessary re-renders when users use inline handlers on
  12779. // components.
  12780. ret.props[0].value = context.cache(ret.props[0].value);
  12781. }
  12782. return ret;
  12783. };
  12784. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  12785. // codegen for the entire props object. This transform here is only for v-bind
  12786. // *with* args.
  12787. const transformBind = (dir, node, context) => {
  12788. const { exp, modifiers, loc } = dir;
  12789. const arg = dir.arg;
  12790. if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
  12791. arg.children.unshift(`(`);
  12792. arg.children.push(`) || ""`);
  12793. }
  12794. else if (!arg.isStatic) {
  12795. arg.content = `${arg.content} || ""`;
  12796. }
  12797. // .prop is no longer necessary due to new patch behavior
  12798. // .sync is replaced by v-model:arg
  12799. if (modifiers.includes('camel')) {
  12800. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12801. if (arg.isStatic) {
  12802. arg.content = camelize(arg.content);
  12803. }
  12804. else {
  12805. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  12806. }
  12807. }
  12808. else {
  12809. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  12810. arg.children.push(`)`);
  12811. }
  12812. }
  12813. if (!exp ||
  12814. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  12815. context.onError(createCompilerError(33 /* X_V_BIND_NO_EXPRESSION */, loc));
  12816. return {
  12817. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  12818. };
  12819. }
  12820. return {
  12821. props: [createObjectProperty(arg, exp)]
  12822. };
  12823. };
  12824. // Merge adjacent text nodes and expressions into a single expression
  12825. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  12826. const transformText = (node, context) => {
  12827. if (node.type === 0 /* ROOT */ ||
  12828. node.type === 1 /* ELEMENT */ ||
  12829. node.type === 11 /* FOR */ ||
  12830. node.type === 10 /* IF_BRANCH */) {
  12831. // perform the transform on node exit so that all expressions have already
  12832. // been processed.
  12833. return () => {
  12834. const children = node.children;
  12835. let currentContainer = undefined;
  12836. let hasText = false;
  12837. for (let i = 0; i < children.length; i++) {
  12838. const child = children[i];
  12839. if (isText(child)) {
  12840. hasText = true;
  12841. for (let j = i + 1; j < children.length; j++) {
  12842. const next = children[j];
  12843. if (isText(next)) {
  12844. if (!currentContainer) {
  12845. currentContainer = children[i] = {
  12846. type: 8 /* COMPOUND_EXPRESSION */,
  12847. loc: child.loc,
  12848. children: [child]
  12849. };
  12850. }
  12851. // merge adjacent text node into current
  12852. currentContainer.children.push(` + `, next);
  12853. children.splice(j, 1);
  12854. j--;
  12855. }
  12856. else {
  12857. currentContainer = undefined;
  12858. break;
  12859. }
  12860. }
  12861. }
  12862. }
  12863. if (!hasText ||
  12864. // if this is a plain element with a single text child, leave it
  12865. // as-is since the runtime has dedicated fast path for this by directly
  12866. // setting textContent of the element.
  12867. // for component root it's always normalized anyway.
  12868. (children.length === 1 &&
  12869. (node.type === 0 /* ROOT */ ||
  12870. (node.type === 1 /* ELEMENT */ &&
  12871. node.tagType === 0 /* ELEMENT */)))) {
  12872. return;
  12873. }
  12874. // pre-convert text nodes into createTextVNode(text) calls to avoid
  12875. // runtime normalization.
  12876. for (let i = 0; i < children.length; i++) {
  12877. const child = children[i];
  12878. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  12879. const callArgs = [];
  12880. // createTextVNode defaults to single whitespace, so if it is a
  12881. // single space the code could be an empty call to save bytes.
  12882. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  12883. callArgs.push(child);
  12884. }
  12885. // mark dynamic text with flag so it gets patched inside a block
  12886. if (!context.ssr &&
  12887. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  12888. callArgs.push(1 /* TEXT */ +
  12889. (` /* ${PatchFlagNames[1 /* TEXT */]} */` ));
  12890. }
  12891. children[i] = {
  12892. type: 12 /* TEXT_CALL */,
  12893. content: child,
  12894. loc: child.loc,
  12895. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  12896. };
  12897. }
  12898. }
  12899. };
  12900. }
  12901. };
  12902. const seen = new WeakSet();
  12903. const transformOnce = (node, context) => {
  12904. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  12905. if (seen.has(node)) {
  12906. return;
  12907. }
  12908. seen.add(node);
  12909. context.helper(SET_BLOCK_TRACKING);
  12910. return () => {
  12911. const cur = context.currentNode;
  12912. if (cur.codegenNode) {
  12913. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  12914. }
  12915. };
  12916. }
  12917. };
  12918. const transformModel = (dir, node, context) => {
  12919. const { exp, arg } = dir;
  12920. if (!exp) {
  12921. context.onError(createCompilerError(40 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  12922. return createTransformProps();
  12923. }
  12924. const rawExp = exp.loc.source;
  12925. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  12926. // im SFC <script setup> inline mode, the exp may have been transformed into
  12927. // _unref(exp)
  12928. context.bindingMetadata[rawExp];
  12929. const maybeRef = !true /* SETUP_CONST */;
  12930. if (!isMemberExpression(expString) && !maybeRef) {
  12931. context.onError(createCompilerError(41 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  12932. return createTransformProps();
  12933. }
  12934. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  12935. const eventName = arg
  12936. ? isStaticExp(arg)
  12937. ? `onUpdate:${arg.content}`
  12938. : createCompoundExpression(['"onUpdate:" + ', arg])
  12939. : `onUpdate:modelValue`;
  12940. let assignmentExp;
  12941. const eventArg = context.isTS ? `($event: any)` : `$event`;
  12942. {
  12943. assignmentExp = createCompoundExpression([
  12944. `${eventArg} => (`,
  12945. exp,
  12946. ` = $event)`
  12947. ]);
  12948. }
  12949. const props = [
  12950. // modelValue: foo
  12951. createObjectProperty(propName, dir.exp),
  12952. // "onUpdate:modelValue": $event => (foo = $event)
  12953. createObjectProperty(eventName, assignmentExp)
  12954. ];
  12955. // modelModifiers: { foo: true, "bar-baz": true }
  12956. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  12957. const modifiers = dir.modifiers
  12958. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  12959. .join(`, `);
  12960. const modifiersKey = arg
  12961. ? isStaticExp(arg)
  12962. ? `${arg.content}Modifiers`
  12963. : createCompoundExpression([arg, ' + "Modifiers"'])
  12964. : `modelModifiers`;
  12965. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
  12966. }
  12967. return createTransformProps(props);
  12968. };
  12969. function createTransformProps(props = []) {
  12970. return { props };
  12971. }
  12972. function getBaseTransformPreset(prefixIdentifiers) {
  12973. return [
  12974. [
  12975. transformOnce,
  12976. transformIf,
  12977. transformFor,
  12978. ...([transformExpression]
  12979. ),
  12980. transformSlotOutlet,
  12981. transformElement,
  12982. trackSlotScopes,
  12983. transformText
  12984. ],
  12985. {
  12986. on: transformOn,
  12987. bind: transformBind,
  12988. model: transformModel
  12989. }
  12990. ];
  12991. }
  12992. // we name it `baseCompile` so that higher order compilers like
  12993. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  12994. function baseCompile(template, options = {}) {
  12995. const onError = options.onError || defaultOnError;
  12996. const isModuleMode = options.mode === 'module';
  12997. /* istanbul ignore if */
  12998. {
  12999. if (options.prefixIdentifiers === true) {
  13000. onError(createCompilerError(45 /* X_PREFIX_ID_NOT_SUPPORTED */));
  13001. }
  13002. else if (isModuleMode) {
  13003. onError(createCompilerError(46 /* X_MODULE_MODE_NOT_SUPPORTED */));
  13004. }
  13005. }
  13006. const prefixIdentifiers = !true ;
  13007. if (options.cacheHandlers) {
  13008. onError(createCompilerError(47 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  13009. }
  13010. if (options.scopeId && !isModuleMode) {
  13011. onError(createCompilerError(48 /* X_SCOPE_ID_NOT_SUPPORTED */));
  13012. }
  13013. const ast = isString(template) ? baseParse(template, options) : template;
  13014. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  13015. transform(ast, extend({}, options, {
  13016. prefixIdentifiers,
  13017. nodeTransforms: [
  13018. ...nodeTransforms,
  13019. ...(options.nodeTransforms || []) // user transforms
  13020. ],
  13021. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  13022. )
  13023. }));
  13024. return generate(ast, extend({}, options, {
  13025. prefixIdentifiers
  13026. }));
  13027. }
  13028. const noopDirectiveTransform = () => ({ props: [] });
  13029. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  13030. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  13031. const V_MODEL_TEXT = Symbol(`vModelText` );
  13032. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  13033. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  13034. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  13035. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  13036. const V_SHOW = Symbol(`vShow` );
  13037. const TRANSITION$1 = Symbol(`Transition` );
  13038. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  13039. registerRuntimeHelpers({
  13040. [V_MODEL_RADIO]: `vModelRadio`,
  13041. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  13042. [V_MODEL_TEXT]: `vModelText`,
  13043. [V_MODEL_SELECT]: `vModelSelect`,
  13044. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  13045. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  13046. [V_ON_WITH_KEYS]: `withKeys`,
  13047. [V_SHOW]: `vShow`,
  13048. [TRANSITION$1]: `Transition`,
  13049. [TRANSITION_GROUP]: `TransitionGroup`
  13050. });
  13051. /* eslint-disable no-restricted-globals */
  13052. let decoder;
  13053. function decodeHtmlBrowser(raw) {
  13054. (decoder || (decoder = document.createElement('div'))).innerHTML = raw;
  13055. return decoder.textContent;
  13056. }
  13057. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  13058. const parserOptions = {
  13059. isVoidTag,
  13060. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  13061. isPreTag: tag => tag === 'pre',
  13062. decodeEntities: decodeHtmlBrowser ,
  13063. isBuiltInComponent: (tag) => {
  13064. if (isBuiltInType(tag, `Transition`)) {
  13065. return TRANSITION$1;
  13066. }
  13067. else if (isBuiltInType(tag, `TransitionGroup`)) {
  13068. return TRANSITION_GROUP;
  13069. }
  13070. },
  13071. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  13072. getNamespace(tag, parent) {
  13073. let ns = parent ? parent.ns : 0 /* HTML */;
  13074. if (parent && ns === 2 /* MATH_ML */) {
  13075. if (parent.tag === 'annotation-xml') {
  13076. if (tag === 'svg') {
  13077. return 1 /* SVG */;
  13078. }
  13079. if (parent.props.some(a => a.type === 6 /* ATTRIBUTE */ &&
  13080. a.name === 'encoding' &&
  13081. a.value != null &&
  13082. (a.value.content === 'text/html' ||
  13083. a.value.content === 'application/xhtml+xml'))) {
  13084. ns = 0 /* HTML */;
  13085. }
  13086. }
  13087. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  13088. tag !== 'mglyph' &&
  13089. tag !== 'malignmark') {
  13090. ns = 0 /* HTML */;
  13091. }
  13092. }
  13093. else if (parent && ns === 1 /* SVG */) {
  13094. if (parent.tag === 'foreignObject' ||
  13095. parent.tag === 'desc' ||
  13096. parent.tag === 'title') {
  13097. ns = 0 /* HTML */;
  13098. }
  13099. }
  13100. if (ns === 0 /* HTML */) {
  13101. if (tag === 'svg') {
  13102. return 1 /* SVG */;
  13103. }
  13104. if (tag === 'math') {
  13105. return 2 /* MATH_ML */;
  13106. }
  13107. }
  13108. return ns;
  13109. },
  13110. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  13111. getTextMode({ tag, ns }) {
  13112. if (ns === 0 /* HTML */) {
  13113. if (tag === 'textarea' || tag === 'title') {
  13114. return 1 /* RCDATA */;
  13115. }
  13116. if (isRawTextContainer(tag)) {
  13117. return 2 /* RAWTEXT */;
  13118. }
  13119. }
  13120. return 0 /* DATA */;
  13121. }
  13122. };
  13123. // Parse inline CSS strings for static style attributes into an object.
  13124. // This is a NodeTransform since it works on the static `style` attribute and
  13125. // converts it into a dynamic equivalent:
  13126. // style="color: red" -> :style='{ "color": "red" }'
  13127. // It is then processed by `transformElement` and included in the generated
  13128. // props.
  13129. const transformStyle = node => {
  13130. if (node.type === 1 /* ELEMENT */) {
  13131. node.props.forEach((p, i) => {
  13132. if (p.type === 6 /* ATTRIBUTE */ && p.name === 'style' && p.value) {
  13133. // replace p with an expression node
  13134. node.props[i] = {
  13135. type: 7 /* DIRECTIVE */,
  13136. name: `bind`,
  13137. arg: createSimpleExpression(`style`, true, p.loc),
  13138. exp: parseInlineCSS(p.value.content, p.loc),
  13139. modifiers: [],
  13140. loc: p.loc
  13141. };
  13142. }
  13143. });
  13144. }
  13145. };
  13146. const parseInlineCSS = (cssText, loc) => {
  13147. const normalized = parseStringStyle(cssText);
  13148. return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* CAN_STRINGIFY */);
  13149. };
  13150. function createDOMCompilerError(code, loc) {
  13151. return createCompilerError(code, loc, DOMErrorMessages );
  13152. }
  13153. const DOMErrorMessages = {
  13154. [49 /* X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  13155. [50 /* X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  13156. [51 /* X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  13157. [52 /* X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  13158. [53 /* X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  13159. [54 /* X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  13160. [55 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  13161. [56 /* X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  13162. [57 /* X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  13163. [58 /* X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  13164. [59 /* X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  13165. };
  13166. const transformVHtml = (dir, node, context) => {
  13167. const { exp, loc } = dir;
  13168. if (!exp) {
  13169. context.onError(createDOMCompilerError(49 /* X_V_HTML_NO_EXPRESSION */, loc));
  13170. }
  13171. if (node.children.length) {
  13172. context.onError(createDOMCompilerError(50 /* X_V_HTML_WITH_CHILDREN */, loc));
  13173. node.children.length = 0;
  13174. }
  13175. return {
  13176. props: [
  13177. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  13178. ]
  13179. };
  13180. };
  13181. const transformVText = (dir, node, context) => {
  13182. const { exp, loc } = dir;
  13183. if (!exp) {
  13184. context.onError(createDOMCompilerError(51 /* X_V_TEXT_NO_EXPRESSION */, loc));
  13185. }
  13186. if (node.children.length) {
  13187. context.onError(createDOMCompilerError(52 /* X_V_TEXT_WITH_CHILDREN */, loc));
  13188. node.children.length = 0;
  13189. }
  13190. return {
  13191. props: [
  13192. createObjectProperty(createSimpleExpression(`textContent`, true), exp
  13193. ? createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
  13194. : createSimpleExpression('', true))
  13195. ]
  13196. };
  13197. };
  13198. const transformModel$1 = (dir, node, context) => {
  13199. const baseResult = transformModel(dir, node, context);
  13200. // base transform has errors OR component v-model (only need props)
  13201. if (!baseResult.props.length || node.tagType === 1 /* COMPONENT */) {
  13202. return baseResult;
  13203. }
  13204. if (dir.arg) {
  13205. context.onError(createDOMCompilerError(54 /* X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  13206. }
  13207. function checkDuplicatedValue() {
  13208. const value = findProp(node, 'value');
  13209. if (value) {
  13210. context.onError(createDOMCompilerError(56 /* X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  13211. }
  13212. }
  13213. const { tag } = node;
  13214. const isCustomElement = context.isCustomElement(tag);
  13215. if (tag === 'input' ||
  13216. tag === 'textarea' ||
  13217. tag === 'select' ||
  13218. isCustomElement) {
  13219. let directiveToUse = V_MODEL_TEXT;
  13220. let isInvalidType = false;
  13221. if (tag === 'input' || isCustomElement) {
  13222. const type = findProp(node, `type`);
  13223. if (type) {
  13224. if (type.type === 7 /* DIRECTIVE */) {
  13225. // :type="foo"
  13226. directiveToUse = V_MODEL_DYNAMIC;
  13227. }
  13228. else if (type.value) {
  13229. switch (type.value.content) {
  13230. case 'radio':
  13231. directiveToUse = V_MODEL_RADIO;
  13232. break;
  13233. case 'checkbox':
  13234. directiveToUse = V_MODEL_CHECKBOX;
  13235. break;
  13236. case 'file':
  13237. isInvalidType = true;
  13238. context.onError(createDOMCompilerError(55 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  13239. break;
  13240. default:
  13241. // text type
  13242. checkDuplicatedValue();
  13243. break;
  13244. }
  13245. }
  13246. }
  13247. else if (hasDynamicKeyVBind(node)) {
  13248. // element has bindings with dynamic keys, which can possibly contain
  13249. // "type".
  13250. directiveToUse = V_MODEL_DYNAMIC;
  13251. }
  13252. else {
  13253. // text type
  13254. checkDuplicatedValue();
  13255. }
  13256. }
  13257. else if (tag === 'select') {
  13258. directiveToUse = V_MODEL_SELECT;
  13259. }
  13260. else {
  13261. // textarea
  13262. checkDuplicatedValue();
  13263. }
  13264. // inject runtime directive
  13265. // by returning the helper symbol via needRuntime
  13266. // the import will replaced a resolveDirective call.
  13267. if (!isInvalidType) {
  13268. baseResult.needRuntime = context.helper(directiveToUse);
  13269. }
  13270. }
  13271. else {
  13272. context.onError(createDOMCompilerError(53 /* X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  13273. }
  13274. // native vmodel doesn't need the `modelValue` props since they are also
  13275. // passed to the runtime as `binding.value`. removing it reduces code size.
  13276. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  13277. p.key.content === 'modelValue'));
  13278. return baseResult;
  13279. };
  13280. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  13281. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  13282. // event propagation management
  13283. `stop,prevent,self,` +
  13284. // system modifiers + exact
  13285. `ctrl,shift,alt,meta,exact,` +
  13286. // mouse
  13287. `middle`);
  13288. // left & right could be mouse or key modifiers based on event type
  13289. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  13290. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  13291. const resolveModifiers = (key, modifiers) => {
  13292. const keyModifiers = [];
  13293. const nonKeyModifiers = [];
  13294. const eventOptionModifiers = [];
  13295. for (let i = 0; i < modifiers.length; i++) {
  13296. const modifier = modifiers[i];
  13297. if (isEventOptionModifier(modifier)) {
  13298. // eventOptionModifiers: modifiers for addEventListener() options,
  13299. // e.g. .passive & .capture
  13300. eventOptionModifiers.push(modifier);
  13301. }
  13302. else {
  13303. // runtimeModifiers: modifiers that needs runtime guards
  13304. if (maybeKeyModifier(modifier)) {
  13305. if (isStaticExp(key)) {
  13306. if (isKeyboardEvent(key.content)) {
  13307. keyModifiers.push(modifier);
  13308. }
  13309. else {
  13310. nonKeyModifiers.push(modifier);
  13311. }
  13312. }
  13313. else {
  13314. keyModifiers.push(modifier);
  13315. nonKeyModifiers.push(modifier);
  13316. }
  13317. }
  13318. else {
  13319. if (isNonKeyModifier(modifier)) {
  13320. nonKeyModifiers.push(modifier);
  13321. }
  13322. else {
  13323. keyModifiers.push(modifier);
  13324. }
  13325. }
  13326. }
  13327. }
  13328. return {
  13329. keyModifiers,
  13330. nonKeyModifiers,
  13331. eventOptionModifiers
  13332. };
  13333. };
  13334. const transformClick = (key, event) => {
  13335. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  13336. return isStaticClick
  13337. ? createSimpleExpression(event, true)
  13338. : key.type !== 4 /* SIMPLE_EXPRESSION */
  13339. ? createCompoundExpression([
  13340. `(`,
  13341. key,
  13342. `) === "onClick" ? "${event}" : (`,
  13343. key,
  13344. `)`
  13345. ])
  13346. : key;
  13347. };
  13348. const transformOn$1 = (dir, node, context) => {
  13349. return transformOn(dir, node, context, baseResult => {
  13350. const { modifiers } = dir;
  13351. if (!modifiers.length)
  13352. return baseResult;
  13353. let { key, value: handlerExp } = baseResult.props[0];
  13354. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers);
  13355. // normalize click.right and click.middle since they don't actually fire
  13356. if (nonKeyModifiers.includes('right')) {
  13357. key = transformClick(key, `onContextmenu`);
  13358. }
  13359. if (nonKeyModifiers.includes('middle')) {
  13360. key = transformClick(key, `onMouseup`);
  13361. }
  13362. if (nonKeyModifiers.length) {
  13363. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  13364. handlerExp,
  13365. JSON.stringify(nonKeyModifiers)
  13366. ]);
  13367. }
  13368. if (keyModifiers.length &&
  13369. // if event name is dynamic, always wrap with keys guard
  13370. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  13371. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  13372. handlerExp,
  13373. JSON.stringify(keyModifiers)
  13374. ]);
  13375. }
  13376. if (eventOptionModifiers.length) {
  13377. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  13378. key = isStaticExp(key)
  13379. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  13380. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  13381. }
  13382. return {
  13383. props: [createObjectProperty(key, handlerExp)]
  13384. };
  13385. });
  13386. };
  13387. const transformShow = (dir, node, context) => {
  13388. const { exp, loc } = dir;
  13389. if (!exp) {
  13390. context.onError(createDOMCompilerError(57 /* X_V_SHOW_NO_EXPRESSION */, loc));
  13391. }
  13392. return {
  13393. props: [],
  13394. needRuntime: context.helper(V_SHOW)
  13395. };
  13396. };
  13397. const warnTransitionChildren = (node, context) => {
  13398. if (node.type === 1 /* ELEMENT */ &&
  13399. node.tagType === 1 /* COMPONENT */) {
  13400. const component = context.isBuiltInComponent(node.tag);
  13401. if (component === TRANSITION$1) {
  13402. return () => {
  13403. if (node.children.length && hasMultipleChildren(node)) {
  13404. context.onError(createDOMCompilerError(58 /* X_TRANSITION_INVALID_CHILDREN */, {
  13405. start: node.children[0].loc.start,
  13406. end: node.children[node.children.length - 1].loc.end,
  13407. source: ''
  13408. }));
  13409. }
  13410. };
  13411. }
  13412. }
  13413. };
  13414. function hasMultipleChildren(node) {
  13415. // #1352 filter out potential comment nodes.
  13416. const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */));
  13417. const child = children[0];
  13418. return (children.length !== 1 ||
  13419. child.type === 11 /* FOR */ ||
  13420. (child.type === 9 /* IF */ && child.branches.some(hasMultipleChildren)));
  13421. }
  13422. const ignoreSideEffectTags = (node, context) => {
  13423. if (node.type === 1 /* ELEMENT */ &&
  13424. node.tagType === 0 /* ELEMENT */ &&
  13425. (node.tag === 'script' || node.tag === 'style')) {
  13426. context.onError(createDOMCompilerError(59 /* X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  13427. context.removeNode();
  13428. }
  13429. };
  13430. const DOMNodeTransforms = [
  13431. transformStyle,
  13432. ...([warnTransitionChildren] )
  13433. ];
  13434. const DOMDirectiveTransforms = {
  13435. cloak: noopDirectiveTransform,
  13436. html: transformVHtml,
  13437. text: transformVText,
  13438. model: transformModel$1,
  13439. on: transformOn$1,
  13440. show: transformShow
  13441. };
  13442. function compile$1(template, options = {}) {
  13443. return baseCompile(template, extend({}, parserOptions, options, {
  13444. nodeTransforms: [
  13445. // ignore <script> and <tag>
  13446. // this is not put inside DOMNodeTransforms because that list is used
  13447. // by compiler-ssr to generate vnode fallback branches
  13448. ignoreSideEffectTags,
  13449. ...DOMNodeTransforms,
  13450. ...(options.nodeTransforms || [])
  13451. ],
  13452. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  13453. transformHoist: null
  13454. }));
  13455. }
  13456. // This entry is the "full-build" that includes both the runtime
  13457. {
  13458. initDev();
  13459. }
  13460. const compileCache = Object.create(null);
  13461. function compileToFunction(template, options) {
  13462. if (!isString(template)) {
  13463. if (template.nodeType) {
  13464. template = template.innerHTML;
  13465. }
  13466. else {
  13467. warn(`invalid template option: `, template);
  13468. return NOOP;
  13469. }
  13470. }
  13471. const key = template;
  13472. const cached = compileCache[key];
  13473. if (cached) {
  13474. return cached;
  13475. }
  13476. if (template[0] === '#') {
  13477. const el = document.querySelector(template);
  13478. if (!el) {
  13479. warn(`Template element not found or is empty: ${template}`);
  13480. }
  13481. // __UNSAFE__
  13482. // Reason: potential execution of JS expressions in in-DOM template.
  13483. // The user must make sure the in-DOM template is trusted. If it's rendered
  13484. // by the server, the template should not contain any user data.
  13485. template = el ? el.innerHTML : ``;
  13486. }
  13487. const { code } = compile$1(template, extend({
  13488. hoistStatic: true,
  13489. onError(err) {
  13490. {
  13491. const message = `Template compilation error: ${err.message}`;
  13492. const codeFrame = err.loc &&
  13493. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  13494. warn(codeFrame ? `${message}\n${codeFrame}` : message);
  13495. }
  13496. }
  13497. }, options));
  13498. // The wildcard import results in a huge object with every export
  13499. // with keys that cannot be mangled, and can be quite heavy size-wise.
  13500. // In the global build we know `Vue` is available globally so we can avoid
  13501. // the wildcard object.
  13502. const render = (new Function(code)()
  13503. );
  13504. render._rc = true;
  13505. return (compileCache[key] = render);
  13506. }
  13507. registerRuntimeCompiler(compileToFunction);
  13508. exports.BaseTransition = BaseTransition;
  13509. exports.Comment = Comment;
  13510. exports.Fragment = Fragment;
  13511. exports.KeepAlive = KeepAlive;
  13512. exports.Static = Static;
  13513. exports.Suspense = Suspense;
  13514. exports.Teleport = Teleport;
  13515. exports.Text = Text;
  13516. exports.Transition = Transition;
  13517. exports.TransitionGroup = TransitionGroup;
  13518. exports.callWithAsyncErrorHandling = callWithAsyncErrorHandling;
  13519. exports.callWithErrorHandling = callWithErrorHandling;
  13520. exports.camelize = camelize;
  13521. exports.capitalize = capitalize;
  13522. exports.cloneVNode = cloneVNode;
  13523. exports.compile = compileToFunction;
  13524. exports.computed = computed$1;
  13525. exports.createApp = createApp;
  13526. exports.createBlock = createBlock;
  13527. exports.createCommentVNode = createCommentVNode;
  13528. exports.createHydrationRenderer = createHydrationRenderer;
  13529. exports.createRenderer = createRenderer;
  13530. exports.createSSRApp = createSSRApp;
  13531. exports.createSlots = createSlots;
  13532. exports.createStaticVNode = createStaticVNode;
  13533. exports.createTextVNode = createTextVNode;
  13534. exports.createVNode = createVNode;
  13535. exports.customRef = customRef;
  13536. exports.defineAsyncComponent = defineAsyncComponent;
  13537. exports.defineComponent = defineComponent;
  13538. exports.defineEmit = defineEmit;
  13539. exports.defineProps = defineProps;
  13540. exports.getCurrentInstance = getCurrentInstance;
  13541. exports.getTransitionRawChildren = getTransitionRawChildren;
  13542. exports.h = h;
  13543. exports.handleError = handleError;
  13544. exports.hydrate = hydrate;
  13545. exports.initCustomFormatter = initCustomFormatter;
  13546. exports.inject = inject;
  13547. exports.isProxy = isProxy;
  13548. exports.isReactive = isReactive;
  13549. exports.isReadonly = isReadonly;
  13550. exports.isRef = isRef;
  13551. exports.isRuntimeOnly = isRuntimeOnly;
  13552. exports.isVNode = isVNode;
  13553. exports.markRaw = markRaw;
  13554. exports.mergeProps = mergeProps;
  13555. exports.nextTick = nextTick;
  13556. exports.onActivated = onActivated;
  13557. exports.onBeforeMount = onBeforeMount;
  13558. exports.onBeforeUnmount = onBeforeUnmount;
  13559. exports.onBeforeUpdate = onBeforeUpdate;
  13560. exports.onDeactivated = onDeactivated;
  13561. exports.onErrorCaptured = onErrorCaptured;
  13562. exports.onMounted = onMounted;
  13563. exports.onRenderTracked = onRenderTracked;
  13564. exports.onRenderTriggered = onRenderTriggered;
  13565. exports.onUnmounted = onUnmounted;
  13566. exports.onUpdated = onUpdated;
  13567. exports.openBlock = openBlock;
  13568. exports.popScopeId = popScopeId;
  13569. exports.provide = provide;
  13570. exports.proxyRefs = proxyRefs;
  13571. exports.pushScopeId = pushScopeId;
  13572. exports.queuePostFlushCb = queuePostFlushCb;
  13573. exports.reactive = reactive;
  13574. exports.readonly = readonly;
  13575. exports.ref = ref;
  13576. exports.registerRuntimeCompiler = registerRuntimeCompiler;
  13577. exports.render = render;
  13578. exports.renderList = renderList;
  13579. exports.renderSlot = renderSlot;
  13580. exports.resolveComponent = resolveComponent;
  13581. exports.resolveDirective = resolveDirective;
  13582. exports.resolveDynamicComponent = resolveDynamicComponent;
  13583. exports.resolveTransitionHooks = resolveTransitionHooks;
  13584. exports.setBlockTracking = setBlockTracking;
  13585. exports.setDevtoolsHook = setDevtoolsHook;
  13586. exports.setTransitionHooks = setTransitionHooks;
  13587. exports.shallowReactive = shallowReactive;
  13588. exports.shallowReadonly = shallowReadonly;
  13589. exports.shallowRef = shallowRef;
  13590. exports.ssrContextKey = ssrContextKey;
  13591. exports.ssrUtils = ssrUtils;
  13592. exports.toDisplayString = toDisplayString;
  13593. exports.toHandlerKey = toHandlerKey;
  13594. exports.toHandlers = toHandlers;
  13595. exports.toRaw = toRaw;
  13596. exports.toRef = toRef;
  13597. exports.toRefs = toRefs;
  13598. exports.transformVNodeArgs = transformVNodeArgs;
  13599. exports.triggerRef = triggerRef;
  13600. exports.unref = unref;
  13601. exports.useContext = useContext;
  13602. exports.useCssModule = useCssModule;
  13603. exports.useCssVars = useCssVars;
  13604. exports.useSSRContext = useSSRContext;
  13605. exports.useTransitionState = useTransitionState;
  13606. exports.vModelCheckbox = vModelCheckbox;
  13607. exports.vModelDynamic = vModelDynamic;
  13608. exports.vModelRadio = vModelRadio;
  13609. exports.vModelSelect = vModelSelect;
  13610. exports.vModelText = vModelText;
  13611. exports.vShow = vShow;
  13612. exports.version = version;
  13613. exports.warn = warn;
  13614. exports.watch = watch;
  13615. exports.watchEffect = watchEffect;
  13616. exports.withCtx = withCtx;
  13617. exports.withDirectives = withDirectives;
  13618. exports.withKeys = withKeys;
  13619. exports.withModifiers = withModifiers;
  13620. exports.withScopeId = withScopeId;
  13621. Object.defineProperty(exports, '__esModule', { value: true });
  13622. return exports;
  13623. }({}));