vue.esm-browser.js 492 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696
  1. /**
  2. * Make a map and return a function for checking if a key
  3. * is in that map.
  4. * IMPORTANT: all calls of this function must be prefixed with
  5. * \/\*#\_\_PURE\_\_\*\/
  6. * So that rollup can tree-shake them if necessary.
  7. */
  8. function makeMap(str, expectsLowerCase) {
  9. const map = Object.create(null);
  10. const list = str.split(',');
  11. for (let i = 0; i < list.length; i++) {
  12. map[list[i]] = true;
  13. }
  14. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  15. }
  16. /**
  17. * dev only flag -> name mapping
  18. */
  19. const PatchFlagNames = {
  20. [1 /* TEXT */]: `TEXT`,
  21. [2 /* CLASS */]: `CLASS`,
  22. [4 /* STYLE */]: `STYLE`,
  23. [8 /* PROPS */]: `PROPS`,
  24. [16 /* FULL_PROPS */]: `FULL_PROPS`,
  25. [32 /* HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  26. [64 /* STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  27. [128 /* KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  28. [256 /* UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  29. [512 /* NEED_PATCH */]: `NEED_PATCH`,
  30. [1024 /* DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  31. [2048 /* DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
  32. [-1 /* HOISTED */]: `HOISTED`,
  33. [-2 /* BAIL */]: `BAIL`
  34. };
  35. /**
  36. * Dev only
  37. */
  38. const slotFlagsText = {
  39. [1 /* STABLE */]: 'STABLE',
  40. [2 /* DYNAMIC */]: 'DYNAMIC',
  41. [3 /* FORWARDED */]: 'FORWARDED'
  42. };
  43. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  44. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  45. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt';
  46. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  47. const range = 2;
  48. function generateCodeFrame(source, start = 0, end = source.length) {
  49. const lines = source.split(/\r?\n/);
  50. let count = 0;
  51. const res = [];
  52. for (let i = 0; i < lines.length; i++) {
  53. count += lines[i].length + 1;
  54. if (count >= start) {
  55. for (let j = i - range; j <= i + range || end > count; j++) {
  56. if (j < 0 || j >= lines.length)
  57. continue;
  58. const line = j + 1;
  59. res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
  60. const lineLength = lines[j].length;
  61. if (j === i) {
  62. // push underline
  63. const pad = start - (count - lineLength) + 1;
  64. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  65. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  66. }
  67. else if (j > i) {
  68. if (end > count) {
  69. const length = Math.max(Math.min(end - count, lineLength), 1);
  70. res.push(` | ` + '^'.repeat(length));
  71. }
  72. count += lineLength + 1;
  73. }
  74. }
  75. break;
  76. }
  77. }
  78. return res.join('\n');
  79. }
  80. /**
  81. * On the client we only need to offer special cases for boolean attributes that
  82. * have different names from their corresponding dom properties:
  83. * - itemscope -> N/A
  84. * - allowfullscreen -> allowFullscreen
  85. * - formnovalidate -> formNoValidate
  86. * - ismap -> isMap
  87. * - nomodule -> noModule
  88. * - novalidate -> noValidate
  89. * - readonly -> readOnly
  90. */
  91. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  92. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  93. function normalizeStyle(value) {
  94. if (isArray(value)) {
  95. const res = {};
  96. for (let i = 0; i < value.length; i++) {
  97. const item = value[i];
  98. const normalized = normalizeStyle(isString(item) ? parseStringStyle(item) : item);
  99. if (normalized) {
  100. for (const key in normalized) {
  101. res[key] = normalized[key];
  102. }
  103. }
  104. }
  105. return res;
  106. }
  107. else if (isObject(value)) {
  108. return value;
  109. }
  110. }
  111. const listDelimiterRE = /;(?![^(]*\))/g;
  112. const propertyDelimiterRE = /:(.+)/;
  113. function parseStringStyle(cssText) {
  114. const ret = {};
  115. cssText.split(listDelimiterRE).forEach(item => {
  116. if (item) {
  117. const tmp = item.split(propertyDelimiterRE);
  118. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  119. }
  120. });
  121. return ret;
  122. }
  123. function normalizeClass(value) {
  124. let res = '';
  125. if (isString(value)) {
  126. res = value;
  127. }
  128. else if (isArray(value)) {
  129. for (let i = 0; i < value.length; i++) {
  130. const normalized = normalizeClass(value[i]);
  131. if (normalized) {
  132. res += normalized + ' ';
  133. }
  134. }
  135. }
  136. else if (isObject(value)) {
  137. for (const name in value) {
  138. if (value[name]) {
  139. res += name + ' ';
  140. }
  141. }
  142. }
  143. return res.trim();
  144. }
  145. // These tag configs are shared between compiler-dom and runtime-dom, so they
  146. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  147. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  148. 'header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,div,dd,dl,dt,figcaption,' +
  149. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  150. 'data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,s,samp,small,span,strong,sub,sup,' +
  151. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  152. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  153. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  154. 'option,output,progress,select,textarea,details,dialog,menu,' +
  155. 'summary,template,blockquote,iframe,tfoot';
  156. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  157. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  158. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  159. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  160. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  161. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  162. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  163. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  164. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  165. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  166. 'text,textPath,title,tspan,unknown,use,view';
  167. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  168. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  169. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  170. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  171. function looseCompareArrays(a, b) {
  172. if (a.length !== b.length)
  173. return false;
  174. let equal = true;
  175. for (let i = 0; equal && i < a.length; i++) {
  176. equal = looseEqual(a[i], b[i]);
  177. }
  178. return equal;
  179. }
  180. function looseEqual(a, b) {
  181. if (a === b)
  182. return true;
  183. let aValidType = isDate(a);
  184. let bValidType = isDate(b);
  185. if (aValidType || bValidType) {
  186. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  187. }
  188. aValidType = isArray(a);
  189. bValidType = isArray(b);
  190. if (aValidType || bValidType) {
  191. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  192. }
  193. aValidType = isObject(a);
  194. bValidType = isObject(b);
  195. if (aValidType || bValidType) {
  196. /* istanbul ignore if: this if will probably never be called */
  197. if (!aValidType || !bValidType) {
  198. return false;
  199. }
  200. const aKeysCount = Object.keys(a).length;
  201. const bKeysCount = Object.keys(b).length;
  202. if (aKeysCount !== bKeysCount) {
  203. return false;
  204. }
  205. for (const key in a) {
  206. const aHasKey = a.hasOwnProperty(key);
  207. const bHasKey = b.hasOwnProperty(key);
  208. if ((aHasKey && !bHasKey) ||
  209. (!aHasKey && bHasKey) ||
  210. !looseEqual(a[key], b[key])) {
  211. return false;
  212. }
  213. }
  214. }
  215. return String(a) === String(b);
  216. }
  217. function looseIndexOf(arr, val) {
  218. return arr.findIndex(item => looseEqual(item, val));
  219. }
  220. /**
  221. * For converting {{ interpolation }} values to displayed strings.
  222. * @private
  223. */
  224. const toDisplayString = (val) => {
  225. return val == null
  226. ? ''
  227. : isObject(val)
  228. ? JSON.stringify(val, replacer, 2)
  229. : String(val);
  230. };
  231. const replacer = (_key, val) => {
  232. if (isMap(val)) {
  233. return {
  234. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  235. entries[`${key} =>`] = val;
  236. return entries;
  237. }, {})
  238. };
  239. }
  240. else if (isSet(val)) {
  241. return {
  242. [`Set(${val.size})`]: [...val.values()]
  243. };
  244. }
  245. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  246. return String(val);
  247. }
  248. return val;
  249. };
  250. const EMPTY_OBJ = Object.freeze({})
  251. ;
  252. const EMPTY_ARR = Object.freeze([]) ;
  253. const NOOP = () => { };
  254. /**
  255. * Always return false.
  256. */
  257. const NO = () => false;
  258. const onRE = /^on[^a-z]/;
  259. const isOn = (key) => onRE.test(key);
  260. const isModelListener = (key) => key.startsWith('onUpdate:');
  261. const extend = Object.assign;
  262. const remove = (arr, el) => {
  263. const i = arr.indexOf(el);
  264. if (i > -1) {
  265. arr.splice(i, 1);
  266. }
  267. };
  268. const hasOwnProperty = Object.prototype.hasOwnProperty;
  269. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  270. const isArray = Array.isArray;
  271. const isMap = (val) => toTypeString(val) === '[object Map]';
  272. const isSet = (val) => toTypeString(val) === '[object Set]';
  273. const isDate = (val) => val instanceof Date;
  274. const isFunction = (val) => typeof val === 'function';
  275. const isString = (val) => typeof val === 'string';
  276. const isSymbol = (val) => typeof val === 'symbol';
  277. const isObject = (val) => val !== null && typeof val === 'object';
  278. const isPromise = (val) => {
  279. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  280. };
  281. const objectToString = Object.prototype.toString;
  282. const toTypeString = (value) => objectToString.call(value);
  283. const toRawType = (value) => {
  284. // extract "RawType" from strings like "[object RawType]"
  285. return toTypeString(value).slice(8, -1);
  286. };
  287. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  288. const isIntegerKey = (key) => isString(key) &&
  289. key !== 'NaN' &&
  290. key[0] !== '-' &&
  291. '' + parseInt(key, 10) === key;
  292. const isReservedProp = /*#__PURE__*/ makeMap(
  293. // the leading comma is intentional so empty string "" is also included
  294. ',key,ref,' +
  295. 'onVnodeBeforeMount,onVnodeMounted,' +
  296. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  297. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  298. const cacheStringFunction = (fn) => {
  299. const cache = Object.create(null);
  300. return ((str) => {
  301. const hit = cache[str];
  302. return hit || (cache[str] = fn(str));
  303. });
  304. };
  305. const camelizeRE = /-(\w)/g;
  306. /**
  307. * @private
  308. */
  309. const camelize = cacheStringFunction((str) => {
  310. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  311. });
  312. const hyphenateRE = /\B([A-Z])/g;
  313. /**
  314. * @private
  315. */
  316. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  317. /**
  318. * @private
  319. */
  320. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  321. /**
  322. * @private
  323. */
  324. const toHandlerKey = cacheStringFunction((str) => (str ? `on${capitalize(str)}` : ``));
  325. // compare whether a value has changed, accounting for NaN.
  326. const hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
  327. const invokeArrayFns = (fns, arg) => {
  328. for (let i = 0; i < fns.length; i++) {
  329. fns[i](arg);
  330. }
  331. };
  332. const def = (obj, key, value) => {
  333. Object.defineProperty(obj, key, {
  334. configurable: true,
  335. enumerable: false,
  336. value
  337. });
  338. };
  339. const toNumber = (val) => {
  340. const n = parseFloat(val);
  341. return isNaN(n) ? val : n;
  342. };
  343. let _globalThis;
  344. const getGlobalThis = () => {
  345. return (_globalThis ||
  346. (_globalThis =
  347. typeof globalThis !== 'undefined'
  348. ? globalThis
  349. : typeof self !== 'undefined'
  350. ? self
  351. : typeof window !== 'undefined'
  352. ? window
  353. : typeof global !== 'undefined'
  354. ? global
  355. : {}));
  356. };
  357. const targetMap = new WeakMap();
  358. const effectStack = [];
  359. let activeEffect;
  360. const ITERATE_KEY = Symbol('iterate' );
  361. const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' );
  362. function isEffect(fn) {
  363. return fn && fn._isEffect === true;
  364. }
  365. function effect(fn, options = EMPTY_OBJ) {
  366. if (isEffect(fn)) {
  367. fn = fn.raw;
  368. }
  369. const effect = createReactiveEffect(fn, options);
  370. if (!options.lazy) {
  371. effect();
  372. }
  373. return effect;
  374. }
  375. function stop(effect) {
  376. if (effect.active) {
  377. cleanup(effect);
  378. if (effect.options.onStop) {
  379. effect.options.onStop();
  380. }
  381. effect.active = false;
  382. }
  383. }
  384. let uid = 0;
  385. function createReactiveEffect(fn, options) {
  386. const effect = function reactiveEffect() {
  387. if (!effect.active) {
  388. return options.scheduler ? undefined : fn();
  389. }
  390. if (!effectStack.includes(effect)) {
  391. cleanup(effect);
  392. try {
  393. enableTracking();
  394. effectStack.push(effect);
  395. activeEffect = effect;
  396. return fn();
  397. }
  398. finally {
  399. effectStack.pop();
  400. resetTracking();
  401. activeEffect = effectStack[effectStack.length - 1];
  402. }
  403. }
  404. };
  405. effect.id = uid++;
  406. effect.allowRecurse = !!options.allowRecurse;
  407. effect._isEffect = true;
  408. effect.active = true;
  409. effect.raw = fn;
  410. effect.deps = [];
  411. effect.options = options;
  412. return effect;
  413. }
  414. function cleanup(effect) {
  415. const { deps } = effect;
  416. if (deps.length) {
  417. for (let i = 0; i < deps.length; i++) {
  418. deps[i].delete(effect);
  419. }
  420. deps.length = 0;
  421. }
  422. }
  423. let shouldTrack = true;
  424. const trackStack = [];
  425. function pauseTracking() {
  426. trackStack.push(shouldTrack);
  427. shouldTrack = false;
  428. }
  429. function enableTracking() {
  430. trackStack.push(shouldTrack);
  431. shouldTrack = true;
  432. }
  433. function resetTracking() {
  434. const last = trackStack.pop();
  435. shouldTrack = last === undefined ? true : last;
  436. }
  437. function track(target, type, key) {
  438. if (!shouldTrack || activeEffect === undefined) {
  439. return;
  440. }
  441. let depsMap = targetMap.get(target);
  442. if (!depsMap) {
  443. targetMap.set(target, (depsMap = new Map()));
  444. }
  445. let dep = depsMap.get(key);
  446. if (!dep) {
  447. depsMap.set(key, (dep = new Set()));
  448. }
  449. if (!dep.has(activeEffect)) {
  450. dep.add(activeEffect);
  451. activeEffect.deps.push(dep);
  452. if (activeEffect.options.onTrack) {
  453. activeEffect.options.onTrack({
  454. effect: activeEffect,
  455. target,
  456. type,
  457. key
  458. });
  459. }
  460. }
  461. }
  462. function trigger(target, type, key, newValue, oldValue, oldTarget) {
  463. const depsMap = targetMap.get(target);
  464. if (!depsMap) {
  465. // never been tracked
  466. return;
  467. }
  468. const effects = new Set();
  469. const add = (effectsToAdd) => {
  470. if (effectsToAdd) {
  471. effectsToAdd.forEach(effect => {
  472. if (effect !== activeEffect || effect.allowRecurse) {
  473. effects.add(effect);
  474. }
  475. });
  476. }
  477. };
  478. if (type === "clear" /* CLEAR */) {
  479. // collection being cleared
  480. // trigger all effects for target
  481. depsMap.forEach(add);
  482. }
  483. else if (key === 'length' && isArray(target)) {
  484. depsMap.forEach((dep, key) => {
  485. if (key === 'length' || key >= newValue) {
  486. add(dep);
  487. }
  488. });
  489. }
  490. else {
  491. // schedule runs for SET | ADD | DELETE
  492. if (key !== void 0) {
  493. add(depsMap.get(key));
  494. }
  495. // also run for iteration key on ADD | DELETE | Map.SET
  496. switch (type) {
  497. case "add" /* ADD */:
  498. if (!isArray(target)) {
  499. add(depsMap.get(ITERATE_KEY));
  500. if (isMap(target)) {
  501. add(depsMap.get(MAP_KEY_ITERATE_KEY));
  502. }
  503. }
  504. else if (isIntegerKey(key)) {
  505. // new index added to array -> length changes
  506. add(depsMap.get('length'));
  507. }
  508. break;
  509. case "delete" /* DELETE */:
  510. if (!isArray(target)) {
  511. add(depsMap.get(ITERATE_KEY));
  512. if (isMap(target)) {
  513. add(depsMap.get(MAP_KEY_ITERATE_KEY));
  514. }
  515. }
  516. break;
  517. case "set" /* SET */:
  518. if (isMap(target)) {
  519. add(depsMap.get(ITERATE_KEY));
  520. }
  521. break;
  522. }
  523. }
  524. const run = (effect) => {
  525. if (effect.options.onTrigger) {
  526. effect.options.onTrigger({
  527. effect,
  528. target,
  529. key,
  530. type,
  531. newValue,
  532. oldValue,
  533. oldTarget
  534. });
  535. }
  536. if (effect.options.scheduler) {
  537. effect.options.scheduler(effect);
  538. }
  539. else {
  540. effect();
  541. }
  542. };
  543. effects.forEach(run);
  544. }
  545. const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
  546. const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
  547. .map(key => Symbol[key])
  548. .filter(isSymbol));
  549. const get = /*#__PURE__*/ createGetter();
  550. const shallowGet = /*#__PURE__*/ createGetter(false, true);
  551. const readonlyGet = /*#__PURE__*/ createGetter(true);
  552. const shallowReadonlyGet = /*#__PURE__*/ createGetter(true, true);
  553. const arrayInstrumentations = {};
  554. ['includes', 'indexOf', 'lastIndexOf'].forEach(key => {
  555. const method = Array.prototype[key];
  556. arrayInstrumentations[key] = function (...args) {
  557. const arr = toRaw(this);
  558. for (let i = 0, l = this.length; i < l; i++) {
  559. track(arr, "get" /* GET */, i + '');
  560. }
  561. // we run the method using the original args first (which may be reactive)
  562. const res = method.apply(arr, args);
  563. if (res === -1 || res === false) {
  564. // if that didn't work, run it again using raw values.
  565. return method.apply(arr, args.map(toRaw));
  566. }
  567. else {
  568. return res;
  569. }
  570. };
  571. });
  572. ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(key => {
  573. const method = Array.prototype[key];
  574. arrayInstrumentations[key] = function (...args) {
  575. pauseTracking();
  576. const res = method.apply(this, args);
  577. resetTracking();
  578. return res;
  579. };
  580. });
  581. function createGetter(isReadonly = false, shallow = false) {
  582. return function get(target, key, receiver) {
  583. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  584. return !isReadonly;
  585. }
  586. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  587. return isReadonly;
  588. }
  589. else if (key === "__v_raw" /* RAW */ &&
  590. receiver === (isReadonly ? readonlyMap : reactiveMap).get(target)) {
  591. return target;
  592. }
  593. const targetIsArray = isArray(target);
  594. if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) {
  595. return Reflect.get(arrayInstrumentations, key, receiver);
  596. }
  597. const res = Reflect.get(target, key, receiver);
  598. if (isSymbol(key)
  599. ? builtInSymbols.has(key)
  600. : isNonTrackableKeys(key)) {
  601. return res;
  602. }
  603. if (!isReadonly) {
  604. track(target, "get" /* GET */, key);
  605. }
  606. if (shallow) {
  607. return res;
  608. }
  609. if (isRef(res)) {
  610. // ref unwrapping - does not apply for Array + integer key.
  611. const shouldUnwrap = !targetIsArray || !isIntegerKey(key);
  612. return shouldUnwrap ? res.value : res;
  613. }
  614. if (isObject(res)) {
  615. // Convert returned value into a proxy as well. we do the isObject check
  616. // here to avoid invalid value warning. Also need to lazy access readonly
  617. // and reactive here to avoid circular dependency.
  618. return isReadonly ? readonly(res) : reactive(res);
  619. }
  620. return res;
  621. };
  622. }
  623. const set = /*#__PURE__*/ createSetter();
  624. const shallowSet = /*#__PURE__*/ createSetter(true);
  625. function createSetter(shallow = false) {
  626. return function set(target, key, value, receiver) {
  627. const oldValue = target[key];
  628. if (!shallow) {
  629. value = toRaw(value);
  630. if (!isArray(target) && isRef(oldValue) && !isRef(value)) {
  631. oldValue.value = value;
  632. return true;
  633. }
  634. }
  635. const hadKey = isArray(target) && isIntegerKey(key)
  636. ? Number(key) < target.length
  637. : hasOwn(target, key);
  638. const result = Reflect.set(target, key, value, receiver);
  639. // don't trigger if target is something up in the prototype chain of original
  640. if (target === toRaw(receiver)) {
  641. if (!hadKey) {
  642. trigger(target, "add" /* ADD */, key, value);
  643. }
  644. else if (hasChanged(value, oldValue)) {
  645. trigger(target, "set" /* SET */, key, value, oldValue);
  646. }
  647. }
  648. return result;
  649. };
  650. }
  651. function deleteProperty(target, key) {
  652. const hadKey = hasOwn(target, key);
  653. const oldValue = target[key];
  654. const result = Reflect.deleteProperty(target, key);
  655. if (result && hadKey) {
  656. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  657. }
  658. return result;
  659. }
  660. function has(target, key) {
  661. const result = Reflect.has(target, key);
  662. if (!isSymbol(key) || !builtInSymbols.has(key)) {
  663. track(target, "has" /* HAS */, key);
  664. }
  665. return result;
  666. }
  667. function ownKeys(target) {
  668. track(target, "iterate" /* ITERATE */, isArray(target) ? 'length' : ITERATE_KEY);
  669. return Reflect.ownKeys(target);
  670. }
  671. const mutableHandlers = {
  672. get,
  673. set,
  674. deleteProperty,
  675. has,
  676. ownKeys
  677. };
  678. const readonlyHandlers = {
  679. get: readonlyGet,
  680. set(target, key) {
  681. {
  682. console.warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
  683. }
  684. return true;
  685. },
  686. deleteProperty(target, key) {
  687. {
  688. console.warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
  689. }
  690. return true;
  691. }
  692. };
  693. const shallowReactiveHandlers = extend({}, mutableHandlers, {
  694. get: shallowGet,
  695. set: shallowSet
  696. });
  697. // Props handlers are special in the sense that it should not unwrap top-level
  698. // refs (in order to allow refs to be explicitly passed down), but should
  699. // retain the reactivity of the normal readonly object.
  700. const shallowReadonlyHandlers = extend({}, readonlyHandlers, {
  701. get: shallowReadonlyGet
  702. });
  703. const toReactive = (value) => isObject(value) ? reactive(value) : value;
  704. const toReadonly = (value) => isObject(value) ? readonly(value) : value;
  705. const toShallow = (value) => value;
  706. const getProto = (v) => Reflect.getPrototypeOf(v);
  707. function get$1(target, key, isReadonly = false, isShallow = false) {
  708. // #1772: readonly(reactive(Map)) should return readonly + reactive version
  709. // of the value
  710. target = target["__v_raw" /* RAW */];
  711. const rawTarget = toRaw(target);
  712. const rawKey = toRaw(key);
  713. if (key !== rawKey) {
  714. !isReadonly && track(rawTarget, "get" /* GET */, key);
  715. }
  716. !isReadonly && track(rawTarget, "get" /* GET */, rawKey);
  717. const { has } = getProto(rawTarget);
  718. const wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive;
  719. if (has.call(rawTarget, key)) {
  720. return wrap(target.get(key));
  721. }
  722. else if (has.call(rawTarget, rawKey)) {
  723. return wrap(target.get(rawKey));
  724. }
  725. }
  726. function has$1(key, isReadonly = false) {
  727. const target = this["__v_raw" /* RAW */];
  728. const rawTarget = toRaw(target);
  729. const rawKey = toRaw(key);
  730. if (key !== rawKey) {
  731. !isReadonly && track(rawTarget, "has" /* HAS */, key);
  732. }
  733. !isReadonly && track(rawTarget, "has" /* HAS */, rawKey);
  734. return key === rawKey
  735. ? target.has(key)
  736. : target.has(key) || target.has(rawKey);
  737. }
  738. function size(target, isReadonly = false) {
  739. target = target["__v_raw" /* RAW */];
  740. !isReadonly && track(toRaw(target), "iterate" /* ITERATE */, ITERATE_KEY);
  741. return Reflect.get(target, 'size', target);
  742. }
  743. function add(value) {
  744. value = toRaw(value);
  745. const target = toRaw(this);
  746. const proto = getProto(target);
  747. const hadKey = proto.has.call(target, value);
  748. target.add(value);
  749. if (!hadKey) {
  750. trigger(target, "add" /* ADD */, value, value);
  751. }
  752. return this;
  753. }
  754. function set$1(key, value) {
  755. value = toRaw(value);
  756. const target = toRaw(this);
  757. const { has, get } = getProto(target);
  758. let hadKey = has.call(target, key);
  759. if (!hadKey) {
  760. key = toRaw(key);
  761. hadKey = has.call(target, key);
  762. }
  763. else {
  764. checkIdentityKeys(target, has, key);
  765. }
  766. const oldValue = get.call(target, key);
  767. target.set(key, value);
  768. if (!hadKey) {
  769. trigger(target, "add" /* ADD */, key, value);
  770. }
  771. else if (hasChanged(value, oldValue)) {
  772. trigger(target, "set" /* SET */, key, value, oldValue);
  773. }
  774. return this;
  775. }
  776. function deleteEntry(key) {
  777. const target = toRaw(this);
  778. const { has, get } = getProto(target);
  779. let hadKey = has.call(target, key);
  780. if (!hadKey) {
  781. key = toRaw(key);
  782. hadKey = has.call(target, key);
  783. }
  784. else {
  785. checkIdentityKeys(target, has, key);
  786. }
  787. const oldValue = get ? get.call(target, key) : undefined;
  788. // forward the operation before queueing reactions
  789. const result = target.delete(key);
  790. if (hadKey) {
  791. trigger(target, "delete" /* DELETE */, key, undefined, oldValue);
  792. }
  793. return result;
  794. }
  795. function clear() {
  796. const target = toRaw(this);
  797. const hadItems = target.size !== 0;
  798. const oldTarget = isMap(target)
  799. ? new Map(target)
  800. : new Set(target)
  801. ;
  802. // forward the operation before queueing reactions
  803. const result = target.clear();
  804. if (hadItems) {
  805. trigger(target, "clear" /* CLEAR */, undefined, undefined, oldTarget);
  806. }
  807. return result;
  808. }
  809. function createForEach(isReadonly, isShallow) {
  810. return function forEach(callback, thisArg) {
  811. const observed = this;
  812. const target = observed["__v_raw" /* RAW */];
  813. const rawTarget = toRaw(target);
  814. const wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive;
  815. !isReadonly && track(rawTarget, "iterate" /* ITERATE */, ITERATE_KEY);
  816. return target.forEach((value, key) => {
  817. // important: make sure the callback is
  818. // 1. invoked with the reactive map as `this` and 3rd arg
  819. // 2. the value received should be a corresponding reactive/readonly.
  820. return callback.call(thisArg, wrap(value), wrap(key), observed);
  821. });
  822. };
  823. }
  824. function createIterableMethod(method, isReadonly, isShallow) {
  825. return function (...args) {
  826. const target = this["__v_raw" /* RAW */];
  827. const rawTarget = toRaw(target);
  828. const targetIsMap = isMap(rawTarget);
  829. const isPair = method === 'entries' || (method === Symbol.iterator && targetIsMap);
  830. const isKeyOnly = method === 'keys' && targetIsMap;
  831. const innerIterator = target[method](...args);
  832. const wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive;
  833. !isReadonly &&
  834. track(rawTarget, "iterate" /* ITERATE */, isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
  835. // return a wrapped iterator which returns observed versions of the
  836. // values emitted from the real iterator
  837. return {
  838. // iterator protocol
  839. next() {
  840. const { value, done } = innerIterator.next();
  841. return done
  842. ? { value, done }
  843. : {
  844. value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
  845. done
  846. };
  847. },
  848. // iterable protocol
  849. [Symbol.iterator]() {
  850. return this;
  851. }
  852. };
  853. };
  854. }
  855. function createReadonlyMethod(type) {
  856. return function (...args) {
  857. {
  858. const key = args[0] ? `on key "${args[0]}" ` : ``;
  859. console.warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
  860. }
  861. return type === "delete" /* DELETE */ ? false : this;
  862. };
  863. }
  864. const mutableInstrumentations = {
  865. get(key) {
  866. return get$1(this, key);
  867. },
  868. get size() {
  869. return size(this);
  870. },
  871. has: has$1,
  872. add,
  873. set: set$1,
  874. delete: deleteEntry,
  875. clear,
  876. forEach: createForEach(false, false)
  877. };
  878. const shallowInstrumentations = {
  879. get(key) {
  880. return get$1(this, key, false, true);
  881. },
  882. get size() {
  883. return size(this);
  884. },
  885. has: has$1,
  886. add,
  887. set: set$1,
  888. delete: deleteEntry,
  889. clear,
  890. forEach: createForEach(false, true)
  891. };
  892. const readonlyInstrumentations = {
  893. get(key) {
  894. return get$1(this, key, true);
  895. },
  896. get size() {
  897. return size(this, true);
  898. },
  899. has(key) {
  900. return has$1.call(this, key, true);
  901. },
  902. add: createReadonlyMethod("add" /* ADD */),
  903. set: createReadonlyMethod("set" /* SET */),
  904. delete: createReadonlyMethod("delete" /* DELETE */),
  905. clear: createReadonlyMethod("clear" /* CLEAR */),
  906. forEach: createForEach(true, false)
  907. };
  908. const iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator];
  909. iteratorMethods.forEach(method => {
  910. mutableInstrumentations[method] = createIterableMethod(method, false, false);
  911. readonlyInstrumentations[method] = createIterableMethod(method, true, false);
  912. shallowInstrumentations[method] = createIterableMethod(method, false, true);
  913. });
  914. function createInstrumentationGetter(isReadonly, shallow) {
  915. const instrumentations = shallow
  916. ? shallowInstrumentations
  917. : isReadonly
  918. ? readonlyInstrumentations
  919. : mutableInstrumentations;
  920. return (target, key, receiver) => {
  921. if (key === "__v_isReactive" /* IS_REACTIVE */) {
  922. return !isReadonly;
  923. }
  924. else if (key === "__v_isReadonly" /* IS_READONLY */) {
  925. return isReadonly;
  926. }
  927. else if (key === "__v_raw" /* RAW */) {
  928. return target;
  929. }
  930. return Reflect.get(hasOwn(instrumentations, key) && key in target
  931. ? instrumentations
  932. : target, key, receiver);
  933. };
  934. }
  935. const mutableCollectionHandlers = {
  936. get: createInstrumentationGetter(false, false)
  937. };
  938. const shallowCollectionHandlers = {
  939. get: createInstrumentationGetter(false, true)
  940. };
  941. const readonlyCollectionHandlers = {
  942. get: createInstrumentationGetter(true, false)
  943. };
  944. function checkIdentityKeys(target, has, key) {
  945. const rawKey = toRaw(key);
  946. if (rawKey !== key && has.call(target, rawKey)) {
  947. const type = toRawType(target);
  948. console.warn(`Reactive ${type} contains both the raw and reactive ` +
  949. `versions of the same object${type === `Map` ? ` as keys` : ``}, ` +
  950. `which can lead to inconsistencies. ` +
  951. `Avoid differentiating between the raw and reactive versions ` +
  952. `of an object and only use the reactive version if possible.`);
  953. }
  954. }
  955. const reactiveMap = new WeakMap();
  956. const readonlyMap = new WeakMap();
  957. function targetTypeMap(rawType) {
  958. switch (rawType) {
  959. case 'Object':
  960. case 'Array':
  961. return 1 /* COMMON */;
  962. case 'Map':
  963. case 'Set':
  964. case 'WeakMap':
  965. case 'WeakSet':
  966. return 2 /* COLLECTION */;
  967. default:
  968. return 0 /* INVALID */;
  969. }
  970. }
  971. function getTargetType(value) {
  972. return value["__v_skip" /* SKIP */] || !Object.isExtensible(value)
  973. ? 0 /* INVALID */
  974. : targetTypeMap(toRawType(value));
  975. }
  976. function reactive(target) {
  977. // if trying to observe a readonly proxy, return the readonly version.
  978. if (target && target["__v_isReadonly" /* IS_READONLY */]) {
  979. return target;
  980. }
  981. return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers);
  982. }
  983. /**
  984. * Return a shallowly-reactive copy of the original object, where only the root
  985. * level properties are reactive. It also does not auto-unwrap refs (even at the
  986. * root level).
  987. */
  988. function shallowReactive(target) {
  989. return createReactiveObject(target, false, shallowReactiveHandlers, shallowCollectionHandlers);
  990. }
  991. /**
  992. * Creates a readonly copy of the original object. Note the returned copy is not
  993. * made reactive, but `readonly` can be called on an already reactive object.
  994. */
  995. function readonly(target) {
  996. return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers);
  997. }
  998. /**
  999. * Returns a reactive-copy of the original object, where only the root level
  1000. * properties are readonly, and does NOT unwrap refs nor recursively convert
  1001. * returned properties.
  1002. * This is used for creating the props proxy object for stateful components.
  1003. */
  1004. function shallowReadonly(target) {
  1005. return createReactiveObject(target, true, shallowReadonlyHandlers, readonlyCollectionHandlers);
  1006. }
  1007. function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers) {
  1008. if (!isObject(target)) {
  1009. {
  1010. console.warn(`value cannot be made reactive: ${String(target)}`);
  1011. }
  1012. return target;
  1013. }
  1014. // target is already a Proxy, return it.
  1015. // exception: calling readonly() on a reactive object
  1016. if (target["__v_raw" /* RAW */] &&
  1017. !(isReadonly && target["__v_isReactive" /* IS_REACTIVE */])) {
  1018. return target;
  1019. }
  1020. // target already has corresponding Proxy
  1021. const proxyMap = isReadonly ? readonlyMap : reactiveMap;
  1022. const existingProxy = proxyMap.get(target);
  1023. if (existingProxy) {
  1024. return existingProxy;
  1025. }
  1026. // only a whitelist of value types can be observed.
  1027. const targetType = getTargetType(target);
  1028. if (targetType === 0 /* INVALID */) {
  1029. return target;
  1030. }
  1031. const proxy = new Proxy(target, targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers);
  1032. proxyMap.set(target, proxy);
  1033. return proxy;
  1034. }
  1035. function isReactive(value) {
  1036. if (isReadonly(value)) {
  1037. return isReactive(value["__v_raw" /* RAW */]);
  1038. }
  1039. return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
  1040. }
  1041. function isReadonly(value) {
  1042. return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
  1043. }
  1044. function isProxy(value) {
  1045. return isReactive(value) || isReadonly(value);
  1046. }
  1047. function toRaw(observed) {
  1048. return ((observed && toRaw(observed["__v_raw" /* RAW */])) || observed);
  1049. }
  1050. function markRaw(value) {
  1051. def(value, "__v_skip" /* SKIP */, true);
  1052. return value;
  1053. }
  1054. const convert = (val) => isObject(val) ? reactive(val) : val;
  1055. function isRef(r) {
  1056. return Boolean(r && r.__v_isRef === true);
  1057. }
  1058. function ref(value) {
  1059. return createRef(value);
  1060. }
  1061. function shallowRef(value) {
  1062. return createRef(value, true);
  1063. }
  1064. class RefImpl {
  1065. constructor(_rawValue, _shallow = false) {
  1066. this._rawValue = _rawValue;
  1067. this._shallow = _shallow;
  1068. this.__v_isRef = true;
  1069. this._value = _shallow ? _rawValue : convert(_rawValue);
  1070. }
  1071. get value() {
  1072. track(toRaw(this), "get" /* GET */, 'value');
  1073. return this._value;
  1074. }
  1075. set value(newVal) {
  1076. if (hasChanged(toRaw(newVal), this._rawValue)) {
  1077. this._rawValue = newVal;
  1078. this._value = this._shallow ? newVal : convert(newVal);
  1079. trigger(toRaw(this), "set" /* SET */, 'value', newVal);
  1080. }
  1081. }
  1082. }
  1083. function createRef(rawValue, shallow = false) {
  1084. if (isRef(rawValue)) {
  1085. return rawValue;
  1086. }
  1087. return new RefImpl(rawValue, shallow);
  1088. }
  1089. function triggerRef(ref) {
  1090. trigger(toRaw(ref), "set" /* SET */, 'value', ref.value );
  1091. }
  1092. function unref(ref) {
  1093. return isRef(ref) ? ref.value : ref;
  1094. }
  1095. const shallowUnwrapHandlers = {
  1096. get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
  1097. set: (target, key, value, receiver) => {
  1098. const oldValue = target[key];
  1099. if (isRef(oldValue) && !isRef(value)) {
  1100. oldValue.value = value;
  1101. return true;
  1102. }
  1103. else {
  1104. return Reflect.set(target, key, value, receiver);
  1105. }
  1106. }
  1107. };
  1108. function proxyRefs(objectWithRefs) {
  1109. return isReactive(objectWithRefs)
  1110. ? objectWithRefs
  1111. : new Proxy(objectWithRefs, shallowUnwrapHandlers);
  1112. }
  1113. class CustomRefImpl {
  1114. constructor(factory) {
  1115. this.__v_isRef = true;
  1116. const { get, set } = factory(() => track(this, "get" /* GET */, 'value'), () => trigger(this, "set" /* SET */, 'value'));
  1117. this._get = get;
  1118. this._set = set;
  1119. }
  1120. get value() {
  1121. return this._get();
  1122. }
  1123. set value(newVal) {
  1124. this._set(newVal);
  1125. }
  1126. }
  1127. function customRef(factory) {
  1128. return new CustomRefImpl(factory);
  1129. }
  1130. function toRefs(object) {
  1131. if (!isProxy(object)) {
  1132. console.warn(`toRefs() expects a reactive object but received a plain one.`);
  1133. }
  1134. const ret = isArray(object) ? new Array(object.length) : {};
  1135. for (const key in object) {
  1136. ret[key] = toRef(object, key);
  1137. }
  1138. return ret;
  1139. }
  1140. class ObjectRefImpl {
  1141. constructor(_object, _key) {
  1142. this._object = _object;
  1143. this._key = _key;
  1144. this.__v_isRef = true;
  1145. }
  1146. get value() {
  1147. return this._object[this._key];
  1148. }
  1149. set value(newVal) {
  1150. this._object[this._key] = newVal;
  1151. }
  1152. }
  1153. function toRef(object, key) {
  1154. return isRef(object[key])
  1155. ? object[key]
  1156. : new ObjectRefImpl(object, key);
  1157. }
  1158. class ComputedRefImpl {
  1159. constructor(getter, _setter, isReadonly) {
  1160. this._setter = _setter;
  1161. this._dirty = true;
  1162. this.__v_isRef = true;
  1163. this.effect = effect(getter, {
  1164. lazy: true,
  1165. scheduler: () => {
  1166. if (!this._dirty) {
  1167. this._dirty = true;
  1168. trigger(toRaw(this), "set" /* SET */, 'value');
  1169. }
  1170. }
  1171. });
  1172. this["__v_isReadonly" /* IS_READONLY */] = isReadonly;
  1173. }
  1174. get value() {
  1175. if (this._dirty) {
  1176. this._value = this.effect();
  1177. this._dirty = false;
  1178. }
  1179. track(toRaw(this), "get" /* GET */, 'value');
  1180. return this._value;
  1181. }
  1182. set value(newValue) {
  1183. this._setter(newValue);
  1184. }
  1185. }
  1186. function computed(getterOrOptions) {
  1187. let getter;
  1188. let setter;
  1189. if (isFunction(getterOrOptions)) {
  1190. getter = getterOrOptions;
  1191. setter = () => {
  1192. console.warn('Write operation failed: computed value is readonly');
  1193. }
  1194. ;
  1195. }
  1196. else {
  1197. getter = getterOrOptions.get;
  1198. setter = getterOrOptions.set;
  1199. }
  1200. return new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set);
  1201. }
  1202. const stack = [];
  1203. function pushWarningContext(vnode) {
  1204. stack.push(vnode);
  1205. }
  1206. function popWarningContext() {
  1207. stack.pop();
  1208. }
  1209. function warn(msg, ...args) {
  1210. // avoid props formatting or warn handler tracking deps that might be mutated
  1211. // during patch, leading to infinite recursion.
  1212. pauseTracking();
  1213. const instance = stack.length ? stack[stack.length - 1].component : null;
  1214. const appWarnHandler = instance && instance.appContext.config.warnHandler;
  1215. const trace = getComponentTrace();
  1216. if (appWarnHandler) {
  1217. callWithErrorHandling(appWarnHandler, instance, 11 /* APP_WARN_HANDLER */, [
  1218. msg + args.join(''),
  1219. instance && instance.proxy,
  1220. trace
  1221. .map(({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`)
  1222. .join('\n'),
  1223. trace
  1224. ]);
  1225. }
  1226. else {
  1227. const warnArgs = [`[Vue warn]: ${msg}`, ...args];
  1228. /* istanbul ignore if */
  1229. if (trace.length &&
  1230. // avoid spamming console during tests
  1231. !false) {
  1232. warnArgs.push(`\n`, ...formatTrace(trace));
  1233. }
  1234. console.warn(...warnArgs);
  1235. }
  1236. resetTracking();
  1237. }
  1238. function getComponentTrace() {
  1239. let currentVNode = stack[stack.length - 1];
  1240. if (!currentVNode) {
  1241. return [];
  1242. }
  1243. // we can't just use the stack because it will be incomplete during updates
  1244. // that did not start from the root. Re-construct the parent chain using
  1245. // instance parent pointers.
  1246. const normalizedStack = [];
  1247. while (currentVNode) {
  1248. const last = normalizedStack[0];
  1249. if (last && last.vnode === currentVNode) {
  1250. last.recurseCount++;
  1251. }
  1252. else {
  1253. normalizedStack.push({
  1254. vnode: currentVNode,
  1255. recurseCount: 0
  1256. });
  1257. }
  1258. const parentInstance = currentVNode.component && currentVNode.component.parent;
  1259. currentVNode = parentInstance && parentInstance.vnode;
  1260. }
  1261. return normalizedStack;
  1262. }
  1263. /* istanbul ignore next */
  1264. function formatTrace(trace) {
  1265. const logs = [];
  1266. trace.forEach((entry, i) => {
  1267. logs.push(...(i === 0 ? [] : [`\n`]), ...formatTraceEntry(entry));
  1268. });
  1269. return logs;
  1270. }
  1271. function formatTraceEntry({ vnode, recurseCount }) {
  1272. const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
  1273. const isRoot = vnode.component ? vnode.component.parent == null : false;
  1274. const open = ` at <${formatComponentName(vnode.component, vnode.type, isRoot)}`;
  1275. const close = `>` + postfix;
  1276. return vnode.props
  1277. ? [open, ...formatProps(vnode.props), close]
  1278. : [open + close];
  1279. }
  1280. /* istanbul ignore next */
  1281. function formatProps(props) {
  1282. const res = [];
  1283. const keys = Object.keys(props);
  1284. keys.slice(0, 3).forEach(key => {
  1285. res.push(...formatProp(key, props[key]));
  1286. });
  1287. if (keys.length > 3) {
  1288. res.push(` ...`);
  1289. }
  1290. return res;
  1291. }
  1292. /* istanbul ignore next */
  1293. function formatProp(key, value, raw) {
  1294. if (isString(value)) {
  1295. value = JSON.stringify(value);
  1296. return raw ? value : [`${key}=${value}`];
  1297. }
  1298. else if (typeof value === 'number' ||
  1299. typeof value === 'boolean' ||
  1300. value == null) {
  1301. return raw ? value : [`${key}=${value}`];
  1302. }
  1303. else if (isRef(value)) {
  1304. value = formatProp(key, toRaw(value.value), true);
  1305. return raw ? value : [`${key}=Ref<`, value, `>`];
  1306. }
  1307. else if (isFunction(value)) {
  1308. return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
  1309. }
  1310. else {
  1311. value = toRaw(value);
  1312. return raw ? value : [`${key}=`, value];
  1313. }
  1314. }
  1315. const ErrorTypeStrings = {
  1316. ["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
  1317. ["c" /* CREATED */]: 'created hook',
  1318. ["bm" /* BEFORE_MOUNT */]: 'beforeMount hook',
  1319. ["m" /* MOUNTED */]: 'mounted hook',
  1320. ["bu" /* BEFORE_UPDATE */]: 'beforeUpdate hook',
  1321. ["u" /* UPDATED */]: 'updated',
  1322. ["bum" /* BEFORE_UNMOUNT */]: 'beforeUnmount hook',
  1323. ["um" /* UNMOUNTED */]: 'unmounted hook',
  1324. ["a" /* ACTIVATED */]: 'activated hook',
  1325. ["da" /* DEACTIVATED */]: 'deactivated hook',
  1326. ["ec" /* ERROR_CAPTURED */]: 'errorCaptured hook',
  1327. ["rtc" /* RENDER_TRACKED */]: 'renderTracked hook',
  1328. ["rtg" /* RENDER_TRIGGERED */]: 'renderTriggered hook',
  1329. [0 /* SETUP_FUNCTION */]: 'setup function',
  1330. [1 /* RENDER_FUNCTION */]: 'render function',
  1331. [2 /* WATCH_GETTER */]: 'watcher getter',
  1332. [3 /* WATCH_CALLBACK */]: 'watcher callback',
  1333. [4 /* WATCH_CLEANUP */]: 'watcher cleanup function',
  1334. [5 /* NATIVE_EVENT_HANDLER */]: 'native event handler',
  1335. [6 /* COMPONENT_EVENT_HANDLER */]: 'component event handler',
  1336. [7 /* VNODE_HOOK */]: 'vnode hook',
  1337. [8 /* DIRECTIVE_HOOK */]: 'directive hook',
  1338. [9 /* TRANSITION_HOOK */]: 'transition hook',
  1339. [10 /* APP_ERROR_HANDLER */]: 'app errorHandler',
  1340. [11 /* APP_WARN_HANDLER */]: 'app warnHandler',
  1341. [12 /* FUNCTION_REF */]: 'ref function',
  1342. [13 /* ASYNC_COMPONENT_LOADER */]: 'async component loader',
  1343. [14 /* SCHEDULER */]: 'scheduler flush. This is likely a Vue internals bug. ' +
  1344. 'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue-next'
  1345. };
  1346. function callWithErrorHandling(fn, instance, type, args) {
  1347. let res;
  1348. try {
  1349. res = args ? fn(...args) : fn();
  1350. }
  1351. catch (err) {
  1352. handleError(err, instance, type);
  1353. }
  1354. return res;
  1355. }
  1356. function callWithAsyncErrorHandling(fn, instance, type, args) {
  1357. if (isFunction(fn)) {
  1358. const res = callWithErrorHandling(fn, instance, type, args);
  1359. if (res && isPromise(res)) {
  1360. res.catch(err => {
  1361. handleError(err, instance, type);
  1362. });
  1363. }
  1364. return res;
  1365. }
  1366. const values = [];
  1367. for (let i = 0; i < fn.length; i++) {
  1368. values.push(callWithAsyncErrorHandling(fn[i], instance, type, args));
  1369. }
  1370. return values;
  1371. }
  1372. function handleError(err, instance, type, throwInDev = true) {
  1373. const contextVNode = instance ? instance.vnode : null;
  1374. if (instance) {
  1375. let cur = instance.parent;
  1376. // the exposed instance is the render proxy to keep it consistent with 2.x
  1377. const exposedInstance = instance.proxy;
  1378. // in production the hook receives only the error code
  1379. const errorInfo = ErrorTypeStrings[type] ;
  1380. while (cur) {
  1381. const errorCapturedHooks = cur.ec;
  1382. if (errorCapturedHooks) {
  1383. for (let i = 0; i < errorCapturedHooks.length; i++) {
  1384. if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
  1385. return;
  1386. }
  1387. }
  1388. }
  1389. cur = cur.parent;
  1390. }
  1391. // app-level handling
  1392. const appErrorHandler = instance.appContext.config.errorHandler;
  1393. if (appErrorHandler) {
  1394. callWithErrorHandling(appErrorHandler, null, 10 /* APP_ERROR_HANDLER */, [err, exposedInstance, errorInfo]);
  1395. return;
  1396. }
  1397. }
  1398. logError(err, type, contextVNode, throwInDev);
  1399. }
  1400. function logError(err, type, contextVNode, throwInDev = true) {
  1401. {
  1402. const info = ErrorTypeStrings[type];
  1403. if (contextVNode) {
  1404. pushWarningContext(contextVNode);
  1405. }
  1406. warn(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
  1407. if (contextVNode) {
  1408. popWarningContext();
  1409. }
  1410. // crash in dev by default so it's more noticeable
  1411. if (throwInDev) {
  1412. throw err;
  1413. }
  1414. else {
  1415. console.error(err);
  1416. }
  1417. }
  1418. }
  1419. let isFlushing = false;
  1420. let isFlushPending = false;
  1421. const queue = [];
  1422. let flushIndex = 0;
  1423. const pendingPreFlushCbs = [];
  1424. let activePreFlushCbs = null;
  1425. let preFlushIndex = 0;
  1426. const pendingPostFlushCbs = [];
  1427. let activePostFlushCbs = null;
  1428. let postFlushIndex = 0;
  1429. const resolvedPromise = Promise.resolve();
  1430. let currentFlushPromise = null;
  1431. let currentPreFlushParentJob = null;
  1432. const RECURSION_LIMIT = 100;
  1433. function nextTick(fn) {
  1434. const p = currentFlushPromise || resolvedPromise;
  1435. return fn ? p.then(this ? fn.bind(this) : fn) : p;
  1436. }
  1437. function queueJob(job) {
  1438. // the dedupe search uses the startIndex argument of Array.includes()
  1439. // by default the search index includes the current job that is being run
  1440. // so it cannot recursively trigger itself again.
  1441. // if the job is a watch() callback, the search will start with a +1 index to
  1442. // allow it recursively trigger itself - it is the user's responsibility to
  1443. // ensure it doesn't end up in an infinite loop.
  1444. if ((!queue.length ||
  1445. !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
  1446. job !== currentPreFlushParentJob) {
  1447. queue.push(job);
  1448. queueFlush();
  1449. }
  1450. }
  1451. function queueFlush() {
  1452. if (!isFlushing && !isFlushPending) {
  1453. isFlushPending = true;
  1454. currentFlushPromise = resolvedPromise.then(flushJobs);
  1455. }
  1456. }
  1457. function invalidateJob(job) {
  1458. const i = queue.indexOf(job);
  1459. if (i > -1) {
  1460. queue.splice(i, 1);
  1461. }
  1462. }
  1463. function queueCb(cb, activeQueue, pendingQueue, index) {
  1464. if (!isArray(cb)) {
  1465. if (!activeQueue ||
  1466. !activeQueue.includes(cb, cb.allowRecurse ? index + 1 : index)) {
  1467. pendingQueue.push(cb);
  1468. }
  1469. }
  1470. else {
  1471. // if cb is an array, it is a component lifecycle hook which can only be
  1472. // triggered by a job, which is already deduped in the main queue, so
  1473. // we can skip duplicate check here to improve perf
  1474. pendingQueue.push(...cb);
  1475. }
  1476. queueFlush();
  1477. }
  1478. function queuePreFlushCb(cb) {
  1479. queueCb(cb, activePreFlushCbs, pendingPreFlushCbs, preFlushIndex);
  1480. }
  1481. function queuePostFlushCb(cb) {
  1482. queueCb(cb, activePostFlushCbs, pendingPostFlushCbs, postFlushIndex);
  1483. }
  1484. function flushPreFlushCbs(seen, parentJob = null) {
  1485. if (pendingPreFlushCbs.length) {
  1486. currentPreFlushParentJob = parentJob;
  1487. activePreFlushCbs = [...new Set(pendingPreFlushCbs)];
  1488. pendingPreFlushCbs.length = 0;
  1489. {
  1490. seen = seen || new Map();
  1491. }
  1492. for (preFlushIndex = 0; preFlushIndex < activePreFlushCbs.length; preFlushIndex++) {
  1493. {
  1494. checkRecursiveUpdates(seen, activePreFlushCbs[preFlushIndex]);
  1495. }
  1496. activePreFlushCbs[preFlushIndex]();
  1497. }
  1498. activePreFlushCbs = null;
  1499. preFlushIndex = 0;
  1500. currentPreFlushParentJob = null;
  1501. // recursively flush until it drains
  1502. flushPreFlushCbs(seen, parentJob);
  1503. }
  1504. }
  1505. function flushPostFlushCbs(seen) {
  1506. if (pendingPostFlushCbs.length) {
  1507. const deduped = [...new Set(pendingPostFlushCbs)];
  1508. pendingPostFlushCbs.length = 0;
  1509. // #1947 already has active queue, nested flushPostFlushCbs call
  1510. if (activePostFlushCbs) {
  1511. activePostFlushCbs.push(...deduped);
  1512. return;
  1513. }
  1514. activePostFlushCbs = deduped;
  1515. {
  1516. seen = seen || new Map();
  1517. }
  1518. activePostFlushCbs.sort((a, b) => getId(a) - getId(b));
  1519. for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
  1520. {
  1521. checkRecursiveUpdates(seen, activePostFlushCbs[postFlushIndex]);
  1522. }
  1523. activePostFlushCbs[postFlushIndex]();
  1524. }
  1525. activePostFlushCbs = null;
  1526. postFlushIndex = 0;
  1527. }
  1528. }
  1529. const getId = (job) => job.id == null ? Infinity : job.id;
  1530. function flushJobs(seen) {
  1531. isFlushPending = false;
  1532. isFlushing = true;
  1533. {
  1534. seen = seen || new Map();
  1535. }
  1536. flushPreFlushCbs(seen);
  1537. // Sort queue before flush.
  1538. // This ensures that:
  1539. // 1. Components are updated from parent to child. (because parent is always
  1540. // created before the child so its render effect will have smaller
  1541. // priority number)
  1542. // 2. If a component is unmounted during a parent component's update,
  1543. // its update can be skipped.
  1544. queue.sort((a, b) => getId(a) - getId(b));
  1545. try {
  1546. for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
  1547. const job = queue[flushIndex];
  1548. if (job) {
  1549. if (true) {
  1550. checkRecursiveUpdates(seen, job);
  1551. }
  1552. callWithErrorHandling(job, null, 14 /* SCHEDULER */);
  1553. }
  1554. }
  1555. }
  1556. finally {
  1557. flushIndex = 0;
  1558. queue.length = 0;
  1559. flushPostFlushCbs(seen);
  1560. isFlushing = false;
  1561. currentFlushPromise = null;
  1562. // some postFlushCb queued jobs!
  1563. // keep flushing until it drains.
  1564. if (queue.length || pendingPostFlushCbs.length) {
  1565. flushJobs(seen);
  1566. }
  1567. }
  1568. }
  1569. function checkRecursiveUpdates(seen, fn) {
  1570. if (!seen.has(fn)) {
  1571. seen.set(fn, 1);
  1572. }
  1573. else {
  1574. const count = seen.get(fn);
  1575. if (count > RECURSION_LIMIT) {
  1576. throw new Error(`Maximum recursive updates exceeded. ` +
  1577. `This means you have a reactive effect that is mutating its own ` +
  1578. `dependencies and thus recursively triggering itself. Possible sources ` +
  1579. `include component template, render function, updated hook or ` +
  1580. `watcher source function.`);
  1581. }
  1582. else {
  1583. seen.set(fn, count + 1);
  1584. }
  1585. }
  1586. }
  1587. /* eslint-disable no-restricted-globals */
  1588. let isHmrUpdating = false;
  1589. const hmrDirtyComponents = new Set();
  1590. // Expose the HMR runtime on the global object
  1591. // This makes it entirely tree-shakable without polluting the exports and makes
  1592. // it easier to be used in toolings like vue-loader
  1593. // Note: for a component to be eligible for HMR it also needs the __hmrId option
  1594. // to be set so that its instances can be registered / removed.
  1595. {
  1596. const globalObject = typeof global !== 'undefined'
  1597. ? global
  1598. : typeof self !== 'undefined'
  1599. ? self
  1600. : typeof window !== 'undefined'
  1601. ? window
  1602. : {};
  1603. globalObject.__VUE_HMR_RUNTIME__ = {
  1604. createRecord: tryWrap(createRecord),
  1605. rerender: tryWrap(rerender),
  1606. reload: tryWrap(reload)
  1607. };
  1608. }
  1609. const map = new Map();
  1610. function registerHMR(instance) {
  1611. const id = instance.type.__hmrId;
  1612. let record = map.get(id);
  1613. if (!record) {
  1614. createRecord(id, instance.type);
  1615. record = map.get(id);
  1616. }
  1617. record.instances.add(instance);
  1618. }
  1619. function unregisterHMR(instance) {
  1620. map.get(instance.type.__hmrId).instances.delete(instance);
  1621. }
  1622. function createRecord(id, component) {
  1623. if (!component) {
  1624. warn(`HMR API usage is out of date.\n` +
  1625. `Please upgrade vue-loader/vite/rollup-plugin-vue or other relevant ` +
  1626. `dependency that handles Vue SFC compilation.`);
  1627. component = {};
  1628. }
  1629. if (map.has(id)) {
  1630. return false;
  1631. }
  1632. map.set(id, {
  1633. component: isClassComponent(component) ? component.__vccOpts : component,
  1634. instances: new Set()
  1635. });
  1636. return true;
  1637. }
  1638. function rerender(id, newRender) {
  1639. const record = map.get(id);
  1640. if (!record)
  1641. return;
  1642. if (newRender)
  1643. record.component.render = newRender;
  1644. // Array.from creates a snapshot which avoids the set being mutated during
  1645. // updates
  1646. Array.from(record.instances).forEach(instance => {
  1647. if (newRender) {
  1648. instance.render = newRender;
  1649. }
  1650. instance.renderCache = [];
  1651. // this flag forces child components with slot content to update
  1652. isHmrUpdating = true;
  1653. instance.update();
  1654. isHmrUpdating = false;
  1655. });
  1656. }
  1657. function reload(id, newComp) {
  1658. const record = map.get(id);
  1659. if (!record)
  1660. return;
  1661. // Array.from creates a snapshot which avoids the set being mutated during
  1662. // updates
  1663. const { component, instances } = record;
  1664. if (!hmrDirtyComponents.has(component)) {
  1665. // 1. Update existing comp definition to match new one
  1666. newComp = isClassComponent(newComp) ? newComp.__vccOpts : newComp;
  1667. extend(component, newComp);
  1668. for (const key in component) {
  1669. if (!(key in newComp)) {
  1670. delete component[key];
  1671. }
  1672. }
  1673. // 2. Mark component dirty. This forces the renderer to replace the component
  1674. // on patch.
  1675. hmrDirtyComponents.add(component);
  1676. // 3. Make sure to unmark the component after the reload.
  1677. queuePostFlushCb(() => {
  1678. hmrDirtyComponents.delete(component);
  1679. });
  1680. }
  1681. Array.from(instances).forEach(instance => {
  1682. if (instance.parent) {
  1683. // 4. Force the parent instance to re-render. This will cause all updated
  1684. // components to be unmounted and re-mounted. Queue the update so that we
  1685. // don't end up forcing the same parent to re-render multiple times.
  1686. queueJob(instance.parent.update);
  1687. }
  1688. else if (instance.appContext.reload) {
  1689. // root instance mounted via createApp() has a reload method
  1690. instance.appContext.reload();
  1691. }
  1692. else if (typeof window !== 'undefined') {
  1693. // root instance inside tree created via raw render(). Force reload.
  1694. window.location.reload();
  1695. }
  1696. else {
  1697. console.warn('[HMR] Root or manually mounted instance modified. Full reload required.');
  1698. }
  1699. });
  1700. }
  1701. function tryWrap(fn) {
  1702. return (id, arg) => {
  1703. try {
  1704. return fn(id, arg);
  1705. }
  1706. catch (e) {
  1707. console.error(e);
  1708. console.warn(`[HMR] Something went wrong during Vue component hot-reload. ` +
  1709. `Full reload required.`);
  1710. }
  1711. };
  1712. }
  1713. let devtools;
  1714. function setDevtoolsHook(hook) {
  1715. devtools = hook;
  1716. }
  1717. function devtoolsInitApp(app, version) {
  1718. // TODO queue if devtools is undefined
  1719. if (!devtools)
  1720. return;
  1721. devtools.emit("app:init" /* APP_INIT */, app, version, {
  1722. Fragment,
  1723. Text,
  1724. Comment,
  1725. Static
  1726. });
  1727. }
  1728. function devtoolsUnmountApp(app) {
  1729. if (!devtools)
  1730. return;
  1731. devtools.emit("app:unmount" /* APP_UNMOUNT */, app);
  1732. }
  1733. const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook("component:added" /* COMPONENT_ADDED */);
  1734. const devtoolsComponentUpdated = /*#__PURE__*/ createDevtoolsComponentHook("component:updated" /* COMPONENT_UPDATED */);
  1735. const devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook("component:removed" /* COMPONENT_REMOVED */);
  1736. function createDevtoolsComponentHook(hook) {
  1737. return (component) => {
  1738. if (!devtools)
  1739. return;
  1740. devtools.emit(hook, component.appContext.app, component.uid, component.parent ? component.parent.uid : undefined, component);
  1741. };
  1742. }
  1743. function devtoolsComponentEmit(component, event, params) {
  1744. if (!devtools)
  1745. return;
  1746. devtools.emit("component:emit" /* COMPONENT_EMIT */, component.appContext.app, component, event, params);
  1747. }
  1748. function emit(instance, event, ...rawArgs) {
  1749. const props = instance.vnode.props || EMPTY_OBJ;
  1750. {
  1751. const { emitsOptions, propsOptions: [propsOptions] } = instance;
  1752. if (emitsOptions) {
  1753. if (!(event in emitsOptions)) {
  1754. if (!propsOptions || !(toHandlerKey(event) in propsOptions)) {
  1755. warn(`Component emitted event "${event}" but it is neither declared in ` +
  1756. `the emits option nor as an "${toHandlerKey(event)}" prop.`);
  1757. }
  1758. }
  1759. else {
  1760. const validator = emitsOptions[event];
  1761. if (isFunction(validator)) {
  1762. const isValid = validator(...rawArgs);
  1763. if (!isValid) {
  1764. warn(`Invalid event arguments: event validation failed for event "${event}".`);
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. let args = rawArgs;
  1771. const isModelListener = event.startsWith('update:');
  1772. // for v-model update:xxx events, apply modifiers on args
  1773. const modelArg = isModelListener && event.slice(7);
  1774. if (modelArg && modelArg in props) {
  1775. const modifiersKey = `${modelArg === 'modelValue' ? 'model' : modelArg}Modifiers`;
  1776. const { number, trim } = props[modifiersKey] || EMPTY_OBJ;
  1777. if (trim) {
  1778. args = rawArgs.map(a => a.trim());
  1779. }
  1780. else if (number) {
  1781. args = rawArgs.map(toNumber);
  1782. }
  1783. }
  1784. {
  1785. devtoolsComponentEmit(instance, event, args);
  1786. }
  1787. {
  1788. const lowerCaseEvent = event.toLowerCase();
  1789. if (lowerCaseEvent !== event && props[toHandlerKey(lowerCaseEvent)]) {
  1790. warn(`Event "${lowerCaseEvent}" is emitted in component ` +
  1791. `${formatComponentName(instance, instance.type)} but the handler is registered for "${event}". ` +
  1792. `Note that HTML attributes are case-insensitive and you cannot use ` +
  1793. `v-on to listen to camelCase events when using in-DOM templates. ` +
  1794. `You should probably use "${hyphenate(event)}" instead of "${event}".`);
  1795. }
  1796. }
  1797. // convert handler name to camelCase. See issue #2249
  1798. let handlerName = toHandlerKey(camelize(event));
  1799. let handler = props[handlerName];
  1800. // for v-model update:xxx events, also trigger kebab-case equivalent
  1801. // for props passed via kebab-case
  1802. if (!handler && isModelListener) {
  1803. handlerName = toHandlerKey(hyphenate(event));
  1804. handler = props[handlerName];
  1805. }
  1806. if (handler) {
  1807. callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  1808. }
  1809. const onceHandler = props[handlerName + `Once`];
  1810. if (onceHandler) {
  1811. if (!instance.emitted) {
  1812. (instance.emitted = {})[handlerName] = true;
  1813. }
  1814. else if (instance.emitted[handlerName]) {
  1815. return;
  1816. }
  1817. callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args);
  1818. }
  1819. }
  1820. function normalizeEmitsOptions(comp, appContext, asMixin = false) {
  1821. if (!appContext.deopt && comp.__emits !== undefined) {
  1822. return comp.__emits;
  1823. }
  1824. const raw = comp.emits;
  1825. let normalized = {};
  1826. // apply mixin/extends props
  1827. let hasExtends = false;
  1828. if (!isFunction(comp)) {
  1829. const extendEmits = (raw) => {
  1830. hasExtends = true;
  1831. extend(normalized, normalizeEmitsOptions(raw, appContext, true));
  1832. };
  1833. if (!asMixin && appContext.mixins.length) {
  1834. appContext.mixins.forEach(extendEmits);
  1835. }
  1836. if (comp.extends) {
  1837. extendEmits(comp.extends);
  1838. }
  1839. if (comp.mixins) {
  1840. comp.mixins.forEach(extendEmits);
  1841. }
  1842. }
  1843. if (!raw && !hasExtends) {
  1844. return (comp.__emits = null);
  1845. }
  1846. if (isArray(raw)) {
  1847. raw.forEach(key => (normalized[key] = null));
  1848. }
  1849. else {
  1850. extend(normalized, raw);
  1851. }
  1852. return (comp.__emits = normalized);
  1853. }
  1854. // Check if an incoming prop key is a declared emit event listener.
  1855. // e.g. With `emits: { click: null }`, props named `onClick` and `onclick` are
  1856. // both considered matched listeners.
  1857. function isEmitListener(options, key) {
  1858. if (!options || !isOn(key)) {
  1859. return false;
  1860. }
  1861. key = key.slice(2).replace(/Once$/, '');
  1862. return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
  1863. hasOwn(options, hyphenate(key)) ||
  1864. hasOwn(options, key));
  1865. }
  1866. /**
  1867. * mark the current rendering instance for asset resolution (e.g.
  1868. * resolveComponent, resolveDirective) during render
  1869. */
  1870. let currentRenderingInstance = null;
  1871. function setCurrentRenderingInstance(instance) {
  1872. currentRenderingInstance = instance;
  1873. }
  1874. /**
  1875. * dev only flag to track whether $attrs was used during render.
  1876. * If $attrs was used during render then the warning for failed attrs
  1877. * fallthrough can be suppressed.
  1878. */
  1879. let accessedAttrs = false;
  1880. function markAttrsAccessed() {
  1881. accessedAttrs = true;
  1882. }
  1883. function renderComponentRoot(instance) {
  1884. const { type: Component, vnode, proxy, withProxy, props, propsOptions: [propsOptions], slots, attrs, emit, render, renderCache, data, setupState, ctx } = instance;
  1885. let result;
  1886. currentRenderingInstance = instance;
  1887. {
  1888. accessedAttrs = false;
  1889. }
  1890. try {
  1891. let fallthroughAttrs;
  1892. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  1893. // withProxy is a proxy with a different `has` trap only for
  1894. // runtime-compiled render functions using `with` block.
  1895. const proxyToUse = withProxy || proxy;
  1896. result = normalizeVNode(render.call(proxyToUse, proxyToUse, renderCache, props, setupState, data, ctx));
  1897. fallthroughAttrs = attrs;
  1898. }
  1899. else {
  1900. // functional
  1901. const render = Component;
  1902. // in dev, mark attrs accessed if optional props (attrs === props)
  1903. if (true && attrs === props) {
  1904. markAttrsAccessed();
  1905. }
  1906. result = normalizeVNode(render.length > 1
  1907. ? render(props, true
  1908. ? {
  1909. get attrs() {
  1910. markAttrsAccessed();
  1911. return attrs;
  1912. },
  1913. slots,
  1914. emit
  1915. }
  1916. : { attrs, slots, emit })
  1917. : render(props, null /* we know it doesn't need it */));
  1918. fallthroughAttrs = Component.props
  1919. ? attrs
  1920. : getFunctionalFallthrough(attrs);
  1921. }
  1922. // attr merging
  1923. // in dev mode, comments are preserved, and it's possible for a template
  1924. // to have comments along side the root element which makes it a fragment
  1925. let root = result;
  1926. let setRoot = undefined;
  1927. if (true &&
  1928. result.patchFlag > 0 &&
  1929. result.patchFlag & 2048 /* DEV_ROOT_FRAGMENT */) {
  1930. ;
  1931. [root, setRoot] = getChildRoot(result);
  1932. }
  1933. if (Component.inheritAttrs !== false && fallthroughAttrs) {
  1934. const keys = Object.keys(fallthroughAttrs);
  1935. const { shapeFlag } = root;
  1936. if (keys.length) {
  1937. if (shapeFlag & 1 /* ELEMENT */ ||
  1938. shapeFlag & 6 /* COMPONENT */) {
  1939. if (propsOptions && keys.some(isModelListener)) {
  1940. // If a v-model listener (onUpdate:xxx) has a corresponding declared
  1941. // prop, it indicates this component expects to handle v-model and
  1942. // it should not fallthrough.
  1943. // related: #1543, #1643, #1989
  1944. fallthroughAttrs = filterModelListeners(fallthroughAttrs, propsOptions);
  1945. }
  1946. root = cloneVNode(root, fallthroughAttrs);
  1947. }
  1948. else if (true && !accessedAttrs && root.type !== Comment) {
  1949. const allAttrs = Object.keys(attrs);
  1950. const eventAttrs = [];
  1951. const extraAttrs = [];
  1952. for (let i = 0, l = allAttrs.length; i < l; i++) {
  1953. const key = allAttrs[i];
  1954. if (isOn(key)) {
  1955. // ignore v-model handlers when they fail to fallthrough
  1956. if (!isModelListener(key)) {
  1957. // remove `on`, lowercase first letter to reflect event casing
  1958. // accurately
  1959. eventAttrs.push(key[2].toLowerCase() + key.slice(3));
  1960. }
  1961. }
  1962. else {
  1963. extraAttrs.push(key);
  1964. }
  1965. }
  1966. if (extraAttrs.length) {
  1967. warn(`Extraneous non-props attributes (` +
  1968. `${extraAttrs.join(', ')}) ` +
  1969. `were passed to component but could not be automatically inherited ` +
  1970. `because component renders fragment or text root nodes.`);
  1971. }
  1972. if (eventAttrs.length) {
  1973. warn(`Extraneous non-emits event listeners (` +
  1974. `${eventAttrs.join(', ')}) ` +
  1975. `were passed to component but could not be automatically inherited ` +
  1976. `because component renders fragment or text root nodes. ` +
  1977. `If the listener is intended to be a component custom event listener only, ` +
  1978. `declare it using the "emits" option.`);
  1979. }
  1980. }
  1981. }
  1982. }
  1983. // inherit directives
  1984. if (vnode.dirs) {
  1985. if (true && !isElementRoot(root)) {
  1986. warn(`Runtime directive used on component with non-element root node. ` +
  1987. `The directives will not function as intended.`);
  1988. }
  1989. root.dirs = root.dirs ? root.dirs.concat(vnode.dirs) : vnode.dirs;
  1990. }
  1991. // inherit transition data
  1992. if (vnode.transition) {
  1993. if (true && !isElementRoot(root)) {
  1994. warn(`Component inside <Transition> renders non-element root node ` +
  1995. `that cannot be animated.`);
  1996. }
  1997. root.transition = vnode.transition;
  1998. }
  1999. if (true && setRoot) {
  2000. setRoot(root);
  2001. }
  2002. else {
  2003. result = root;
  2004. }
  2005. }
  2006. catch (err) {
  2007. handleError(err, instance, 1 /* RENDER_FUNCTION */);
  2008. result = createVNode(Comment);
  2009. }
  2010. currentRenderingInstance = null;
  2011. return result;
  2012. }
  2013. /**
  2014. * dev only
  2015. * In dev mode, template root level comments are rendered, which turns the
  2016. * template into a fragment root, but we need to locate the single element
  2017. * root for attrs and scope id processing.
  2018. */
  2019. const getChildRoot = (vnode) => {
  2020. const rawChildren = vnode.children;
  2021. const dynamicChildren = vnode.dynamicChildren;
  2022. const childRoot = filterSingleRoot(rawChildren);
  2023. if (!childRoot) {
  2024. return [vnode, undefined];
  2025. }
  2026. const index = rawChildren.indexOf(childRoot);
  2027. const dynamicIndex = dynamicChildren ? dynamicChildren.indexOf(childRoot) : -1;
  2028. const setRoot = (updatedRoot) => {
  2029. rawChildren[index] = updatedRoot;
  2030. if (dynamicChildren) {
  2031. if (dynamicIndex > -1) {
  2032. dynamicChildren[dynamicIndex] = updatedRoot;
  2033. }
  2034. else if (updatedRoot.patchFlag > 0) {
  2035. vnode.dynamicChildren = [...dynamicChildren, updatedRoot];
  2036. }
  2037. }
  2038. };
  2039. return [normalizeVNode(childRoot), setRoot];
  2040. };
  2041. function filterSingleRoot(children) {
  2042. let singleRoot;
  2043. for (let i = 0; i < children.length; i++) {
  2044. const child = children[i];
  2045. if (isVNode(child)) {
  2046. // ignore user comment
  2047. if (child.type !== Comment || child.children === 'v-if') {
  2048. if (singleRoot) {
  2049. // has more than 1 non-comment child, return now
  2050. return;
  2051. }
  2052. else {
  2053. singleRoot = child;
  2054. }
  2055. }
  2056. }
  2057. else {
  2058. return;
  2059. }
  2060. }
  2061. return singleRoot;
  2062. }
  2063. const getFunctionalFallthrough = (attrs) => {
  2064. let res;
  2065. for (const key in attrs) {
  2066. if (key === 'class' || key === 'style' || isOn(key)) {
  2067. (res || (res = {}))[key] = attrs[key];
  2068. }
  2069. }
  2070. return res;
  2071. };
  2072. const filterModelListeners = (attrs, props) => {
  2073. const res = {};
  2074. for (const key in attrs) {
  2075. if (!isModelListener(key) || !(key.slice(9) in props)) {
  2076. res[key] = attrs[key];
  2077. }
  2078. }
  2079. return res;
  2080. };
  2081. const isElementRoot = (vnode) => {
  2082. return (vnode.shapeFlag & 6 /* COMPONENT */ ||
  2083. vnode.shapeFlag & 1 /* ELEMENT */ ||
  2084. vnode.type === Comment // potential v-if branch switch
  2085. );
  2086. };
  2087. function shouldUpdateComponent(prevVNode, nextVNode, optimized) {
  2088. const { props: prevProps, children: prevChildren, component } = prevVNode;
  2089. const { props: nextProps, children: nextChildren, patchFlag } = nextVNode;
  2090. const emits = component.emitsOptions;
  2091. // Parent component's render function was hot-updated. Since this may have
  2092. // caused the child component's slots content to have changed, we need to
  2093. // force the child to update as well.
  2094. if ((prevChildren || nextChildren) && isHmrUpdating) {
  2095. return true;
  2096. }
  2097. // force child update for runtime directive or transition on component vnode.
  2098. if (nextVNode.dirs || nextVNode.transition) {
  2099. return true;
  2100. }
  2101. if (optimized && patchFlag >= 0) {
  2102. if (patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  2103. // slot content that references values that might have changed,
  2104. // e.g. in a v-for
  2105. return true;
  2106. }
  2107. if (patchFlag & 16 /* FULL_PROPS */) {
  2108. if (!prevProps) {
  2109. return !!nextProps;
  2110. }
  2111. // presence of this flag indicates props are always non-null
  2112. return hasPropsChanged(prevProps, nextProps, emits);
  2113. }
  2114. else if (patchFlag & 8 /* PROPS */) {
  2115. const dynamicProps = nextVNode.dynamicProps;
  2116. for (let i = 0; i < dynamicProps.length; i++) {
  2117. const key = dynamicProps[i];
  2118. if (nextProps[key] !== prevProps[key] &&
  2119. !isEmitListener(emits, key)) {
  2120. return true;
  2121. }
  2122. }
  2123. }
  2124. }
  2125. else {
  2126. // this path is only taken by manually written render functions
  2127. // so presence of any children leads to a forced update
  2128. if (prevChildren || nextChildren) {
  2129. if (!nextChildren || !nextChildren.$stable) {
  2130. return true;
  2131. }
  2132. }
  2133. if (prevProps === nextProps) {
  2134. return false;
  2135. }
  2136. if (!prevProps) {
  2137. return !!nextProps;
  2138. }
  2139. if (!nextProps) {
  2140. return true;
  2141. }
  2142. return hasPropsChanged(prevProps, nextProps, emits);
  2143. }
  2144. return false;
  2145. }
  2146. function hasPropsChanged(prevProps, nextProps, emitsOptions) {
  2147. const nextKeys = Object.keys(nextProps);
  2148. if (nextKeys.length !== Object.keys(prevProps).length) {
  2149. return true;
  2150. }
  2151. for (let i = 0; i < nextKeys.length; i++) {
  2152. const key = nextKeys[i];
  2153. if (nextProps[key] !== prevProps[key] &&
  2154. !isEmitListener(emitsOptions, key)) {
  2155. return true;
  2156. }
  2157. }
  2158. return false;
  2159. }
  2160. function updateHOCHostEl({ vnode, parent }, el // HostNode
  2161. ) {
  2162. while (parent && parent.subTree === vnode) {
  2163. (vnode = parent.vnode).el = el;
  2164. parent = parent.parent;
  2165. }
  2166. }
  2167. const isSuspense = (type) => type.__isSuspense;
  2168. // Suspense exposes a component-like API, and is treated like a component
  2169. // in the compiler, but internally it's a special built-in type that hooks
  2170. // directly into the renderer.
  2171. const SuspenseImpl = {
  2172. // In order to make Suspense tree-shakable, we need to avoid importing it
  2173. // directly in the renderer. The renderer checks for the __isSuspense flag
  2174. // on a vnode's type and calls the `process` method, passing in renderer
  2175. // internals.
  2176. __isSuspense: true,
  2177. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized,
  2178. // platform-specific impl passed from renderer
  2179. rendererInternals) {
  2180. if (n1 == null) {
  2181. mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, rendererInternals);
  2182. }
  2183. else {
  2184. patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, rendererInternals);
  2185. }
  2186. },
  2187. hydrate: hydrateSuspense,
  2188. create: createSuspenseBoundary
  2189. };
  2190. // Force-casted public typing for h and TSX props inference
  2191. const Suspense = (SuspenseImpl
  2192. );
  2193. function mountSuspense(vnode, container, anchor, parentComponent, parentSuspense, isSVG, optimized, rendererInternals) {
  2194. const { p: patch, o: { createElement } } = rendererInternals;
  2195. const hiddenContainer = createElement('div');
  2196. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, optimized, rendererInternals));
  2197. // start mounting the content subtree in an off-dom container
  2198. patch(null, (suspense.pendingBranch = vnode.ssContent), hiddenContainer, null, parentComponent, suspense, isSVG);
  2199. // now check if we have encountered any async deps
  2200. if (suspense.deps > 0) {
  2201. // has async
  2202. // mount the fallback tree
  2203. patch(null, vnode.ssFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2204. isSVG);
  2205. setActiveBranch(suspense, vnode.ssFallback);
  2206. }
  2207. else {
  2208. // Suspense has no async deps. Just resolve.
  2209. suspense.resolve();
  2210. }
  2211. }
  2212. function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, { p: patch, um: unmount, o: { createElement } }) {
  2213. const suspense = (n2.suspense = n1.suspense);
  2214. suspense.vnode = n2;
  2215. n2.el = n1.el;
  2216. const newBranch = n2.ssContent;
  2217. const newFallback = n2.ssFallback;
  2218. const { activeBranch, pendingBranch, isInFallback, isHydrating } = suspense;
  2219. if (pendingBranch) {
  2220. suspense.pendingBranch = newBranch;
  2221. if (isSameVNodeType(newBranch, pendingBranch)) {
  2222. // same root type but content may have changed.
  2223. patch(pendingBranch, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  2224. if (suspense.deps <= 0) {
  2225. suspense.resolve();
  2226. }
  2227. else if (isInFallback) {
  2228. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2229. isSVG);
  2230. setActiveBranch(suspense, newFallback);
  2231. }
  2232. }
  2233. else {
  2234. // toggled before pending tree is resolved
  2235. suspense.pendingId++;
  2236. if (isHydrating) {
  2237. // if toggled before hydration is finished, the current DOM tree is
  2238. // no longer valid. set it as the active branch so it will be unmounted
  2239. // when resolved
  2240. suspense.isHydrating = false;
  2241. suspense.activeBranch = pendingBranch;
  2242. }
  2243. else {
  2244. unmount(pendingBranch, parentComponent, suspense);
  2245. }
  2246. // increment pending ID. this is used to invalidate async callbacks
  2247. // reset suspense state
  2248. suspense.deps = 0;
  2249. // discard effects from pending branch
  2250. suspense.effects.length = 0;
  2251. // discard previous container
  2252. suspense.hiddenContainer = createElement('div');
  2253. if (isInFallback) {
  2254. // already in fallback state
  2255. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  2256. if (suspense.deps <= 0) {
  2257. suspense.resolve();
  2258. }
  2259. else {
  2260. patch(activeBranch, newFallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2261. isSVG);
  2262. setActiveBranch(suspense, newFallback);
  2263. }
  2264. }
  2265. else if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2266. // toggled "back" to current active branch
  2267. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG);
  2268. // force resolve
  2269. suspense.resolve(true);
  2270. }
  2271. else {
  2272. // switched to a 3rd branch
  2273. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  2274. if (suspense.deps <= 0) {
  2275. suspense.resolve();
  2276. }
  2277. }
  2278. }
  2279. }
  2280. else {
  2281. if (activeBranch && isSameVNodeType(newBranch, activeBranch)) {
  2282. // root did not change, just normal patch
  2283. patch(activeBranch, newBranch, container, anchor, parentComponent, suspense, isSVG);
  2284. setActiveBranch(suspense, newBranch);
  2285. }
  2286. else {
  2287. // root node toggled
  2288. // invoke @pending event
  2289. const onPending = n2.props && n2.props.onPending;
  2290. if (isFunction(onPending)) {
  2291. onPending();
  2292. }
  2293. // mount pending branch in off-dom container
  2294. suspense.pendingBranch = newBranch;
  2295. suspense.pendingId++;
  2296. patch(null, newBranch, suspense.hiddenContainer, null, parentComponent, suspense, isSVG);
  2297. if (suspense.deps <= 0) {
  2298. // incoming branch has no async deps, resolve now.
  2299. suspense.resolve();
  2300. }
  2301. else {
  2302. const { timeout, pendingId } = suspense;
  2303. if (timeout > 0) {
  2304. setTimeout(() => {
  2305. if (suspense.pendingId === pendingId) {
  2306. suspense.fallback(newFallback);
  2307. }
  2308. }, timeout);
  2309. }
  2310. else if (timeout === 0) {
  2311. suspense.fallback(newFallback);
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. let hasWarned = false;
  2318. function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, optimized, rendererInternals, isHydrating = false) {
  2319. /* istanbul ignore if */
  2320. if (!hasWarned) {
  2321. hasWarned = true;
  2322. // @ts-ignore `console.info` cannot be null error
  2323. console[console.info ? 'info' : 'log'](`<Suspense> is an experimental feature and its API will likely change.`);
  2324. }
  2325. const { p: patch, m: move, um: unmount, n: next, o: { parentNode, remove } } = rendererInternals;
  2326. const timeout = toNumber(vnode.props && vnode.props.timeout);
  2327. const suspense = {
  2328. vnode,
  2329. parent,
  2330. parentComponent,
  2331. isSVG,
  2332. container,
  2333. hiddenContainer,
  2334. anchor,
  2335. deps: 0,
  2336. pendingId: 0,
  2337. timeout: typeof timeout === 'number' ? timeout : -1,
  2338. activeBranch: null,
  2339. pendingBranch: null,
  2340. isInFallback: true,
  2341. isHydrating,
  2342. isUnmounted: false,
  2343. effects: [],
  2344. resolve(resume = false) {
  2345. {
  2346. if (!resume && !suspense.pendingBranch) {
  2347. throw new Error(`suspense.resolve() is called without a pending branch.`);
  2348. }
  2349. if (suspense.isUnmounted) {
  2350. throw new Error(`suspense.resolve() is called on an already unmounted suspense boundary.`);
  2351. }
  2352. }
  2353. const { vnode, activeBranch, pendingBranch, pendingId, effects, parentComponent, container } = suspense;
  2354. if (suspense.isHydrating) {
  2355. suspense.isHydrating = false;
  2356. }
  2357. else if (!resume) {
  2358. const delayEnter = activeBranch &&
  2359. pendingBranch.transition &&
  2360. pendingBranch.transition.mode === 'out-in';
  2361. if (delayEnter) {
  2362. activeBranch.transition.afterLeave = () => {
  2363. if (pendingId === suspense.pendingId) {
  2364. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2365. }
  2366. };
  2367. }
  2368. // this is initial anchor on mount
  2369. let { anchor } = suspense;
  2370. // unmount current active tree
  2371. if (activeBranch) {
  2372. // if the fallback tree was mounted, it may have been moved
  2373. // as part of a parent suspense. get the latest anchor for insertion
  2374. anchor = next(activeBranch);
  2375. unmount(activeBranch, parentComponent, suspense, true);
  2376. }
  2377. if (!delayEnter) {
  2378. // move content from off-dom container to actual container
  2379. move(pendingBranch, container, anchor, 0 /* ENTER */);
  2380. }
  2381. }
  2382. setActiveBranch(suspense, pendingBranch);
  2383. suspense.pendingBranch = null;
  2384. suspense.isInFallback = false;
  2385. // flush buffered effects
  2386. // check if there is a pending parent suspense
  2387. let parent = suspense.parent;
  2388. let hasUnresolvedAncestor = false;
  2389. while (parent) {
  2390. if (parent.pendingBranch) {
  2391. // found a pending parent suspense, merge buffered post jobs
  2392. // into that parent
  2393. parent.effects.push(...effects);
  2394. hasUnresolvedAncestor = true;
  2395. break;
  2396. }
  2397. parent = parent.parent;
  2398. }
  2399. // no pending parent suspense, flush all jobs
  2400. if (!hasUnresolvedAncestor) {
  2401. queuePostFlushCb(effects);
  2402. }
  2403. suspense.effects = [];
  2404. // invoke @resolve event
  2405. const onResolve = vnode.props && vnode.props.onResolve;
  2406. if (isFunction(onResolve)) {
  2407. onResolve();
  2408. }
  2409. },
  2410. fallback(fallbackVNode) {
  2411. if (!suspense.pendingBranch) {
  2412. return;
  2413. }
  2414. const { vnode, activeBranch, parentComponent, container, isSVG } = suspense;
  2415. // invoke @fallback event
  2416. const onFallback = vnode.props && vnode.props.onFallback;
  2417. if (isFunction(onFallback)) {
  2418. onFallback();
  2419. }
  2420. const anchor = next(activeBranch);
  2421. const mountFallback = () => {
  2422. if (!suspense.isInFallback) {
  2423. return;
  2424. }
  2425. // mount the fallback tree
  2426. patch(null, fallbackVNode, container, anchor, parentComponent, null, // fallback tree will not have suspense context
  2427. isSVG);
  2428. setActiveBranch(suspense, fallbackVNode);
  2429. };
  2430. const delayEnter = fallbackVNode.transition && fallbackVNode.transition.mode === 'out-in';
  2431. if (delayEnter) {
  2432. activeBranch.transition.afterLeave = mountFallback;
  2433. }
  2434. // unmount current active branch
  2435. unmount(activeBranch, parentComponent, null, // no suspense so unmount hooks fire now
  2436. true // shouldRemove
  2437. );
  2438. suspense.isInFallback = true;
  2439. if (!delayEnter) {
  2440. mountFallback();
  2441. }
  2442. },
  2443. move(container, anchor, type) {
  2444. suspense.activeBranch &&
  2445. move(suspense.activeBranch, container, anchor, type);
  2446. suspense.container = container;
  2447. },
  2448. next() {
  2449. return suspense.activeBranch && next(suspense.activeBranch);
  2450. },
  2451. registerDep(instance, setupRenderEffect) {
  2452. const isInPendingSuspense = !!suspense.pendingBranch;
  2453. if (isInPendingSuspense) {
  2454. suspense.deps++;
  2455. }
  2456. const hydratedEl = instance.vnode.el;
  2457. instance
  2458. .asyncDep.catch(err => {
  2459. handleError(err, instance, 0 /* SETUP_FUNCTION */);
  2460. })
  2461. .then(asyncSetupResult => {
  2462. // retry when the setup() promise resolves.
  2463. // component may have been unmounted before resolve.
  2464. if (instance.isUnmounted ||
  2465. suspense.isUnmounted ||
  2466. suspense.pendingId !== instance.suspenseId) {
  2467. return;
  2468. }
  2469. // retry from this component
  2470. instance.asyncResolved = true;
  2471. const { vnode } = instance;
  2472. {
  2473. pushWarningContext(vnode);
  2474. }
  2475. handleSetupResult(instance, asyncSetupResult);
  2476. if (hydratedEl) {
  2477. // vnode may have been replaced if an update happened before the
  2478. // async dep is resolved.
  2479. vnode.el = hydratedEl;
  2480. }
  2481. const placeholder = !hydratedEl && instance.subTree.el;
  2482. setupRenderEffect(instance, vnode,
  2483. // component may have been moved before resolve.
  2484. // if this is not a hydration, instance.subTree will be the comment
  2485. // placeholder.
  2486. parentNode(hydratedEl || instance.subTree.el),
  2487. // anchor will not be used if this is hydration, so only need to
  2488. // consider the comment placeholder case.
  2489. hydratedEl ? null : next(instance.subTree), suspense, isSVG, optimized);
  2490. if (placeholder) {
  2491. remove(placeholder);
  2492. }
  2493. updateHOCHostEl(instance, vnode.el);
  2494. {
  2495. popWarningContext();
  2496. }
  2497. // only decrease deps count if suspense is not already resolved
  2498. if (isInPendingSuspense && --suspense.deps === 0) {
  2499. suspense.resolve();
  2500. }
  2501. });
  2502. },
  2503. unmount(parentSuspense, doRemove) {
  2504. suspense.isUnmounted = true;
  2505. if (suspense.activeBranch) {
  2506. unmount(suspense.activeBranch, parentComponent, parentSuspense, doRemove);
  2507. }
  2508. if (suspense.pendingBranch) {
  2509. unmount(suspense.pendingBranch, parentComponent, parentSuspense, doRemove);
  2510. }
  2511. }
  2512. };
  2513. return suspense;
  2514. }
  2515. function hydrateSuspense(node, vnode, parentComponent, parentSuspense, isSVG, optimized, rendererInternals, hydrateNode) {
  2516. /* eslint-disable no-restricted-globals */
  2517. const suspense = (vnode.suspense = createSuspenseBoundary(vnode, parentSuspense, parentComponent, node.parentNode, document.createElement('div'), null, isSVG, optimized, rendererInternals, true /* hydrating */));
  2518. // there are two possible scenarios for server-rendered suspense:
  2519. // - success: ssr content should be fully resolved
  2520. // - failure: ssr content should be the fallback branch.
  2521. // however, on the client we don't really know if it has failed or not
  2522. // attempt to hydrate the DOM assuming it has succeeded, but we still
  2523. // need to construct a suspense boundary first
  2524. const result = hydrateNode(node, (suspense.pendingBranch = vnode.ssContent), parentComponent, suspense, optimized);
  2525. if (suspense.deps === 0) {
  2526. suspense.resolve();
  2527. }
  2528. return result;
  2529. /* eslint-enable no-restricted-globals */
  2530. }
  2531. function normalizeSuspenseChildren(vnode) {
  2532. const { shapeFlag, children } = vnode;
  2533. let content;
  2534. let fallback;
  2535. if (shapeFlag & 32 /* SLOTS_CHILDREN */) {
  2536. content = normalizeSuspenseSlot(children.default);
  2537. fallback = normalizeSuspenseSlot(children.fallback);
  2538. }
  2539. else {
  2540. content = normalizeSuspenseSlot(children);
  2541. fallback = normalizeVNode(null);
  2542. }
  2543. return {
  2544. content,
  2545. fallback
  2546. };
  2547. }
  2548. function normalizeSuspenseSlot(s) {
  2549. if (isFunction(s)) {
  2550. s = s();
  2551. }
  2552. if (isArray(s)) {
  2553. const singleChild = filterSingleRoot(s);
  2554. if (!singleChild) {
  2555. warn(`<Suspense> slots expect a single root node.`);
  2556. }
  2557. s = singleChild;
  2558. }
  2559. return normalizeVNode(s);
  2560. }
  2561. function queueEffectWithSuspense(fn, suspense) {
  2562. if (suspense && suspense.pendingBranch) {
  2563. if (isArray(fn)) {
  2564. suspense.effects.push(...fn);
  2565. }
  2566. else {
  2567. suspense.effects.push(fn);
  2568. }
  2569. }
  2570. else {
  2571. queuePostFlushCb(fn);
  2572. }
  2573. }
  2574. function setActiveBranch(suspense, branch) {
  2575. suspense.activeBranch = branch;
  2576. const { vnode, parentComponent } = suspense;
  2577. const el = (vnode.el = branch.el);
  2578. // in case suspense is the root node of a component,
  2579. // recursively update the HOC el
  2580. if (parentComponent && parentComponent.subTree === vnode) {
  2581. parentComponent.vnode.el = el;
  2582. updateHOCHostEl(parentComponent, el);
  2583. }
  2584. }
  2585. let isRenderingCompiledSlot = 0;
  2586. const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
  2587. /**
  2588. * Compiler runtime helper for rendering `<slot/>`
  2589. * @private
  2590. */
  2591. function renderSlot(slots, name, props = {},
  2592. // this is not a user-facing function, so the fallback is always generated by
  2593. // the compiler and guaranteed to be a function returning an array
  2594. fallback) {
  2595. let slot = slots[name];
  2596. if (slot && slot.length > 1) {
  2597. warn(`SSR-optimized slot function detected in a non-SSR-optimized render ` +
  2598. `function. You need to mark this component with $dynamic-slots in the ` +
  2599. `parent template.`);
  2600. slot = () => [];
  2601. }
  2602. // a compiled slot disables block tracking by default to avoid manual
  2603. // invocation interfering with template-based block tracking, but in
  2604. // `renderSlot` we can be sure that it's template-based so we can force
  2605. // enable it.
  2606. isRenderingCompiledSlot++;
  2607. openBlock();
  2608. const validSlotContent = slot && ensureValidVNode(slot(props));
  2609. const rendered = createBlock(Fragment, { key: props.key || `_${name}` }, validSlotContent || (fallback ? fallback() : []), validSlotContent && slots._ === 1 /* STABLE */
  2610. ? 64 /* STABLE_FRAGMENT */
  2611. : -2 /* BAIL */);
  2612. isRenderingCompiledSlot--;
  2613. return rendered;
  2614. }
  2615. function ensureValidVNode(vnodes) {
  2616. return vnodes.some(child => {
  2617. if (!isVNode(child))
  2618. return true;
  2619. if (child.type === Comment)
  2620. return false;
  2621. if (child.type === Fragment &&
  2622. !ensureValidVNode(child.children))
  2623. return false;
  2624. return true;
  2625. })
  2626. ? vnodes
  2627. : null;
  2628. }
  2629. /**
  2630. * Wrap a slot function to memoize current rendering instance
  2631. * @private
  2632. */
  2633. function withCtx(fn, ctx = currentRenderingInstance) {
  2634. if (!ctx)
  2635. return fn;
  2636. const renderFnWithContext = (...args) => {
  2637. // If a user calls a compiled slot inside a template expression (#1745), it
  2638. // can mess up block tracking, so by default we need to push a null block to
  2639. // avoid that. This isn't necessary if rendering a compiled `<slot>`.
  2640. if (!isRenderingCompiledSlot) {
  2641. openBlock(true /* null block that disables tracking */);
  2642. }
  2643. const owner = currentRenderingInstance;
  2644. setCurrentRenderingInstance(ctx);
  2645. const res = fn(...args);
  2646. setCurrentRenderingInstance(owner);
  2647. if (!isRenderingCompiledSlot) {
  2648. closeBlock();
  2649. }
  2650. return res;
  2651. };
  2652. renderFnWithContext._c = true;
  2653. return renderFnWithContext;
  2654. }
  2655. // SFC scoped style ID management.
  2656. let currentScopeId = null;
  2657. const scopeIdStack = [];
  2658. /**
  2659. * @private
  2660. */
  2661. function pushScopeId(id) {
  2662. scopeIdStack.push((currentScopeId = id));
  2663. }
  2664. /**
  2665. * @private
  2666. */
  2667. function popScopeId() {
  2668. scopeIdStack.pop();
  2669. currentScopeId = scopeIdStack[scopeIdStack.length - 1] || null;
  2670. }
  2671. /**
  2672. * @private
  2673. */
  2674. function withScopeId(id) {
  2675. return ((fn) => withCtx(function () {
  2676. pushScopeId(id);
  2677. const res = fn.apply(this, arguments);
  2678. popScopeId();
  2679. return res;
  2680. }));
  2681. }
  2682. function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
  2683. isSSR = false) {
  2684. const props = {};
  2685. const attrs = {};
  2686. def(attrs, InternalObjectKey, 1);
  2687. setFullProps(instance, rawProps, props, attrs);
  2688. // validation
  2689. {
  2690. validateProps(props, instance);
  2691. }
  2692. if (isStateful) {
  2693. // stateful
  2694. instance.props = isSSR ? props : shallowReactive(props);
  2695. }
  2696. else {
  2697. if (!instance.type.props) {
  2698. // functional w/ optional props, props === attrs
  2699. instance.props = attrs;
  2700. }
  2701. else {
  2702. // functional w/ declared props
  2703. instance.props = props;
  2704. }
  2705. }
  2706. instance.attrs = attrs;
  2707. }
  2708. function updateProps(instance, rawProps, rawPrevProps, optimized) {
  2709. const { props, attrs, vnode: { patchFlag } } = instance;
  2710. const rawCurrentProps = toRaw(props);
  2711. const [options] = instance.propsOptions;
  2712. if (
  2713. // always force full diff in dev
  2714. // - #1942 if hmr is enabled with sfc component
  2715. // - vite#872 non-sfc component used by sfc component
  2716. !((instance.type.__hmrId ||
  2717. (instance.parent && instance.parent.type.__hmrId))) &&
  2718. (optimized || patchFlag > 0) &&
  2719. !(patchFlag & 16 /* FULL_PROPS */)) {
  2720. if (patchFlag & 8 /* PROPS */) {
  2721. // Compiler-generated props & no keys change, just set the updated
  2722. // the props.
  2723. const propsToUpdate = instance.vnode.dynamicProps;
  2724. for (let i = 0; i < propsToUpdate.length; i++) {
  2725. const key = propsToUpdate[i];
  2726. // PROPS flag guarantees rawProps to be non-null
  2727. const value = rawProps[key];
  2728. if (options) {
  2729. // attr / props separation was done on init and will be consistent
  2730. // in this code path, so just check if attrs have it.
  2731. if (hasOwn(attrs, key)) {
  2732. attrs[key] = value;
  2733. }
  2734. else {
  2735. const camelizedKey = camelize(key);
  2736. props[camelizedKey] = resolvePropValue(options, rawCurrentProps, camelizedKey, value, instance);
  2737. }
  2738. }
  2739. else {
  2740. attrs[key] = value;
  2741. }
  2742. }
  2743. }
  2744. }
  2745. else {
  2746. // full props update.
  2747. setFullProps(instance, rawProps, props, attrs);
  2748. // in case of dynamic props, check if we need to delete keys from
  2749. // the props object
  2750. let kebabKey;
  2751. for (const key in rawCurrentProps) {
  2752. if (!rawProps ||
  2753. // for camelCase
  2754. (!hasOwn(rawProps, key) &&
  2755. // it's possible the original props was passed in as kebab-case
  2756. // and converted to camelCase (#955)
  2757. ((kebabKey = hyphenate(key)) === key || !hasOwn(rawProps, kebabKey)))) {
  2758. if (options) {
  2759. if (rawPrevProps &&
  2760. // for camelCase
  2761. (rawPrevProps[key] !== undefined ||
  2762. // for kebab-case
  2763. rawPrevProps[kebabKey] !== undefined)) {
  2764. props[key] = resolvePropValue(options, rawProps || EMPTY_OBJ, key, undefined, instance);
  2765. }
  2766. }
  2767. else {
  2768. delete props[key];
  2769. }
  2770. }
  2771. }
  2772. // in the case of functional component w/o props declaration, props and
  2773. // attrs point to the same object so it should already have been updated.
  2774. if (attrs !== rawCurrentProps) {
  2775. for (const key in attrs) {
  2776. if (!rawProps || !hasOwn(rawProps, key)) {
  2777. delete attrs[key];
  2778. }
  2779. }
  2780. }
  2781. }
  2782. // trigger updates for $attrs in case it's used in component slots
  2783. trigger(instance, "set" /* SET */, '$attrs');
  2784. if (rawProps) {
  2785. validateProps(props, instance);
  2786. }
  2787. }
  2788. function setFullProps(instance, rawProps, props, attrs) {
  2789. const [options, needCastKeys] = instance.propsOptions;
  2790. if (rawProps) {
  2791. for (const key in rawProps) {
  2792. const value = rawProps[key];
  2793. // key, ref are reserved and never passed down
  2794. if (isReservedProp(key)) {
  2795. continue;
  2796. }
  2797. // prop option names are camelized during normalization, so to support
  2798. // kebab -> camel conversion here we need to camelize the key.
  2799. let camelKey;
  2800. if (options && hasOwn(options, (camelKey = camelize(key)))) {
  2801. props[camelKey] = value;
  2802. }
  2803. else if (!isEmitListener(instance.emitsOptions, key)) {
  2804. // Any non-declared (either as a prop or an emitted event) props are put
  2805. // into a separate `attrs` object for spreading. Make sure to preserve
  2806. // original key casing
  2807. attrs[key] = value;
  2808. }
  2809. }
  2810. }
  2811. if (needCastKeys) {
  2812. const rawCurrentProps = toRaw(props);
  2813. for (let i = 0; i < needCastKeys.length; i++) {
  2814. const key = needCastKeys[i];
  2815. props[key] = resolvePropValue(options, rawCurrentProps, key, rawCurrentProps[key], instance);
  2816. }
  2817. }
  2818. }
  2819. function resolvePropValue(options, props, key, value, instance) {
  2820. const opt = options[key];
  2821. if (opt != null) {
  2822. const hasDefault = hasOwn(opt, 'default');
  2823. // default values
  2824. if (hasDefault && value === undefined) {
  2825. const defaultValue = opt.default;
  2826. if (opt.type !== Function && isFunction(defaultValue)) {
  2827. setCurrentInstance(instance);
  2828. value = defaultValue(props);
  2829. setCurrentInstance(null);
  2830. }
  2831. else {
  2832. value = defaultValue;
  2833. }
  2834. }
  2835. // boolean casting
  2836. if (opt[0 /* shouldCast */]) {
  2837. if (!hasOwn(props, key) && !hasDefault) {
  2838. value = false;
  2839. }
  2840. else if (opt[1 /* shouldCastTrue */] &&
  2841. (value === '' || value === hyphenate(key))) {
  2842. value = true;
  2843. }
  2844. }
  2845. }
  2846. return value;
  2847. }
  2848. function normalizePropsOptions(comp, appContext, asMixin = false) {
  2849. if (!appContext.deopt && comp.__props) {
  2850. return comp.__props;
  2851. }
  2852. const raw = comp.props;
  2853. const normalized = {};
  2854. const needCastKeys = [];
  2855. // apply mixin/extends props
  2856. let hasExtends = false;
  2857. if (!isFunction(comp)) {
  2858. const extendProps = (raw) => {
  2859. hasExtends = true;
  2860. const [props, keys] = normalizePropsOptions(raw, appContext, true);
  2861. extend(normalized, props);
  2862. if (keys)
  2863. needCastKeys.push(...keys);
  2864. };
  2865. if (!asMixin && appContext.mixins.length) {
  2866. appContext.mixins.forEach(extendProps);
  2867. }
  2868. if (comp.extends) {
  2869. extendProps(comp.extends);
  2870. }
  2871. if (comp.mixins) {
  2872. comp.mixins.forEach(extendProps);
  2873. }
  2874. }
  2875. if (!raw && !hasExtends) {
  2876. return (comp.__props = EMPTY_ARR);
  2877. }
  2878. if (isArray(raw)) {
  2879. for (let i = 0; i < raw.length; i++) {
  2880. if (!isString(raw[i])) {
  2881. warn(`props must be strings when using array syntax.`, raw[i]);
  2882. }
  2883. const normalizedKey = camelize(raw[i]);
  2884. if (validatePropName(normalizedKey)) {
  2885. normalized[normalizedKey] = EMPTY_OBJ;
  2886. }
  2887. }
  2888. }
  2889. else if (raw) {
  2890. if (!isObject(raw)) {
  2891. warn(`invalid props options`, raw);
  2892. }
  2893. for (const key in raw) {
  2894. const normalizedKey = camelize(key);
  2895. if (validatePropName(normalizedKey)) {
  2896. const opt = raw[key];
  2897. const prop = (normalized[normalizedKey] =
  2898. isArray(opt) || isFunction(opt) ? { type: opt } : opt);
  2899. if (prop) {
  2900. const booleanIndex = getTypeIndex(Boolean, prop.type);
  2901. const stringIndex = getTypeIndex(String, prop.type);
  2902. prop[0 /* shouldCast */] = booleanIndex > -1;
  2903. prop[1 /* shouldCastTrue */] =
  2904. stringIndex < 0 || booleanIndex < stringIndex;
  2905. // if the prop needs boolean casting or default value
  2906. if (booleanIndex > -1 || hasOwn(prop, 'default')) {
  2907. needCastKeys.push(normalizedKey);
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. return (comp.__props = [normalized, needCastKeys]);
  2914. }
  2915. function validatePropName(key) {
  2916. if (key[0] !== '$') {
  2917. return true;
  2918. }
  2919. else {
  2920. warn(`Invalid prop name: "${key}" is a reserved property.`);
  2921. }
  2922. return false;
  2923. }
  2924. // use function string name to check type constructors
  2925. // so that it works across vms / iframes.
  2926. function getType(ctor) {
  2927. const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
  2928. return match ? match[1] : '';
  2929. }
  2930. function isSameType(a, b) {
  2931. return getType(a) === getType(b);
  2932. }
  2933. function getTypeIndex(type, expectedTypes) {
  2934. if (isArray(expectedTypes)) {
  2935. for (let i = 0, len = expectedTypes.length; i < len; i++) {
  2936. if (isSameType(expectedTypes[i], type)) {
  2937. return i;
  2938. }
  2939. }
  2940. }
  2941. else if (isFunction(expectedTypes)) {
  2942. return isSameType(expectedTypes, type) ? 0 : -1;
  2943. }
  2944. return -1;
  2945. }
  2946. /**
  2947. * dev only
  2948. */
  2949. function validateProps(props, instance) {
  2950. const rawValues = toRaw(props);
  2951. const options = instance.propsOptions[0];
  2952. for (const key in options) {
  2953. let opt = options[key];
  2954. if (opt == null)
  2955. continue;
  2956. validateProp(key, rawValues[key], opt, !hasOwn(rawValues, key));
  2957. }
  2958. }
  2959. /**
  2960. * dev only
  2961. */
  2962. function validateProp(name, value, prop, isAbsent) {
  2963. const { type, required, validator } = prop;
  2964. // required!
  2965. if (required && isAbsent) {
  2966. warn('Missing required prop: "' + name + '"');
  2967. return;
  2968. }
  2969. // missing but optional
  2970. if (value == null && !prop.required) {
  2971. return;
  2972. }
  2973. // type check
  2974. if (type != null && type !== true) {
  2975. let isValid = false;
  2976. const types = isArray(type) ? type : [type];
  2977. const expectedTypes = [];
  2978. // value is valid as long as one of the specified types match
  2979. for (let i = 0; i < types.length && !isValid; i++) {
  2980. const { valid, expectedType } = assertType(value, types[i]);
  2981. expectedTypes.push(expectedType || '');
  2982. isValid = valid;
  2983. }
  2984. if (!isValid) {
  2985. warn(getInvalidTypeMessage(name, value, expectedTypes));
  2986. return;
  2987. }
  2988. }
  2989. // custom validator
  2990. if (validator && !validator(value)) {
  2991. warn('Invalid prop: custom validator check failed for prop "' + name + '".');
  2992. }
  2993. }
  2994. const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol,BigInt');
  2995. /**
  2996. * dev only
  2997. */
  2998. function assertType(value, type) {
  2999. let valid;
  3000. const expectedType = getType(type);
  3001. if (isSimpleType(expectedType)) {
  3002. const t = typeof value;
  3003. valid = t === expectedType.toLowerCase();
  3004. // for primitive wrapper objects
  3005. if (!valid && t === 'object') {
  3006. valid = value instanceof type;
  3007. }
  3008. }
  3009. else if (expectedType === 'Object') {
  3010. valid = isObject(value);
  3011. }
  3012. else if (expectedType === 'Array') {
  3013. valid = isArray(value);
  3014. }
  3015. else {
  3016. valid = value instanceof type;
  3017. }
  3018. return {
  3019. valid,
  3020. expectedType
  3021. };
  3022. }
  3023. /**
  3024. * dev only
  3025. */
  3026. function getInvalidTypeMessage(name, value, expectedTypes) {
  3027. let message = `Invalid prop: type check failed for prop "${name}".` +
  3028. ` Expected ${expectedTypes.map(capitalize).join(', ')}`;
  3029. const expectedType = expectedTypes[0];
  3030. const receivedType = toRawType(value);
  3031. const expectedValue = styleValue(value, expectedType);
  3032. const receivedValue = styleValue(value, receivedType);
  3033. // check if we need to specify expected value
  3034. if (expectedTypes.length === 1 &&
  3035. isExplicable(expectedType) &&
  3036. !isBoolean(expectedType, receivedType)) {
  3037. message += ` with value ${expectedValue}`;
  3038. }
  3039. message += `, got ${receivedType} `;
  3040. // check if we need to specify received value
  3041. if (isExplicable(receivedType)) {
  3042. message += `with value ${receivedValue}.`;
  3043. }
  3044. return message;
  3045. }
  3046. /**
  3047. * dev only
  3048. */
  3049. function styleValue(value, type) {
  3050. if (type === 'String') {
  3051. return `"${value}"`;
  3052. }
  3053. else if (type === 'Number') {
  3054. return `${Number(value)}`;
  3055. }
  3056. else {
  3057. return `${value}`;
  3058. }
  3059. }
  3060. /**
  3061. * dev only
  3062. */
  3063. function isExplicable(type) {
  3064. const explicitTypes = ['string', 'number', 'boolean'];
  3065. return explicitTypes.some(elem => type.toLowerCase() === elem);
  3066. }
  3067. /**
  3068. * dev only
  3069. */
  3070. function isBoolean(...args) {
  3071. return args.some(elem => elem.toLowerCase() === 'boolean');
  3072. }
  3073. function injectHook(type, hook, target = currentInstance, prepend = false) {
  3074. if (target) {
  3075. const hooks = target[type] || (target[type] = []);
  3076. // cache the error handling wrapper for injected hooks so the same hook
  3077. // can be properly deduped by the scheduler. "__weh" stands for "with error
  3078. // handling".
  3079. const wrappedHook = hook.__weh ||
  3080. (hook.__weh = (...args) => {
  3081. if (target.isUnmounted) {
  3082. return;
  3083. }
  3084. // disable tracking inside all lifecycle hooks
  3085. // since they can potentially be called inside effects.
  3086. pauseTracking();
  3087. // Set currentInstance during hook invocation.
  3088. // This assumes the hook does not synchronously trigger other hooks, which
  3089. // can only be false when the user does something really funky.
  3090. setCurrentInstance(target);
  3091. const res = callWithAsyncErrorHandling(hook, target, type, args);
  3092. setCurrentInstance(null);
  3093. resetTracking();
  3094. return res;
  3095. });
  3096. if (prepend) {
  3097. hooks.unshift(wrappedHook);
  3098. }
  3099. else {
  3100. hooks.push(wrappedHook);
  3101. }
  3102. return wrappedHook;
  3103. }
  3104. else {
  3105. const apiName = toHandlerKey(ErrorTypeStrings[type].replace(/ hook$/, ''));
  3106. warn(`${apiName} is called when there is no active component instance to be ` +
  3107. `associated with. ` +
  3108. `Lifecycle injection APIs can only be used during execution of setup().` +
  3109. (` If you are using async setup(), make sure to register lifecycle ` +
  3110. `hooks before the first await statement.`
  3111. ));
  3112. }
  3113. }
  3114. const createHook = (lifecycle) => (hook, target = currentInstance) =>
  3115. // post-create lifecycle registrations are noops during SSR
  3116. !isInSSRComponentSetup && injectHook(lifecycle, hook, target);
  3117. const onBeforeMount = createHook("bm" /* BEFORE_MOUNT */);
  3118. const onMounted = createHook("m" /* MOUNTED */);
  3119. const onBeforeUpdate = createHook("bu" /* BEFORE_UPDATE */);
  3120. const onUpdated = createHook("u" /* UPDATED */);
  3121. const onBeforeUnmount = createHook("bum" /* BEFORE_UNMOUNT */);
  3122. const onUnmounted = createHook("um" /* UNMOUNTED */);
  3123. const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
  3124. const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
  3125. const onErrorCaptured = (hook, target = currentInstance) => {
  3126. injectHook("ec" /* ERROR_CAPTURED */, hook, target);
  3127. };
  3128. // Simple effect.
  3129. function watchEffect(effect, options) {
  3130. return doWatch(effect, null, options);
  3131. }
  3132. // initial value for watchers to trigger on undefined initial values
  3133. const INITIAL_WATCHER_VALUE = {};
  3134. // implementation
  3135. function watch(source, cb, options) {
  3136. if (!isFunction(cb)) {
  3137. warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
  3138. `Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
  3139. `supports \`watch(source, cb, options?) signature.`);
  3140. }
  3141. return doWatch(source, cb, options);
  3142. }
  3143. function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EMPTY_OBJ, instance = currentInstance) {
  3144. if (!cb) {
  3145. if (immediate !== undefined) {
  3146. warn(`watch() "immediate" option is only respected when using the ` +
  3147. `watch(source, callback, options?) signature.`);
  3148. }
  3149. if (deep !== undefined) {
  3150. warn(`watch() "deep" option is only respected when using the ` +
  3151. `watch(source, callback, options?) signature.`);
  3152. }
  3153. }
  3154. const warnInvalidSource = (s) => {
  3155. warn(`Invalid watch source: `, s, `A watch source can only be a getter/effect function, a ref, ` +
  3156. `a reactive object, or an array of these types.`);
  3157. };
  3158. let getter;
  3159. let forceTrigger = false;
  3160. if (isRef(source)) {
  3161. getter = () => source.value;
  3162. forceTrigger = !!source._shallow;
  3163. }
  3164. else if (isReactive(source)) {
  3165. getter = () => source;
  3166. deep = true;
  3167. }
  3168. else if (isArray(source)) {
  3169. getter = () => source.map(s => {
  3170. if (isRef(s)) {
  3171. return s.value;
  3172. }
  3173. else if (isReactive(s)) {
  3174. return traverse(s);
  3175. }
  3176. else if (isFunction(s)) {
  3177. return callWithErrorHandling(s, instance, 2 /* WATCH_GETTER */, [
  3178. instance && instance.proxy
  3179. ]);
  3180. }
  3181. else {
  3182. warnInvalidSource(s);
  3183. }
  3184. });
  3185. }
  3186. else if (isFunction(source)) {
  3187. if (cb) {
  3188. // getter with cb
  3189. getter = () => callWithErrorHandling(source, instance, 2 /* WATCH_GETTER */, [
  3190. instance && instance.proxy
  3191. ]);
  3192. }
  3193. else {
  3194. // no cb -> simple effect
  3195. getter = () => {
  3196. if (instance && instance.isUnmounted) {
  3197. return;
  3198. }
  3199. if (cleanup) {
  3200. cleanup();
  3201. }
  3202. return callWithErrorHandling(source, instance, 3 /* WATCH_CALLBACK */, [onInvalidate]);
  3203. };
  3204. }
  3205. }
  3206. else {
  3207. getter = NOOP;
  3208. warnInvalidSource(source);
  3209. }
  3210. if (cb && deep) {
  3211. const baseGetter = getter;
  3212. getter = () => traverse(baseGetter());
  3213. }
  3214. let cleanup;
  3215. const onInvalidate = (fn) => {
  3216. cleanup = runner.options.onStop = () => {
  3217. callWithErrorHandling(fn, instance, 4 /* WATCH_CLEANUP */);
  3218. };
  3219. };
  3220. let oldValue = isArray(source) ? [] : INITIAL_WATCHER_VALUE;
  3221. const job = () => {
  3222. if (!runner.active) {
  3223. return;
  3224. }
  3225. if (cb) {
  3226. // watch(source, cb)
  3227. const newValue = runner();
  3228. if (deep || forceTrigger || hasChanged(newValue, oldValue)) {
  3229. // cleanup before running cb again
  3230. if (cleanup) {
  3231. cleanup();
  3232. }
  3233. callWithAsyncErrorHandling(cb, instance, 3 /* WATCH_CALLBACK */, [
  3234. newValue,
  3235. // pass undefined as the old value when it's changed for the first time
  3236. oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
  3237. onInvalidate
  3238. ]);
  3239. oldValue = newValue;
  3240. }
  3241. }
  3242. else {
  3243. // watchEffect
  3244. runner();
  3245. }
  3246. };
  3247. // important: mark the job as a watcher callback so that scheduler knows
  3248. // it is allowed to self-trigger (#1727)
  3249. job.allowRecurse = !!cb;
  3250. let scheduler;
  3251. if (flush === 'sync') {
  3252. scheduler = job;
  3253. }
  3254. else if (flush === 'post') {
  3255. scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
  3256. }
  3257. else {
  3258. // default: 'pre'
  3259. scheduler = () => {
  3260. if (!instance || instance.isMounted) {
  3261. queuePreFlushCb(job);
  3262. }
  3263. else {
  3264. // with 'pre' option, the first call must happen before
  3265. // the component is mounted so it is called synchronously.
  3266. job();
  3267. }
  3268. };
  3269. }
  3270. const runner = effect(getter, {
  3271. lazy: true,
  3272. onTrack,
  3273. onTrigger,
  3274. scheduler
  3275. });
  3276. recordInstanceBoundEffect(runner, instance);
  3277. // initial run
  3278. if (cb) {
  3279. if (immediate) {
  3280. job();
  3281. }
  3282. else {
  3283. oldValue = runner();
  3284. }
  3285. }
  3286. else if (flush === 'post') {
  3287. queuePostRenderEffect(runner, instance && instance.suspense);
  3288. }
  3289. else {
  3290. runner();
  3291. }
  3292. return () => {
  3293. stop(runner);
  3294. if (instance) {
  3295. remove(instance.effects, runner);
  3296. }
  3297. };
  3298. }
  3299. // this.$watch
  3300. function instanceWatch(source, cb, options) {
  3301. const publicThis = this.proxy;
  3302. const getter = isString(source)
  3303. ? () => publicThis[source]
  3304. : source.bind(publicThis);
  3305. return doWatch(getter, cb.bind(publicThis), options, this);
  3306. }
  3307. function traverse(value, seen = new Set()) {
  3308. if (!isObject(value) || seen.has(value)) {
  3309. return value;
  3310. }
  3311. seen.add(value);
  3312. if (isRef(value)) {
  3313. traverse(value.value, seen);
  3314. }
  3315. else if (isArray(value)) {
  3316. for (let i = 0; i < value.length; i++) {
  3317. traverse(value[i], seen);
  3318. }
  3319. }
  3320. else if (isSet(value) || isMap(value)) {
  3321. value.forEach((v) => {
  3322. traverse(v, seen);
  3323. });
  3324. }
  3325. else {
  3326. for (const key in value) {
  3327. traverse(value[key], seen);
  3328. }
  3329. }
  3330. return value;
  3331. }
  3332. function useTransitionState() {
  3333. const state = {
  3334. isMounted: false,
  3335. isLeaving: false,
  3336. isUnmounting: false,
  3337. leavingVNodes: new Map()
  3338. };
  3339. onMounted(() => {
  3340. state.isMounted = true;
  3341. });
  3342. onBeforeUnmount(() => {
  3343. state.isUnmounting = true;
  3344. });
  3345. return state;
  3346. }
  3347. const TransitionHookValidator = [Function, Array];
  3348. const BaseTransitionImpl = {
  3349. name: `BaseTransition`,
  3350. props: {
  3351. mode: String,
  3352. appear: Boolean,
  3353. persisted: Boolean,
  3354. // enter
  3355. onBeforeEnter: TransitionHookValidator,
  3356. onEnter: TransitionHookValidator,
  3357. onAfterEnter: TransitionHookValidator,
  3358. onEnterCancelled: TransitionHookValidator,
  3359. // leave
  3360. onBeforeLeave: TransitionHookValidator,
  3361. onLeave: TransitionHookValidator,
  3362. onAfterLeave: TransitionHookValidator,
  3363. onLeaveCancelled: TransitionHookValidator,
  3364. // appear
  3365. onBeforeAppear: TransitionHookValidator,
  3366. onAppear: TransitionHookValidator,
  3367. onAfterAppear: TransitionHookValidator,
  3368. onAppearCancelled: TransitionHookValidator
  3369. },
  3370. setup(props, { slots }) {
  3371. const instance = getCurrentInstance();
  3372. const state = useTransitionState();
  3373. let prevTransitionKey;
  3374. return () => {
  3375. const children = slots.default && getTransitionRawChildren(slots.default(), true);
  3376. if (!children || !children.length) {
  3377. return;
  3378. }
  3379. // warn multiple elements
  3380. if (children.length > 1) {
  3381. warn('<transition> can only be used on a single element or component. Use ' +
  3382. '<transition-group> for lists.');
  3383. }
  3384. // there's no need to track reactivity for these props so use the raw
  3385. // props for a bit better perf
  3386. const rawProps = toRaw(props);
  3387. const { mode } = rawProps;
  3388. // check mode
  3389. if (mode && !['in-out', 'out-in', 'default'].includes(mode)) {
  3390. warn(`invalid <transition> mode: ${mode}`);
  3391. }
  3392. // at this point children has a guaranteed length of 1.
  3393. const child = children[0];
  3394. if (state.isLeaving) {
  3395. return emptyPlaceholder(child);
  3396. }
  3397. // in the case of <transition><keep-alive/></transition>, we need to
  3398. // compare the type of the kept-alive children.
  3399. const innerChild = getKeepAliveChild(child);
  3400. if (!innerChild) {
  3401. return emptyPlaceholder(child);
  3402. }
  3403. const enterHooks = resolveTransitionHooks(innerChild, rawProps, state, instance);
  3404. setTransitionHooks(innerChild, enterHooks);
  3405. const oldChild = instance.subTree;
  3406. const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
  3407. let transitionKeyChanged = false;
  3408. const { getTransitionKey } = innerChild.type;
  3409. if (getTransitionKey) {
  3410. const key = getTransitionKey();
  3411. if (prevTransitionKey === undefined) {
  3412. prevTransitionKey = key;
  3413. }
  3414. else if (key !== prevTransitionKey) {
  3415. prevTransitionKey = key;
  3416. transitionKeyChanged = true;
  3417. }
  3418. }
  3419. // handle mode
  3420. if (oldInnerChild &&
  3421. oldInnerChild.type !== Comment &&
  3422. (!isSameVNodeType(innerChild, oldInnerChild) || transitionKeyChanged)) {
  3423. const leavingHooks = resolveTransitionHooks(oldInnerChild, rawProps, state, instance);
  3424. // update old tree's hooks in case of dynamic transition
  3425. setTransitionHooks(oldInnerChild, leavingHooks);
  3426. // switching between different views
  3427. if (mode === 'out-in') {
  3428. state.isLeaving = true;
  3429. // return placeholder node and queue update when leave finishes
  3430. leavingHooks.afterLeave = () => {
  3431. state.isLeaving = false;
  3432. instance.update();
  3433. };
  3434. return emptyPlaceholder(child);
  3435. }
  3436. else if (mode === 'in-out') {
  3437. leavingHooks.delayLeave = (el, earlyRemove, delayedLeave) => {
  3438. const leavingVNodesCache = getLeavingNodesForType(state, oldInnerChild);
  3439. leavingVNodesCache[String(oldInnerChild.key)] = oldInnerChild;
  3440. // early removal callback
  3441. el._leaveCb = () => {
  3442. earlyRemove();
  3443. el._leaveCb = undefined;
  3444. delete enterHooks.delayedLeave;
  3445. };
  3446. enterHooks.delayedLeave = delayedLeave;
  3447. };
  3448. }
  3449. }
  3450. return child;
  3451. };
  3452. }
  3453. };
  3454. // export the public type for h/tsx inference
  3455. // also to avoid inline import() in generated d.ts files
  3456. const BaseTransition = BaseTransitionImpl;
  3457. function getLeavingNodesForType(state, vnode) {
  3458. const { leavingVNodes } = state;
  3459. let leavingVNodesCache = leavingVNodes.get(vnode.type);
  3460. if (!leavingVNodesCache) {
  3461. leavingVNodesCache = Object.create(null);
  3462. leavingVNodes.set(vnode.type, leavingVNodesCache);
  3463. }
  3464. return leavingVNodesCache;
  3465. }
  3466. // The transition hooks are attached to the vnode as vnode.transition
  3467. // and will be called at appropriate timing in the renderer.
  3468. function resolveTransitionHooks(vnode, props, state, instance) {
  3469. const { appear, mode, persisted = false, onBeforeEnter, onEnter, onAfterEnter, onEnterCancelled, onBeforeLeave, onLeave, onAfterLeave, onLeaveCancelled, onBeforeAppear, onAppear, onAfterAppear, onAppearCancelled } = props;
  3470. const key = String(vnode.key);
  3471. const leavingVNodesCache = getLeavingNodesForType(state, vnode);
  3472. const callHook = (hook, args) => {
  3473. hook &&
  3474. callWithAsyncErrorHandling(hook, instance, 9 /* TRANSITION_HOOK */, args);
  3475. };
  3476. const hooks = {
  3477. mode,
  3478. persisted,
  3479. beforeEnter(el) {
  3480. let hook = onBeforeEnter;
  3481. if (!state.isMounted) {
  3482. if (appear) {
  3483. hook = onBeforeAppear || onBeforeEnter;
  3484. }
  3485. else {
  3486. return;
  3487. }
  3488. }
  3489. // for same element (v-show)
  3490. if (el._leaveCb) {
  3491. el._leaveCb(true /* cancelled */);
  3492. }
  3493. // for toggled element with same key (v-if)
  3494. const leavingVNode = leavingVNodesCache[key];
  3495. if (leavingVNode &&
  3496. isSameVNodeType(vnode, leavingVNode) &&
  3497. leavingVNode.el._leaveCb) {
  3498. // force early removal (not cancelled)
  3499. leavingVNode.el._leaveCb();
  3500. }
  3501. callHook(hook, [el]);
  3502. },
  3503. enter(el) {
  3504. let hook = onEnter;
  3505. let afterHook = onAfterEnter;
  3506. let cancelHook = onEnterCancelled;
  3507. if (!state.isMounted) {
  3508. if (appear) {
  3509. hook = onAppear || onEnter;
  3510. afterHook = onAfterAppear || onAfterEnter;
  3511. cancelHook = onAppearCancelled || onEnterCancelled;
  3512. }
  3513. else {
  3514. return;
  3515. }
  3516. }
  3517. let called = false;
  3518. const done = (el._enterCb = (cancelled) => {
  3519. if (called)
  3520. return;
  3521. called = true;
  3522. if (cancelled) {
  3523. callHook(cancelHook, [el]);
  3524. }
  3525. else {
  3526. callHook(afterHook, [el]);
  3527. }
  3528. if (hooks.delayedLeave) {
  3529. hooks.delayedLeave();
  3530. }
  3531. el._enterCb = undefined;
  3532. });
  3533. if (hook) {
  3534. hook(el, done);
  3535. if (hook.length <= 1) {
  3536. done();
  3537. }
  3538. }
  3539. else {
  3540. done();
  3541. }
  3542. },
  3543. leave(el, remove) {
  3544. const key = String(vnode.key);
  3545. if (el._enterCb) {
  3546. el._enterCb(true /* cancelled */);
  3547. }
  3548. if (state.isUnmounting) {
  3549. return remove();
  3550. }
  3551. callHook(onBeforeLeave, [el]);
  3552. let called = false;
  3553. const done = (el._leaveCb = (cancelled) => {
  3554. if (called)
  3555. return;
  3556. called = true;
  3557. remove();
  3558. if (cancelled) {
  3559. callHook(onLeaveCancelled, [el]);
  3560. }
  3561. else {
  3562. callHook(onAfterLeave, [el]);
  3563. }
  3564. el._leaveCb = undefined;
  3565. if (leavingVNodesCache[key] === vnode) {
  3566. delete leavingVNodesCache[key];
  3567. }
  3568. });
  3569. leavingVNodesCache[key] = vnode;
  3570. if (onLeave) {
  3571. onLeave(el, done);
  3572. if (onLeave.length <= 1) {
  3573. done();
  3574. }
  3575. }
  3576. else {
  3577. done();
  3578. }
  3579. },
  3580. clone(vnode) {
  3581. return resolveTransitionHooks(vnode, props, state, instance);
  3582. }
  3583. };
  3584. return hooks;
  3585. }
  3586. // the placeholder really only handles one special case: KeepAlive
  3587. // in the case of a KeepAlive in a leave phase we need to return a KeepAlive
  3588. // placeholder with empty content to avoid the KeepAlive instance from being
  3589. // unmounted.
  3590. function emptyPlaceholder(vnode) {
  3591. if (isKeepAlive(vnode)) {
  3592. vnode = cloneVNode(vnode);
  3593. vnode.children = null;
  3594. return vnode;
  3595. }
  3596. }
  3597. function getKeepAliveChild(vnode) {
  3598. return isKeepAlive(vnode)
  3599. ? vnode.children
  3600. ? vnode.children[0]
  3601. : undefined
  3602. : vnode;
  3603. }
  3604. function setTransitionHooks(vnode, hooks) {
  3605. if (vnode.shapeFlag & 6 /* COMPONENT */ && vnode.component) {
  3606. setTransitionHooks(vnode.component.subTree, hooks);
  3607. }
  3608. else if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  3609. vnode.ssContent.transition = hooks.clone(vnode.ssContent);
  3610. vnode.ssFallback.transition = hooks.clone(vnode.ssFallback);
  3611. }
  3612. else {
  3613. vnode.transition = hooks;
  3614. }
  3615. }
  3616. function getTransitionRawChildren(children, keepComment = false) {
  3617. let ret = [];
  3618. let keyedFragmentCount = 0;
  3619. for (let i = 0; i < children.length; i++) {
  3620. const child = children[i];
  3621. // handle fragment children case, e.g. v-for
  3622. if (child.type === Fragment) {
  3623. if (child.patchFlag & 128 /* KEYED_FRAGMENT */)
  3624. keyedFragmentCount++;
  3625. ret = ret.concat(getTransitionRawChildren(child.children, keepComment));
  3626. }
  3627. // comment placeholders should be skipped, e.g. v-if
  3628. else if (keepComment || child.type !== Comment) {
  3629. ret.push(child);
  3630. }
  3631. }
  3632. // #1126 if a transition children list contains multiple sub fragments, these
  3633. // fragments will be merged into a flat children array. Since each v-for
  3634. // fragment may contain different static bindings inside, we need to de-op
  3635. // these children to force full diffs to ensure correct behavior.
  3636. if (keyedFragmentCount > 1) {
  3637. for (let i = 0; i < ret.length; i++) {
  3638. ret[i].patchFlag = -2 /* BAIL */;
  3639. }
  3640. }
  3641. return ret;
  3642. }
  3643. const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
  3644. const KeepAliveImpl = {
  3645. name: `KeepAlive`,
  3646. // Marker for special handling inside the renderer. We are not using a ===
  3647. // check directly on KeepAlive in the renderer, because importing it directly
  3648. // would prevent it from being tree-shaken.
  3649. __isKeepAlive: true,
  3650. props: {
  3651. include: [String, RegExp, Array],
  3652. exclude: [String, RegExp, Array],
  3653. max: [String, Number]
  3654. },
  3655. setup(props, { slots }) {
  3656. const cache = new Map();
  3657. const keys = new Set();
  3658. let current = null;
  3659. const instance = getCurrentInstance();
  3660. const parentSuspense = instance.suspense;
  3661. // KeepAlive communicates with the instantiated renderer via the
  3662. // ctx where the renderer passes in its internals,
  3663. // and the KeepAlive instance exposes activate/deactivate implementations.
  3664. // The whole point of this is to avoid importing KeepAlive directly in the
  3665. // renderer to facilitate tree-shaking.
  3666. const sharedContext = instance.ctx;
  3667. const { renderer: { p: patch, m: move, um: _unmount, o: { createElement } } } = sharedContext;
  3668. const storageContainer = createElement('div');
  3669. sharedContext.activate = (vnode, container, anchor, isSVG, optimized) => {
  3670. const instance = vnode.component;
  3671. move(vnode, container, anchor, 0 /* ENTER */, parentSuspense);
  3672. // in case props have changed
  3673. patch(instance.vnode, vnode, container, anchor, instance, parentSuspense, isSVG, optimized);
  3674. queuePostRenderEffect(() => {
  3675. instance.isDeactivated = false;
  3676. if (instance.a) {
  3677. invokeArrayFns(instance.a);
  3678. }
  3679. const vnodeHook = vnode.props && vnode.props.onVnodeMounted;
  3680. if (vnodeHook) {
  3681. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3682. }
  3683. }, parentSuspense);
  3684. };
  3685. sharedContext.deactivate = (vnode) => {
  3686. const instance = vnode.component;
  3687. move(vnode, storageContainer, null, 1 /* LEAVE */, parentSuspense);
  3688. queuePostRenderEffect(() => {
  3689. if (instance.da) {
  3690. invokeArrayFns(instance.da);
  3691. }
  3692. const vnodeHook = vnode.props && vnode.props.onVnodeUnmounted;
  3693. if (vnodeHook) {
  3694. invokeVNodeHook(vnodeHook, instance.parent, vnode);
  3695. }
  3696. instance.isDeactivated = true;
  3697. }, parentSuspense);
  3698. };
  3699. function unmount(vnode) {
  3700. // reset the shapeFlag so it can be properly unmounted
  3701. resetShapeFlag(vnode);
  3702. _unmount(vnode, instance, parentSuspense);
  3703. }
  3704. function pruneCache(filter) {
  3705. cache.forEach((vnode, key) => {
  3706. const name = getComponentName(vnode.type);
  3707. if (name && (!filter || !filter(name))) {
  3708. pruneCacheEntry(key);
  3709. }
  3710. });
  3711. }
  3712. function pruneCacheEntry(key) {
  3713. const cached = cache.get(key);
  3714. if (!current || cached.type !== current.type) {
  3715. unmount(cached);
  3716. }
  3717. else if (current) {
  3718. // current active instance should no longer be kept-alive.
  3719. // we can't unmount it now but it might be later, so reset its flag now.
  3720. resetShapeFlag(current);
  3721. }
  3722. cache.delete(key);
  3723. keys.delete(key);
  3724. }
  3725. // prune cache on include/exclude prop change
  3726. watch(() => [props.include, props.exclude], ([include, exclude]) => {
  3727. include && pruneCache(name => matches(include, name));
  3728. exclude && pruneCache(name => !matches(exclude, name));
  3729. },
  3730. // prune post-render after `current` has been updated
  3731. { flush: 'post', deep: true });
  3732. // cache sub tree after render
  3733. let pendingCacheKey = null;
  3734. const cacheSubtree = () => {
  3735. // fix #1621, the pendingCacheKey could be 0
  3736. if (pendingCacheKey != null) {
  3737. cache.set(pendingCacheKey, getInnerChild(instance.subTree));
  3738. }
  3739. };
  3740. onMounted(cacheSubtree);
  3741. onUpdated(cacheSubtree);
  3742. onBeforeUnmount(() => {
  3743. cache.forEach(cached => {
  3744. const { subTree, suspense } = instance;
  3745. const vnode = getInnerChild(subTree);
  3746. if (cached.type === vnode.type) {
  3747. // current instance will be unmounted as part of keep-alive's unmount
  3748. resetShapeFlag(vnode);
  3749. // but invoke its deactivated hook here
  3750. const da = vnode.component.da;
  3751. da && queuePostRenderEffect(da, suspense);
  3752. return;
  3753. }
  3754. unmount(cached);
  3755. });
  3756. });
  3757. return () => {
  3758. pendingCacheKey = null;
  3759. if (!slots.default) {
  3760. return null;
  3761. }
  3762. const children = slots.default();
  3763. const rawVNode = children[0];
  3764. if (children.length > 1) {
  3765. {
  3766. warn(`KeepAlive should contain exactly one component child.`);
  3767. }
  3768. current = null;
  3769. return children;
  3770. }
  3771. else if (!isVNode(rawVNode) ||
  3772. (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&
  3773. !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {
  3774. current = null;
  3775. return rawVNode;
  3776. }
  3777. let vnode = getInnerChild(rawVNode);
  3778. const comp = vnode.type;
  3779. const name = getComponentName(comp);
  3780. const { include, exclude, max } = props;
  3781. if ((include && (!name || !matches(include, name))) ||
  3782. (exclude && name && matches(exclude, name))) {
  3783. current = vnode;
  3784. return rawVNode;
  3785. }
  3786. const key = vnode.key == null ? comp : vnode.key;
  3787. const cachedVNode = cache.get(key);
  3788. // clone vnode if it's reused because we are going to mutate it
  3789. if (vnode.el) {
  3790. vnode = cloneVNode(vnode);
  3791. if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {
  3792. rawVNode.ssContent = vnode;
  3793. }
  3794. }
  3795. // #1513 it's possible for the returned vnode to be cloned due to attr
  3796. // fallthrough or scopeId, so the vnode here may not be the final vnode
  3797. // that is mounted. Instead of caching it directly, we store the pending
  3798. // key and cache `instance.subTree` (the normalized vnode) in
  3799. // beforeMount/beforeUpdate hooks.
  3800. pendingCacheKey = key;
  3801. if (cachedVNode) {
  3802. // copy over mounted state
  3803. vnode.el = cachedVNode.el;
  3804. vnode.component = cachedVNode.component;
  3805. if (vnode.transition) {
  3806. // recursively update transition hooks on subTree
  3807. setTransitionHooks(vnode, vnode.transition);
  3808. }
  3809. // avoid vnode being mounted as fresh
  3810. vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;
  3811. // make this key the freshest
  3812. keys.delete(key);
  3813. keys.add(key);
  3814. }
  3815. else {
  3816. keys.add(key);
  3817. // prune oldest entry
  3818. if (max && keys.size > parseInt(max, 10)) {
  3819. pruneCacheEntry(keys.values().next().value);
  3820. }
  3821. }
  3822. // avoid vnode being unmounted
  3823. vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  3824. current = vnode;
  3825. return rawVNode;
  3826. };
  3827. }
  3828. };
  3829. // export the public type for h/tsx inference
  3830. // also to avoid inline import() in generated d.ts files
  3831. const KeepAlive = KeepAliveImpl;
  3832. function matches(pattern, name) {
  3833. if (isArray(pattern)) {
  3834. return pattern.some((p) => matches(p, name));
  3835. }
  3836. else if (isString(pattern)) {
  3837. return pattern.split(',').indexOf(name) > -1;
  3838. }
  3839. else if (pattern.test) {
  3840. return pattern.test(name);
  3841. }
  3842. /* istanbul ignore next */
  3843. return false;
  3844. }
  3845. function onActivated(hook, target) {
  3846. registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
  3847. }
  3848. function onDeactivated(hook, target) {
  3849. registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);
  3850. }
  3851. function registerKeepAliveHook(hook, type, target = currentInstance) {
  3852. // cache the deactivate branch check wrapper for injected hooks so the same
  3853. // hook can be properly deduped by the scheduler. "__wdc" stands for "with
  3854. // deactivation check".
  3855. const wrappedHook = hook.__wdc ||
  3856. (hook.__wdc = () => {
  3857. // only fire the hook if the target instance is NOT in a deactivated branch.
  3858. let current = target;
  3859. while (current) {
  3860. if (current.isDeactivated) {
  3861. return;
  3862. }
  3863. current = current.parent;
  3864. }
  3865. hook();
  3866. });
  3867. injectHook(type, wrappedHook, target);
  3868. // In addition to registering it on the target instance, we walk up the parent
  3869. // chain and register it on all ancestor instances that are keep-alive roots.
  3870. // This avoids the need to walk the entire component tree when invoking these
  3871. // hooks, and more importantly, avoids the need to track child components in
  3872. // arrays.
  3873. if (target) {
  3874. let current = target.parent;
  3875. while (current && current.parent) {
  3876. if (isKeepAlive(current.parent.vnode)) {
  3877. injectToKeepAliveRoot(wrappedHook, type, target, current);
  3878. }
  3879. current = current.parent;
  3880. }
  3881. }
  3882. }
  3883. function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
  3884. // injectHook wraps the original for error handling, so make sure to remove
  3885. // the wrapped version.
  3886. const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);
  3887. onUnmounted(() => {
  3888. remove(keepAliveRoot[type], injected);
  3889. }, target);
  3890. }
  3891. function resetShapeFlag(vnode) {
  3892. let shapeFlag = vnode.shapeFlag;
  3893. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  3894. shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;
  3895. }
  3896. if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  3897. shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;
  3898. }
  3899. vnode.shapeFlag = shapeFlag;
  3900. }
  3901. function getInnerChild(vnode) {
  3902. return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;
  3903. }
  3904. const isInternalKey = (key) => key[0] === '_' || key === '$stable';
  3905. const normalizeSlotValue = (value) => isArray(value)
  3906. ? value.map(normalizeVNode)
  3907. : [normalizeVNode(value)];
  3908. const normalizeSlot = (key, rawSlot, ctx) => withCtx((props) => {
  3909. if (currentInstance) {
  3910. warn(`Slot "${key}" invoked outside of the render function: ` +
  3911. `this will not track dependencies used in the slot. ` +
  3912. `Invoke the slot function inside the render function instead.`);
  3913. }
  3914. return normalizeSlotValue(rawSlot(props));
  3915. }, ctx);
  3916. const normalizeObjectSlots = (rawSlots, slots) => {
  3917. const ctx = rawSlots._ctx;
  3918. for (const key in rawSlots) {
  3919. if (isInternalKey(key))
  3920. continue;
  3921. const value = rawSlots[key];
  3922. if (isFunction(value)) {
  3923. slots[key] = normalizeSlot(key, value, ctx);
  3924. }
  3925. else if (value != null) {
  3926. {
  3927. warn(`Non-function value encountered for slot "${key}". ` +
  3928. `Prefer function slots for better performance.`);
  3929. }
  3930. const normalized = normalizeSlotValue(value);
  3931. slots[key] = () => normalized;
  3932. }
  3933. }
  3934. };
  3935. const normalizeVNodeSlots = (instance, children) => {
  3936. if (!isKeepAlive(instance.vnode)) {
  3937. warn(`Non-function value encountered for default slot. ` +
  3938. `Prefer function slots for better performance.`);
  3939. }
  3940. const normalized = normalizeSlotValue(children);
  3941. instance.slots.default = () => normalized;
  3942. };
  3943. const initSlots = (instance, children) => {
  3944. if (instance.vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  3945. const type = children._;
  3946. if (type) {
  3947. instance.slots = children;
  3948. // make compiler marker non-enumerable
  3949. def(children, '_', type);
  3950. }
  3951. else {
  3952. normalizeObjectSlots(children, (instance.slots = {}));
  3953. }
  3954. }
  3955. else {
  3956. instance.slots = {};
  3957. if (children) {
  3958. normalizeVNodeSlots(instance, children);
  3959. }
  3960. }
  3961. def(instance.slots, InternalObjectKey, 1);
  3962. };
  3963. const updateSlots = (instance, children) => {
  3964. const { vnode, slots } = instance;
  3965. let needDeletionCheck = true;
  3966. let deletionComparisonTarget = EMPTY_OBJ;
  3967. if (vnode.shapeFlag & 32 /* SLOTS_CHILDREN */) {
  3968. const type = children._;
  3969. if (type) {
  3970. // compiled slots.
  3971. if (isHmrUpdating) {
  3972. // Parent was HMR updated so slot content may have changed.
  3973. // force update slots and mark instance for hmr as well
  3974. extend(slots, children);
  3975. }
  3976. else if (type === 1 /* STABLE */) {
  3977. // compiled AND stable.
  3978. // no need to update, and skip stale slots removal.
  3979. needDeletionCheck = false;
  3980. }
  3981. else {
  3982. // compiled but dynamic (v-if/v-for on slots) - update slots, but skip
  3983. // normalization.
  3984. extend(slots, children);
  3985. }
  3986. }
  3987. else {
  3988. needDeletionCheck = !children.$stable;
  3989. normalizeObjectSlots(children, slots);
  3990. }
  3991. deletionComparisonTarget = children;
  3992. }
  3993. else if (children) {
  3994. // non slot object children (direct value) passed to a component
  3995. normalizeVNodeSlots(instance, children);
  3996. deletionComparisonTarget = { default: 1 };
  3997. }
  3998. // delete stale slots
  3999. if (needDeletionCheck) {
  4000. for (const key in slots) {
  4001. if (!isInternalKey(key) && !(key in deletionComparisonTarget)) {
  4002. delete slots[key];
  4003. }
  4004. }
  4005. }
  4006. };
  4007. /**
  4008. Runtime helper for applying directives to a vnode. Example usage:
  4009. const comp = resolveComponent('comp')
  4010. const foo = resolveDirective('foo')
  4011. const bar = resolveDirective('bar')
  4012. return withDirectives(h(comp), [
  4013. [foo, this.x],
  4014. [bar, this.y]
  4015. ])
  4016. */
  4017. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text');
  4018. function validateDirectiveName(name) {
  4019. if (isBuiltInDirective(name)) {
  4020. warn('Do not use built-in directive ids as custom directive id: ' + name);
  4021. }
  4022. }
  4023. /**
  4024. * Adds directives to a VNode.
  4025. */
  4026. function withDirectives(vnode, directives) {
  4027. const internalInstance = currentRenderingInstance;
  4028. if (internalInstance === null) {
  4029. warn(`withDirectives can only be used inside render functions.`);
  4030. return vnode;
  4031. }
  4032. const instance = internalInstance.proxy;
  4033. const bindings = vnode.dirs || (vnode.dirs = []);
  4034. for (let i = 0; i < directives.length; i++) {
  4035. let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];
  4036. if (isFunction(dir)) {
  4037. dir = {
  4038. mounted: dir,
  4039. updated: dir
  4040. };
  4041. }
  4042. bindings.push({
  4043. dir,
  4044. instance,
  4045. value,
  4046. oldValue: void 0,
  4047. arg,
  4048. modifiers
  4049. });
  4050. }
  4051. return vnode;
  4052. }
  4053. function invokeDirectiveHook(vnode, prevVNode, instance, name) {
  4054. const bindings = vnode.dirs;
  4055. const oldBindings = prevVNode && prevVNode.dirs;
  4056. for (let i = 0; i < bindings.length; i++) {
  4057. const binding = bindings[i];
  4058. if (oldBindings) {
  4059. binding.oldValue = oldBindings[i].value;
  4060. }
  4061. const hook = binding.dir[name];
  4062. if (hook) {
  4063. callWithAsyncErrorHandling(hook, instance, 8 /* DIRECTIVE_HOOK */, [
  4064. vnode.el,
  4065. binding,
  4066. vnode,
  4067. prevVNode
  4068. ]);
  4069. }
  4070. }
  4071. }
  4072. function createAppContext() {
  4073. return {
  4074. app: null,
  4075. config: {
  4076. isNativeTag: NO,
  4077. performance: false,
  4078. globalProperties: {},
  4079. optionMergeStrategies: {},
  4080. isCustomElement: NO,
  4081. errorHandler: undefined,
  4082. warnHandler: undefined
  4083. },
  4084. mixins: [],
  4085. components: {},
  4086. directives: {},
  4087. provides: Object.create(null)
  4088. };
  4089. }
  4090. let uid$1 = 0;
  4091. function createAppAPI(render, hydrate) {
  4092. return function createApp(rootComponent, rootProps = null) {
  4093. if (rootProps != null && !isObject(rootProps)) {
  4094. warn(`root props passed to app.mount() must be an object.`);
  4095. rootProps = null;
  4096. }
  4097. const context = createAppContext();
  4098. const installedPlugins = new Set();
  4099. let isMounted = false;
  4100. const app = (context.app = {
  4101. _uid: uid$1++,
  4102. _component: rootComponent,
  4103. _props: rootProps,
  4104. _container: null,
  4105. _context: context,
  4106. version,
  4107. get config() {
  4108. return context.config;
  4109. },
  4110. set config(v) {
  4111. {
  4112. warn(`app.config cannot be replaced. Modify individual options instead.`);
  4113. }
  4114. },
  4115. use(plugin, ...options) {
  4116. if (installedPlugins.has(plugin)) {
  4117. warn(`Plugin has already been applied to target app.`);
  4118. }
  4119. else if (plugin && isFunction(plugin.install)) {
  4120. installedPlugins.add(plugin);
  4121. plugin.install(app, ...options);
  4122. }
  4123. else if (isFunction(plugin)) {
  4124. installedPlugins.add(plugin);
  4125. plugin(app, ...options);
  4126. }
  4127. else {
  4128. warn(`A plugin must either be a function or an object with an "install" ` +
  4129. `function.`);
  4130. }
  4131. return app;
  4132. },
  4133. mixin(mixin) {
  4134. {
  4135. if (!context.mixins.includes(mixin)) {
  4136. context.mixins.push(mixin);
  4137. // global mixin with props/emits de-optimizes props/emits
  4138. // normalization caching.
  4139. if (mixin.props || mixin.emits) {
  4140. context.deopt = true;
  4141. }
  4142. }
  4143. else {
  4144. warn('Mixin has already been applied to target app' +
  4145. (mixin.name ? `: ${mixin.name}` : ''));
  4146. }
  4147. }
  4148. return app;
  4149. },
  4150. component(name, component) {
  4151. {
  4152. validateComponentName(name, context.config);
  4153. }
  4154. if (!component) {
  4155. return context.components[name];
  4156. }
  4157. if (context.components[name]) {
  4158. warn(`Component "${name}" has already been registered in target app.`);
  4159. }
  4160. context.components[name] = component;
  4161. return app;
  4162. },
  4163. directive(name, directive) {
  4164. {
  4165. validateDirectiveName(name);
  4166. }
  4167. if (!directive) {
  4168. return context.directives[name];
  4169. }
  4170. if (context.directives[name]) {
  4171. warn(`Directive "${name}" has already been registered in target app.`);
  4172. }
  4173. context.directives[name] = directive;
  4174. return app;
  4175. },
  4176. mount(rootContainer, isHydrate) {
  4177. if (!isMounted) {
  4178. const vnode = createVNode(rootComponent, rootProps);
  4179. // store app context on the root VNode.
  4180. // this will be set on the root instance on initial mount.
  4181. vnode.appContext = context;
  4182. // HMR root reload
  4183. {
  4184. context.reload = () => {
  4185. render(cloneVNode(vnode), rootContainer);
  4186. };
  4187. }
  4188. if (isHydrate && hydrate) {
  4189. hydrate(vnode, rootContainer);
  4190. }
  4191. else {
  4192. render(vnode, rootContainer);
  4193. }
  4194. isMounted = true;
  4195. app._container = rootContainer;
  4196. rootContainer.__vue_app__ = app;
  4197. {
  4198. devtoolsInitApp(app, version);
  4199. }
  4200. return vnode.component.proxy;
  4201. }
  4202. else {
  4203. warn(`App has already been mounted.\n` +
  4204. `If you want to remount the same app, move your app creation logic ` +
  4205. `into a factory function and create fresh app instances for each ` +
  4206. `mount - e.g. \`const createMyApp = () => createApp(App)\``);
  4207. }
  4208. },
  4209. unmount() {
  4210. if (isMounted) {
  4211. render(null, app._container);
  4212. {
  4213. devtoolsUnmountApp(app);
  4214. }
  4215. delete app._container.__vue_app__;
  4216. }
  4217. else {
  4218. warn(`Cannot unmount an app that is not mounted.`);
  4219. }
  4220. },
  4221. provide(key, value) {
  4222. if (key in context.provides) {
  4223. warn(`App already provides property with key "${String(key)}". ` +
  4224. `It will be overwritten with the new value.`);
  4225. }
  4226. // TypeScript doesn't allow symbols as index type
  4227. // https://github.com/Microsoft/TypeScript/issues/24587
  4228. context.provides[key] = value;
  4229. return app;
  4230. }
  4231. });
  4232. return app;
  4233. };
  4234. }
  4235. let hasMismatch = false;
  4236. const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
  4237. const isComment = (node) => node.nodeType === 8 /* COMMENT */;
  4238. // Note: hydration is DOM-specific
  4239. // But we have to place it in core due to tight coupling with core - splitting
  4240. // it out creates a ton of unnecessary complexity.
  4241. // Hydration also depends on some renderer internal logic which needs to be
  4242. // passed in via arguments.
  4243. function createHydrationFunctions(rendererInternals) {
  4244. const { mt: mountComponent, p: patch, o: { patchProp, nextSibling, parentNode, remove, insert, createComment } } = rendererInternals;
  4245. const hydrate = (vnode, container) => {
  4246. if (!container.hasChildNodes()) {
  4247. warn(`Attempting to hydrate existing markup but container is empty. ` +
  4248. `Performing full mount instead.`);
  4249. patch(null, vnode, container);
  4250. return;
  4251. }
  4252. hasMismatch = false;
  4253. hydrateNode(container.firstChild, vnode, null, null);
  4254. flushPostFlushCbs();
  4255. if (hasMismatch && !false) {
  4256. // this error should show up in production
  4257. console.error(`Hydration completed but contains mismatches.`);
  4258. }
  4259. };
  4260. const hydrateNode = (node, vnode, parentComponent, parentSuspense, optimized = false) => {
  4261. const isFragmentStart = isComment(node) && node.data === '[';
  4262. const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, isFragmentStart);
  4263. const { type, ref, shapeFlag } = vnode;
  4264. const domType = node.nodeType;
  4265. vnode.el = node;
  4266. let nextNode = null;
  4267. switch (type) {
  4268. case Text:
  4269. if (domType !== 3 /* TEXT */) {
  4270. nextNode = onMismatch();
  4271. }
  4272. else {
  4273. if (node.data !== vnode.children) {
  4274. hasMismatch = true;
  4275. warn(`Hydration text mismatch:` +
  4276. `\n- Client: ${JSON.stringify(node.data)}` +
  4277. `\n- Server: ${JSON.stringify(vnode.children)}`);
  4278. node.data = vnode.children;
  4279. }
  4280. nextNode = nextSibling(node);
  4281. }
  4282. break;
  4283. case Comment:
  4284. if (domType !== 8 /* COMMENT */ || isFragmentStart) {
  4285. nextNode = onMismatch();
  4286. }
  4287. else {
  4288. nextNode = nextSibling(node);
  4289. }
  4290. break;
  4291. case Static:
  4292. if (domType !== 1 /* ELEMENT */) {
  4293. nextNode = onMismatch();
  4294. }
  4295. else {
  4296. // determine anchor, adopt content
  4297. nextNode = node;
  4298. // if the static vnode has its content stripped during build,
  4299. // adopt it from the server-rendered HTML.
  4300. const needToAdoptContent = !vnode.children.length;
  4301. for (let i = 0; i < vnode.staticCount; i++) {
  4302. if (needToAdoptContent)
  4303. vnode.children += nextNode.outerHTML;
  4304. if (i === vnode.staticCount - 1) {
  4305. vnode.anchor = nextNode;
  4306. }
  4307. nextNode = nextSibling(nextNode);
  4308. }
  4309. return nextNode;
  4310. }
  4311. break;
  4312. case Fragment:
  4313. if (!isFragmentStart) {
  4314. nextNode = onMismatch();
  4315. }
  4316. else {
  4317. nextNode = hydrateFragment(node, vnode, parentComponent, parentSuspense, optimized);
  4318. }
  4319. break;
  4320. default:
  4321. if (shapeFlag & 1 /* ELEMENT */) {
  4322. if (domType !== 1 /* ELEMENT */ ||
  4323. vnode.type !== node.tagName.toLowerCase()) {
  4324. nextNode = onMismatch();
  4325. }
  4326. else {
  4327. nextNode = hydrateElement(node, vnode, parentComponent, parentSuspense, optimized);
  4328. }
  4329. }
  4330. else if (shapeFlag & 6 /* COMPONENT */) {
  4331. // when setting up the render effect, if the initial vnode already
  4332. // has .el set, the component will perform hydration instead of mount
  4333. // on its sub-tree.
  4334. const container = parentNode(node);
  4335. const hydrateComponent = () => {
  4336. mountComponent(vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container), optimized);
  4337. };
  4338. // async component
  4339. const loadAsync = vnode.type.__asyncLoader;
  4340. if (loadAsync) {
  4341. loadAsync().then(hydrateComponent);
  4342. }
  4343. else {
  4344. hydrateComponent();
  4345. }
  4346. // component may be async, so in the case of fragments we cannot rely
  4347. // on component's rendered output to determine the end of the fragment
  4348. // instead, we do a lookahead to find the end anchor node.
  4349. nextNode = isFragmentStart
  4350. ? locateClosingAsyncAnchor(node)
  4351. : nextSibling(node);
  4352. }
  4353. else if (shapeFlag & 64 /* TELEPORT */) {
  4354. if (domType !== 8 /* COMMENT */) {
  4355. nextNode = onMismatch();
  4356. }
  4357. else {
  4358. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, optimized, rendererInternals, hydrateChildren);
  4359. }
  4360. }
  4361. else if (shapeFlag & 128 /* SUSPENSE */) {
  4362. nextNode = vnode.type.hydrate(node, vnode, parentComponent, parentSuspense, isSVGContainer(parentNode(node)), optimized, rendererInternals, hydrateNode);
  4363. }
  4364. else {
  4365. warn('Invalid HostVNode type:', type, `(${typeof type})`);
  4366. }
  4367. }
  4368. if (ref != null) {
  4369. setRef(ref, null, parentSuspense, vnode);
  4370. }
  4371. return nextNode;
  4372. };
  4373. const hydrateElement = (el, vnode, parentComponent, parentSuspense, optimized) => {
  4374. optimized = optimized || !!vnode.dynamicChildren;
  4375. const { props, patchFlag, shapeFlag, dirs } = vnode;
  4376. // skip props & children if this is hoisted static nodes
  4377. if (patchFlag !== -1 /* HOISTED */) {
  4378. if (dirs) {
  4379. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  4380. }
  4381. // props
  4382. if (props) {
  4383. if (!optimized ||
  4384. (patchFlag & 16 /* FULL_PROPS */ ||
  4385. patchFlag & 32 /* HYDRATE_EVENTS */)) {
  4386. for (const key in props) {
  4387. if (!isReservedProp(key) && isOn(key)) {
  4388. patchProp(el, key, null, props[key]);
  4389. }
  4390. }
  4391. }
  4392. else if (props.onClick) {
  4393. // Fast path for click listeners (which is most often) to avoid
  4394. // iterating through props.
  4395. patchProp(el, 'onClick', null, props.onClick);
  4396. }
  4397. }
  4398. // vnode / directive hooks
  4399. let vnodeHooks;
  4400. if ((vnodeHooks = props && props.onVnodeBeforeMount)) {
  4401. invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4402. }
  4403. if (dirs) {
  4404. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  4405. }
  4406. if ((vnodeHooks = props && props.onVnodeMounted) || dirs) {
  4407. queueEffectWithSuspense(() => {
  4408. vnodeHooks && invokeVNodeHook(vnodeHooks, parentComponent, vnode);
  4409. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  4410. }, parentSuspense);
  4411. }
  4412. // children
  4413. if (shapeFlag & 16 /* ARRAY_CHILDREN */ &&
  4414. // skip if element has innerHTML / textContent
  4415. !(props && (props.innerHTML || props.textContent))) {
  4416. let next = hydrateChildren(el.firstChild, vnode, el, parentComponent, parentSuspense, optimized);
  4417. let hasWarned = false;
  4418. while (next) {
  4419. hasMismatch = true;
  4420. if (!hasWarned) {
  4421. warn(`Hydration children mismatch in <${vnode.type}>: ` +
  4422. `server rendered element contains more child nodes than client vdom.`);
  4423. hasWarned = true;
  4424. }
  4425. // The SSRed DOM contains more nodes than it should. Remove them.
  4426. const cur = next;
  4427. next = next.nextSibling;
  4428. remove(cur);
  4429. }
  4430. }
  4431. else if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  4432. if (el.textContent !== vnode.children) {
  4433. hasMismatch = true;
  4434. warn(`Hydration text content mismatch in <${vnode.type}>:\n` +
  4435. `- Client: ${el.textContent}\n` +
  4436. `- Server: ${vnode.children}`);
  4437. el.textContent = vnode.children;
  4438. }
  4439. }
  4440. }
  4441. return el.nextSibling;
  4442. };
  4443. const hydrateChildren = (node, parentVNode, container, parentComponent, parentSuspense, optimized) => {
  4444. optimized = optimized || !!parentVNode.dynamicChildren;
  4445. const children = parentVNode.children;
  4446. const l = children.length;
  4447. let hasWarned = false;
  4448. for (let i = 0; i < l; i++) {
  4449. const vnode = optimized
  4450. ? children[i]
  4451. : (children[i] = normalizeVNode(children[i]));
  4452. if (node) {
  4453. node = hydrateNode(node, vnode, parentComponent, parentSuspense, optimized);
  4454. }
  4455. else {
  4456. hasMismatch = true;
  4457. if (!hasWarned) {
  4458. warn(`Hydration children mismatch in <${container.tagName.toLowerCase()}>: ` +
  4459. `server rendered element contains fewer child nodes than client vdom.`);
  4460. hasWarned = true;
  4461. }
  4462. // the SSRed DOM didn't contain enough nodes. Mount the missing ones.
  4463. patch(null, vnode, container, null, parentComponent, parentSuspense, isSVGContainer(container));
  4464. }
  4465. }
  4466. return node;
  4467. };
  4468. const hydrateFragment = (node, vnode, parentComponent, parentSuspense, optimized) => {
  4469. const container = parentNode(node);
  4470. const next = hydrateChildren(nextSibling(node), vnode, container, parentComponent, parentSuspense, optimized);
  4471. if (next && isComment(next) && next.data === ']') {
  4472. return nextSibling((vnode.anchor = next));
  4473. }
  4474. else {
  4475. // fragment didn't hydrate successfully, since we didn't get a end anchor
  4476. // back. This should have led to node/children mismatch warnings.
  4477. hasMismatch = true;
  4478. // since the anchor is missing, we need to create one and insert it
  4479. insert((vnode.anchor = createComment(`]`)), container, next);
  4480. return next;
  4481. }
  4482. };
  4483. const handleMismatch = (node, vnode, parentComponent, parentSuspense, isFragment) => {
  4484. hasMismatch = true;
  4485. warn(`Hydration node mismatch:\n- Client vnode:`, vnode.type, `\n- Server rendered DOM:`, node, node.nodeType === 3 /* TEXT */
  4486. ? `(text)`
  4487. : isComment(node) && node.data === '['
  4488. ? `(start of fragment)`
  4489. : ``);
  4490. vnode.el = null;
  4491. if (isFragment) {
  4492. // remove excessive fragment nodes
  4493. const end = locateClosingAsyncAnchor(node);
  4494. while (true) {
  4495. const next = nextSibling(node);
  4496. if (next && next !== end) {
  4497. remove(next);
  4498. }
  4499. else {
  4500. break;
  4501. }
  4502. }
  4503. }
  4504. const next = nextSibling(node);
  4505. const container = parentNode(node);
  4506. remove(node);
  4507. patch(null, vnode, container, next, parentComponent, parentSuspense, isSVGContainer(container));
  4508. return next;
  4509. };
  4510. const locateClosingAsyncAnchor = (node) => {
  4511. let match = 0;
  4512. while (node) {
  4513. node = nextSibling(node);
  4514. if (node && isComment(node)) {
  4515. if (node.data === '[')
  4516. match++;
  4517. if (node.data === ']') {
  4518. if (match === 0) {
  4519. return nextSibling(node);
  4520. }
  4521. else {
  4522. match--;
  4523. }
  4524. }
  4525. }
  4526. }
  4527. return node;
  4528. };
  4529. return [hydrate, hydrateNode];
  4530. }
  4531. let supported;
  4532. let perf;
  4533. function startMeasure(instance, type) {
  4534. if (instance.appContext.config.performance && isSupported()) {
  4535. perf.mark(`vue-${type}-${instance.uid}`);
  4536. }
  4537. }
  4538. function endMeasure(instance, type) {
  4539. if (instance.appContext.config.performance && isSupported()) {
  4540. const startTag = `vue-${type}-${instance.uid}`;
  4541. const endTag = startTag + `:end`;
  4542. perf.mark(endTag);
  4543. perf.measure(`<${formatComponentName(instance, instance.type)}> ${type}`, startTag, endTag);
  4544. perf.clearMarks(startTag);
  4545. perf.clearMarks(endTag);
  4546. }
  4547. }
  4548. function isSupported() {
  4549. if (supported !== undefined) {
  4550. return supported;
  4551. }
  4552. /* eslint-disable no-restricted-globals */
  4553. if (typeof window !== 'undefined' && window.performance) {
  4554. supported = true;
  4555. perf = window.performance;
  4556. }
  4557. else {
  4558. supported = false;
  4559. }
  4560. /* eslint-enable no-restricted-globals */
  4561. return supported;
  4562. }
  4563. // implementation, close to no-op
  4564. function defineComponent(options) {
  4565. return isFunction(options) ? { setup: options, name: options.name } : options;
  4566. }
  4567. const isAsyncWrapper = (i) => !!i.type.__asyncLoader;
  4568. function defineAsyncComponent(source) {
  4569. if (isFunction(source)) {
  4570. source = { loader: source };
  4571. }
  4572. const { loader, loadingComponent, errorComponent, delay = 200, timeout, // undefined = never times out
  4573. suspensible = true, onError: userOnError } = source;
  4574. let pendingRequest = null;
  4575. let resolvedComp;
  4576. let retries = 0;
  4577. const retry = () => {
  4578. retries++;
  4579. pendingRequest = null;
  4580. return load();
  4581. };
  4582. const load = () => {
  4583. let thisRequest;
  4584. return (pendingRequest ||
  4585. (thisRequest = pendingRequest = loader()
  4586. .catch(err => {
  4587. err = err instanceof Error ? err : new Error(String(err));
  4588. if (userOnError) {
  4589. return new Promise((resolve, reject) => {
  4590. const userRetry = () => resolve(retry());
  4591. const userFail = () => reject(err);
  4592. userOnError(err, userRetry, userFail, retries + 1);
  4593. });
  4594. }
  4595. else {
  4596. throw err;
  4597. }
  4598. })
  4599. .then((comp) => {
  4600. if (thisRequest !== pendingRequest && pendingRequest) {
  4601. return pendingRequest;
  4602. }
  4603. if (!comp) {
  4604. warn(`Async component loader resolved to undefined. ` +
  4605. `If you are using retry(), make sure to return its return value.`);
  4606. }
  4607. // interop module default
  4608. if (comp &&
  4609. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  4610. comp = comp.default;
  4611. }
  4612. if (comp && !isObject(comp) && !isFunction(comp)) {
  4613. throw new Error(`Invalid async component load result: ${comp}`);
  4614. }
  4615. resolvedComp = comp;
  4616. return comp;
  4617. })));
  4618. };
  4619. return defineComponent({
  4620. __asyncLoader: load,
  4621. name: 'AsyncComponentWrapper',
  4622. setup() {
  4623. const instance = currentInstance;
  4624. // already resolved
  4625. if (resolvedComp) {
  4626. return () => createInnerComp(resolvedComp, instance);
  4627. }
  4628. const onError = (err) => {
  4629. pendingRequest = null;
  4630. handleError(err, instance, 13 /* ASYNC_COMPONENT_LOADER */, !errorComponent /* do not throw in dev if user provided error component */);
  4631. };
  4632. // suspense-controlled or SSR.
  4633. if ((suspensible && instance.suspense) ||
  4634. (false )) {
  4635. return load()
  4636. .then(comp => {
  4637. return () => createInnerComp(comp, instance);
  4638. })
  4639. .catch(err => {
  4640. onError(err);
  4641. return () => errorComponent
  4642. ? createVNode(errorComponent, {
  4643. error: err
  4644. })
  4645. : null;
  4646. });
  4647. }
  4648. const loaded = ref(false);
  4649. const error = ref();
  4650. const delayed = ref(!!delay);
  4651. if (delay) {
  4652. setTimeout(() => {
  4653. delayed.value = false;
  4654. }, delay);
  4655. }
  4656. if (timeout != null) {
  4657. setTimeout(() => {
  4658. if (!loaded.value && !error.value) {
  4659. const err = new Error(`Async component timed out after ${timeout}ms.`);
  4660. onError(err);
  4661. error.value = err;
  4662. }
  4663. }, timeout);
  4664. }
  4665. load()
  4666. .then(() => {
  4667. loaded.value = true;
  4668. })
  4669. .catch(err => {
  4670. onError(err);
  4671. error.value = err;
  4672. });
  4673. return () => {
  4674. if (loaded.value && resolvedComp) {
  4675. return createInnerComp(resolvedComp, instance);
  4676. }
  4677. else if (error.value && errorComponent) {
  4678. return createVNode(errorComponent, {
  4679. error: error.value
  4680. });
  4681. }
  4682. else if (loadingComponent && !delayed.value) {
  4683. return createVNode(loadingComponent);
  4684. }
  4685. };
  4686. }
  4687. });
  4688. }
  4689. function createInnerComp(comp, { vnode: { ref, props, children } }) {
  4690. const vnode = createVNode(comp, props, children);
  4691. // ensure inner component inherits the async wrapper's ref owner
  4692. vnode.ref = ref;
  4693. return vnode;
  4694. }
  4695. function createDevEffectOptions(instance) {
  4696. return {
  4697. scheduler: queueJob,
  4698. allowRecurse: true,
  4699. onTrack: instance.rtc ? e => invokeArrayFns(instance.rtc, e) : void 0,
  4700. onTrigger: instance.rtg ? e => invokeArrayFns(instance.rtg, e) : void 0
  4701. };
  4702. }
  4703. const queuePostRenderEffect = queueEffectWithSuspense
  4704. ;
  4705. const setRef = (rawRef, oldRawRef, parentSuspense, vnode) => {
  4706. if (isArray(rawRef)) {
  4707. rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode));
  4708. return;
  4709. }
  4710. let value;
  4711. if (!vnode || isAsyncWrapper(vnode)) {
  4712. value = null;
  4713. }
  4714. else {
  4715. if (vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {
  4716. value = vnode.component.exposed || vnode.component.proxy;
  4717. }
  4718. else {
  4719. value = vnode.el;
  4720. }
  4721. }
  4722. const { i: owner, r: ref } = rawRef;
  4723. if (!owner) {
  4724. warn(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
  4725. `A vnode with ref must be created inside the render function.`);
  4726. return;
  4727. }
  4728. const oldRef = oldRawRef && oldRawRef.r;
  4729. const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
  4730. const setupState = owner.setupState;
  4731. // unset old ref
  4732. if (oldRef != null && oldRef !== ref) {
  4733. if (isString(oldRef)) {
  4734. refs[oldRef] = null;
  4735. if (hasOwn(setupState, oldRef)) {
  4736. setupState[oldRef] = null;
  4737. }
  4738. }
  4739. else if (isRef(oldRef)) {
  4740. oldRef.value = null;
  4741. }
  4742. }
  4743. if (isString(ref)) {
  4744. const doSet = () => {
  4745. refs[ref] = value;
  4746. if (hasOwn(setupState, ref)) {
  4747. setupState[ref] = value;
  4748. }
  4749. };
  4750. // #1789: for non-null values, set them after render
  4751. // null values means this is unmount and it should not overwrite another
  4752. // ref with the same key
  4753. if (value) {
  4754. doSet.id = -1;
  4755. queuePostRenderEffect(doSet, parentSuspense);
  4756. }
  4757. else {
  4758. doSet();
  4759. }
  4760. }
  4761. else if (isRef(ref)) {
  4762. const doSet = () => {
  4763. ref.value = value;
  4764. };
  4765. if (value) {
  4766. doSet.id = -1;
  4767. queuePostRenderEffect(doSet, parentSuspense);
  4768. }
  4769. else {
  4770. doSet();
  4771. }
  4772. }
  4773. else if (isFunction(ref)) {
  4774. callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
  4775. }
  4776. else {
  4777. warn('Invalid template ref type:', value, `(${typeof value})`);
  4778. }
  4779. };
  4780. /**
  4781. * The createRenderer function accepts two generic arguments:
  4782. * HostNode and HostElement, corresponding to Node and Element types in the
  4783. * host environment. For example, for runtime-dom, HostNode would be the DOM
  4784. * `Node` interface and HostElement would be the DOM `Element` interface.
  4785. *
  4786. * Custom renderers can pass in the platform specific types like this:
  4787. *
  4788. * ``` js
  4789. * const { render, createApp } = createRenderer<Node, Element>({
  4790. * patchProp,
  4791. * ...nodeOps
  4792. * })
  4793. * ```
  4794. */
  4795. function createRenderer(options) {
  4796. return baseCreateRenderer(options);
  4797. }
  4798. // Separate API for creating hydration-enabled renderer.
  4799. // Hydration logic is only used when calling this function, making it
  4800. // tree-shakable.
  4801. function createHydrationRenderer(options) {
  4802. return baseCreateRenderer(options, createHydrationFunctions);
  4803. }
  4804. // implementation
  4805. function baseCreateRenderer(options, createHydrationFns) {
  4806. 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;
  4807. // Note: functions inside this closure should use `const xxx = () => {}`
  4808. // style in order to prevent being inlined by minifiers.
  4809. const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, optimized = false) => {
  4810. // patching & not same type, unmount old tree
  4811. if (n1 && !isSameVNodeType(n1, n2)) {
  4812. anchor = getNextHostNode(n1);
  4813. unmount(n1, parentComponent, parentSuspense, true);
  4814. n1 = null;
  4815. }
  4816. if (n2.patchFlag === -2 /* BAIL */) {
  4817. optimized = false;
  4818. n2.dynamicChildren = null;
  4819. }
  4820. const { type, ref, shapeFlag } = n2;
  4821. switch (type) {
  4822. case Text:
  4823. processText(n1, n2, container, anchor);
  4824. break;
  4825. case Comment:
  4826. processCommentNode(n1, n2, container, anchor);
  4827. break;
  4828. case Static:
  4829. if (n1 == null) {
  4830. mountStaticNode(n2, container, anchor, isSVG);
  4831. }
  4832. else {
  4833. patchStaticNode(n1, n2, container, isSVG);
  4834. }
  4835. break;
  4836. case Fragment:
  4837. processFragment(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  4838. break;
  4839. default:
  4840. if (shapeFlag & 1 /* ELEMENT */) {
  4841. processElement(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  4842. }
  4843. else if (shapeFlag & 6 /* COMPONENT */) {
  4844. processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  4845. }
  4846. else if (shapeFlag & 64 /* TELEPORT */) {
  4847. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals);
  4848. }
  4849. else if (shapeFlag & 128 /* SUSPENSE */) {
  4850. type.process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals);
  4851. }
  4852. else {
  4853. warn('Invalid VNode type:', type, `(${typeof type})`);
  4854. }
  4855. }
  4856. // set ref
  4857. if (ref != null && parentComponent) {
  4858. setRef(ref, n1 && n1.ref, parentSuspense, n2);
  4859. }
  4860. };
  4861. const processText = (n1, n2, container, anchor) => {
  4862. if (n1 == null) {
  4863. hostInsert((n2.el = hostCreateText(n2.children)), container, anchor);
  4864. }
  4865. else {
  4866. const el = (n2.el = n1.el);
  4867. if (n2.children !== n1.children) {
  4868. hostSetText(el, n2.children);
  4869. }
  4870. }
  4871. };
  4872. const processCommentNode = (n1, n2, container, anchor) => {
  4873. if (n1 == null) {
  4874. hostInsert((n2.el = hostCreateComment(n2.children || '')), container, anchor);
  4875. }
  4876. else {
  4877. // there's no support for dynamic comments
  4878. n2.el = n1.el;
  4879. }
  4880. };
  4881. const mountStaticNode = (n2, container, anchor, isSVG) => {
  4882. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  4883. };
  4884. /**
  4885. * Dev / HMR only
  4886. */
  4887. const patchStaticNode = (n1, n2, container, isSVG) => {
  4888. // static nodes are only patched during dev for HMR
  4889. if (n2.children !== n1.children) {
  4890. const anchor = hostNextSibling(n1.anchor);
  4891. // remove existing
  4892. removeStaticNode(n1);
  4893. [n2.el, n2.anchor] = hostInsertStaticContent(n2.children, container, anchor, isSVG);
  4894. }
  4895. else {
  4896. n2.el = n1.el;
  4897. n2.anchor = n1.anchor;
  4898. }
  4899. };
  4900. const moveStaticNode = ({ el, anchor }, container, nextSibling) => {
  4901. let next;
  4902. while (el && el !== anchor) {
  4903. next = hostNextSibling(el);
  4904. hostInsert(el, container, nextSibling);
  4905. el = next;
  4906. }
  4907. hostInsert(anchor, container, nextSibling);
  4908. };
  4909. const removeStaticNode = ({ el, anchor }) => {
  4910. let next;
  4911. while (el && el !== anchor) {
  4912. next = hostNextSibling(el);
  4913. hostRemove(el);
  4914. el = next;
  4915. }
  4916. hostRemove(anchor);
  4917. };
  4918. const processElement = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  4919. isSVG = isSVG || n2.type === 'svg';
  4920. if (n1 == null) {
  4921. mountElement(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  4922. }
  4923. else {
  4924. patchElement(n1, n2, parentComponent, parentSuspense, isSVG, optimized);
  4925. }
  4926. };
  4927. const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  4928. let el;
  4929. let vnodeHook;
  4930. const { type, props, shapeFlag, transition, scopeId, patchFlag, dirs } = vnode;
  4931. {
  4932. el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is);
  4933. // mount children first, since some props may rely on child content
  4934. // being already rendered, e.g. `<select value>`
  4935. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  4936. hostSetElementText(el, vnode.children);
  4937. }
  4938. else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  4939. mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', optimized || !!vnode.dynamicChildren);
  4940. }
  4941. if (dirs) {
  4942. invokeDirectiveHook(vnode, null, parentComponent, 'created');
  4943. }
  4944. // props
  4945. if (props) {
  4946. for (const key in props) {
  4947. if (!isReservedProp(key)) {
  4948. hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  4949. }
  4950. }
  4951. if ((vnodeHook = props.onVnodeBeforeMount)) {
  4952. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  4953. }
  4954. }
  4955. // scopeId
  4956. setScopeId(el, scopeId, vnode, parentComponent);
  4957. }
  4958. {
  4959. Object.defineProperty(el, '__vnode', {
  4960. value: vnode,
  4961. enumerable: false
  4962. });
  4963. Object.defineProperty(el, '__vueParentComponent', {
  4964. value: parentComponent,
  4965. enumerable: false
  4966. });
  4967. }
  4968. if (dirs) {
  4969. invokeDirectiveHook(vnode, null, parentComponent, 'beforeMount');
  4970. }
  4971. // #1583 For inside suspense + suspense not resolved case, enter hook should call when suspense resolved
  4972. // #1689 For inside suspense + suspense resolved case, just call it
  4973. const needCallTransitionHooks = (!parentSuspense || (parentSuspense && !parentSuspense.pendingBranch)) &&
  4974. transition &&
  4975. !transition.persisted;
  4976. if (needCallTransitionHooks) {
  4977. transition.beforeEnter(el);
  4978. }
  4979. hostInsert(el, container, anchor);
  4980. if ((vnodeHook = props && props.onVnodeMounted) ||
  4981. needCallTransitionHooks ||
  4982. dirs) {
  4983. queuePostRenderEffect(() => {
  4984. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  4985. needCallTransitionHooks && transition.enter(el);
  4986. dirs && invokeDirectiveHook(vnode, null, parentComponent, 'mounted');
  4987. }, parentSuspense);
  4988. }
  4989. };
  4990. const setScopeId = (el, scopeId, vnode, parentComponent) => {
  4991. if (scopeId) {
  4992. hostSetScopeId(el, scopeId);
  4993. }
  4994. if (parentComponent) {
  4995. const treeOwnerId = parentComponent.type.__scopeId;
  4996. // vnode's own scopeId and the current patched component's scopeId is
  4997. // different - this is a slot content node.
  4998. if (treeOwnerId && treeOwnerId !== scopeId) {
  4999. hostSetScopeId(el, treeOwnerId + '-s');
  5000. }
  5001. let subTree = parentComponent.subTree;
  5002. if (subTree.type === Fragment) {
  5003. subTree =
  5004. filterSingleRoot(subTree.children) || subTree;
  5005. }
  5006. if (vnode === subTree) {
  5007. setScopeId(el, parentComponent.vnode.scopeId, parentComponent.vnode, parentComponent.parent);
  5008. }
  5009. }
  5010. };
  5011. const mountChildren = (children, container, anchor, parentComponent, parentSuspense, isSVG, optimized, start = 0) => {
  5012. for (let i = start; i < children.length; i++) {
  5013. const child = (children[i] = optimized
  5014. ? cloneIfMounted(children[i])
  5015. : normalizeVNode(children[i]));
  5016. patch(null, child, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5017. }
  5018. };
  5019. const patchElement = (n1, n2, parentComponent, parentSuspense, isSVG, optimized) => {
  5020. const el = (n2.el = n1.el);
  5021. let { patchFlag, dynamicChildren, dirs } = n2;
  5022. // #1426 take the old vnode's patch flag into account since user may clone a
  5023. // compiler-generated vnode, which de-opts to FULL_PROPS
  5024. patchFlag |= n1.patchFlag & 16 /* FULL_PROPS */;
  5025. const oldProps = n1.props || EMPTY_OBJ;
  5026. const newProps = n2.props || EMPTY_OBJ;
  5027. let vnodeHook;
  5028. if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
  5029. invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5030. }
  5031. if (dirs) {
  5032. invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
  5033. }
  5034. if (isHmrUpdating) {
  5035. // HMR updated, force full diff
  5036. patchFlag = 0;
  5037. optimized = false;
  5038. dynamicChildren = null;
  5039. }
  5040. if (patchFlag > 0) {
  5041. // the presence of a patchFlag means this element's render code was
  5042. // generated by the compiler and can take the fast path.
  5043. // in this path old node and new node are guaranteed to have the same shape
  5044. // (i.e. at the exact same position in the source template)
  5045. if (patchFlag & 16 /* FULL_PROPS */) {
  5046. // element props contain dynamic keys, full diff needed
  5047. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5048. }
  5049. else {
  5050. // class
  5051. // this flag is matched when the element has dynamic class bindings.
  5052. if (patchFlag & 2 /* CLASS */) {
  5053. if (oldProps.class !== newProps.class) {
  5054. hostPatchProp(el, 'class', null, newProps.class, isSVG);
  5055. }
  5056. }
  5057. // style
  5058. // this flag is matched when the element has dynamic style bindings
  5059. if (patchFlag & 4 /* STYLE */) {
  5060. hostPatchProp(el, 'style', oldProps.style, newProps.style, isSVG);
  5061. }
  5062. // props
  5063. // This flag is matched when the element has dynamic prop/attr bindings
  5064. // other than class and style. The keys of dynamic prop/attrs are saved for
  5065. // faster iteration.
  5066. // Note dynamic keys like :[foo]="bar" will cause this optimization to
  5067. // bail out and go through a full diff because we need to unset the old key
  5068. if (patchFlag & 8 /* PROPS */) {
  5069. // if the flag is present then dynamicProps must be non-null
  5070. const propsToUpdate = n2.dynamicProps;
  5071. for (let i = 0; i < propsToUpdate.length; i++) {
  5072. const key = propsToUpdate[i];
  5073. const prev = oldProps[key];
  5074. const next = newProps[key];
  5075. if (next !== prev ||
  5076. (hostForcePatchProp && hostForcePatchProp(el, key))) {
  5077. hostPatchProp(el, key, prev, next, isSVG, n1.children, parentComponent, parentSuspense, unmountChildren);
  5078. }
  5079. }
  5080. }
  5081. }
  5082. // text
  5083. // This flag is matched when the element has only dynamic text children.
  5084. if (patchFlag & 1 /* TEXT */) {
  5085. if (n1.children !== n2.children) {
  5086. hostSetElementText(el, n2.children);
  5087. }
  5088. }
  5089. }
  5090. else if (!optimized && dynamicChildren == null) {
  5091. // unoptimized, full diff
  5092. patchProps(el, n2, oldProps, newProps, parentComponent, parentSuspense, isSVG);
  5093. }
  5094. const areChildrenSVG = isSVG && n2.type !== 'foreignObject';
  5095. if (dynamicChildren) {
  5096. patchBlockChildren(n1.dynamicChildren, dynamicChildren, el, parentComponent, parentSuspense, areChildrenSVG);
  5097. if (parentComponent && parentComponent.type.__hmrId) {
  5098. traverseStaticChildren(n1, n2);
  5099. }
  5100. }
  5101. else if (!optimized) {
  5102. // full diff
  5103. patchChildren(n1, n2, el, null, parentComponent, parentSuspense, areChildrenSVG);
  5104. }
  5105. if ((vnodeHook = newProps.onVnodeUpdated) || dirs) {
  5106. queuePostRenderEffect(() => {
  5107. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
  5108. dirs && invokeDirectiveHook(n2, n1, parentComponent, 'updated');
  5109. }, parentSuspense);
  5110. }
  5111. };
  5112. // The fast path for blocks.
  5113. const patchBlockChildren = (oldChildren, newChildren, fallbackContainer, parentComponent, parentSuspense, isSVG) => {
  5114. for (let i = 0; i < newChildren.length; i++) {
  5115. const oldVNode = oldChildren[i];
  5116. const newVNode = newChildren[i];
  5117. // Determine the container (parent element) for the patch.
  5118. const container =
  5119. // - In the case of a Fragment, we need to provide the actual parent
  5120. // of the Fragment itself so it can move its children.
  5121. oldVNode.type === Fragment ||
  5122. // - In the case of different nodes, there is going to be a replacement
  5123. // which also requires the correct parent container
  5124. !isSameVNodeType(oldVNode, newVNode) ||
  5125. // - In the case of a component, it could contain anything.
  5126. oldVNode.shapeFlag & 6 /* COMPONENT */ ||
  5127. oldVNode.shapeFlag & 64 /* TELEPORT */
  5128. ? hostParentNode(oldVNode.el)
  5129. : // In other cases, the parent container is not actually used so we
  5130. // just pass the block element here to avoid a DOM parentNode call.
  5131. fallbackContainer;
  5132. patch(oldVNode, newVNode, container, null, parentComponent, parentSuspense, isSVG, true);
  5133. }
  5134. };
  5135. const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
  5136. if (oldProps !== newProps) {
  5137. for (const key in newProps) {
  5138. // empty string is not valid prop
  5139. if (isReservedProp(key))
  5140. continue;
  5141. const next = newProps[key];
  5142. const prev = oldProps[key];
  5143. if (next !== prev ||
  5144. (hostForcePatchProp && hostForcePatchProp(el, key))) {
  5145. hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5146. }
  5147. }
  5148. if (oldProps !== EMPTY_OBJ) {
  5149. for (const key in oldProps) {
  5150. if (!isReservedProp(key) && !(key in newProps)) {
  5151. hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
  5152. }
  5153. }
  5154. }
  5155. }
  5156. };
  5157. const processFragment = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5158. const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateText(''));
  5159. const fragmentEndAnchor = (n2.anchor = n1 ? n1.anchor : hostCreateText(''));
  5160. let { patchFlag, dynamicChildren } = n2;
  5161. if (patchFlag > 0) {
  5162. optimized = true;
  5163. }
  5164. if (isHmrUpdating) {
  5165. // HMR updated, force full diff
  5166. patchFlag = 0;
  5167. optimized = false;
  5168. dynamicChildren = null;
  5169. }
  5170. if (n1 == null) {
  5171. hostInsert(fragmentStartAnchor, container, anchor);
  5172. hostInsert(fragmentEndAnchor, container, anchor);
  5173. // a fragment can only have array children
  5174. // since they are either generated by the compiler, or implicitly created
  5175. // from arrays.
  5176. mountChildren(n2.children, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, optimized);
  5177. }
  5178. else {
  5179. if (patchFlag > 0 &&
  5180. patchFlag & 64 /* STABLE_FRAGMENT */ &&
  5181. dynamicChildren &&
  5182. // #2715 the previous fragment could've been a BAILed one as a result
  5183. // of renderSlot() with no valid children
  5184. n1.dynamicChildren) {
  5185. // a stable fragment (template root or <template v-for>) doesn't need to
  5186. // patch children order, but it may contain dynamicChildren.
  5187. patchBlockChildren(n1.dynamicChildren, dynamicChildren, container, parentComponent, parentSuspense, isSVG);
  5188. if (parentComponent && parentComponent.type.__hmrId) {
  5189. traverseStaticChildren(n1, n2);
  5190. }
  5191. else if (
  5192. // #2080 if the stable fragment has a key, it's a <template v-for> that may
  5193. // get moved around. Make sure all root level vnodes inherit el.
  5194. // #2134 or if it's a component root, it may also get moved around
  5195. // as the component is being moved.
  5196. n2.key != null ||
  5197. (parentComponent && n2 === parentComponent.subTree)) {
  5198. traverseStaticChildren(n1, n2, true /* shallow */);
  5199. }
  5200. }
  5201. else {
  5202. // keyed / unkeyed, or manual fragments.
  5203. // for keyed & unkeyed, since they are compiler generated from v-for,
  5204. // each child is guaranteed to be a block so the fragment will never
  5205. // have dynamicChildren.
  5206. patchChildren(n1, n2, container, fragmentEndAnchor, parentComponent, parentSuspense, isSVG, optimized);
  5207. }
  5208. }
  5209. };
  5210. const processComponent = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5211. if (n1 == null) {
  5212. if (n2.shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
  5213. parentComponent.ctx.activate(n2, container, anchor, isSVG, optimized);
  5214. }
  5215. else {
  5216. mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5217. }
  5218. }
  5219. else {
  5220. updateComponent(n1, n2, optimized);
  5221. }
  5222. };
  5223. const mountComponent = (initialVNode, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5224. const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent, parentSuspense));
  5225. if (instance.type.__hmrId) {
  5226. registerHMR(instance);
  5227. }
  5228. {
  5229. pushWarningContext(initialVNode);
  5230. startMeasure(instance, `mount`);
  5231. }
  5232. // inject renderer internals for keepAlive
  5233. if (isKeepAlive(initialVNode)) {
  5234. instance.ctx.renderer = internals;
  5235. }
  5236. // resolve props and slots for setup context
  5237. {
  5238. startMeasure(instance, `init`);
  5239. }
  5240. setupComponent(instance);
  5241. {
  5242. endMeasure(instance, `init`);
  5243. }
  5244. // setup() is async. This component relies on async logic to be resolved
  5245. // before proceeding
  5246. if (instance.asyncDep) {
  5247. parentSuspense && parentSuspense.registerDep(instance, setupRenderEffect);
  5248. // Give it a placeholder if this is not hydration
  5249. // TODO handle self-defined fallback
  5250. if (!initialVNode.el) {
  5251. const placeholder = (instance.subTree = createVNode(Comment));
  5252. processCommentNode(null, placeholder, container, anchor);
  5253. }
  5254. return;
  5255. }
  5256. setupRenderEffect(instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized);
  5257. {
  5258. popWarningContext();
  5259. endMeasure(instance, `mount`);
  5260. }
  5261. };
  5262. const updateComponent = (n1, n2, optimized) => {
  5263. const instance = (n2.component = n1.component);
  5264. if (shouldUpdateComponent(n1, n2, optimized)) {
  5265. if (instance.asyncDep &&
  5266. !instance.asyncResolved) {
  5267. // async & still pending - just update props and slots
  5268. // since the component's reactive effect for render isn't set-up yet
  5269. {
  5270. pushWarningContext(n2);
  5271. }
  5272. updateComponentPreRender(instance, n2, optimized);
  5273. {
  5274. popWarningContext();
  5275. }
  5276. return;
  5277. }
  5278. else {
  5279. // normal update
  5280. instance.next = n2;
  5281. // in case the child component is also queued, remove it to avoid
  5282. // double updating the same child component in the same flush.
  5283. invalidateJob(instance.update);
  5284. // instance.update is the reactive effect runner.
  5285. instance.update();
  5286. }
  5287. }
  5288. else {
  5289. // no update needed. just copy over properties
  5290. n2.component = n1.component;
  5291. n2.el = n1.el;
  5292. instance.vnode = n2;
  5293. }
  5294. };
  5295. const setupRenderEffect = (instance, initialVNode, container, anchor, parentSuspense, isSVG, optimized) => {
  5296. // create reactive effect for rendering
  5297. instance.update = effect(function componentEffect() {
  5298. if (!instance.isMounted) {
  5299. let vnodeHook;
  5300. const { el, props } = initialVNode;
  5301. const { bm, m, parent } = instance;
  5302. // beforeMount hook
  5303. if (bm) {
  5304. invokeArrayFns(bm);
  5305. }
  5306. // onVnodeBeforeMount
  5307. if ((vnodeHook = props && props.onVnodeBeforeMount)) {
  5308. invokeVNodeHook(vnodeHook, parent, initialVNode);
  5309. }
  5310. // render
  5311. {
  5312. startMeasure(instance, `render`);
  5313. }
  5314. const subTree = (instance.subTree = renderComponentRoot(instance));
  5315. {
  5316. endMeasure(instance, `render`);
  5317. }
  5318. if (el && hydrateNode) {
  5319. {
  5320. startMeasure(instance, `hydrate`);
  5321. }
  5322. // vnode has adopted host node - perform hydration instead of mount.
  5323. hydrateNode(initialVNode.el, subTree, instance, parentSuspense);
  5324. {
  5325. endMeasure(instance, `hydrate`);
  5326. }
  5327. }
  5328. else {
  5329. {
  5330. startMeasure(instance, `patch`);
  5331. }
  5332. patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);
  5333. {
  5334. endMeasure(instance, `patch`);
  5335. }
  5336. initialVNode.el = subTree.el;
  5337. }
  5338. // mounted hook
  5339. if (m) {
  5340. queuePostRenderEffect(m, parentSuspense);
  5341. }
  5342. // onVnodeMounted
  5343. if ((vnodeHook = props && props.onVnodeMounted)) {
  5344. const scopedInitialVNode = initialVNode;
  5345. queuePostRenderEffect(() => {
  5346. invokeVNodeHook(vnodeHook, parent, scopedInitialVNode);
  5347. }, parentSuspense);
  5348. }
  5349. // activated hook for keep-alive roots.
  5350. // #1742 activated hook must be accessed after first render
  5351. // since the hook may be injected by a child keep-alive
  5352. const { a } = instance;
  5353. if (a &&
  5354. initialVNode.shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  5355. queuePostRenderEffect(a, parentSuspense);
  5356. }
  5357. instance.isMounted = true;
  5358. {
  5359. devtoolsComponentAdded(instance);
  5360. }
  5361. // #2458: deference mount-only object parameters to prevent memleaks
  5362. initialVNode = container = anchor = null;
  5363. }
  5364. else {
  5365. // updateComponent
  5366. // This is triggered by mutation of component's own state (next: null)
  5367. // OR parent calling processComponent (next: VNode)
  5368. let { next, bu, u, parent, vnode } = instance;
  5369. let originNext = next;
  5370. let vnodeHook;
  5371. {
  5372. pushWarningContext(next || instance.vnode);
  5373. }
  5374. if (next) {
  5375. next.el = vnode.el;
  5376. updateComponentPreRender(instance, next, optimized);
  5377. }
  5378. else {
  5379. next = vnode;
  5380. }
  5381. // beforeUpdate hook
  5382. if (bu) {
  5383. invokeArrayFns(bu);
  5384. }
  5385. // onVnodeBeforeUpdate
  5386. if ((vnodeHook = next.props && next.props.onVnodeBeforeUpdate)) {
  5387. invokeVNodeHook(vnodeHook, parent, next, vnode);
  5388. }
  5389. // render
  5390. {
  5391. startMeasure(instance, `render`);
  5392. }
  5393. const nextTree = renderComponentRoot(instance);
  5394. {
  5395. endMeasure(instance, `render`);
  5396. }
  5397. const prevTree = instance.subTree;
  5398. instance.subTree = nextTree;
  5399. {
  5400. startMeasure(instance, `patch`);
  5401. }
  5402. patch(prevTree, nextTree,
  5403. // parent may have changed if it's in a teleport
  5404. hostParentNode(prevTree.el),
  5405. // anchor may have changed if it's in a fragment
  5406. getNextHostNode(prevTree), instance, parentSuspense, isSVG);
  5407. {
  5408. endMeasure(instance, `patch`);
  5409. }
  5410. next.el = nextTree.el;
  5411. if (originNext === null) {
  5412. // self-triggered update. In case of HOC, update parent component
  5413. // vnode el. HOC is indicated by parent instance's subTree pointing
  5414. // to child component's vnode
  5415. updateHOCHostEl(instance, nextTree.el);
  5416. }
  5417. // updated hook
  5418. if (u) {
  5419. queuePostRenderEffect(u, parentSuspense);
  5420. }
  5421. // onVnodeUpdated
  5422. if ((vnodeHook = next.props && next.props.onVnodeUpdated)) {
  5423. queuePostRenderEffect(() => {
  5424. invokeVNodeHook(vnodeHook, parent, next, vnode);
  5425. }, parentSuspense);
  5426. }
  5427. {
  5428. devtoolsComponentUpdated(instance);
  5429. }
  5430. {
  5431. popWarningContext();
  5432. }
  5433. }
  5434. }, createDevEffectOptions(instance) );
  5435. };
  5436. const updateComponentPreRender = (instance, nextVNode, optimized) => {
  5437. nextVNode.component = instance;
  5438. const prevProps = instance.vnode.props;
  5439. instance.vnode = nextVNode;
  5440. instance.next = null;
  5441. updateProps(instance, nextVNode.props, prevProps, optimized);
  5442. updateSlots(instance, nextVNode.children);
  5443. // props update may have triggered pre-flush watchers.
  5444. // flush them before the render update.
  5445. flushPreFlushCbs(undefined, instance.update);
  5446. };
  5447. const patchChildren = (n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized = false) => {
  5448. const c1 = n1 && n1.children;
  5449. const prevShapeFlag = n1 ? n1.shapeFlag : 0;
  5450. const c2 = n2.children;
  5451. const { patchFlag, shapeFlag } = n2;
  5452. // fast path
  5453. if (patchFlag > 0) {
  5454. if (patchFlag & 128 /* KEYED_FRAGMENT */) {
  5455. // this could be either fully-keyed or mixed (some keyed some not)
  5456. // presence of patchFlag means children are guaranteed to be arrays
  5457. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5458. return;
  5459. }
  5460. else if (patchFlag & 256 /* UNKEYED_FRAGMENT */) {
  5461. // unkeyed
  5462. patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5463. return;
  5464. }
  5465. }
  5466. // children has 3 possibilities: text, array or no children.
  5467. if (shapeFlag & 8 /* TEXT_CHILDREN */) {
  5468. // text children fast path
  5469. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  5470. unmountChildren(c1, parentComponent, parentSuspense);
  5471. }
  5472. if (c2 !== c1) {
  5473. hostSetElementText(container, c2);
  5474. }
  5475. }
  5476. else {
  5477. if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {
  5478. // prev children was array
  5479. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5480. // two arrays, cannot assume anything, do full diff
  5481. patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5482. }
  5483. else {
  5484. // no new children, just unmount old
  5485. unmountChildren(c1, parentComponent, parentSuspense, true);
  5486. }
  5487. }
  5488. else {
  5489. // prev children was text OR null
  5490. // new children is array OR null
  5491. if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {
  5492. hostSetElementText(container, '');
  5493. }
  5494. // mount new if array
  5495. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  5496. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  5497. }
  5498. }
  5499. }
  5500. };
  5501. const patchUnkeyedChildren = (c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5502. c1 = c1 || EMPTY_ARR;
  5503. c2 = c2 || EMPTY_ARR;
  5504. const oldLength = c1.length;
  5505. const newLength = c2.length;
  5506. const commonLength = Math.min(oldLength, newLength);
  5507. let i;
  5508. for (i = 0; i < commonLength; i++) {
  5509. const nextChild = (c2[i] = optimized
  5510. ? cloneIfMounted(c2[i])
  5511. : normalizeVNode(c2[i]));
  5512. patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, optimized);
  5513. }
  5514. if (oldLength > newLength) {
  5515. // remove old
  5516. unmountChildren(c1, parentComponent, parentSuspense, true, false, commonLength);
  5517. }
  5518. else {
  5519. // mount new
  5520. mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, commonLength);
  5521. }
  5522. };
  5523. // can be all-keyed or mixed
  5524. const patchKeyedChildren = (c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, optimized) => {
  5525. let i = 0;
  5526. const l2 = c2.length;
  5527. let e1 = c1.length - 1; // prev ending index
  5528. let e2 = l2 - 1; // next ending index
  5529. // 1. sync from start
  5530. // (a b) c
  5531. // (a b) d e
  5532. while (i <= e1 && i <= e2) {
  5533. const n1 = c1[i];
  5534. const n2 = (c2[i] = optimized
  5535. ? cloneIfMounted(c2[i])
  5536. : normalizeVNode(c2[i]));
  5537. if (isSameVNodeType(n1, n2)) {
  5538. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, optimized);
  5539. }
  5540. else {
  5541. break;
  5542. }
  5543. i++;
  5544. }
  5545. // 2. sync from end
  5546. // a (b c)
  5547. // d e (b c)
  5548. while (i <= e1 && i <= e2) {
  5549. const n1 = c1[e1];
  5550. const n2 = (c2[e2] = optimized
  5551. ? cloneIfMounted(c2[e2])
  5552. : normalizeVNode(c2[e2]));
  5553. if (isSameVNodeType(n1, n2)) {
  5554. patch(n1, n2, container, null, parentComponent, parentSuspense, isSVG, optimized);
  5555. }
  5556. else {
  5557. break;
  5558. }
  5559. e1--;
  5560. e2--;
  5561. }
  5562. // 3. common sequence + mount
  5563. // (a b)
  5564. // (a b) c
  5565. // i = 2, e1 = 1, e2 = 2
  5566. // (a b)
  5567. // c (a b)
  5568. // i = 0, e1 = -1, e2 = 0
  5569. if (i > e1) {
  5570. if (i <= e2) {
  5571. const nextPos = e2 + 1;
  5572. const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;
  5573. while (i <= e2) {
  5574. patch(null, (c2[i] = optimized
  5575. ? cloneIfMounted(c2[i])
  5576. : normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG);
  5577. i++;
  5578. }
  5579. }
  5580. }
  5581. // 4. common sequence + unmount
  5582. // (a b) c
  5583. // (a b)
  5584. // i = 2, e1 = 2, e2 = 1
  5585. // a (b c)
  5586. // (b c)
  5587. // i = 0, e1 = 0, e2 = -1
  5588. else if (i > e2) {
  5589. while (i <= e1) {
  5590. unmount(c1[i], parentComponent, parentSuspense, true);
  5591. i++;
  5592. }
  5593. }
  5594. // 5. unknown sequence
  5595. // [i ... e1 + 1]: a b [c d e] f g
  5596. // [i ... e2 + 1]: a b [e d c h] f g
  5597. // i = 2, e1 = 4, e2 = 5
  5598. else {
  5599. const s1 = i; // prev starting index
  5600. const s2 = i; // next starting index
  5601. // 5.1 build key:index map for newChildren
  5602. const keyToNewIndexMap = new Map();
  5603. for (i = s2; i <= e2; i++) {
  5604. const nextChild = (c2[i] = optimized
  5605. ? cloneIfMounted(c2[i])
  5606. : normalizeVNode(c2[i]));
  5607. if (nextChild.key != null) {
  5608. if (keyToNewIndexMap.has(nextChild.key)) {
  5609. warn(`Duplicate keys found during update:`, JSON.stringify(nextChild.key), `Make sure keys are unique.`);
  5610. }
  5611. keyToNewIndexMap.set(nextChild.key, i);
  5612. }
  5613. }
  5614. // 5.2 loop through old children left to be patched and try to patch
  5615. // matching nodes & remove nodes that are no longer present
  5616. let j;
  5617. let patched = 0;
  5618. const toBePatched = e2 - s2 + 1;
  5619. let moved = false;
  5620. // used to track whether any node has moved
  5621. let maxNewIndexSoFar = 0;
  5622. // works as Map<newIndex, oldIndex>
  5623. // Note that oldIndex is offset by +1
  5624. // and oldIndex = 0 is a special value indicating the new node has
  5625. // no corresponding old node.
  5626. // used for determining longest stable subsequence
  5627. const newIndexToOldIndexMap = new Array(toBePatched);
  5628. for (i = 0; i < toBePatched; i++)
  5629. newIndexToOldIndexMap[i] = 0;
  5630. for (i = s1; i <= e1; i++) {
  5631. const prevChild = c1[i];
  5632. if (patched >= toBePatched) {
  5633. // all new children have been patched so this can only be a removal
  5634. unmount(prevChild, parentComponent, parentSuspense, true);
  5635. continue;
  5636. }
  5637. let newIndex;
  5638. if (prevChild.key != null) {
  5639. newIndex = keyToNewIndexMap.get(prevChild.key);
  5640. }
  5641. else {
  5642. // key-less node, try to locate a key-less node of the same type
  5643. for (j = s2; j <= e2; j++) {
  5644. if (newIndexToOldIndexMap[j - s2] === 0 &&
  5645. isSameVNodeType(prevChild, c2[j])) {
  5646. newIndex = j;
  5647. break;
  5648. }
  5649. }
  5650. }
  5651. if (newIndex === undefined) {
  5652. unmount(prevChild, parentComponent, parentSuspense, true);
  5653. }
  5654. else {
  5655. newIndexToOldIndexMap[newIndex - s2] = i + 1;
  5656. if (newIndex >= maxNewIndexSoFar) {
  5657. maxNewIndexSoFar = newIndex;
  5658. }
  5659. else {
  5660. moved = true;
  5661. }
  5662. patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, optimized);
  5663. patched++;
  5664. }
  5665. }
  5666. // 5.3 move and mount
  5667. // generate longest stable subsequence only when nodes have moved
  5668. const increasingNewIndexSequence = moved
  5669. ? getSequence(newIndexToOldIndexMap)
  5670. : EMPTY_ARR;
  5671. j = increasingNewIndexSequence.length - 1;
  5672. // looping backwards so that we can use last patched node as anchor
  5673. for (i = toBePatched - 1; i >= 0; i--) {
  5674. const nextIndex = s2 + i;
  5675. const nextChild = c2[nextIndex];
  5676. const anchor = nextIndex + 1 < l2 ? c2[nextIndex + 1].el : parentAnchor;
  5677. if (newIndexToOldIndexMap[i] === 0) {
  5678. // mount new
  5679. patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG);
  5680. }
  5681. else if (moved) {
  5682. // move if:
  5683. // There is no stable subsequence (e.g. a reverse)
  5684. // OR current node is not among the stable sequence
  5685. if (j < 0 || i !== increasingNewIndexSequence[j]) {
  5686. move(nextChild, container, anchor, 2 /* REORDER */);
  5687. }
  5688. else {
  5689. j--;
  5690. }
  5691. }
  5692. }
  5693. }
  5694. };
  5695. const move = (vnode, container, anchor, moveType, parentSuspense = null) => {
  5696. const { el, type, transition, children, shapeFlag } = vnode;
  5697. if (shapeFlag & 6 /* COMPONENT */) {
  5698. move(vnode.component.subTree, container, anchor, moveType);
  5699. return;
  5700. }
  5701. if (shapeFlag & 128 /* SUSPENSE */) {
  5702. vnode.suspense.move(container, anchor, moveType);
  5703. return;
  5704. }
  5705. if (shapeFlag & 64 /* TELEPORT */) {
  5706. type.move(vnode, container, anchor, internals);
  5707. return;
  5708. }
  5709. if (type === Fragment) {
  5710. hostInsert(el, container, anchor);
  5711. for (let i = 0; i < children.length; i++) {
  5712. move(children[i], container, anchor, moveType);
  5713. }
  5714. hostInsert(vnode.anchor, container, anchor);
  5715. return;
  5716. }
  5717. if (type === Static) {
  5718. moveStaticNode(vnode, container, anchor);
  5719. return;
  5720. }
  5721. // single nodes
  5722. const needTransition = moveType !== 2 /* REORDER */ &&
  5723. shapeFlag & 1 /* ELEMENT */ &&
  5724. transition;
  5725. if (needTransition) {
  5726. if (moveType === 0 /* ENTER */) {
  5727. transition.beforeEnter(el);
  5728. hostInsert(el, container, anchor);
  5729. queuePostRenderEffect(() => transition.enter(el), parentSuspense);
  5730. }
  5731. else {
  5732. const { leave, delayLeave, afterLeave } = transition;
  5733. const remove = () => hostInsert(el, container, anchor);
  5734. const performLeave = () => {
  5735. leave(el, () => {
  5736. remove();
  5737. afterLeave && afterLeave();
  5738. });
  5739. };
  5740. if (delayLeave) {
  5741. delayLeave(el, remove, performLeave);
  5742. }
  5743. else {
  5744. performLeave();
  5745. }
  5746. }
  5747. }
  5748. else {
  5749. hostInsert(el, container, anchor);
  5750. }
  5751. };
  5752. const unmount = (vnode, parentComponent, parentSuspense, doRemove = false, optimized = false) => {
  5753. const { type, props, ref, children, dynamicChildren, shapeFlag, patchFlag, dirs } = vnode;
  5754. // unset ref
  5755. if (ref != null) {
  5756. setRef(ref, null, parentSuspense, null);
  5757. }
  5758. if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
  5759. parentComponent.ctx.deactivate(vnode);
  5760. return;
  5761. }
  5762. const shouldInvokeDirs = shapeFlag & 1 /* ELEMENT */ && dirs;
  5763. let vnodeHook;
  5764. if ((vnodeHook = props && props.onVnodeBeforeUnmount)) {
  5765. invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5766. }
  5767. if (shapeFlag & 6 /* COMPONENT */) {
  5768. unmountComponent(vnode.component, parentSuspense, doRemove);
  5769. }
  5770. else {
  5771. if (shapeFlag & 128 /* SUSPENSE */) {
  5772. vnode.suspense.unmount(parentSuspense, doRemove);
  5773. return;
  5774. }
  5775. if (shouldInvokeDirs) {
  5776. invokeDirectiveHook(vnode, null, parentComponent, 'beforeUnmount');
  5777. }
  5778. if (dynamicChildren &&
  5779. // #1153: fast path should not be taken for non-stable (v-for) fragments
  5780. (type !== Fragment ||
  5781. (patchFlag > 0 && patchFlag & 64 /* STABLE_FRAGMENT */))) {
  5782. // fast path for block nodes: only need to unmount dynamic children.
  5783. unmountChildren(dynamicChildren, parentComponent, parentSuspense, false, true);
  5784. }
  5785. else if ((type === Fragment &&
  5786. (patchFlag & 128 /* KEYED_FRAGMENT */ ||
  5787. patchFlag & 256 /* UNKEYED_FRAGMENT */)) ||
  5788. (!optimized && shapeFlag & 16 /* ARRAY_CHILDREN */)) {
  5789. unmountChildren(children, parentComponent, parentSuspense);
  5790. }
  5791. // an unmounted teleport should always remove its children if not disabled
  5792. if (shapeFlag & 64 /* TELEPORT */ &&
  5793. (doRemove || !isTeleportDisabled(vnode.props))) {
  5794. vnode.type.remove(vnode, internals);
  5795. }
  5796. if (doRemove) {
  5797. remove(vnode);
  5798. }
  5799. }
  5800. if ((vnodeHook = props && props.onVnodeUnmounted) || shouldInvokeDirs) {
  5801. queuePostRenderEffect(() => {
  5802. vnodeHook && invokeVNodeHook(vnodeHook, parentComponent, vnode);
  5803. shouldInvokeDirs &&
  5804. invokeDirectiveHook(vnode, null, parentComponent, 'unmounted');
  5805. }, parentSuspense);
  5806. }
  5807. };
  5808. const remove = vnode => {
  5809. const { type, el, anchor, transition } = vnode;
  5810. if (type === Fragment) {
  5811. removeFragment(el, anchor);
  5812. return;
  5813. }
  5814. if (type === Static) {
  5815. removeStaticNode(vnode);
  5816. return;
  5817. }
  5818. const performRemove = () => {
  5819. hostRemove(el);
  5820. if (transition && !transition.persisted && transition.afterLeave) {
  5821. transition.afterLeave();
  5822. }
  5823. };
  5824. if (vnode.shapeFlag & 1 /* ELEMENT */ &&
  5825. transition &&
  5826. !transition.persisted) {
  5827. const { leave, delayLeave } = transition;
  5828. const performLeave = () => leave(el, performRemove);
  5829. if (delayLeave) {
  5830. delayLeave(vnode.el, performRemove, performLeave);
  5831. }
  5832. else {
  5833. performLeave();
  5834. }
  5835. }
  5836. else {
  5837. performRemove();
  5838. }
  5839. };
  5840. const removeFragment = (cur, end) => {
  5841. // For fragments, directly remove all contained DOM nodes.
  5842. // (fragment child nodes cannot have transition)
  5843. let next;
  5844. while (cur !== end) {
  5845. next = hostNextSibling(cur);
  5846. hostRemove(cur);
  5847. cur = next;
  5848. }
  5849. hostRemove(end);
  5850. };
  5851. const unmountComponent = (instance, parentSuspense, doRemove) => {
  5852. if (instance.type.__hmrId) {
  5853. unregisterHMR(instance);
  5854. }
  5855. const { bum, effects, update, subTree, um } = instance;
  5856. // beforeUnmount hook
  5857. if (bum) {
  5858. invokeArrayFns(bum);
  5859. }
  5860. if (effects) {
  5861. for (let i = 0; i < effects.length; i++) {
  5862. stop(effects[i]);
  5863. }
  5864. }
  5865. // update may be null if a component is unmounted before its async
  5866. // setup has resolved.
  5867. if (update) {
  5868. stop(update);
  5869. unmount(subTree, instance, parentSuspense, doRemove);
  5870. }
  5871. // unmounted hook
  5872. if (um) {
  5873. queuePostRenderEffect(um, parentSuspense);
  5874. }
  5875. queuePostRenderEffect(() => {
  5876. instance.isUnmounted = true;
  5877. }, parentSuspense);
  5878. // A component with async dep inside a pending suspense is unmounted before
  5879. // its async dep resolves. This should remove the dep from the suspense, and
  5880. // cause the suspense to resolve immediately if that was the last dep.
  5881. if (parentSuspense &&
  5882. parentSuspense.pendingBranch &&
  5883. !parentSuspense.isUnmounted &&
  5884. instance.asyncDep &&
  5885. !instance.asyncResolved &&
  5886. instance.suspenseId === parentSuspense.pendingId) {
  5887. parentSuspense.deps--;
  5888. if (parentSuspense.deps === 0) {
  5889. parentSuspense.resolve();
  5890. }
  5891. }
  5892. {
  5893. devtoolsComponentRemoved(instance);
  5894. }
  5895. };
  5896. const unmountChildren = (children, parentComponent, parentSuspense, doRemove = false, optimized = false, start = 0) => {
  5897. for (let i = start; i < children.length; i++) {
  5898. unmount(children[i], parentComponent, parentSuspense, doRemove, optimized);
  5899. }
  5900. };
  5901. const getNextHostNode = vnode => {
  5902. if (vnode.shapeFlag & 6 /* COMPONENT */) {
  5903. return getNextHostNode(vnode.component.subTree);
  5904. }
  5905. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  5906. return vnode.suspense.next();
  5907. }
  5908. return hostNextSibling((vnode.anchor || vnode.el));
  5909. };
  5910. const render = (vnode, container) => {
  5911. if (vnode == null) {
  5912. if (container._vnode) {
  5913. unmount(container._vnode, null, null, true);
  5914. }
  5915. }
  5916. else {
  5917. patch(container._vnode || null, vnode, container);
  5918. }
  5919. flushPostFlushCbs();
  5920. container._vnode = vnode;
  5921. };
  5922. const internals = {
  5923. p: patch,
  5924. um: unmount,
  5925. m: move,
  5926. r: remove,
  5927. mt: mountComponent,
  5928. mc: mountChildren,
  5929. pc: patchChildren,
  5930. pbc: patchBlockChildren,
  5931. n: getNextHostNode,
  5932. o: options
  5933. };
  5934. let hydrate;
  5935. let hydrateNode;
  5936. if (createHydrationFns) {
  5937. [hydrate, hydrateNode] = createHydrationFns(internals);
  5938. }
  5939. return {
  5940. render,
  5941. hydrate,
  5942. createApp: createAppAPI(render, hydrate)
  5943. };
  5944. }
  5945. function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
  5946. callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
  5947. vnode,
  5948. prevVNode
  5949. ]);
  5950. }
  5951. /**
  5952. * #1156
  5953. * When a component is HMR-enabled, we need to make sure that all static nodes
  5954. * inside a block also inherit the DOM element from the previous tree so that
  5955. * HMR updates (which are full updates) can retrieve the element for patching.
  5956. *
  5957. * #2080
  5958. * Inside keyed `template` fragment static children, if a fragment is moved,
  5959. * the children will always moved so that need inherit el form previous nodes
  5960. * to ensure correct moved position.
  5961. */
  5962. function traverseStaticChildren(n1, n2, shallow = false) {
  5963. const ch1 = n1.children;
  5964. const ch2 = n2.children;
  5965. if (isArray(ch1) && isArray(ch2)) {
  5966. for (let i = 0; i < ch1.length; i++) {
  5967. // this is only called in the optimized path so array children are
  5968. // guaranteed to be vnodes
  5969. const c1 = ch1[i];
  5970. let c2 = ch2[i];
  5971. if (c2.shapeFlag & 1 /* ELEMENT */ && !c2.dynamicChildren) {
  5972. if (c2.patchFlag <= 0 || c2.patchFlag === 32 /* HYDRATE_EVENTS */) {
  5973. c2 = ch2[i] = cloneIfMounted(ch2[i]);
  5974. c2.el = c1.el;
  5975. }
  5976. if (!shallow)
  5977. traverseStaticChildren(c1, c2);
  5978. }
  5979. // also inherit for comment nodes, but not placeholders (e.g. v-if which
  5980. // would have received .el during block patch)
  5981. if (c2.type === Comment && !c2.el) {
  5982. c2.el = c1.el;
  5983. }
  5984. }
  5985. }
  5986. }
  5987. // https://en.wikipedia.org/wiki/Longest_increasing_subsequence
  5988. function getSequence(arr) {
  5989. const p = arr.slice();
  5990. const result = [0];
  5991. let i, j, u, v, c;
  5992. const len = arr.length;
  5993. for (i = 0; i < len; i++) {
  5994. const arrI = arr[i];
  5995. if (arrI !== 0) {
  5996. j = result[result.length - 1];
  5997. if (arr[j] < arrI) {
  5998. p[i] = j;
  5999. result.push(i);
  6000. continue;
  6001. }
  6002. u = 0;
  6003. v = result.length - 1;
  6004. while (u < v) {
  6005. c = ((u + v) / 2) | 0;
  6006. if (arr[result[c]] < arrI) {
  6007. u = c + 1;
  6008. }
  6009. else {
  6010. v = c;
  6011. }
  6012. }
  6013. if (arrI < arr[result[u]]) {
  6014. if (u > 0) {
  6015. p[i] = result[u - 1];
  6016. }
  6017. result[u] = i;
  6018. }
  6019. }
  6020. }
  6021. u = result.length;
  6022. v = result[u - 1];
  6023. while (u-- > 0) {
  6024. result[u] = v;
  6025. v = p[v];
  6026. }
  6027. return result;
  6028. }
  6029. const isTeleport = (type) => type.__isTeleport;
  6030. const isTeleportDisabled = (props) => props && (props.disabled || props.disabled === '');
  6031. const isTargetSVG = (target) => typeof SVGElement !== 'undefined' && target instanceof SVGElement;
  6032. const resolveTarget = (props, select) => {
  6033. const targetSelector = props && props.to;
  6034. if (isString(targetSelector)) {
  6035. if (!select) {
  6036. warn(`Current renderer does not support string target for Teleports. ` +
  6037. `(missing querySelector renderer option)`);
  6038. return null;
  6039. }
  6040. else {
  6041. const target = select(targetSelector);
  6042. if (!target) {
  6043. warn(`Failed to locate Teleport target with selector "${targetSelector}". ` +
  6044. `Note the target element must exist before the component is mounted - ` +
  6045. `i.e. the target cannot be rendered by the component itself, and ` +
  6046. `ideally should be outside of the entire Vue component tree.`);
  6047. }
  6048. return target;
  6049. }
  6050. }
  6051. else {
  6052. if (!targetSelector && !isTeleportDisabled(props)) {
  6053. warn(`Invalid Teleport target: ${targetSelector}`);
  6054. }
  6055. return targetSelector;
  6056. }
  6057. };
  6058. const TeleportImpl = {
  6059. __isTeleport: true,
  6060. process(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized, internals) {
  6061. const { mc: mountChildren, pc: patchChildren, pbc: patchBlockChildren, o: { insert, querySelector, createText, createComment } } = internals;
  6062. const disabled = isTeleportDisabled(n2.props);
  6063. const { shapeFlag, children } = n2;
  6064. if (n1 == null) {
  6065. // insert anchors in the main view
  6066. const placeholder = (n2.el = createComment('teleport start')
  6067. );
  6068. const mainAnchor = (n2.anchor = createComment('teleport end')
  6069. );
  6070. insert(placeholder, container, anchor);
  6071. insert(mainAnchor, container, anchor);
  6072. const target = (n2.target = resolveTarget(n2.props, querySelector));
  6073. const targetAnchor = (n2.targetAnchor = createText(''));
  6074. if (target) {
  6075. insert(targetAnchor, target);
  6076. // #2652 we could be teleporting from a non-SVG tree into an SVG tree
  6077. isSVG = isSVG || isTargetSVG(target);
  6078. }
  6079. else if (!disabled) {
  6080. warn('Invalid Teleport target on mount:', target, `(${typeof target})`);
  6081. }
  6082. const mount = (container, anchor) => {
  6083. // Teleport *always* has Array children. This is enforced in both the
  6084. // compiler and vnode children normalization.
  6085. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6086. mountChildren(children, container, anchor, parentComponent, parentSuspense, isSVG, optimized);
  6087. }
  6088. };
  6089. if (disabled) {
  6090. mount(container, mainAnchor);
  6091. }
  6092. else if (target) {
  6093. mount(target, targetAnchor);
  6094. }
  6095. }
  6096. else {
  6097. // update content
  6098. n2.el = n1.el;
  6099. const mainAnchor = (n2.anchor = n1.anchor);
  6100. const target = (n2.target = n1.target);
  6101. const targetAnchor = (n2.targetAnchor = n1.targetAnchor);
  6102. const wasDisabled = isTeleportDisabled(n1.props);
  6103. const currentContainer = wasDisabled ? container : target;
  6104. const currentAnchor = wasDisabled ? mainAnchor : targetAnchor;
  6105. isSVG = isSVG || isTargetSVG(target);
  6106. if (n2.dynamicChildren) {
  6107. // fast path when the teleport happens to be a block root
  6108. patchBlockChildren(n1.dynamicChildren, n2.dynamicChildren, currentContainer, parentComponent, parentSuspense, isSVG);
  6109. // even in block tree mode we need to make sure all root-level nodes
  6110. // in the teleport inherit previous DOM references so that they can
  6111. // be moved in future patches.
  6112. traverseStaticChildren(n1, n2, true);
  6113. }
  6114. else if (!optimized) {
  6115. patchChildren(n1, n2, currentContainer, currentAnchor, parentComponent, parentSuspense, isSVG);
  6116. }
  6117. if (disabled) {
  6118. if (!wasDisabled) {
  6119. // enabled -> disabled
  6120. // move into main container
  6121. moveTeleport(n2, container, mainAnchor, internals, 1 /* TOGGLE */);
  6122. }
  6123. }
  6124. else {
  6125. // target changed
  6126. if ((n2.props && n2.props.to) !== (n1.props && n1.props.to)) {
  6127. const nextTarget = (n2.target = resolveTarget(n2.props, querySelector));
  6128. if (nextTarget) {
  6129. moveTeleport(n2, nextTarget, null, internals, 0 /* TARGET_CHANGE */);
  6130. }
  6131. else {
  6132. warn('Invalid Teleport target on update:', target, `(${typeof target})`);
  6133. }
  6134. }
  6135. else if (wasDisabled) {
  6136. // disabled -> enabled
  6137. // move into teleport target
  6138. moveTeleport(n2, target, targetAnchor, internals, 1 /* TOGGLE */);
  6139. }
  6140. }
  6141. }
  6142. },
  6143. remove(vnode, { r: remove, o: { remove: hostRemove } }) {
  6144. const { shapeFlag, children, anchor } = vnode;
  6145. hostRemove(anchor);
  6146. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6147. for (let i = 0; i < children.length; i++) {
  6148. remove(children[i]);
  6149. }
  6150. }
  6151. },
  6152. move: moveTeleport,
  6153. hydrate: hydrateTeleport
  6154. };
  6155. function moveTeleport(vnode, container, parentAnchor, { o: { insert }, m: move }, moveType = 2 /* REORDER */) {
  6156. // move target anchor if this is a target change.
  6157. if (moveType === 0 /* TARGET_CHANGE */) {
  6158. insert(vnode.targetAnchor, container, parentAnchor);
  6159. }
  6160. const { el, anchor, shapeFlag, children, props } = vnode;
  6161. const isReorder = moveType === 2 /* REORDER */;
  6162. // move main view anchor if this is a re-order.
  6163. if (isReorder) {
  6164. insert(el, container, parentAnchor);
  6165. }
  6166. // if this is a re-order and teleport is enabled (content is in target)
  6167. // do not move children. So the opposite is: only move children if this
  6168. // is not a reorder, or the teleport is disabled
  6169. if (!isReorder || isTeleportDisabled(props)) {
  6170. // Teleport has either Array children or no children.
  6171. if (shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6172. for (let i = 0; i < children.length; i++) {
  6173. move(children[i], container, parentAnchor, 2 /* REORDER */);
  6174. }
  6175. }
  6176. }
  6177. // move main view anchor if this is a re-order.
  6178. if (isReorder) {
  6179. insert(anchor, container, parentAnchor);
  6180. }
  6181. }
  6182. function hydrateTeleport(node, vnode, parentComponent, parentSuspense, optimized, { o: { nextSibling, parentNode, querySelector } }, hydrateChildren) {
  6183. const target = (vnode.target = resolveTarget(vnode.props, querySelector));
  6184. if (target) {
  6185. // if multiple teleports rendered to the same target element, we need to
  6186. // pick up from where the last teleport finished instead of the first node
  6187. const targetNode = target._lpa || target.firstChild;
  6188. if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
  6189. if (isTeleportDisabled(vnode.props)) {
  6190. vnode.anchor = hydrateChildren(nextSibling(node), vnode, parentNode(node), parentComponent, parentSuspense, optimized);
  6191. vnode.targetAnchor = targetNode;
  6192. }
  6193. else {
  6194. vnode.anchor = nextSibling(node);
  6195. vnode.targetAnchor = hydrateChildren(targetNode, vnode, target, parentComponent, parentSuspense, optimized);
  6196. }
  6197. target._lpa =
  6198. vnode.targetAnchor && nextSibling(vnode.targetAnchor);
  6199. }
  6200. }
  6201. return vnode.anchor && nextSibling(vnode.anchor);
  6202. }
  6203. // Force-casted public typing for h and TSX props inference
  6204. const Teleport = TeleportImpl;
  6205. const COMPONENTS = 'components';
  6206. const DIRECTIVES = 'directives';
  6207. /**
  6208. * @private
  6209. */
  6210. function resolveComponent(name) {
  6211. return resolveAsset(COMPONENTS, name) || name;
  6212. }
  6213. const NULL_DYNAMIC_COMPONENT = Symbol();
  6214. /**
  6215. * @private
  6216. */
  6217. function resolveDynamicComponent(component) {
  6218. if (isString(component)) {
  6219. return resolveAsset(COMPONENTS, component, false) || component;
  6220. }
  6221. else {
  6222. // invalid types will fallthrough to createVNode and raise warning
  6223. return (component || NULL_DYNAMIC_COMPONENT);
  6224. }
  6225. }
  6226. /**
  6227. * @private
  6228. */
  6229. function resolveDirective(name) {
  6230. return resolveAsset(DIRECTIVES, name);
  6231. }
  6232. // implementation
  6233. function resolveAsset(type, name, warnMissing = true) {
  6234. const instance = currentRenderingInstance || currentInstance;
  6235. if (instance) {
  6236. const Component = instance.type;
  6237. // self name has highest priority
  6238. if (type === COMPONENTS) {
  6239. // special self referencing call generated by compiler
  6240. // inferred from SFC filename
  6241. if (name === `_self`) {
  6242. return Component;
  6243. }
  6244. const selfName = getComponentName(Component);
  6245. if (selfName &&
  6246. (selfName === name ||
  6247. selfName === camelize(name) ||
  6248. selfName === capitalize(camelize(name)))) {
  6249. return Component;
  6250. }
  6251. }
  6252. const res =
  6253. // local registration
  6254. // check instance[type] first for components with mixin or extends.
  6255. resolve(instance[type] || Component[type], name) ||
  6256. // global registration
  6257. resolve(instance.appContext[type], name);
  6258. if (warnMissing && !res) {
  6259. warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`);
  6260. }
  6261. return res;
  6262. }
  6263. else {
  6264. warn(`resolve${capitalize(type.slice(0, -1))} ` +
  6265. `can only be used in render() or setup().`);
  6266. }
  6267. }
  6268. function resolve(registry, name) {
  6269. return (registry &&
  6270. (registry[name] ||
  6271. registry[camelize(name)] ||
  6272. registry[capitalize(camelize(name))]));
  6273. }
  6274. const Fragment = Symbol('Fragment' );
  6275. const Text = Symbol('Text' );
  6276. const Comment = Symbol('Comment' );
  6277. const Static = Symbol('Static' );
  6278. // Since v-if and v-for are the two possible ways node structure can dynamically
  6279. // change, once we consider v-if branches and each v-for fragment a block, we
  6280. // can divide a template into nested blocks, and within each block the node
  6281. // structure would be stable. This allows us to skip most children diffing
  6282. // and only worry about the dynamic nodes (indicated by patch flags).
  6283. const blockStack = [];
  6284. let currentBlock = null;
  6285. /**
  6286. * Open a block.
  6287. * This must be called before `createBlock`. It cannot be part of `createBlock`
  6288. * because the children of the block are evaluated before `createBlock` itself
  6289. * is called. The generated code typically looks like this:
  6290. *
  6291. * ```js
  6292. * function render() {
  6293. * return (openBlock(),createBlock('div', null, [...]))
  6294. * }
  6295. * ```
  6296. * disableTracking is true when creating a v-for fragment block, since a v-for
  6297. * fragment always diffs its children.
  6298. *
  6299. * @private
  6300. */
  6301. function openBlock(disableTracking = false) {
  6302. blockStack.push((currentBlock = disableTracking ? null : []));
  6303. }
  6304. function closeBlock() {
  6305. blockStack.pop();
  6306. currentBlock = blockStack[blockStack.length - 1] || null;
  6307. }
  6308. // Whether we should be tracking dynamic child nodes inside a block.
  6309. // Only tracks when this value is > 0
  6310. // We are not using a simple boolean because this value may need to be
  6311. // incremented/decremented by nested usage of v-once (see below)
  6312. let shouldTrack$1 = 1;
  6313. /**
  6314. * Block tracking sometimes needs to be disabled, for example during the
  6315. * creation of a tree that needs to be cached by v-once. The compiler generates
  6316. * code like this:
  6317. *
  6318. * ``` js
  6319. * _cache[1] || (
  6320. * setBlockTracking(-1),
  6321. * _cache[1] = createVNode(...),
  6322. * setBlockTracking(1),
  6323. * _cache[1]
  6324. * )
  6325. * ```
  6326. *
  6327. * @private
  6328. */
  6329. function setBlockTracking(value) {
  6330. shouldTrack$1 += value;
  6331. }
  6332. /**
  6333. * Create a block root vnode. Takes the same exact arguments as `createVNode`.
  6334. * A block root keeps track of dynamic nodes within the block in the
  6335. * `dynamicChildren` array.
  6336. *
  6337. * @private
  6338. */
  6339. function createBlock(type, props, children, patchFlag, dynamicProps) {
  6340. const vnode = createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */);
  6341. // save current block children on the block vnode
  6342. vnode.dynamicChildren = currentBlock || EMPTY_ARR;
  6343. // close block
  6344. closeBlock();
  6345. // a block is always going to be patched, so track it as a child of its
  6346. // parent block
  6347. if (shouldTrack$1 > 0 && currentBlock) {
  6348. currentBlock.push(vnode);
  6349. }
  6350. return vnode;
  6351. }
  6352. function isVNode(value) {
  6353. return value ? value.__v_isVNode === true : false;
  6354. }
  6355. function isSameVNodeType(n1, n2) {
  6356. if (n2.shapeFlag & 6 /* COMPONENT */ &&
  6357. hmrDirtyComponents.has(n2.type)) {
  6358. // HMR only: if the component has been hot-updated, force a reload.
  6359. return false;
  6360. }
  6361. return n1.type === n2.type && n1.key === n2.key;
  6362. }
  6363. let vnodeArgsTransformer;
  6364. /**
  6365. * Internal API for registering an arguments transform for createVNode
  6366. * used for creating stubs in the test-utils
  6367. * It is *internal* but needs to be exposed for test-utils to pick up proper
  6368. * typings
  6369. */
  6370. function transformVNodeArgs(transformer) {
  6371. vnodeArgsTransformer = transformer;
  6372. }
  6373. const createVNodeWithArgsTransform = (...args) => {
  6374. return _createVNode(...(vnodeArgsTransformer
  6375. ? vnodeArgsTransformer(args, currentRenderingInstance)
  6376. : args));
  6377. };
  6378. const InternalObjectKey = `__vInternal`;
  6379. const normalizeKey = ({ key }) => key != null ? key : null;
  6380. const normalizeRef = ({ ref }) => {
  6381. return (ref != null
  6382. ? isString(ref) || isRef(ref) || isFunction(ref)
  6383. ? { i: currentRenderingInstance, r: ref }
  6384. : ref
  6385. : null);
  6386. };
  6387. const createVNode = (createVNodeWithArgsTransform
  6388. );
  6389. function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {
  6390. if (!type || type === NULL_DYNAMIC_COMPONENT) {
  6391. if (!type) {
  6392. warn(`Invalid vnode type when creating vnode: ${type}.`);
  6393. }
  6394. type = Comment;
  6395. }
  6396. if (isVNode(type)) {
  6397. // createVNode receiving an existing vnode. This happens in cases like
  6398. // <component :is="vnode"/>
  6399. // #2078 make sure to merge refs during the clone instead of overwriting it
  6400. const cloned = cloneVNode(type, props, true /* mergeRef: true */);
  6401. if (children) {
  6402. normalizeChildren(cloned, children);
  6403. }
  6404. return cloned;
  6405. }
  6406. // class component normalization.
  6407. if (isClassComponent(type)) {
  6408. type = type.__vccOpts;
  6409. }
  6410. // class & style normalization.
  6411. if (props) {
  6412. // for reactive or proxy objects, we need to clone it to enable mutation.
  6413. if (isProxy(props) || InternalObjectKey in props) {
  6414. props = extend({}, props);
  6415. }
  6416. let { class: klass, style } = props;
  6417. if (klass && !isString(klass)) {
  6418. props.class = normalizeClass(klass);
  6419. }
  6420. if (isObject(style)) {
  6421. // reactive state objects need to be cloned since they are likely to be
  6422. // mutated
  6423. if (isProxy(style) && !isArray(style)) {
  6424. style = extend({}, style);
  6425. }
  6426. props.style = normalizeStyle(style);
  6427. }
  6428. }
  6429. // encode the vnode type information into a bitmap
  6430. const shapeFlag = isString(type)
  6431. ? 1 /* ELEMENT */
  6432. : isSuspense(type)
  6433. ? 128 /* SUSPENSE */
  6434. : isTeleport(type)
  6435. ? 64 /* TELEPORT */
  6436. : isObject(type)
  6437. ? 4 /* STATEFUL_COMPONENT */
  6438. : isFunction(type)
  6439. ? 2 /* FUNCTIONAL_COMPONENT */
  6440. : 0;
  6441. if (shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {
  6442. type = toRaw(type);
  6443. warn(`Vue received a Component which was made a reactive object. This can ` +
  6444. `lead to unnecessary performance overhead, and should be avoided by ` +
  6445. `marking the component with \`markRaw\` or using \`shallowRef\` ` +
  6446. `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);
  6447. }
  6448. const vnode = {
  6449. __v_isVNode: true,
  6450. ["__v_skip" /* SKIP */]: true,
  6451. type,
  6452. props,
  6453. key: props && normalizeKey(props),
  6454. ref: props && normalizeRef(props),
  6455. scopeId: currentScopeId,
  6456. children: null,
  6457. component: null,
  6458. suspense: null,
  6459. ssContent: null,
  6460. ssFallback: null,
  6461. dirs: null,
  6462. transition: null,
  6463. el: null,
  6464. anchor: null,
  6465. target: null,
  6466. targetAnchor: null,
  6467. staticCount: 0,
  6468. shapeFlag,
  6469. patchFlag,
  6470. dynamicProps,
  6471. dynamicChildren: null,
  6472. appContext: null
  6473. };
  6474. // validate key
  6475. if (vnode.key !== vnode.key) {
  6476. warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);
  6477. }
  6478. normalizeChildren(vnode, children);
  6479. // normalize suspense children
  6480. if (shapeFlag & 128 /* SUSPENSE */) {
  6481. const { content, fallback } = normalizeSuspenseChildren(vnode);
  6482. vnode.ssContent = content;
  6483. vnode.ssFallback = fallback;
  6484. }
  6485. if (shouldTrack$1 > 0 &&
  6486. // avoid a block node from tracking itself
  6487. !isBlockNode &&
  6488. // has current parent block
  6489. currentBlock &&
  6490. // presence of a patch flag indicates this node needs patching on updates.
  6491. // component nodes also should always be patched, because even if the
  6492. // component doesn't need to update, it needs to persist the instance on to
  6493. // the next vnode so that it can be properly unmounted later.
  6494. (patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&
  6495. // the EVENTS flag is only for hydration and if it is the only flag, the
  6496. // vnode should not be considered dynamic due to handler caching.
  6497. patchFlag !== 32 /* HYDRATE_EVENTS */) {
  6498. currentBlock.push(vnode);
  6499. }
  6500. return vnode;
  6501. }
  6502. function cloneVNode(vnode, extraProps, mergeRef = false) {
  6503. // This is intentionally NOT using spread or extend to avoid the runtime
  6504. // key enumeration cost.
  6505. const { props, ref, patchFlag, children } = vnode;
  6506. const mergedProps = extraProps ? mergeProps(props || {}, extraProps) : props;
  6507. return {
  6508. __v_isVNode: true,
  6509. ["__v_skip" /* SKIP */]: true,
  6510. type: vnode.type,
  6511. props: mergedProps,
  6512. key: mergedProps && normalizeKey(mergedProps),
  6513. ref: extraProps && extraProps.ref
  6514. ? // #2078 in the case of <component :is="vnode" ref="extra"/>
  6515. // if the vnode itself already has a ref, cloneVNode will need to merge
  6516. // the refs so the single vnode can be set on multiple refs
  6517. mergeRef && ref
  6518. ? isArray(ref)
  6519. ? ref.concat(normalizeRef(extraProps))
  6520. : [ref, normalizeRef(extraProps)]
  6521. : normalizeRef(extraProps)
  6522. : ref,
  6523. scopeId: vnode.scopeId,
  6524. children: patchFlag === -1 /* HOISTED */ && isArray(children)
  6525. ? children.map(deepCloneVNode)
  6526. : children,
  6527. target: vnode.target,
  6528. targetAnchor: vnode.targetAnchor,
  6529. staticCount: vnode.staticCount,
  6530. shapeFlag: vnode.shapeFlag,
  6531. // if the vnode is cloned with extra props, we can no longer assume its
  6532. // existing patch flag to be reliable and need to add the FULL_PROPS flag.
  6533. // note: perserve flag for fragments since they use the flag for children
  6534. // fast paths only.
  6535. patchFlag: extraProps && vnode.type !== Fragment
  6536. ? patchFlag === -1 // hoisted node
  6537. ? 16 /* FULL_PROPS */
  6538. : patchFlag | 16 /* FULL_PROPS */
  6539. : patchFlag,
  6540. dynamicProps: vnode.dynamicProps,
  6541. dynamicChildren: vnode.dynamicChildren,
  6542. appContext: vnode.appContext,
  6543. dirs: vnode.dirs,
  6544. transition: vnode.transition,
  6545. // These should technically only be non-null on mounted VNodes. However,
  6546. // they *should* be copied for kept-alive vnodes. So we just always copy
  6547. // them since them being non-null during a mount doesn't affect the logic as
  6548. // they will simply be overwritten.
  6549. component: vnode.component,
  6550. suspense: vnode.suspense,
  6551. ssContent: vnode.ssContent && cloneVNode(vnode.ssContent),
  6552. ssFallback: vnode.ssFallback && cloneVNode(vnode.ssFallback),
  6553. el: vnode.el,
  6554. anchor: vnode.anchor
  6555. };
  6556. }
  6557. /**
  6558. * Dev only, for HMR of hoisted vnodes reused in v-for
  6559. * https://github.com/vitejs/vite/issues/2022
  6560. */
  6561. function deepCloneVNode(vnode) {
  6562. const cloned = cloneVNode(vnode);
  6563. if (isArray(vnode.children)) {
  6564. cloned.children = vnode.children.map(deepCloneVNode);
  6565. }
  6566. return cloned;
  6567. }
  6568. /**
  6569. * @private
  6570. */
  6571. function createTextVNode(text = ' ', flag = 0) {
  6572. return createVNode(Text, null, text, flag);
  6573. }
  6574. /**
  6575. * @private
  6576. */
  6577. function createStaticVNode(content, numberOfNodes) {
  6578. // A static vnode can contain multiple stringified elements, and the number
  6579. // of elements is necessary for hydration.
  6580. const vnode = createVNode(Static, null, content);
  6581. vnode.staticCount = numberOfNodes;
  6582. return vnode;
  6583. }
  6584. /**
  6585. * @private
  6586. */
  6587. function createCommentVNode(text = '',
  6588. // when used as the v-else branch, the comment node must be created as a
  6589. // block to ensure correct updates.
  6590. asBlock = false) {
  6591. return asBlock
  6592. ? (openBlock(), createBlock(Comment, null, text))
  6593. : createVNode(Comment, null, text);
  6594. }
  6595. function normalizeVNode(child) {
  6596. if (child == null || typeof child === 'boolean') {
  6597. // empty placeholder
  6598. return createVNode(Comment);
  6599. }
  6600. else if (isArray(child)) {
  6601. // fragment
  6602. return createVNode(Fragment, null, child);
  6603. }
  6604. else if (typeof child === 'object') {
  6605. // already vnode, this should be the most common since compiled templates
  6606. // always produce all-vnode children arrays
  6607. return child.el === null ? child : cloneVNode(child);
  6608. }
  6609. else {
  6610. // strings and numbers
  6611. return createVNode(Text, null, String(child));
  6612. }
  6613. }
  6614. // optimized normalization for template-compiled render fns
  6615. function cloneIfMounted(child) {
  6616. return child.el === null ? child : cloneVNode(child);
  6617. }
  6618. function normalizeChildren(vnode, children) {
  6619. let type = 0;
  6620. const { shapeFlag } = vnode;
  6621. if (children == null) {
  6622. children = null;
  6623. }
  6624. else if (isArray(children)) {
  6625. type = 16 /* ARRAY_CHILDREN */;
  6626. }
  6627. else if (typeof children === 'object') {
  6628. if (shapeFlag & 1 /* ELEMENT */ || shapeFlag & 64 /* TELEPORT */) {
  6629. // Normalize slot to plain children for plain element and Teleport
  6630. const slot = children.default;
  6631. if (slot) {
  6632. // _c marker is added by withCtx() indicating this is a compiled slot
  6633. slot._c && setCompiledSlotRendering(1);
  6634. normalizeChildren(vnode, slot());
  6635. slot._c && setCompiledSlotRendering(-1);
  6636. }
  6637. return;
  6638. }
  6639. else {
  6640. type = 32 /* SLOTS_CHILDREN */;
  6641. const slotFlag = children._;
  6642. if (!slotFlag && !(InternalObjectKey in children)) {
  6643. children._ctx = currentRenderingInstance;
  6644. }
  6645. else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {
  6646. // a child component receives forwarded slots from the parent.
  6647. // its slot type is determined by its parent's slot type.
  6648. if (currentRenderingInstance.vnode.patchFlag & 1024 /* DYNAMIC_SLOTS */) {
  6649. children._ = 2 /* DYNAMIC */;
  6650. vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  6651. }
  6652. else {
  6653. children._ = 1 /* STABLE */;
  6654. }
  6655. }
  6656. }
  6657. }
  6658. else if (isFunction(children)) {
  6659. children = { default: children, _ctx: currentRenderingInstance };
  6660. type = 32 /* SLOTS_CHILDREN */;
  6661. }
  6662. else {
  6663. children = String(children);
  6664. // force teleport children to array so it can be moved around
  6665. if (shapeFlag & 64 /* TELEPORT */) {
  6666. type = 16 /* ARRAY_CHILDREN */;
  6667. children = [createTextVNode(children)];
  6668. }
  6669. else {
  6670. type = 8 /* TEXT_CHILDREN */;
  6671. }
  6672. }
  6673. vnode.children = children;
  6674. vnode.shapeFlag |= type;
  6675. }
  6676. function mergeProps(...args) {
  6677. const ret = extend({}, args[0]);
  6678. for (let i = 1; i < args.length; i++) {
  6679. const toMerge = args[i];
  6680. for (const key in toMerge) {
  6681. if (key === 'class') {
  6682. if (ret.class !== toMerge.class) {
  6683. ret.class = normalizeClass([ret.class, toMerge.class]);
  6684. }
  6685. }
  6686. else if (key === 'style') {
  6687. ret.style = normalizeStyle([ret.style, toMerge.style]);
  6688. }
  6689. else if (isOn(key)) {
  6690. const existing = ret[key];
  6691. const incoming = toMerge[key];
  6692. if (existing !== incoming) {
  6693. ret[key] = existing
  6694. ? [].concat(existing, toMerge[key])
  6695. : incoming;
  6696. }
  6697. }
  6698. else if (key !== '') {
  6699. ret[key] = toMerge[key];
  6700. }
  6701. }
  6702. }
  6703. return ret;
  6704. }
  6705. function provide(key, value) {
  6706. if (!currentInstance) {
  6707. {
  6708. warn(`provide() can only be used inside setup().`);
  6709. }
  6710. }
  6711. else {
  6712. let provides = currentInstance.provides;
  6713. // by default an instance inherits its parent's provides object
  6714. // but when it needs to provide values of its own, it creates its
  6715. // own provides object using parent provides object as prototype.
  6716. // this way in `inject` we can simply look up injections from direct
  6717. // parent and let the prototype chain do the work.
  6718. const parentProvides = currentInstance.parent && currentInstance.parent.provides;
  6719. if (parentProvides === provides) {
  6720. provides = currentInstance.provides = Object.create(parentProvides);
  6721. }
  6722. // TS doesn't allow symbol as index type
  6723. provides[key] = value;
  6724. }
  6725. }
  6726. function inject(key, defaultValue, treatDefaultAsFactory = false) {
  6727. // fallback to `currentRenderingInstance` so that this can be called in
  6728. // a functional component
  6729. const instance = currentInstance || currentRenderingInstance;
  6730. if (instance) {
  6731. // #2400
  6732. // to support `app.use` plugins,
  6733. // fallback to appContext's `provides` if the intance is at root
  6734. const provides = instance.parent == null
  6735. ? instance.vnode.appContext && instance.vnode.appContext.provides
  6736. : instance.parent.provides;
  6737. if (provides && key in provides) {
  6738. // TS doesn't allow symbol as index type
  6739. return provides[key];
  6740. }
  6741. else if (arguments.length > 1) {
  6742. return treatDefaultAsFactory && isFunction(defaultValue)
  6743. ? defaultValue()
  6744. : defaultValue;
  6745. }
  6746. else {
  6747. warn(`injection "${String(key)}" not found.`);
  6748. }
  6749. }
  6750. else {
  6751. warn(`inject() can only be used inside setup() or functional components.`);
  6752. }
  6753. }
  6754. function createDuplicateChecker() {
  6755. const cache = Object.create(null);
  6756. return (type, key) => {
  6757. if (cache[key]) {
  6758. warn(`${type} property "${key}" is already defined in ${cache[key]}.`);
  6759. }
  6760. else {
  6761. cache[key] = type;
  6762. }
  6763. };
  6764. }
  6765. let isInBeforeCreate = false;
  6766. function applyOptions(instance, options, deferredData = [], deferredWatch = [], deferredProvide = [], asMixin = false) {
  6767. const {
  6768. // composition
  6769. mixins, extends: extendsOptions,
  6770. // state
  6771. data: dataOptions, computed: computedOptions, methods, watch: watchOptions, provide: provideOptions, inject: injectOptions,
  6772. // assets
  6773. components, directives,
  6774. // lifecycle
  6775. beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy, beforeUnmount, destroyed, unmounted, render, renderTracked, renderTriggered, errorCaptured,
  6776. // public API
  6777. expose } = options;
  6778. const publicThis = instance.proxy;
  6779. const ctx = instance.ctx;
  6780. const globalMixins = instance.appContext.mixins;
  6781. if (asMixin && render && instance.render === NOOP) {
  6782. instance.render = render;
  6783. }
  6784. // applyOptions is called non-as-mixin once per instance
  6785. if (!asMixin) {
  6786. isInBeforeCreate = true;
  6787. callSyncHook('beforeCreate', "bc" /* BEFORE_CREATE */, options, instance, globalMixins);
  6788. isInBeforeCreate = false;
  6789. // global mixins are applied first
  6790. applyMixins(instance, globalMixins, deferredData, deferredWatch, deferredProvide);
  6791. }
  6792. // extending a base component...
  6793. if (extendsOptions) {
  6794. applyOptions(instance, extendsOptions, deferredData, deferredWatch, deferredProvide, true);
  6795. }
  6796. // local mixins
  6797. if (mixins) {
  6798. applyMixins(instance, mixins, deferredData, deferredWatch, deferredProvide);
  6799. }
  6800. const checkDuplicateProperties = createDuplicateChecker() ;
  6801. {
  6802. const [propsOptions] = instance.propsOptions;
  6803. if (propsOptions) {
  6804. for (const key in propsOptions) {
  6805. checkDuplicateProperties("Props" /* PROPS */, key);
  6806. }
  6807. }
  6808. }
  6809. // options initialization order (to be consistent with Vue 2):
  6810. // - props (already done outside of this function)
  6811. // - inject
  6812. // - methods
  6813. // - data (deferred since it relies on `this` access)
  6814. // - computed
  6815. // - watch (deferred since it relies on `this` access)
  6816. if (injectOptions) {
  6817. if (isArray(injectOptions)) {
  6818. for (let i = 0; i < injectOptions.length; i++) {
  6819. const key = injectOptions[i];
  6820. ctx[key] = inject(key);
  6821. {
  6822. checkDuplicateProperties("Inject" /* INJECT */, key);
  6823. }
  6824. }
  6825. }
  6826. else {
  6827. for (const key in injectOptions) {
  6828. const opt = injectOptions[key];
  6829. if (isObject(opt)) {
  6830. ctx[key] = inject(opt.from || key, opt.default, true /* treat default function as factory */);
  6831. }
  6832. else {
  6833. ctx[key] = inject(opt);
  6834. }
  6835. {
  6836. checkDuplicateProperties("Inject" /* INJECT */, key);
  6837. }
  6838. }
  6839. }
  6840. }
  6841. if (methods) {
  6842. for (const key in methods) {
  6843. const methodHandler = methods[key];
  6844. if (isFunction(methodHandler)) {
  6845. // In dev mode, we use the `createRenderContext` function to define methods to the proxy target,
  6846. // and those are read-only but reconfigurable, so it needs to be redefined here
  6847. {
  6848. Object.defineProperty(ctx, key, {
  6849. value: methodHandler.bind(publicThis),
  6850. configurable: true,
  6851. enumerable: false
  6852. });
  6853. }
  6854. {
  6855. checkDuplicateProperties("Methods" /* METHODS */, key);
  6856. }
  6857. }
  6858. else {
  6859. warn(`Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
  6860. `Did you reference the function correctly?`);
  6861. }
  6862. }
  6863. }
  6864. if (!asMixin) {
  6865. if (deferredData.length) {
  6866. deferredData.forEach(dataFn => resolveData(instance, dataFn, publicThis));
  6867. }
  6868. if (dataOptions) {
  6869. // @ts-ignore dataOptions is not fully type safe
  6870. resolveData(instance, dataOptions, publicThis);
  6871. }
  6872. {
  6873. const rawData = toRaw(instance.data);
  6874. for (const key in rawData) {
  6875. checkDuplicateProperties("Data" /* DATA */, key);
  6876. // expose data on ctx during dev
  6877. if (key[0] !== '$' && key[0] !== '_') {
  6878. Object.defineProperty(ctx, key, {
  6879. configurable: true,
  6880. enumerable: true,
  6881. get: () => rawData[key],
  6882. set: NOOP
  6883. });
  6884. }
  6885. }
  6886. }
  6887. }
  6888. else if (dataOptions) {
  6889. deferredData.push(dataOptions);
  6890. }
  6891. if (computedOptions) {
  6892. for (const key in computedOptions) {
  6893. const opt = computedOptions[key];
  6894. const get = isFunction(opt)
  6895. ? opt.bind(publicThis, publicThis)
  6896. : isFunction(opt.get)
  6897. ? opt.get.bind(publicThis, publicThis)
  6898. : NOOP;
  6899. if (get === NOOP) {
  6900. warn(`Computed property "${key}" has no getter.`);
  6901. }
  6902. const set = !isFunction(opt) && isFunction(opt.set)
  6903. ? opt.set.bind(publicThis)
  6904. : () => {
  6905. warn(`Write operation failed: computed property "${key}" is readonly.`);
  6906. }
  6907. ;
  6908. const c = computed$1({
  6909. get,
  6910. set
  6911. });
  6912. Object.defineProperty(ctx, key, {
  6913. enumerable: true,
  6914. configurable: true,
  6915. get: () => c.value,
  6916. set: v => (c.value = v)
  6917. });
  6918. {
  6919. checkDuplicateProperties("Computed" /* COMPUTED */, key);
  6920. }
  6921. }
  6922. }
  6923. if (watchOptions) {
  6924. deferredWatch.push(watchOptions);
  6925. }
  6926. if (!asMixin && deferredWatch.length) {
  6927. deferredWatch.forEach(watchOptions => {
  6928. for (const key in watchOptions) {
  6929. createWatcher(watchOptions[key], ctx, publicThis, key);
  6930. }
  6931. });
  6932. }
  6933. if (provideOptions) {
  6934. deferredProvide.push(provideOptions);
  6935. }
  6936. if (!asMixin && deferredProvide.length) {
  6937. deferredProvide.forEach(provideOptions => {
  6938. const provides = isFunction(provideOptions)
  6939. ? provideOptions.call(publicThis)
  6940. : provideOptions;
  6941. Reflect.ownKeys(provides).forEach(key => {
  6942. provide(key, provides[key]);
  6943. });
  6944. });
  6945. }
  6946. // asset options.
  6947. // To reduce memory usage, only components with mixins or extends will have
  6948. // resolved asset registry attached to instance.
  6949. if (asMixin) {
  6950. if (components) {
  6951. extend(instance.components ||
  6952. (instance.components = extend({}, instance.type.components)), components);
  6953. }
  6954. if (directives) {
  6955. extend(instance.directives ||
  6956. (instance.directives = extend({}, instance.type.directives)), directives);
  6957. }
  6958. }
  6959. // lifecycle options
  6960. if (!asMixin) {
  6961. callSyncHook('created', "c" /* CREATED */, options, instance, globalMixins);
  6962. }
  6963. if (beforeMount) {
  6964. onBeforeMount(beforeMount.bind(publicThis));
  6965. }
  6966. if (mounted) {
  6967. onMounted(mounted.bind(publicThis));
  6968. }
  6969. if (beforeUpdate) {
  6970. onBeforeUpdate(beforeUpdate.bind(publicThis));
  6971. }
  6972. if (updated) {
  6973. onUpdated(updated.bind(publicThis));
  6974. }
  6975. if (activated) {
  6976. onActivated(activated.bind(publicThis));
  6977. }
  6978. if (deactivated) {
  6979. onDeactivated(deactivated.bind(publicThis));
  6980. }
  6981. if (errorCaptured) {
  6982. onErrorCaptured(errorCaptured.bind(publicThis));
  6983. }
  6984. if (renderTracked) {
  6985. onRenderTracked(renderTracked.bind(publicThis));
  6986. }
  6987. if (renderTriggered) {
  6988. onRenderTriggered(renderTriggered.bind(publicThis));
  6989. }
  6990. if (beforeDestroy) {
  6991. warn(`\`beforeDestroy\` has been renamed to \`beforeUnmount\`.`);
  6992. }
  6993. if (beforeUnmount) {
  6994. onBeforeUnmount(beforeUnmount.bind(publicThis));
  6995. }
  6996. if (destroyed) {
  6997. warn(`\`destroyed\` has been renamed to \`unmounted\`.`);
  6998. }
  6999. if (unmounted) {
  7000. onUnmounted(unmounted.bind(publicThis));
  7001. }
  7002. if (isArray(expose)) {
  7003. if (!asMixin) {
  7004. if (expose.length) {
  7005. const exposed = instance.exposed || (instance.exposed = proxyRefs({}));
  7006. expose.forEach(key => {
  7007. exposed[key] = toRef(publicThis, key);
  7008. });
  7009. }
  7010. else if (!instance.exposed) {
  7011. instance.exposed = EMPTY_OBJ;
  7012. }
  7013. }
  7014. else {
  7015. warn(`The \`expose\` option is ignored when used in mixins.`);
  7016. }
  7017. }
  7018. }
  7019. function callSyncHook(name, type, options, instance, globalMixins) {
  7020. callHookFromMixins(name, type, globalMixins, instance);
  7021. const { extends: base, mixins } = options;
  7022. if (base) {
  7023. callHookFromExtends(name, type, base, instance);
  7024. }
  7025. if (mixins) {
  7026. callHookFromMixins(name, type, mixins, instance);
  7027. }
  7028. const selfHook = options[name];
  7029. if (selfHook) {
  7030. callWithAsyncErrorHandling(selfHook.bind(instance.proxy), instance, type);
  7031. }
  7032. }
  7033. function callHookFromExtends(name, type, base, instance) {
  7034. if (base.extends) {
  7035. callHookFromExtends(name, type, base.extends, instance);
  7036. }
  7037. const baseHook = base[name];
  7038. if (baseHook) {
  7039. callWithAsyncErrorHandling(baseHook.bind(instance.proxy), instance, type);
  7040. }
  7041. }
  7042. function callHookFromMixins(name, type, mixins, instance) {
  7043. for (let i = 0; i < mixins.length; i++) {
  7044. const chainedMixins = mixins[i].mixins;
  7045. if (chainedMixins) {
  7046. callHookFromMixins(name, type, chainedMixins, instance);
  7047. }
  7048. const fn = mixins[i][name];
  7049. if (fn) {
  7050. callWithAsyncErrorHandling(fn.bind(instance.proxy), instance, type);
  7051. }
  7052. }
  7053. }
  7054. function applyMixins(instance, mixins, deferredData, deferredWatch, deferredProvide) {
  7055. for (let i = 0; i < mixins.length; i++) {
  7056. applyOptions(instance, mixins[i], deferredData, deferredWatch, deferredProvide, true);
  7057. }
  7058. }
  7059. function resolveData(instance, dataFn, publicThis) {
  7060. if (!isFunction(dataFn)) {
  7061. warn(`The data option must be a function. ` +
  7062. `Plain object usage is no longer supported.`);
  7063. }
  7064. const data = dataFn.call(publicThis, publicThis);
  7065. if (isPromise(data)) {
  7066. warn(`data() returned a Promise - note data() cannot be async; If you ` +
  7067. `intend to perform data fetching before component renders, use ` +
  7068. `async setup() + <Suspense>.`);
  7069. }
  7070. if (!isObject(data)) {
  7071. warn(`data() should return an object.`);
  7072. }
  7073. else if (instance.data === EMPTY_OBJ) {
  7074. instance.data = reactive(data);
  7075. }
  7076. else {
  7077. // existing data: this is a mixin or extends.
  7078. extend(instance.data, data);
  7079. }
  7080. }
  7081. function createWatcher(raw, ctx, publicThis, key) {
  7082. const getter = key.includes('.')
  7083. ? createPathGetter(publicThis, key)
  7084. : () => publicThis[key];
  7085. if (isString(raw)) {
  7086. const handler = ctx[raw];
  7087. if (isFunction(handler)) {
  7088. watch(getter, handler);
  7089. }
  7090. else {
  7091. warn(`Invalid watch handler specified by key "${raw}"`, handler);
  7092. }
  7093. }
  7094. else if (isFunction(raw)) {
  7095. watch(getter, raw.bind(publicThis));
  7096. }
  7097. else if (isObject(raw)) {
  7098. if (isArray(raw)) {
  7099. raw.forEach(r => createWatcher(r, ctx, publicThis, key));
  7100. }
  7101. else {
  7102. const handler = isFunction(raw.handler)
  7103. ? raw.handler.bind(publicThis)
  7104. : ctx[raw.handler];
  7105. if (isFunction(handler)) {
  7106. watch(getter, handler, raw);
  7107. }
  7108. else {
  7109. warn(`Invalid watch handler specified by key "${raw.handler}"`, handler);
  7110. }
  7111. }
  7112. }
  7113. else {
  7114. warn(`Invalid watch option: "${key}"`, raw);
  7115. }
  7116. }
  7117. function createPathGetter(ctx, path) {
  7118. const segments = path.split('.');
  7119. return () => {
  7120. let cur = ctx;
  7121. for (let i = 0; i < segments.length && cur; i++) {
  7122. cur = cur[segments[i]];
  7123. }
  7124. return cur;
  7125. };
  7126. }
  7127. function resolveMergedOptions(instance) {
  7128. const raw = instance.type;
  7129. const { __merged, mixins, extends: extendsOptions } = raw;
  7130. if (__merged)
  7131. return __merged;
  7132. const globalMixins = instance.appContext.mixins;
  7133. if (!globalMixins.length && !mixins && !extendsOptions)
  7134. return raw;
  7135. const options = {};
  7136. globalMixins.forEach(m => mergeOptions(options, m, instance));
  7137. mergeOptions(options, raw, instance);
  7138. return (raw.__merged = options);
  7139. }
  7140. function mergeOptions(to, from, instance) {
  7141. const strats = instance.appContext.config.optionMergeStrategies;
  7142. const { mixins, extends: extendsOptions } = from;
  7143. extendsOptions && mergeOptions(to, extendsOptions, instance);
  7144. mixins &&
  7145. mixins.forEach((m) => mergeOptions(to, m, instance));
  7146. for (const key in from) {
  7147. if (strats && hasOwn(strats, key)) {
  7148. to[key] = strats[key](to[key], from[key], instance.proxy, key);
  7149. }
  7150. else {
  7151. to[key] = from[key];
  7152. }
  7153. }
  7154. }
  7155. /**
  7156. * #2437 In Vue 3, functional components do not have a public instance proxy but
  7157. * they exist in the internal parent chain. For code that relies on traversing
  7158. * public $parent chains, skip functional ones and go to the parent instead.
  7159. */
  7160. const getPublicInstance = (i) => {
  7161. if (!i)
  7162. return null;
  7163. if (isStatefulComponent(i))
  7164. return i.exposed ? i.exposed : i.proxy;
  7165. return getPublicInstance(i.parent);
  7166. };
  7167. const publicPropertiesMap = extend(Object.create(null), {
  7168. $: i => i,
  7169. $el: i => i.vnode.el,
  7170. $data: i => i.data,
  7171. $props: i => (shallowReadonly(i.props) ),
  7172. $attrs: i => (shallowReadonly(i.attrs) ),
  7173. $slots: i => (shallowReadonly(i.slots) ),
  7174. $refs: i => (shallowReadonly(i.refs) ),
  7175. $parent: i => getPublicInstance(i.parent),
  7176. $root: i => getPublicInstance(i.root),
  7177. $emit: i => i.emit,
  7178. $options: i => (resolveMergedOptions(i) ),
  7179. $forceUpdate: i => () => queueJob(i.update),
  7180. $nextTick: i => nextTick.bind(i.proxy),
  7181. $watch: i => (instanceWatch.bind(i) )
  7182. });
  7183. const PublicInstanceProxyHandlers = {
  7184. get({ _: instance }, key) {
  7185. const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
  7186. // let @vue/reactivity know it should never observe Vue public instances.
  7187. if (key === "__v_skip" /* SKIP */) {
  7188. return true;
  7189. }
  7190. // for internal formatters to know that this is a Vue instance
  7191. if (key === '__isVue') {
  7192. return true;
  7193. }
  7194. // data / props / ctx
  7195. // This getter gets called for every property access on the render context
  7196. // during render and is a major hotspot. The most expensive part of this
  7197. // is the multiple hasOwn() calls. It's much faster to do a simple property
  7198. // access on a plain object, so we use an accessCache object (with null
  7199. // prototype) to memoize what access type a key corresponds to.
  7200. let normalizedProps;
  7201. if (key[0] !== '$') {
  7202. const n = accessCache[key];
  7203. if (n !== undefined) {
  7204. switch (n) {
  7205. case 0 /* SETUP */:
  7206. return setupState[key];
  7207. case 1 /* DATA */:
  7208. return data[key];
  7209. case 3 /* CONTEXT */:
  7210. return ctx[key];
  7211. case 2 /* PROPS */:
  7212. return props[key];
  7213. // default: just fallthrough
  7214. }
  7215. }
  7216. else if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  7217. accessCache[key] = 0 /* SETUP */;
  7218. return setupState[key];
  7219. }
  7220. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  7221. accessCache[key] = 1 /* DATA */;
  7222. return data[key];
  7223. }
  7224. else if (
  7225. // only cache other properties when instance has declared (thus stable)
  7226. // props
  7227. (normalizedProps = instance.propsOptions[0]) &&
  7228. hasOwn(normalizedProps, key)) {
  7229. accessCache[key] = 2 /* PROPS */;
  7230. return props[key];
  7231. }
  7232. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  7233. accessCache[key] = 3 /* CONTEXT */;
  7234. return ctx[key];
  7235. }
  7236. else if (!isInBeforeCreate) {
  7237. accessCache[key] = 4 /* OTHER */;
  7238. }
  7239. }
  7240. const publicGetter = publicPropertiesMap[key];
  7241. let cssModule, globalProperties;
  7242. // public $xxx properties
  7243. if (publicGetter) {
  7244. if (key === '$attrs') {
  7245. track(instance, "get" /* GET */, key);
  7246. markAttrsAccessed();
  7247. }
  7248. return publicGetter(instance);
  7249. }
  7250. else if (
  7251. // css module (injected by vue-loader)
  7252. (cssModule = type.__cssModules) &&
  7253. (cssModule = cssModule[key])) {
  7254. return cssModule;
  7255. }
  7256. else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
  7257. // user may set custom properties to `this` that start with `$`
  7258. accessCache[key] = 3 /* CONTEXT */;
  7259. return ctx[key];
  7260. }
  7261. else if (
  7262. // global properties
  7263. ((globalProperties = appContext.config.globalProperties),
  7264. hasOwn(globalProperties, key))) {
  7265. return globalProperties[key];
  7266. }
  7267. else if (currentRenderingInstance &&
  7268. (!isString(key) ||
  7269. // #1091 avoid internal isRef/isVNode checks on component instance leading
  7270. // to infinite warning loop
  7271. key.indexOf('__v') !== 0)) {
  7272. if (data !== EMPTY_OBJ &&
  7273. (key[0] === '$' || key[0] === '_') &&
  7274. hasOwn(data, key)) {
  7275. warn(`Property ${JSON.stringify(key)} must be accessed via $data because it starts with a reserved ` +
  7276. `character ("$" or "_") and is not proxied on the render context.`);
  7277. }
  7278. else if (instance === currentRenderingInstance) {
  7279. warn(`Property ${JSON.stringify(key)} was accessed during render ` +
  7280. `but is not defined on instance.`);
  7281. }
  7282. }
  7283. },
  7284. set({ _: instance }, key, value) {
  7285. const { data, setupState, ctx } = instance;
  7286. if (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) {
  7287. setupState[key] = value;
  7288. }
  7289. else if (data !== EMPTY_OBJ && hasOwn(data, key)) {
  7290. data[key] = value;
  7291. }
  7292. else if (hasOwn(instance.props, key)) {
  7293. warn(`Attempting to mutate prop "${key}". Props are readonly.`, instance);
  7294. return false;
  7295. }
  7296. if (key[0] === '$' && key.slice(1) in instance) {
  7297. warn(`Attempting to mutate public property "${key}". ` +
  7298. `Properties starting with $ are reserved and readonly.`, instance);
  7299. return false;
  7300. }
  7301. else {
  7302. if (key in instance.appContext.config.globalProperties) {
  7303. Object.defineProperty(ctx, key, {
  7304. enumerable: true,
  7305. configurable: true,
  7306. value
  7307. });
  7308. }
  7309. else {
  7310. ctx[key] = value;
  7311. }
  7312. }
  7313. return true;
  7314. },
  7315. has({ _: { data, setupState, accessCache, ctx, appContext, propsOptions } }, key) {
  7316. let normalizedProps;
  7317. return (accessCache[key] !== undefined ||
  7318. (data !== EMPTY_OBJ && hasOwn(data, key)) ||
  7319. (setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
  7320. ((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
  7321. hasOwn(ctx, key) ||
  7322. hasOwn(publicPropertiesMap, key) ||
  7323. hasOwn(appContext.config.globalProperties, key));
  7324. }
  7325. };
  7326. {
  7327. PublicInstanceProxyHandlers.ownKeys = (target) => {
  7328. warn(`Avoid app logic that relies on enumerating keys on a component instance. ` +
  7329. `The keys will be empty in production mode to avoid performance overhead.`);
  7330. return Reflect.ownKeys(target);
  7331. };
  7332. }
  7333. const RuntimeCompiledPublicInstanceProxyHandlers = extend({}, PublicInstanceProxyHandlers, {
  7334. get(target, key) {
  7335. // fast path for unscopables when using `with` block
  7336. if (key === Symbol.unscopables) {
  7337. return;
  7338. }
  7339. return PublicInstanceProxyHandlers.get(target, key, target);
  7340. },
  7341. has(_, key) {
  7342. const has = key[0] !== '_' && !isGloballyWhitelisted(key);
  7343. if (!has && PublicInstanceProxyHandlers.has(_, key)) {
  7344. warn(`Property ${JSON.stringify(key)} should not start with _ which is a reserved prefix for Vue internals.`);
  7345. }
  7346. return has;
  7347. }
  7348. });
  7349. // In dev mode, the proxy target exposes the same properties as seen on `this`
  7350. // for easier console inspection. In prod mode it will be an empty object so
  7351. // these properties definitions can be skipped.
  7352. function createRenderContext(instance) {
  7353. const target = {};
  7354. // expose internal instance for proxy handlers
  7355. Object.defineProperty(target, `_`, {
  7356. configurable: true,
  7357. enumerable: false,
  7358. get: () => instance
  7359. });
  7360. // expose public properties
  7361. Object.keys(publicPropertiesMap).forEach(key => {
  7362. Object.defineProperty(target, key, {
  7363. configurable: true,
  7364. enumerable: false,
  7365. get: () => publicPropertiesMap[key](instance),
  7366. // intercepted by the proxy so no need for implementation,
  7367. // but needed to prevent set errors
  7368. set: NOOP
  7369. });
  7370. });
  7371. // expose global properties
  7372. const { globalProperties } = instance.appContext.config;
  7373. Object.keys(globalProperties).forEach(key => {
  7374. Object.defineProperty(target, key, {
  7375. configurable: true,
  7376. enumerable: false,
  7377. get: () => globalProperties[key],
  7378. set: NOOP
  7379. });
  7380. });
  7381. return target;
  7382. }
  7383. // dev only
  7384. function exposePropsOnRenderContext(instance) {
  7385. const { ctx, propsOptions: [propsOptions] } = instance;
  7386. if (propsOptions) {
  7387. Object.keys(propsOptions).forEach(key => {
  7388. Object.defineProperty(ctx, key, {
  7389. enumerable: true,
  7390. configurable: true,
  7391. get: () => instance.props[key],
  7392. set: NOOP
  7393. });
  7394. });
  7395. }
  7396. }
  7397. // dev only
  7398. function exposeSetupStateOnRenderContext(instance) {
  7399. const { ctx, setupState } = instance;
  7400. Object.keys(toRaw(setupState)).forEach(key => {
  7401. if (key[0] === '$' || key[0] === '_') {
  7402. warn(`setup() return property ${JSON.stringify(key)} should not start with "$" or "_" ` +
  7403. `which are reserved prefixes for Vue internals.`);
  7404. return;
  7405. }
  7406. Object.defineProperty(ctx, key, {
  7407. enumerable: true,
  7408. configurable: true,
  7409. get: () => setupState[key],
  7410. set: NOOP
  7411. });
  7412. });
  7413. }
  7414. const emptyAppContext = createAppContext();
  7415. let uid$2 = 0;
  7416. function createComponentInstance(vnode, parent, suspense) {
  7417. const type = vnode.type;
  7418. // inherit parent app context - or - if root, adopt from root vnode
  7419. const appContext = (parent ? parent.appContext : vnode.appContext) || emptyAppContext;
  7420. const instance = {
  7421. uid: uid$2++,
  7422. vnode,
  7423. type,
  7424. parent,
  7425. appContext,
  7426. root: null,
  7427. next: null,
  7428. subTree: null,
  7429. update: null,
  7430. render: null,
  7431. proxy: null,
  7432. exposed: null,
  7433. withProxy: null,
  7434. effects: null,
  7435. provides: parent ? parent.provides : Object.create(appContext.provides),
  7436. accessCache: null,
  7437. renderCache: [],
  7438. // local resovled assets
  7439. components: null,
  7440. directives: null,
  7441. // resolved props and emits options
  7442. propsOptions: normalizePropsOptions(type, appContext),
  7443. emitsOptions: normalizeEmitsOptions(type, appContext),
  7444. // emit
  7445. emit: null,
  7446. emitted: null,
  7447. // state
  7448. ctx: EMPTY_OBJ,
  7449. data: EMPTY_OBJ,
  7450. props: EMPTY_OBJ,
  7451. attrs: EMPTY_OBJ,
  7452. slots: EMPTY_OBJ,
  7453. refs: EMPTY_OBJ,
  7454. setupState: EMPTY_OBJ,
  7455. setupContext: null,
  7456. // suspense related
  7457. suspense,
  7458. suspenseId: suspense ? suspense.pendingId : 0,
  7459. asyncDep: null,
  7460. asyncResolved: false,
  7461. // lifecycle hooks
  7462. // not using enums here because it results in computed properties
  7463. isMounted: false,
  7464. isUnmounted: false,
  7465. isDeactivated: false,
  7466. bc: null,
  7467. c: null,
  7468. bm: null,
  7469. m: null,
  7470. bu: null,
  7471. u: null,
  7472. um: null,
  7473. bum: null,
  7474. da: null,
  7475. a: null,
  7476. rtg: null,
  7477. rtc: null,
  7478. ec: null
  7479. };
  7480. {
  7481. instance.ctx = createRenderContext(instance);
  7482. }
  7483. instance.root = parent ? parent.root : instance;
  7484. instance.emit = emit.bind(null, instance);
  7485. return instance;
  7486. }
  7487. let currentInstance = null;
  7488. const getCurrentInstance = () => currentInstance || currentRenderingInstance;
  7489. const setCurrentInstance = (instance) => {
  7490. currentInstance = instance;
  7491. };
  7492. const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component');
  7493. function validateComponentName(name, config) {
  7494. const appIsNativeTag = config.isNativeTag || NO;
  7495. if (isBuiltInTag(name) || appIsNativeTag(name)) {
  7496. warn('Do not use built-in or reserved HTML elements as component id: ' + name);
  7497. }
  7498. }
  7499. function isStatefulComponent(instance) {
  7500. return instance.vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */;
  7501. }
  7502. let isInSSRComponentSetup = false;
  7503. function setupComponent(instance, isSSR = false) {
  7504. isInSSRComponentSetup = isSSR;
  7505. const { props, children } = instance.vnode;
  7506. const isStateful = isStatefulComponent(instance);
  7507. initProps(instance, props, isStateful, isSSR);
  7508. initSlots(instance, children);
  7509. const setupResult = isStateful
  7510. ? setupStatefulComponent(instance, isSSR)
  7511. : undefined;
  7512. isInSSRComponentSetup = false;
  7513. return setupResult;
  7514. }
  7515. function setupStatefulComponent(instance, isSSR) {
  7516. const Component = instance.type;
  7517. {
  7518. if (Component.name) {
  7519. validateComponentName(Component.name, instance.appContext.config);
  7520. }
  7521. if (Component.components) {
  7522. const names = Object.keys(Component.components);
  7523. for (let i = 0; i < names.length; i++) {
  7524. validateComponentName(names[i], instance.appContext.config);
  7525. }
  7526. }
  7527. if (Component.directives) {
  7528. const names = Object.keys(Component.directives);
  7529. for (let i = 0; i < names.length; i++) {
  7530. validateDirectiveName(names[i]);
  7531. }
  7532. }
  7533. }
  7534. // 0. create render proxy property access cache
  7535. instance.accessCache = Object.create(null);
  7536. // 1. create public instance / render proxy
  7537. // also mark it raw so it's never observed
  7538. instance.proxy = new Proxy(instance.ctx, PublicInstanceProxyHandlers);
  7539. {
  7540. exposePropsOnRenderContext(instance);
  7541. }
  7542. // 2. call setup()
  7543. const { setup } = Component;
  7544. if (setup) {
  7545. const setupContext = (instance.setupContext =
  7546. setup.length > 1 ? createSetupContext(instance) : null);
  7547. currentInstance = instance;
  7548. pauseTracking();
  7549. const setupResult = callWithErrorHandling(setup, instance, 0 /* SETUP_FUNCTION */, [shallowReadonly(instance.props) , setupContext]);
  7550. resetTracking();
  7551. currentInstance = null;
  7552. if (isPromise(setupResult)) {
  7553. if (isSSR) {
  7554. // return the promise so server-renderer can wait on it
  7555. return setupResult.then((resolvedResult) => {
  7556. handleSetupResult(instance, resolvedResult);
  7557. });
  7558. }
  7559. else {
  7560. // async setup returned Promise.
  7561. // bail here and wait for re-entry.
  7562. instance.asyncDep = setupResult;
  7563. }
  7564. }
  7565. else {
  7566. handleSetupResult(instance, setupResult);
  7567. }
  7568. }
  7569. else {
  7570. finishComponentSetup(instance);
  7571. }
  7572. }
  7573. function handleSetupResult(instance, setupResult, isSSR) {
  7574. if (isFunction(setupResult)) {
  7575. // setup returned an inline render function
  7576. {
  7577. instance.render = setupResult;
  7578. }
  7579. }
  7580. else if (isObject(setupResult)) {
  7581. if (isVNode(setupResult)) {
  7582. warn(`setup() should not return VNodes directly - ` +
  7583. `return a render function instead.`);
  7584. }
  7585. // setup returned bindings.
  7586. // assuming a render function compiled from template is present.
  7587. {
  7588. instance.devtoolsRawSetupState = setupResult;
  7589. }
  7590. instance.setupState = proxyRefs(setupResult);
  7591. {
  7592. exposeSetupStateOnRenderContext(instance);
  7593. }
  7594. }
  7595. else if (setupResult !== undefined) {
  7596. warn(`setup() should return an object. Received: ${setupResult === null ? 'null' : typeof setupResult}`);
  7597. }
  7598. finishComponentSetup(instance);
  7599. }
  7600. let compile;
  7601. /**
  7602. * For runtime-dom to register the compiler.
  7603. * Note the exported method uses any to avoid d.ts relying on the compiler types.
  7604. */
  7605. function registerRuntimeCompiler(_compile) {
  7606. compile = _compile;
  7607. }
  7608. function finishComponentSetup(instance, isSSR) {
  7609. const Component = instance.type;
  7610. // template / render function normalization
  7611. if (!instance.render) {
  7612. // could be set from setup()
  7613. if (compile && Component.template && !Component.render) {
  7614. {
  7615. startMeasure(instance, `compile`);
  7616. }
  7617. Component.render = compile(Component.template, {
  7618. isCustomElement: instance.appContext.config.isCustomElement,
  7619. delimiters: Component.delimiters
  7620. });
  7621. {
  7622. endMeasure(instance, `compile`);
  7623. }
  7624. }
  7625. instance.render = (Component.render || NOOP);
  7626. // for runtime-compiled render functions using `with` blocks, the render
  7627. // proxy used needs a different `has` handler which is more performant and
  7628. // also only allows a whitelist of globals to fallthrough.
  7629. if (instance.render._rc) {
  7630. instance.withProxy = new Proxy(instance.ctx, RuntimeCompiledPublicInstanceProxyHandlers);
  7631. }
  7632. }
  7633. // support for 2.x options
  7634. {
  7635. currentInstance = instance;
  7636. pauseTracking();
  7637. applyOptions(instance, Component);
  7638. resetTracking();
  7639. currentInstance = null;
  7640. }
  7641. // warn missing template/render
  7642. if (!Component.render && instance.render === NOOP) {
  7643. /* istanbul ignore if */
  7644. if (!compile && Component.template) {
  7645. warn(`Component provided template option but ` +
  7646. `runtime compilation is not supported in this build of Vue.` +
  7647. (` Use "vue.esm-browser.js" instead.`
  7648. ) /* should not happen */);
  7649. }
  7650. else {
  7651. warn(`Component is missing template or render function.`);
  7652. }
  7653. }
  7654. }
  7655. const attrHandlers = {
  7656. get: (target, key) => {
  7657. {
  7658. markAttrsAccessed();
  7659. }
  7660. return target[key];
  7661. },
  7662. set: () => {
  7663. warn(`setupContext.attrs is readonly.`);
  7664. return false;
  7665. },
  7666. deleteProperty: () => {
  7667. warn(`setupContext.attrs is readonly.`);
  7668. return false;
  7669. }
  7670. };
  7671. function createSetupContext(instance) {
  7672. const expose = exposed => {
  7673. if (instance.exposed) {
  7674. warn(`expose() should be called only once per setup().`);
  7675. }
  7676. instance.exposed = proxyRefs(exposed);
  7677. };
  7678. {
  7679. // We use getters in dev in case libs like test-utils overwrite instance
  7680. // properties (overwrites should not be done in prod)
  7681. return Object.freeze({
  7682. get props() {
  7683. return instance.props;
  7684. },
  7685. get attrs() {
  7686. return new Proxy(instance.attrs, attrHandlers);
  7687. },
  7688. get slots() {
  7689. return shallowReadonly(instance.slots);
  7690. },
  7691. get emit() {
  7692. return (event, ...args) => instance.emit(event, ...args);
  7693. },
  7694. expose
  7695. });
  7696. }
  7697. }
  7698. // record effects created during a component's setup() so that they can be
  7699. // stopped when the component unmounts
  7700. function recordInstanceBoundEffect(effect, instance = currentInstance) {
  7701. if (instance) {
  7702. (instance.effects || (instance.effects = [])).push(effect);
  7703. }
  7704. }
  7705. const classifyRE = /(?:^|[-_])(\w)/g;
  7706. const classify = (str) => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
  7707. function getComponentName(Component) {
  7708. return isFunction(Component)
  7709. ? Component.displayName || Component.name
  7710. : Component.name;
  7711. }
  7712. /* istanbul ignore next */
  7713. function formatComponentName(instance, Component, isRoot = false) {
  7714. let name = getComponentName(Component);
  7715. if (!name && Component.__file) {
  7716. const match = Component.__file.match(/([^/\\]+)\.\w+$/);
  7717. if (match) {
  7718. name = match[1];
  7719. }
  7720. }
  7721. if (!name && instance && instance.parent) {
  7722. // try to infer the name based on reverse resolution
  7723. const inferFromRegistry = (registry) => {
  7724. for (const key in registry) {
  7725. if (registry[key] === Component) {
  7726. return key;
  7727. }
  7728. }
  7729. };
  7730. name =
  7731. inferFromRegistry(instance.components ||
  7732. instance.parent.type.components) || inferFromRegistry(instance.appContext.components);
  7733. }
  7734. return name ? classify(name) : isRoot ? `App` : `Anonymous`;
  7735. }
  7736. function isClassComponent(value) {
  7737. return isFunction(value) && '__vccOpts' in value;
  7738. }
  7739. function computed$1(getterOrOptions) {
  7740. const c = computed(getterOrOptions);
  7741. recordInstanceBoundEffect(c.effect);
  7742. return c;
  7743. }
  7744. // implementation
  7745. function defineProps() {
  7746. {
  7747. warn(`defineProps() is a compiler-hint helper that is only usable inside ` +
  7748. `<script setup> of a single file component. Its arguments should be ` +
  7749. `compiled away and passing it at runtime has no effect.`);
  7750. }
  7751. return null;
  7752. }
  7753. // implementation
  7754. function defineEmit() {
  7755. {
  7756. warn(`defineEmit() is a compiler-hint helper that is only usable inside ` +
  7757. `<script setup> of a single file component. Its arguments should be ` +
  7758. `compiled away and passing it at runtime has no effect.`);
  7759. }
  7760. return null;
  7761. }
  7762. function useContext() {
  7763. const i = getCurrentInstance();
  7764. if (!i) {
  7765. warn(`useContext() called without active instance.`);
  7766. }
  7767. return i.setupContext || (i.setupContext = createSetupContext(i));
  7768. }
  7769. // Actual implementation
  7770. function h(type, propsOrChildren, children) {
  7771. const l = arguments.length;
  7772. if (l === 2) {
  7773. if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
  7774. // single vnode without props
  7775. if (isVNode(propsOrChildren)) {
  7776. return createVNode(type, null, [propsOrChildren]);
  7777. }
  7778. // props without children
  7779. return createVNode(type, propsOrChildren);
  7780. }
  7781. else {
  7782. // omit props
  7783. return createVNode(type, null, propsOrChildren);
  7784. }
  7785. }
  7786. else {
  7787. if (l > 3) {
  7788. children = Array.prototype.slice.call(arguments, 2);
  7789. }
  7790. else if (l === 3 && isVNode(children)) {
  7791. children = [children];
  7792. }
  7793. return createVNode(type, propsOrChildren, children);
  7794. }
  7795. }
  7796. const ssrContextKey = Symbol(`ssrContext` );
  7797. const useSSRContext = () => {
  7798. {
  7799. const ctx = inject(ssrContextKey);
  7800. if (!ctx) {
  7801. warn(`Server rendering context not provided. Make sure to only call ` +
  7802. `useSSRContext() conditionally in the server build.`);
  7803. }
  7804. return ctx;
  7805. }
  7806. };
  7807. function initCustomFormatter() {
  7808. /* eslint-disable no-restricted-globals */
  7809. if (typeof window === 'undefined') {
  7810. return;
  7811. }
  7812. const vueStyle = { style: 'color:#3ba776' };
  7813. const numberStyle = { style: 'color:#0b1bc9' };
  7814. const stringStyle = { style: 'color:#b62e24' };
  7815. const keywordStyle = { style: 'color:#9d288c' };
  7816. // custom formatter for Chrome
  7817. // https://www.mattzeunert.com/2016/02/19/custom-chrome-devtools-object-formatters.html
  7818. const formatter = {
  7819. header(obj) {
  7820. // TODO also format ComponentPublicInstance & ctx.slots/attrs in setup
  7821. if (!isObject(obj)) {
  7822. return null;
  7823. }
  7824. if (obj.__isVue) {
  7825. return ['div', vueStyle, `VueInstance`];
  7826. }
  7827. else if (isRef(obj)) {
  7828. return [
  7829. 'div',
  7830. {},
  7831. ['span', vueStyle, genRefFlag(obj)],
  7832. '<',
  7833. formatValue(obj.value),
  7834. `>`
  7835. ];
  7836. }
  7837. else if (isReactive(obj)) {
  7838. return [
  7839. 'div',
  7840. {},
  7841. ['span', vueStyle, 'Reactive'],
  7842. '<',
  7843. formatValue(obj),
  7844. `>${isReadonly(obj) ? ` (readonly)` : ``}`
  7845. ];
  7846. }
  7847. else if (isReadonly(obj)) {
  7848. return [
  7849. 'div',
  7850. {},
  7851. ['span', vueStyle, 'Readonly'],
  7852. '<',
  7853. formatValue(obj),
  7854. '>'
  7855. ];
  7856. }
  7857. return null;
  7858. },
  7859. hasBody(obj) {
  7860. return obj && obj.__isVue;
  7861. },
  7862. body(obj) {
  7863. if (obj && obj.__isVue) {
  7864. return [
  7865. 'div',
  7866. {},
  7867. ...formatInstance(obj.$)
  7868. ];
  7869. }
  7870. }
  7871. };
  7872. function formatInstance(instance) {
  7873. const blocks = [];
  7874. if (instance.type.props && instance.props) {
  7875. blocks.push(createInstanceBlock('props', toRaw(instance.props)));
  7876. }
  7877. if (instance.setupState !== EMPTY_OBJ) {
  7878. blocks.push(createInstanceBlock('setup', instance.setupState));
  7879. }
  7880. if (instance.data !== EMPTY_OBJ) {
  7881. blocks.push(createInstanceBlock('data', toRaw(instance.data)));
  7882. }
  7883. const computed = extractKeys(instance, 'computed');
  7884. if (computed) {
  7885. blocks.push(createInstanceBlock('computed', computed));
  7886. }
  7887. const injected = extractKeys(instance, 'inject');
  7888. if (injected) {
  7889. blocks.push(createInstanceBlock('injected', injected));
  7890. }
  7891. blocks.push([
  7892. 'div',
  7893. {},
  7894. [
  7895. 'span',
  7896. {
  7897. style: keywordStyle.style + ';opacity:0.66'
  7898. },
  7899. '$ (internal): '
  7900. ],
  7901. ['object', { object: instance }]
  7902. ]);
  7903. return blocks;
  7904. }
  7905. function createInstanceBlock(type, target) {
  7906. target = extend({}, target);
  7907. if (!Object.keys(target).length) {
  7908. return ['span', {}];
  7909. }
  7910. return [
  7911. 'div',
  7912. { style: 'line-height:1.25em;margin-bottom:0.6em' },
  7913. [
  7914. 'div',
  7915. {
  7916. style: 'color:#476582'
  7917. },
  7918. type
  7919. ],
  7920. [
  7921. 'div',
  7922. {
  7923. style: 'padding-left:1.25em'
  7924. },
  7925. ...Object.keys(target).map(key => {
  7926. return [
  7927. 'div',
  7928. {},
  7929. ['span', keywordStyle, key + ': '],
  7930. formatValue(target[key], false)
  7931. ];
  7932. })
  7933. ]
  7934. ];
  7935. }
  7936. function formatValue(v, asRaw = true) {
  7937. if (typeof v === 'number') {
  7938. return ['span', numberStyle, v];
  7939. }
  7940. else if (typeof v === 'string') {
  7941. return ['span', stringStyle, JSON.stringify(v)];
  7942. }
  7943. else if (typeof v === 'boolean') {
  7944. return ['span', keywordStyle, v];
  7945. }
  7946. else if (isObject(v)) {
  7947. return ['object', { object: asRaw ? toRaw(v) : v }];
  7948. }
  7949. else {
  7950. return ['span', stringStyle, String(v)];
  7951. }
  7952. }
  7953. function extractKeys(instance, type) {
  7954. const Comp = instance.type;
  7955. if (isFunction(Comp)) {
  7956. return;
  7957. }
  7958. const extracted = {};
  7959. for (const key in instance.ctx) {
  7960. if (isKeyOfType(Comp, key, type)) {
  7961. extracted[key] = instance.ctx[key];
  7962. }
  7963. }
  7964. return extracted;
  7965. }
  7966. function isKeyOfType(Comp, key, type) {
  7967. const opts = Comp[type];
  7968. if ((isArray(opts) && opts.includes(key)) ||
  7969. (isObject(opts) && key in opts)) {
  7970. return true;
  7971. }
  7972. if (Comp.extends && isKeyOfType(Comp.extends, key, type)) {
  7973. return true;
  7974. }
  7975. if (Comp.mixins && Comp.mixins.some(m => isKeyOfType(m, key, type))) {
  7976. return true;
  7977. }
  7978. }
  7979. function genRefFlag(v) {
  7980. if (v._shallow) {
  7981. return `ShallowRef`;
  7982. }
  7983. if (v.effect) {
  7984. return `ComputedRef`;
  7985. }
  7986. return `Ref`;
  7987. }
  7988. if (window.devtoolsFormatters) {
  7989. window.devtoolsFormatters.push(formatter);
  7990. }
  7991. else {
  7992. window.devtoolsFormatters = [formatter];
  7993. }
  7994. }
  7995. /**
  7996. * Actual implementation
  7997. */
  7998. function renderList(source, renderItem) {
  7999. let ret;
  8000. if (isArray(source) || isString(source)) {
  8001. ret = new Array(source.length);
  8002. for (let i = 0, l = source.length; i < l; i++) {
  8003. ret[i] = renderItem(source[i], i);
  8004. }
  8005. }
  8006. else if (typeof source === 'number') {
  8007. if (!Number.isInteger(source)) {
  8008. warn(`The v-for range expect an integer value but got ${source}.`);
  8009. return [];
  8010. }
  8011. ret = new Array(source);
  8012. for (let i = 0; i < source; i++) {
  8013. ret[i] = renderItem(i + 1, i);
  8014. }
  8015. }
  8016. else if (isObject(source)) {
  8017. if (source[Symbol.iterator]) {
  8018. ret = Array.from(source, renderItem);
  8019. }
  8020. else {
  8021. const keys = Object.keys(source);
  8022. ret = new Array(keys.length);
  8023. for (let i = 0, l = keys.length; i < l; i++) {
  8024. const key = keys[i];
  8025. ret[i] = renderItem(source[key], key, i);
  8026. }
  8027. }
  8028. }
  8029. else {
  8030. ret = [];
  8031. }
  8032. return ret;
  8033. }
  8034. /**
  8035. * For prefixing keys in v-on="obj" with "on"
  8036. * @private
  8037. */
  8038. function toHandlers(obj) {
  8039. const ret = {};
  8040. if (!isObject(obj)) {
  8041. warn(`v-on with no argument expects an object value.`);
  8042. return ret;
  8043. }
  8044. for (const key in obj) {
  8045. ret[toHandlerKey(key)] = obj[key];
  8046. }
  8047. return ret;
  8048. }
  8049. /**
  8050. * Compiler runtime helper for creating dynamic slots object
  8051. * @private
  8052. */
  8053. function createSlots(slots, dynamicSlots) {
  8054. for (let i = 0; i < dynamicSlots.length; i++) {
  8055. const slot = dynamicSlots[i];
  8056. // array of dynamic slot generated by <template v-for="..." #[...]>
  8057. if (isArray(slot)) {
  8058. for (let j = 0; j < slot.length; j++) {
  8059. slots[slot[j].name] = slot[j].fn;
  8060. }
  8061. }
  8062. else if (slot) {
  8063. // conditional single slot generated by <template v-if="..." #foo>
  8064. slots[slot.name] = slot.fn;
  8065. }
  8066. }
  8067. return slots;
  8068. }
  8069. // Core API ------------------------------------------------------------------
  8070. const version = "3.0.6";
  8071. /**
  8072. * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
  8073. * @internal
  8074. */
  8075. const ssrUtils = (null);
  8076. const svgNS = 'http://www.w3.org/2000/svg';
  8077. const doc = (typeof document !== 'undefined' ? document : null);
  8078. let tempContainer;
  8079. let tempSVGContainer;
  8080. const nodeOps = {
  8081. insert: (child, parent, anchor) => {
  8082. parent.insertBefore(child, anchor || null);
  8083. },
  8084. remove: child => {
  8085. const parent = child.parentNode;
  8086. if (parent) {
  8087. parent.removeChild(child);
  8088. }
  8089. },
  8090. createElement: (tag, isSVG, is) => isSVG
  8091. ? doc.createElementNS(svgNS, tag)
  8092. : doc.createElement(tag, is ? { is } : undefined),
  8093. createText: text => doc.createTextNode(text),
  8094. createComment: text => doc.createComment(text),
  8095. setText: (node, text) => {
  8096. node.nodeValue = text;
  8097. },
  8098. setElementText: (el, text) => {
  8099. el.textContent = text;
  8100. },
  8101. parentNode: node => node.parentNode,
  8102. nextSibling: node => node.nextSibling,
  8103. querySelector: selector => doc.querySelector(selector),
  8104. setScopeId(el, id) {
  8105. el.setAttribute(id, '');
  8106. },
  8107. cloneNode(el) {
  8108. return el.cloneNode(true);
  8109. },
  8110. // __UNSAFE__
  8111. // Reason: innerHTML.
  8112. // Static content here can only come from compiled templates.
  8113. // As long as the user only uses trusted templates, this is safe.
  8114. insertStaticContent(content, parent, anchor, isSVG) {
  8115. const temp = isSVG
  8116. ? tempSVGContainer ||
  8117. (tempSVGContainer = doc.createElementNS(svgNS, 'svg'))
  8118. : tempContainer || (tempContainer = doc.createElement('div'));
  8119. temp.innerHTML = content;
  8120. const first = temp.firstChild;
  8121. let node = first;
  8122. let last = node;
  8123. while (node) {
  8124. last = node;
  8125. nodeOps.insert(node, parent, anchor);
  8126. node = temp.firstChild;
  8127. }
  8128. return [first, last];
  8129. }
  8130. };
  8131. // compiler should normalize class + :class bindings on the same element
  8132. // into a single binding ['staticClass', dynamic]
  8133. function patchClass(el, value, isSVG) {
  8134. if (value == null) {
  8135. value = '';
  8136. }
  8137. if (isSVG) {
  8138. el.setAttribute('class', value);
  8139. }
  8140. else {
  8141. // directly setting className should be faster than setAttribute in theory
  8142. // if this is an element during a transition, take the temporary transition
  8143. // classes into account.
  8144. const transitionClasses = el._vtc;
  8145. if (transitionClasses) {
  8146. value = (value
  8147. ? [value, ...transitionClasses]
  8148. : [...transitionClasses]).join(' ');
  8149. }
  8150. el.className = value;
  8151. }
  8152. }
  8153. function patchStyle(el, prev, next) {
  8154. const style = el.style;
  8155. if (!next) {
  8156. el.removeAttribute('style');
  8157. }
  8158. else if (isString(next)) {
  8159. if (prev !== next) {
  8160. style.cssText = next;
  8161. }
  8162. }
  8163. else {
  8164. for (const key in next) {
  8165. setStyle(style, key, next[key]);
  8166. }
  8167. if (prev && !isString(prev)) {
  8168. for (const key in prev) {
  8169. if (next[key] == null) {
  8170. setStyle(style, key, '');
  8171. }
  8172. }
  8173. }
  8174. }
  8175. }
  8176. const importantRE = /\s*!important$/;
  8177. function setStyle(style, name, val) {
  8178. if (isArray(val)) {
  8179. val.forEach(v => setStyle(style, name, v));
  8180. }
  8181. else {
  8182. if (name.startsWith('--')) {
  8183. // custom property definition
  8184. style.setProperty(name, val);
  8185. }
  8186. else {
  8187. const prefixed = autoPrefix(style, name);
  8188. if (importantRE.test(val)) {
  8189. // !important
  8190. style.setProperty(hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  8191. }
  8192. else {
  8193. style[prefixed] = val;
  8194. }
  8195. }
  8196. }
  8197. }
  8198. const prefixes = ['Webkit', 'Moz', 'ms'];
  8199. const prefixCache = {};
  8200. function autoPrefix(style, rawName) {
  8201. const cached = prefixCache[rawName];
  8202. if (cached) {
  8203. return cached;
  8204. }
  8205. let name = camelize(rawName);
  8206. if (name !== 'filter' && name in style) {
  8207. return (prefixCache[rawName] = name);
  8208. }
  8209. name = capitalize(name);
  8210. for (let i = 0; i < prefixes.length; i++) {
  8211. const prefixed = prefixes[i] + name;
  8212. if (prefixed in style) {
  8213. return (prefixCache[rawName] = prefixed);
  8214. }
  8215. }
  8216. return rawName;
  8217. }
  8218. const xlinkNS = 'http://www.w3.org/1999/xlink';
  8219. function patchAttr(el, key, value, isSVG) {
  8220. if (isSVG && key.startsWith('xlink:')) {
  8221. if (value == null) {
  8222. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  8223. }
  8224. else {
  8225. el.setAttributeNS(xlinkNS, key, value);
  8226. }
  8227. }
  8228. else {
  8229. // note we are only checking boolean attributes that don't have a
  8230. // corresponding dom prop of the same name here.
  8231. const isBoolean = isSpecialBooleanAttr(key);
  8232. if (value == null || (isBoolean && value === false)) {
  8233. el.removeAttribute(key);
  8234. }
  8235. else {
  8236. el.setAttribute(key, isBoolean ? '' : value);
  8237. }
  8238. }
  8239. }
  8240. // __UNSAFE__
  8241. // functions. The user is responsible for using them with only trusted content.
  8242. function patchDOMProp(el, key, value,
  8243. // the following args are passed only due to potential innerHTML/textContent
  8244. // overriding existing VNodes, in which case the old tree must be properly
  8245. // unmounted.
  8246. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  8247. if (key === 'innerHTML' || key === 'textContent') {
  8248. if (prevChildren) {
  8249. unmountChildren(prevChildren, parentComponent, parentSuspense);
  8250. }
  8251. el[key] = value == null ? '' : value;
  8252. return;
  8253. }
  8254. if (key === 'value' && el.tagName !== 'PROGRESS') {
  8255. // store value as _value as well since
  8256. // non-string values will be stringified.
  8257. el._value = value;
  8258. const newValue = value == null ? '' : value;
  8259. if (el.value !== newValue) {
  8260. el.value = newValue;
  8261. }
  8262. return;
  8263. }
  8264. if (value === '' || value == null) {
  8265. const type = typeof el[key];
  8266. if (value === '' && type === 'boolean') {
  8267. // e.g. <select multiple> compiles to { multiple: '' }
  8268. el[key] = true;
  8269. return;
  8270. }
  8271. else if (value == null && type === 'string') {
  8272. // e.g. <div :id="null">
  8273. el[key] = '';
  8274. el.removeAttribute(key);
  8275. return;
  8276. }
  8277. else if (type === 'number') {
  8278. // e.g. <img :width="null">
  8279. el[key] = 0;
  8280. el.removeAttribute(key);
  8281. return;
  8282. }
  8283. }
  8284. // some properties perform value validation and throw
  8285. try {
  8286. el[key] = value;
  8287. }
  8288. catch (e) {
  8289. {
  8290. warn(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  8291. `value ${value} is invalid.`, e);
  8292. }
  8293. }
  8294. }
  8295. // Async edge case fix requires storing an event listener's attach timestamp.
  8296. let _getNow = Date.now;
  8297. // Determine what event timestamp the browser is using. Annoyingly, the
  8298. // timestamp can either be hi-res (relative to page load) or low-res
  8299. // (relative to UNIX epoch), so in order to compare time we have to use the
  8300. // same timestamp type when saving the flush timestamp.
  8301. if (typeof document !== 'undefined' &&
  8302. _getNow() > document.createEvent('Event').timeStamp) {
  8303. // if the low-res timestamp which is bigger than the event timestamp
  8304. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  8305. // and we need to use the hi-res version for event listeners as well.
  8306. _getNow = () => performance.now();
  8307. }
  8308. // To avoid the overhead of repeatedly calling performance.now(), we cache
  8309. // and use the same timestamp for all event listeners attached in the same tick.
  8310. let cachedNow = 0;
  8311. const p = Promise.resolve();
  8312. const reset = () => {
  8313. cachedNow = 0;
  8314. };
  8315. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  8316. function addEventListener(el, event, handler, options) {
  8317. el.addEventListener(event, handler, options);
  8318. }
  8319. function removeEventListener(el, event, handler, options) {
  8320. el.removeEventListener(event, handler, options);
  8321. }
  8322. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  8323. // vei = vue event invokers
  8324. const invokers = el._vei || (el._vei = {});
  8325. const existingInvoker = invokers[rawName];
  8326. if (nextValue && existingInvoker) {
  8327. // patch
  8328. existingInvoker.value = nextValue;
  8329. }
  8330. else {
  8331. const [name, options] = parseName(rawName);
  8332. if (nextValue) {
  8333. // add
  8334. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  8335. addEventListener(el, name, invoker, options);
  8336. }
  8337. else if (existingInvoker) {
  8338. // remove
  8339. removeEventListener(el, name, existingInvoker, options);
  8340. invokers[rawName] = undefined;
  8341. }
  8342. }
  8343. }
  8344. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  8345. function parseName(name) {
  8346. let options;
  8347. if (optionsModifierRE.test(name)) {
  8348. options = {};
  8349. let m;
  8350. while ((m = name.match(optionsModifierRE))) {
  8351. name = name.slice(0, name.length - m[0].length);
  8352. options[m[0].toLowerCase()] = true;
  8353. }
  8354. }
  8355. return [hyphenate(name.slice(2)), options];
  8356. }
  8357. function createInvoker(initialValue, instance) {
  8358. const invoker = (e) => {
  8359. // async edge case #6566: inner click event triggers patch, event handler
  8360. // attached to outer element during patch, and triggered again. This
  8361. // happens because browsers fire microtask ticks between event propagation.
  8362. // the solution is simple: we save the timestamp when a handler is attached,
  8363. // and the handler would only fire if the event passed to it was fired
  8364. // AFTER it was attached.
  8365. const timeStamp = e.timeStamp || _getNow();
  8366. if (timeStamp >= invoker.attached - 1) {
  8367. callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  8368. }
  8369. };
  8370. invoker.value = initialValue;
  8371. invoker.attached = getNow();
  8372. return invoker;
  8373. }
  8374. function patchStopImmediatePropagation(e, value) {
  8375. if (isArray(value)) {
  8376. const originalStop = e.stopImmediatePropagation;
  8377. e.stopImmediatePropagation = () => {
  8378. originalStop.call(e);
  8379. e._stopped = true;
  8380. };
  8381. return value.map(fn => (e) => !e._stopped && fn(e));
  8382. }
  8383. else {
  8384. return value;
  8385. }
  8386. }
  8387. const nativeOnRE = /^on[a-z]/;
  8388. const forcePatchProp = (_, key) => key === 'value';
  8389. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  8390. switch (key) {
  8391. // special
  8392. case 'class':
  8393. patchClass(el, nextValue, isSVG);
  8394. break;
  8395. case 'style':
  8396. patchStyle(el, prevValue, nextValue);
  8397. break;
  8398. default:
  8399. if (isOn(key)) {
  8400. // ignore v-model listeners
  8401. if (!isModelListener(key)) {
  8402. patchEvent(el, key, prevValue, nextValue, parentComponent);
  8403. }
  8404. }
  8405. else if (shouldSetAsProp(el, key, nextValue, isSVG)) {
  8406. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  8407. }
  8408. else {
  8409. // special case for <input v-model type="checkbox"> with
  8410. // :true-value & :false-value
  8411. // store value as dom properties since non-string values will be
  8412. // stringified.
  8413. if (key === 'true-value') {
  8414. el._trueValue = nextValue;
  8415. }
  8416. else if (key === 'false-value') {
  8417. el._falseValue = nextValue;
  8418. }
  8419. patchAttr(el, key, nextValue, isSVG);
  8420. }
  8421. break;
  8422. }
  8423. };
  8424. function shouldSetAsProp(el, key, value, isSVG) {
  8425. if (isSVG) {
  8426. // most keys must be set as attribute on svg elements to work
  8427. // ...except innerHTML
  8428. if (key === 'innerHTML') {
  8429. return true;
  8430. }
  8431. // or native onclick with function values
  8432. if (key in el && nativeOnRE.test(key) && isFunction(value)) {
  8433. return true;
  8434. }
  8435. return false;
  8436. }
  8437. // spellcheck and draggable are numerated attrs, however their
  8438. // corresponding DOM properties are actually booleans - this leads to
  8439. // setting it with a string "false" value leading it to be coerced to
  8440. // `true`, so we need to always treat them as attributes.
  8441. // Note that `contentEditable` doesn't have this problem: its DOM
  8442. // property is also enumerated string values.
  8443. if (key === 'spellcheck' || key === 'draggable') {
  8444. return false;
  8445. }
  8446. // #1787, #2840 form property on form elements is readonly and must be set as
  8447. // attribute.
  8448. if (key === 'form') {
  8449. return false;
  8450. }
  8451. // #1526 <input list> must be set as attribute
  8452. if (key === 'list' && el.tagName === 'INPUT') {
  8453. return false;
  8454. }
  8455. // #2766 <textarea type> must be set as attribute
  8456. if (key === 'type' && el.tagName === 'TEXTAREA') {
  8457. return false;
  8458. }
  8459. // native onclick with string value, must be set as attribute
  8460. if (nativeOnRE.test(key) && isString(value)) {
  8461. return false;
  8462. }
  8463. return key in el;
  8464. }
  8465. function useCssModule(name = '$style') {
  8466. /* istanbul ignore else */
  8467. {
  8468. const instance = getCurrentInstance();
  8469. if (!instance) {
  8470. warn(`useCssModule must be called inside setup()`);
  8471. return EMPTY_OBJ;
  8472. }
  8473. const modules = instance.type.__cssModules;
  8474. if (!modules) {
  8475. warn(`Current instance does not have CSS modules injected.`);
  8476. return EMPTY_OBJ;
  8477. }
  8478. const mod = modules[name];
  8479. if (!mod) {
  8480. warn(`Current instance does not have CSS module named "${name}".`);
  8481. return EMPTY_OBJ;
  8482. }
  8483. return mod;
  8484. }
  8485. }
  8486. /**
  8487. * Runtime helper for SFC's CSS variable injection feature.
  8488. * @private
  8489. */
  8490. function useCssVars(getter) {
  8491. const instance = getCurrentInstance();
  8492. /* istanbul ignore next */
  8493. if (!instance) {
  8494. warn(`useCssVars is called without current active component instance.`);
  8495. return;
  8496. }
  8497. const setVars = () => setVarsOnVNode(instance.subTree, getter(instance.proxy));
  8498. onMounted(() => watchEffect(setVars, { flush: 'post' }));
  8499. onUpdated(setVars);
  8500. }
  8501. function setVarsOnVNode(vnode, vars) {
  8502. if (vnode.shapeFlag & 128 /* SUSPENSE */) {
  8503. const suspense = vnode.suspense;
  8504. vnode = suspense.activeBranch;
  8505. if (suspense.pendingBranch && !suspense.isHydrating) {
  8506. suspense.effects.push(() => {
  8507. setVarsOnVNode(suspense.activeBranch, vars);
  8508. });
  8509. }
  8510. }
  8511. // drill down HOCs until it's a non-component vnode
  8512. while (vnode.component) {
  8513. vnode = vnode.component.subTree;
  8514. }
  8515. if (vnode.shapeFlag & 1 /* ELEMENT */ && vnode.el) {
  8516. const style = vnode.el.style;
  8517. for (const key in vars) {
  8518. style.setProperty(`--${key}`, vars[key]);
  8519. }
  8520. }
  8521. else if (vnode.type === Fragment) {
  8522. vnode.children.forEach(c => setVarsOnVNode(c, vars));
  8523. }
  8524. }
  8525. const TRANSITION = 'transition';
  8526. const ANIMATION = 'animation';
  8527. // DOM Transition is a higher-order-component based on the platform-agnostic
  8528. // base Transition component, with DOM-specific logic.
  8529. const Transition = (props, { slots }) => h(BaseTransition, resolveTransitionProps(props), slots);
  8530. Transition.displayName = 'Transition';
  8531. const DOMTransitionPropsValidators = {
  8532. name: String,
  8533. type: String,
  8534. css: {
  8535. type: Boolean,
  8536. default: true
  8537. },
  8538. duration: [String, Number, Object],
  8539. enterFromClass: String,
  8540. enterActiveClass: String,
  8541. enterToClass: String,
  8542. appearFromClass: String,
  8543. appearActiveClass: String,
  8544. appearToClass: String,
  8545. leaveFromClass: String,
  8546. leaveActiveClass: String,
  8547. leaveToClass: String
  8548. };
  8549. const TransitionPropsValidators = (Transition.props = /*#__PURE__*/ extend({}, BaseTransition.props, DOMTransitionPropsValidators));
  8550. function resolveTransitionProps(rawProps) {
  8551. 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;
  8552. const baseProps = {};
  8553. for (const key in rawProps) {
  8554. if (!(key in DOMTransitionPropsValidators)) {
  8555. baseProps[key] = rawProps[key];
  8556. }
  8557. }
  8558. if (!css) {
  8559. return baseProps;
  8560. }
  8561. const durations = normalizeDuration(duration);
  8562. const enterDuration = durations && durations[0];
  8563. const leaveDuration = durations && durations[1];
  8564. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  8565. const finishEnter = (el, isAppear, done) => {
  8566. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  8567. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  8568. done && done();
  8569. };
  8570. const finishLeave = (el, done) => {
  8571. removeTransitionClass(el, leaveToClass);
  8572. removeTransitionClass(el, leaveActiveClass);
  8573. done && done();
  8574. };
  8575. const makeEnterHook = (isAppear) => {
  8576. return (el, done) => {
  8577. const hook = isAppear ? onAppear : onEnter;
  8578. const resolve = () => finishEnter(el, isAppear, done);
  8579. hook && hook(el, resolve);
  8580. nextFrame(() => {
  8581. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  8582. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  8583. if (!(hook && hook.length > 1)) {
  8584. whenTransitionEnds(el, type, enterDuration, resolve);
  8585. }
  8586. });
  8587. };
  8588. };
  8589. return extend(baseProps, {
  8590. onBeforeEnter(el) {
  8591. onBeforeEnter && onBeforeEnter(el);
  8592. addTransitionClass(el, enterFromClass);
  8593. addTransitionClass(el, enterActiveClass);
  8594. },
  8595. onBeforeAppear(el) {
  8596. onBeforeAppear && onBeforeAppear(el);
  8597. addTransitionClass(el, appearFromClass);
  8598. addTransitionClass(el, appearActiveClass);
  8599. },
  8600. onEnter: makeEnterHook(false),
  8601. onAppear: makeEnterHook(true),
  8602. onLeave(el, done) {
  8603. const resolve = () => finishLeave(el, done);
  8604. addTransitionClass(el, leaveFromClass);
  8605. // force reflow so *-leave-from classes immediately take effect (#2593)
  8606. forceReflow();
  8607. addTransitionClass(el, leaveActiveClass);
  8608. nextFrame(() => {
  8609. removeTransitionClass(el, leaveFromClass);
  8610. addTransitionClass(el, leaveToClass);
  8611. if (!(onLeave && onLeave.length > 1)) {
  8612. whenTransitionEnds(el, type, leaveDuration, resolve);
  8613. }
  8614. });
  8615. onLeave && onLeave(el, resolve);
  8616. },
  8617. onEnterCancelled(el) {
  8618. finishEnter(el, false);
  8619. onEnterCancelled && onEnterCancelled(el);
  8620. },
  8621. onAppearCancelled(el) {
  8622. finishEnter(el, true);
  8623. onAppearCancelled && onAppearCancelled(el);
  8624. },
  8625. onLeaveCancelled(el) {
  8626. finishLeave(el);
  8627. onLeaveCancelled && onLeaveCancelled(el);
  8628. }
  8629. });
  8630. }
  8631. function normalizeDuration(duration) {
  8632. if (duration == null) {
  8633. return null;
  8634. }
  8635. else if (isObject(duration)) {
  8636. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  8637. }
  8638. else {
  8639. const n = NumberOf(duration);
  8640. return [n, n];
  8641. }
  8642. }
  8643. function NumberOf(val) {
  8644. const res = toNumber(val);
  8645. validateDuration(res);
  8646. return res;
  8647. }
  8648. function validateDuration(val) {
  8649. if (typeof val !== 'number') {
  8650. warn(`<transition> explicit duration is not a valid number - ` +
  8651. `got ${JSON.stringify(val)}.`);
  8652. }
  8653. else if (isNaN(val)) {
  8654. warn(`<transition> explicit duration is NaN - ` +
  8655. 'the duration expression might be incorrect.');
  8656. }
  8657. }
  8658. function addTransitionClass(el, cls) {
  8659. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  8660. (el._vtc ||
  8661. (el._vtc = new Set())).add(cls);
  8662. }
  8663. function removeTransitionClass(el, cls) {
  8664. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  8665. const { _vtc } = el;
  8666. if (_vtc) {
  8667. _vtc.delete(cls);
  8668. if (!_vtc.size) {
  8669. el._vtc = undefined;
  8670. }
  8671. }
  8672. }
  8673. function nextFrame(cb) {
  8674. requestAnimationFrame(() => {
  8675. requestAnimationFrame(cb);
  8676. });
  8677. }
  8678. let endId = 0;
  8679. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  8680. const id = (el._endId = ++endId);
  8681. const resolveIfNotStale = () => {
  8682. if (id === el._endId) {
  8683. resolve();
  8684. }
  8685. };
  8686. if (explicitTimeout) {
  8687. return setTimeout(resolveIfNotStale, explicitTimeout);
  8688. }
  8689. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  8690. if (!type) {
  8691. return resolve();
  8692. }
  8693. const endEvent = type + 'end';
  8694. let ended = 0;
  8695. const end = () => {
  8696. el.removeEventListener(endEvent, onEnd);
  8697. resolveIfNotStale();
  8698. };
  8699. const onEnd = (e) => {
  8700. if (e.target === el && ++ended >= propCount) {
  8701. end();
  8702. }
  8703. };
  8704. setTimeout(() => {
  8705. if (ended < propCount) {
  8706. end();
  8707. }
  8708. }, timeout + 1);
  8709. el.addEventListener(endEvent, onEnd);
  8710. }
  8711. function getTransitionInfo(el, expectedType) {
  8712. const styles = window.getComputedStyle(el);
  8713. // JSDOM may return undefined for transition properties
  8714. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  8715. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  8716. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  8717. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  8718. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  8719. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  8720. const animationTimeout = getTimeout(animationDelays, animationDurations);
  8721. let type = null;
  8722. let timeout = 0;
  8723. let propCount = 0;
  8724. /* istanbul ignore if */
  8725. if (expectedType === TRANSITION) {
  8726. if (transitionTimeout > 0) {
  8727. type = TRANSITION;
  8728. timeout = transitionTimeout;
  8729. propCount = transitionDurations.length;
  8730. }
  8731. }
  8732. else if (expectedType === ANIMATION) {
  8733. if (animationTimeout > 0) {
  8734. type = ANIMATION;
  8735. timeout = animationTimeout;
  8736. propCount = animationDurations.length;
  8737. }
  8738. }
  8739. else {
  8740. timeout = Math.max(transitionTimeout, animationTimeout);
  8741. type =
  8742. timeout > 0
  8743. ? transitionTimeout > animationTimeout
  8744. ? TRANSITION
  8745. : ANIMATION
  8746. : null;
  8747. propCount = type
  8748. ? type === TRANSITION
  8749. ? transitionDurations.length
  8750. : animationDurations.length
  8751. : 0;
  8752. }
  8753. const hasTransform = type === TRANSITION &&
  8754. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  8755. return {
  8756. type,
  8757. timeout,
  8758. propCount,
  8759. hasTransform
  8760. };
  8761. }
  8762. function getTimeout(delays, durations) {
  8763. while (delays.length < durations.length) {
  8764. delays = delays.concat(delays);
  8765. }
  8766. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  8767. }
  8768. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  8769. // numbers in a locale-dependent way, using a comma instead of a dot.
  8770. // If comma is not replaced with a dot, the input will be rounded down
  8771. // (i.e. acting as a floor function) causing unexpected behaviors
  8772. function toMs(s) {
  8773. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  8774. }
  8775. // synchronously force layout to put elements into a certain state
  8776. function forceReflow() {
  8777. return document.body.offsetHeight;
  8778. }
  8779. const positionMap = new WeakMap();
  8780. const newPositionMap = new WeakMap();
  8781. const TransitionGroupImpl = {
  8782. name: 'TransitionGroup',
  8783. props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
  8784. tag: String,
  8785. moveClass: String
  8786. }),
  8787. setup(props, { slots }) {
  8788. const instance = getCurrentInstance();
  8789. const state = useTransitionState();
  8790. let prevChildren;
  8791. let children;
  8792. onUpdated(() => {
  8793. // children is guaranteed to exist after initial render
  8794. if (!prevChildren.length) {
  8795. return;
  8796. }
  8797. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  8798. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  8799. return;
  8800. }
  8801. // we divide the work into three loops to avoid mixing DOM reads and writes
  8802. // in each iteration - which helps prevent layout thrashing.
  8803. prevChildren.forEach(callPendingCbs);
  8804. prevChildren.forEach(recordPosition);
  8805. const movedChildren = prevChildren.filter(applyTranslation);
  8806. // force reflow to put everything in position
  8807. forceReflow();
  8808. movedChildren.forEach(c => {
  8809. const el = c.el;
  8810. const style = el.style;
  8811. addTransitionClass(el, moveClass);
  8812. style.transform = style.webkitTransform = style.transitionDuration = '';
  8813. const cb = (el._moveCb = (e) => {
  8814. if (e && e.target !== el) {
  8815. return;
  8816. }
  8817. if (!e || /transform$/.test(e.propertyName)) {
  8818. el.removeEventListener('transitionend', cb);
  8819. el._moveCb = null;
  8820. removeTransitionClass(el, moveClass);
  8821. }
  8822. });
  8823. el.addEventListener('transitionend', cb);
  8824. });
  8825. });
  8826. return () => {
  8827. const rawProps = toRaw(props);
  8828. const cssTransitionProps = resolveTransitionProps(rawProps);
  8829. const tag = rawProps.tag || Fragment;
  8830. prevChildren = children;
  8831. children = slots.default ? getTransitionRawChildren(slots.default()) : [];
  8832. for (let i = 0; i < children.length; i++) {
  8833. const child = children[i];
  8834. if (child.key != null) {
  8835. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  8836. }
  8837. else {
  8838. warn(`<TransitionGroup> children must be keyed.`);
  8839. }
  8840. }
  8841. if (prevChildren) {
  8842. for (let i = 0; i < prevChildren.length; i++) {
  8843. const child = prevChildren[i];
  8844. setTransitionHooks(child, resolveTransitionHooks(child, cssTransitionProps, state, instance));
  8845. positionMap.set(child, child.el.getBoundingClientRect());
  8846. }
  8847. }
  8848. return createVNode(tag, null, children);
  8849. };
  8850. }
  8851. };
  8852. const TransitionGroup = TransitionGroupImpl;
  8853. function callPendingCbs(c) {
  8854. const el = c.el;
  8855. if (el._moveCb) {
  8856. el._moveCb();
  8857. }
  8858. if (el._enterCb) {
  8859. el._enterCb();
  8860. }
  8861. }
  8862. function recordPosition(c) {
  8863. newPositionMap.set(c, c.el.getBoundingClientRect());
  8864. }
  8865. function applyTranslation(c) {
  8866. const oldPos = positionMap.get(c);
  8867. const newPos = newPositionMap.get(c);
  8868. const dx = oldPos.left - newPos.left;
  8869. const dy = oldPos.top - newPos.top;
  8870. if (dx || dy) {
  8871. const s = c.el.style;
  8872. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  8873. s.transitionDuration = '0s';
  8874. return c;
  8875. }
  8876. }
  8877. function hasCSSTransform(el, root, moveClass) {
  8878. // Detect whether an element with the move class applied has
  8879. // CSS transitions. Since the element may be inside an entering
  8880. // transition at this very moment, we make a clone of it and remove
  8881. // all other transition classes applied to ensure only the move class
  8882. // is applied.
  8883. const clone = el.cloneNode();
  8884. if (el._vtc) {
  8885. el._vtc.forEach(cls => {
  8886. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  8887. });
  8888. }
  8889. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  8890. clone.style.display = 'none';
  8891. const container = (root.nodeType === 1
  8892. ? root
  8893. : root.parentNode);
  8894. container.appendChild(clone);
  8895. const { hasTransform } = getTransitionInfo(clone);
  8896. container.removeChild(clone);
  8897. return hasTransform;
  8898. }
  8899. const getModelAssigner = (vnode) => {
  8900. const fn = vnode.props['onUpdate:modelValue'];
  8901. return isArray(fn) ? value => invokeArrayFns(fn, value) : fn;
  8902. };
  8903. function onCompositionStart(e) {
  8904. e.target.composing = true;
  8905. }
  8906. function onCompositionEnd(e) {
  8907. const target = e.target;
  8908. if (target.composing) {
  8909. target.composing = false;
  8910. trigger$1(target, 'input');
  8911. }
  8912. }
  8913. function trigger$1(el, type) {
  8914. const e = document.createEvent('HTMLEvents');
  8915. e.initEvent(type, true, true);
  8916. el.dispatchEvent(e);
  8917. }
  8918. // We are exporting the v-model runtime directly as vnode hooks so that it can
  8919. // be tree-shaken in case v-model is never used.
  8920. const vModelText = {
  8921. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  8922. el._assign = getModelAssigner(vnode);
  8923. const castToNumber = number || el.type === 'number';
  8924. addEventListener(el, lazy ? 'change' : 'input', e => {
  8925. if (e.target.composing)
  8926. return;
  8927. let domValue = el.value;
  8928. if (trim) {
  8929. domValue = domValue.trim();
  8930. }
  8931. else if (castToNumber) {
  8932. domValue = toNumber(domValue);
  8933. }
  8934. el._assign(domValue);
  8935. });
  8936. if (trim) {
  8937. addEventListener(el, 'change', () => {
  8938. el.value = el.value.trim();
  8939. });
  8940. }
  8941. if (!lazy) {
  8942. addEventListener(el, 'compositionstart', onCompositionStart);
  8943. addEventListener(el, 'compositionend', onCompositionEnd);
  8944. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  8945. // switching focus before confirming composition choice
  8946. // this also fixes the issue where some browsers e.g. iOS Chrome
  8947. // fires "change" instead of "input" on autocomplete.
  8948. addEventListener(el, 'change', onCompositionEnd);
  8949. }
  8950. },
  8951. // set value on mounted so it's after min/max for type="range"
  8952. mounted(el, { value }) {
  8953. el.value = value == null ? '' : value;
  8954. },
  8955. beforeUpdate(el, { value, modifiers: { trim, number } }, vnode) {
  8956. el._assign = getModelAssigner(vnode);
  8957. // avoid clearing unresolved text. #2302
  8958. if (el.composing)
  8959. return;
  8960. if (document.activeElement === el) {
  8961. if (trim && el.value.trim() === value) {
  8962. return;
  8963. }
  8964. if ((number || el.type === 'number') && toNumber(el.value) === value) {
  8965. return;
  8966. }
  8967. }
  8968. const newValue = value == null ? '' : value;
  8969. if (el.value !== newValue) {
  8970. el.value = newValue;
  8971. }
  8972. }
  8973. };
  8974. const vModelCheckbox = {
  8975. created(el, _, vnode) {
  8976. el._assign = getModelAssigner(vnode);
  8977. addEventListener(el, 'change', () => {
  8978. const modelValue = el._modelValue;
  8979. const elementValue = getValue(el);
  8980. const checked = el.checked;
  8981. const assign = el._assign;
  8982. if (isArray(modelValue)) {
  8983. const index = looseIndexOf(modelValue, elementValue);
  8984. const found = index !== -1;
  8985. if (checked && !found) {
  8986. assign(modelValue.concat(elementValue));
  8987. }
  8988. else if (!checked && found) {
  8989. const filtered = [...modelValue];
  8990. filtered.splice(index, 1);
  8991. assign(filtered);
  8992. }
  8993. }
  8994. else if (isSet(modelValue)) {
  8995. const cloned = new Set(modelValue);
  8996. if (checked) {
  8997. cloned.add(elementValue);
  8998. }
  8999. else {
  9000. cloned.delete(elementValue);
  9001. }
  9002. assign(cloned);
  9003. }
  9004. else {
  9005. assign(getCheckboxValue(el, checked));
  9006. }
  9007. });
  9008. },
  9009. // set initial checked on mount to wait for true-value/false-value
  9010. mounted: setChecked,
  9011. beforeUpdate(el, binding, vnode) {
  9012. el._assign = getModelAssigner(vnode);
  9013. setChecked(el, binding, vnode);
  9014. }
  9015. };
  9016. function setChecked(el, { value, oldValue }, vnode) {
  9017. el._modelValue = value;
  9018. if (isArray(value)) {
  9019. el.checked = looseIndexOf(value, vnode.props.value) > -1;
  9020. }
  9021. else if (isSet(value)) {
  9022. el.checked = value.has(vnode.props.value);
  9023. }
  9024. else if (value !== oldValue) {
  9025. el.checked = looseEqual(value, getCheckboxValue(el, true));
  9026. }
  9027. }
  9028. const vModelRadio = {
  9029. created(el, { value }, vnode) {
  9030. el.checked = looseEqual(value, vnode.props.value);
  9031. el._assign = getModelAssigner(vnode);
  9032. addEventListener(el, 'change', () => {
  9033. el._assign(getValue(el));
  9034. });
  9035. },
  9036. beforeUpdate(el, { value, oldValue }, vnode) {
  9037. el._assign = getModelAssigner(vnode);
  9038. if (value !== oldValue) {
  9039. el.checked = looseEqual(value, vnode.props.value);
  9040. }
  9041. }
  9042. };
  9043. const vModelSelect = {
  9044. created(el, { value, modifiers: { number } }, vnode) {
  9045. const isSetModel = isSet(value);
  9046. addEventListener(el, 'change', () => {
  9047. const selectedVal = Array.prototype.filter
  9048. .call(el.options, (o) => o.selected)
  9049. .map((o) => number ? toNumber(getValue(o)) : getValue(o));
  9050. el._assign(el.multiple
  9051. ? isSetModel
  9052. ? new Set(selectedVal)
  9053. : selectedVal
  9054. : selectedVal[0]);
  9055. });
  9056. el._assign = getModelAssigner(vnode);
  9057. },
  9058. // set value in mounted & updated because <select> relies on its children
  9059. // <option>s.
  9060. mounted(el, { value }) {
  9061. setSelected(el, value);
  9062. },
  9063. beforeUpdate(el, _binding, vnode) {
  9064. el._assign = getModelAssigner(vnode);
  9065. },
  9066. updated(el, { value }) {
  9067. setSelected(el, value);
  9068. }
  9069. };
  9070. function setSelected(el, value) {
  9071. const isMultiple = el.multiple;
  9072. if (isMultiple && !isArray(value) && !isSet(value)) {
  9073. warn(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  9074. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  9075. return;
  9076. }
  9077. for (let i = 0, l = el.options.length; i < l; i++) {
  9078. const option = el.options[i];
  9079. const optionValue = getValue(option);
  9080. if (isMultiple) {
  9081. if (isArray(value)) {
  9082. option.selected = looseIndexOf(value, optionValue) > -1;
  9083. }
  9084. else {
  9085. option.selected = value.has(optionValue);
  9086. }
  9087. }
  9088. else {
  9089. if (looseEqual(getValue(option), value)) {
  9090. el.selectedIndex = i;
  9091. return;
  9092. }
  9093. }
  9094. }
  9095. if (!isMultiple) {
  9096. el.selectedIndex = -1;
  9097. }
  9098. }
  9099. // retrieve raw value set via :value bindings
  9100. function getValue(el) {
  9101. return '_value' in el ? el._value : el.value;
  9102. }
  9103. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  9104. function getCheckboxValue(el, checked) {
  9105. const key = checked ? '_trueValue' : '_falseValue';
  9106. return key in el ? el[key] : checked;
  9107. }
  9108. const vModelDynamic = {
  9109. created(el, binding, vnode) {
  9110. callModelHook(el, binding, vnode, null, 'created');
  9111. },
  9112. mounted(el, binding, vnode) {
  9113. callModelHook(el, binding, vnode, null, 'mounted');
  9114. },
  9115. beforeUpdate(el, binding, vnode, prevVNode) {
  9116. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  9117. },
  9118. updated(el, binding, vnode, prevVNode) {
  9119. callModelHook(el, binding, vnode, prevVNode, 'updated');
  9120. }
  9121. };
  9122. function callModelHook(el, binding, vnode, prevVNode, hook) {
  9123. let modelToUse;
  9124. switch (el.tagName) {
  9125. case 'SELECT':
  9126. modelToUse = vModelSelect;
  9127. break;
  9128. case 'TEXTAREA':
  9129. modelToUse = vModelText;
  9130. break;
  9131. default:
  9132. switch (vnode.props && vnode.props.type) {
  9133. case 'checkbox':
  9134. modelToUse = vModelCheckbox;
  9135. break;
  9136. case 'radio':
  9137. modelToUse = vModelRadio;
  9138. break;
  9139. default:
  9140. modelToUse = vModelText;
  9141. }
  9142. }
  9143. const fn = modelToUse[hook];
  9144. fn && fn(el, binding, vnode, prevVNode);
  9145. }
  9146. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  9147. const modifierGuards = {
  9148. stop: e => e.stopPropagation(),
  9149. prevent: e => e.preventDefault(),
  9150. self: e => e.target !== e.currentTarget,
  9151. ctrl: e => !e.ctrlKey,
  9152. shift: e => !e.shiftKey,
  9153. alt: e => !e.altKey,
  9154. meta: e => !e.metaKey,
  9155. left: e => 'button' in e && e.button !== 0,
  9156. middle: e => 'button' in e && e.button !== 1,
  9157. right: e => 'button' in e && e.button !== 2,
  9158. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  9159. };
  9160. /**
  9161. * @private
  9162. */
  9163. const withModifiers = (fn, modifiers) => {
  9164. return (event, ...args) => {
  9165. for (let i = 0; i < modifiers.length; i++) {
  9166. const guard = modifierGuards[modifiers[i]];
  9167. if (guard && guard(event, modifiers))
  9168. return;
  9169. }
  9170. return fn(event, ...args);
  9171. };
  9172. };
  9173. // Kept for 2.x compat.
  9174. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  9175. const keyNames = {
  9176. esc: 'escape',
  9177. space: ' ',
  9178. up: 'arrow-up',
  9179. left: 'arrow-left',
  9180. right: 'arrow-right',
  9181. down: 'arrow-down',
  9182. delete: 'backspace'
  9183. };
  9184. /**
  9185. * @private
  9186. */
  9187. const withKeys = (fn, modifiers) => {
  9188. return (event) => {
  9189. if (!('key' in event))
  9190. return;
  9191. const eventKey = hyphenate(event.key);
  9192. if (
  9193. // None of the provided key modifiers match the current event key
  9194. !modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  9195. return;
  9196. }
  9197. return fn(event);
  9198. };
  9199. };
  9200. const vShow = {
  9201. beforeMount(el, { value }, { transition }) {
  9202. el._vod = el.style.display === 'none' ? '' : el.style.display;
  9203. if (transition && value) {
  9204. transition.beforeEnter(el);
  9205. }
  9206. else {
  9207. setDisplay(el, value);
  9208. }
  9209. },
  9210. mounted(el, { value }, { transition }) {
  9211. if (transition && value) {
  9212. transition.enter(el);
  9213. }
  9214. },
  9215. updated(el, { value, oldValue }, { transition }) {
  9216. if (transition && value !== oldValue) {
  9217. if (value) {
  9218. transition.beforeEnter(el);
  9219. setDisplay(el, true);
  9220. transition.enter(el);
  9221. }
  9222. else {
  9223. transition.leave(el, () => {
  9224. setDisplay(el, false);
  9225. });
  9226. }
  9227. }
  9228. else {
  9229. setDisplay(el, value);
  9230. }
  9231. },
  9232. beforeUnmount(el, { value }) {
  9233. setDisplay(el, value);
  9234. }
  9235. };
  9236. function setDisplay(el, value) {
  9237. el.style.display = value ? el._vod : 'none';
  9238. }
  9239. const rendererOptions = extend({ patchProp, forcePatchProp }, nodeOps);
  9240. // lazy create the renderer - this makes core renderer logic tree-shakable
  9241. // in case the user only imports reactivity utilities from Vue.
  9242. let renderer;
  9243. let enabledHydration = false;
  9244. function ensureRenderer() {
  9245. return renderer || (renderer = createRenderer(rendererOptions));
  9246. }
  9247. function ensureHydrationRenderer() {
  9248. renderer = enabledHydration
  9249. ? renderer
  9250. : createHydrationRenderer(rendererOptions);
  9251. enabledHydration = true;
  9252. return renderer;
  9253. }
  9254. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  9255. const render = ((...args) => {
  9256. ensureRenderer().render(...args);
  9257. });
  9258. const hydrate = ((...args) => {
  9259. ensureHydrationRenderer().hydrate(...args);
  9260. });
  9261. const createApp = ((...args) => {
  9262. const app = ensureRenderer().createApp(...args);
  9263. {
  9264. injectNativeTagCheck(app);
  9265. }
  9266. const { mount } = app;
  9267. app.mount = (containerOrSelector) => {
  9268. const container = normalizeContainer(containerOrSelector);
  9269. if (!container)
  9270. return;
  9271. const component = app._component;
  9272. if (!isFunction(component) && !component.render && !component.template) {
  9273. component.template = container.innerHTML;
  9274. }
  9275. // clear content before mounting
  9276. container.innerHTML = '';
  9277. const proxy = mount(container);
  9278. if (container instanceof Element) {
  9279. container.removeAttribute('v-cloak');
  9280. container.setAttribute('data-v-app', '');
  9281. }
  9282. return proxy;
  9283. };
  9284. return app;
  9285. });
  9286. const createSSRApp = ((...args) => {
  9287. const app = ensureHydrationRenderer().createApp(...args);
  9288. {
  9289. injectNativeTagCheck(app);
  9290. }
  9291. const { mount } = app;
  9292. app.mount = (containerOrSelector) => {
  9293. const container = normalizeContainer(containerOrSelector);
  9294. if (container) {
  9295. return mount(container, true);
  9296. }
  9297. };
  9298. return app;
  9299. });
  9300. function injectNativeTagCheck(app) {
  9301. // Inject `isNativeTag`
  9302. // this is used for component name validation (dev only)
  9303. Object.defineProperty(app.config, 'isNativeTag', {
  9304. value: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  9305. writable: false
  9306. });
  9307. }
  9308. function normalizeContainer(container) {
  9309. if (isString(container)) {
  9310. const res = document.querySelector(container);
  9311. if (!res) {
  9312. warn(`Failed to mount app: mount target selector "${container}" returned null.`);
  9313. }
  9314. return res;
  9315. }
  9316. if (container instanceof window.ShadowRoot &&
  9317. container.mode === 'closed') {
  9318. warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  9319. }
  9320. return container;
  9321. }
  9322. var runtimeDom = /*#__PURE__*/Object.freeze({
  9323. __proto__: null,
  9324. render: render,
  9325. hydrate: hydrate,
  9326. createApp: createApp,
  9327. createSSRApp: createSSRApp,
  9328. useCssModule: useCssModule,
  9329. useCssVars: useCssVars,
  9330. Transition: Transition,
  9331. TransitionGroup: TransitionGroup,
  9332. vModelText: vModelText,
  9333. vModelCheckbox: vModelCheckbox,
  9334. vModelRadio: vModelRadio,
  9335. vModelSelect: vModelSelect,
  9336. vModelDynamic: vModelDynamic,
  9337. withModifiers: withModifiers,
  9338. withKeys: withKeys,
  9339. vShow: vShow,
  9340. reactive: reactive,
  9341. ref: ref,
  9342. readonly: readonly,
  9343. unref: unref,
  9344. proxyRefs: proxyRefs,
  9345. isRef: isRef,
  9346. toRef: toRef,
  9347. toRefs: toRefs,
  9348. isProxy: isProxy,
  9349. isReactive: isReactive,
  9350. isReadonly: isReadonly,
  9351. customRef: customRef,
  9352. triggerRef: triggerRef,
  9353. shallowRef: shallowRef,
  9354. shallowReactive: shallowReactive,
  9355. shallowReadonly: shallowReadonly,
  9356. markRaw: markRaw,
  9357. toRaw: toRaw,
  9358. computed: computed$1,
  9359. watch: watch,
  9360. watchEffect: watchEffect,
  9361. onBeforeMount: onBeforeMount,
  9362. onMounted: onMounted,
  9363. onBeforeUpdate: onBeforeUpdate,
  9364. onUpdated: onUpdated,
  9365. onBeforeUnmount: onBeforeUnmount,
  9366. onUnmounted: onUnmounted,
  9367. onActivated: onActivated,
  9368. onDeactivated: onDeactivated,
  9369. onRenderTracked: onRenderTracked,
  9370. onRenderTriggered: onRenderTriggered,
  9371. onErrorCaptured: onErrorCaptured,
  9372. provide: provide,
  9373. inject: inject,
  9374. nextTick: nextTick,
  9375. defineComponent: defineComponent,
  9376. defineAsyncComponent: defineAsyncComponent,
  9377. defineProps: defineProps,
  9378. defineEmit: defineEmit,
  9379. useContext: useContext,
  9380. getCurrentInstance: getCurrentInstance,
  9381. h: h,
  9382. createVNode: createVNode,
  9383. cloneVNode: cloneVNode,
  9384. mergeProps: mergeProps,
  9385. isVNode: isVNode,
  9386. Fragment: Fragment,
  9387. Text: Text,
  9388. Comment: Comment,
  9389. Static: Static,
  9390. Teleport: Teleport,
  9391. Suspense: Suspense,
  9392. KeepAlive: KeepAlive,
  9393. BaseTransition: BaseTransition,
  9394. withDirectives: withDirectives,
  9395. useSSRContext: useSSRContext,
  9396. ssrContextKey: ssrContextKey,
  9397. createRenderer: createRenderer,
  9398. createHydrationRenderer: createHydrationRenderer,
  9399. queuePostFlushCb: queuePostFlushCb,
  9400. warn: warn,
  9401. handleError: handleError,
  9402. callWithErrorHandling: callWithErrorHandling,
  9403. callWithAsyncErrorHandling: callWithAsyncErrorHandling,
  9404. resolveComponent: resolveComponent,
  9405. resolveDirective: resolveDirective,
  9406. resolveDynamicComponent: resolveDynamicComponent,
  9407. registerRuntimeCompiler: registerRuntimeCompiler,
  9408. useTransitionState: useTransitionState,
  9409. resolveTransitionHooks: resolveTransitionHooks,
  9410. setTransitionHooks: setTransitionHooks,
  9411. getTransitionRawChildren: getTransitionRawChildren,
  9412. initCustomFormatter: initCustomFormatter,
  9413. get devtools () { return devtools; },
  9414. setDevtoolsHook: setDevtoolsHook,
  9415. withCtx: withCtx,
  9416. renderList: renderList,
  9417. toHandlers: toHandlers,
  9418. renderSlot: renderSlot,
  9419. createSlots: createSlots,
  9420. pushScopeId: pushScopeId,
  9421. popScopeId: popScopeId,
  9422. withScopeId: withScopeId,
  9423. openBlock: openBlock,
  9424. createBlock: createBlock,
  9425. setBlockTracking: setBlockTracking,
  9426. createTextVNode: createTextVNode,
  9427. createCommentVNode: createCommentVNode,
  9428. createStaticVNode: createStaticVNode,
  9429. toDisplayString: toDisplayString,
  9430. camelize: camelize,
  9431. capitalize: capitalize,
  9432. toHandlerKey: toHandlerKey,
  9433. transformVNodeArgs: transformVNodeArgs,
  9434. version: version,
  9435. ssrUtils: ssrUtils
  9436. });
  9437. function initDev() {
  9438. const target = getGlobalThis();
  9439. target.__VUE__ = true;
  9440. setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__);
  9441. {
  9442. {
  9443. console.info(`You are running a development build of Vue.\n` +
  9444. `Make sure to use the production build (*.prod.js) when deploying for production.`);
  9445. }
  9446. initCustomFormatter();
  9447. }
  9448. }
  9449. function defaultOnError(error) {
  9450. throw error;
  9451. }
  9452. function createCompilerError(code, loc, messages, additionalMessage) {
  9453. const msg = (messages || errorMessages)[code] + (additionalMessage || ``)
  9454. ;
  9455. const error = new SyntaxError(String(msg));
  9456. error.code = code;
  9457. error.loc = loc;
  9458. return error;
  9459. }
  9460. const errorMessages = {
  9461. // parse errors
  9462. [0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
  9463. [1 /* CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
  9464. [2 /* DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
  9465. [3 /* END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
  9466. [4 /* END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
  9467. [5 /* EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
  9468. [6 /* EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
  9469. [7 /* EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
  9470. [8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
  9471. [9 /* EOF_IN_TAG */]: 'Unexpected EOF in tag.',
  9472. [10 /* INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
  9473. [11 /* INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
  9474. [12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '&lt;' to print '<'.",
  9475. [13 /* MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
  9476. [14 /* MISSING_END_TAG_NAME */]: 'End tag name was expected.',
  9477. [15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
  9478. [16 /* NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
  9479. [17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
  9480. [18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
  9481. [19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
  9482. [21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
  9483. [22 /* UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
  9484. // Vue-specific parse errors
  9485. [23 /* X_INVALID_END_TAG */]: 'Invalid end tag.',
  9486. [24 /* X_MISSING_END_TAG */]: 'Element is missing end tag.',
  9487. [25 /* X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
  9488. [26 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
  9489. 'Note that dynamic directive argument cannot contain spaces.',
  9490. // transform errors
  9491. [27 /* X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
  9492. [28 /* X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
  9493. [29 /* X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if.`,
  9494. [30 /* X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
  9495. [31 /* X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
  9496. [32 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
  9497. [33 /* X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
  9498. [34 /* X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
  9499. [35 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
  9500. [36 /* X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>.` +
  9501. `When there are multiple named slots, all slots should use <template> ` +
  9502. `syntax to avoid scope ambiguity.`,
  9503. [37 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
  9504. [38 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
  9505. `default slot. These children will be ignored.`,
  9506. [39 /* X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
  9507. [40 /* X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
  9508. [41 /* X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
  9509. [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.`,
  9510. [43 /* X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
  9511. [44 /* X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
  9512. // generic errors
  9513. [45 /* X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  9514. [46 /* X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
  9515. [47 /* X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  9516. [48 /* X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`
  9517. };
  9518. const FRAGMENT = Symbol(`Fragment` );
  9519. const TELEPORT = Symbol(`Teleport` );
  9520. const SUSPENSE = Symbol(`Suspense` );
  9521. const KEEP_ALIVE = Symbol(`KeepAlive` );
  9522. const BASE_TRANSITION = Symbol(`BaseTransition` );
  9523. const OPEN_BLOCK = Symbol(`openBlock` );
  9524. const CREATE_BLOCK = Symbol(`createBlock` );
  9525. const CREATE_VNODE = Symbol(`createVNode` );
  9526. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  9527. const CREATE_TEXT = Symbol(`createTextVNode` );
  9528. const CREATE_STATIC = Symbol(`createStaticVNode` );
  9529. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  9530. const RESOLVE_DYNAMIC_COMPONENT = Symbol(`resolveDynamicComponent` );
  9531. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  9532. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  9533. const RENDER_LIST = Symbol(`renderList` );
  9534. const RENDER_SLOT = Symbol(`renderSlot` );
  9535. const CREATE_SLOTS = Symbol(`createSlots` );
  9536. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  9537. const MERGE_PROPS = Symbol(`mergeProps` );
  9538. const TO_HANDLERS = Symbol(`toHandlers` );
  9539. const CAMELIZE = Symbol(`camelize` );
  9540. const CAPITALIZE = Symbol(`capitalize` );
  9541. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  9542. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  9543. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  9544. const POP_SCOPE_ID = Symbol(`popScopeId` );
  9545. const WITH_SCOPE_ID = Symbol(`withScopeId` );
  9546. const WITH_CTX = Symbol(`withCtx` );
  9547. const UNREF = Symbol(`unref` );
  9548. const IS_REF = Symbol(`isRef` );
  9549. // Name mapping for runtime helpers that need to be imported from 'vue' in
  9550. // generated code. Make sure these are correctly exported in the runtime!
  9551. // Using `any` here because TS doesn't allow symbols as index type.
  9552. const helperNameMap = {
  9553. [FRAGMENT]: `Fragment`,
  9554. [TELEPORT]: `Teleport`,
  9555. [SUSPENSE]: `Suspense`,
  9556. [KEEP_ALIVE]: `KeepAlive`,
  9557. [BASE_TRANSITION]: `BaseTransition`,
  9558. [OPEN_BLOCK]: `openBlock`,
  9559. [CREATE_BLOCK]: `createBlock`,
  9560. [CREATE_VNODE]: `createVNode`,
  9561. [CREATE_COMMENT]: `createCommentVNode`,
  9562. [CREATE_TEXT]: `createTextVNode`,
  9563. [CREATE_STATIC]: `createStaticVNode`,
  9564. [RESOLVE_COMPONENT]: `resolveComponent`,
  9565. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  9566. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  9567. [WITH_DIRECTIVES]: `withDirectives`,
  9568. [RENDER_LIST]: `renderList`,
  9569. [RENDER_SLOT]: `renderSlot`,
  9570. [CREATE_SLOTS]: `createSlots`,
  9571. [TO_DISPLAY_STRING]: `toDisplayString`,
  9572. [MERGE_PROPS]: `mergeProps`,
  9573. [TO_HANDLERS]: `toHandlers`,
  9574. [CAMELIZE]: `camelize`,
  9575. [CAPITALIZE]: `capitalize`,
  9576. [TO_HANDLER_KEY]: `toHandlerKey`,
  9577. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  9578. [PUSH_SCOPE_ID]: `pushScopeId`,
  9579. [POP_SCOPE_ID]: `popScopeId`,
  9580. [WITH_SCOPE_ID]: `withScopeId`,
  9581. [WITH_CTX]: `withCtx`,
  9582. [UNREF]: `unref`,
  9583. [IS_REF]: `isRef`
  9584. };
  9585. function registerRuntimeHelpers(helpers) {
  9586. Object.getOwnPropertySymbols(helpers).forEach(s => {
  9587. helperNameMap[s] = helpers[s];
  9588. });
  9589. }
  9590. // AST Utilities ---------------------------------------------------------------
  9591. // Some expressions, e.g. sequence and conditional expressions, are never
  9592. // associated with template nodes, so their source locations are just a stub.
  9593. // Container types like CompoundExpression also don't need a real location.
  9594. const locStub = {
  9595. source: '',
  9596. start: { line: 1, column: 1, offset: 0 },
  9597. end: { line: 1, column: 1, offset: 0 }
  9598. };
  9599. function createRoot(children, loc = locStub) {
  9600. return {
  9601. type: 0 /* ROOT */,
  9602. children,
  9603. helpers: [],
  9604. components: [],
  9605. directives: [],
  9606. hoists: [],
  9607. imports: [],
  9608. cached: 0,
  9609. temps: 0,
  9610. codegenNode: undefined,
  9611. loc
  9612. };
  9613. }
  9614. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, loc = locStub) {
  9615. if (context) {
  9616. if (isBlock) {
  9617. context.helper(OPEN_BLOCK);
  9618. context.helper(CREATE_BLOCK);
  9619. }
  9620. else {
  9621. context.helper(CREATE_VNODE);
  9622. }
  9623. if (directives) {
  9624. context.helper(WITH_DIRECTIVES);
  9625. }
  9626. }
  9627. return {
  9628. type: 13 /* VNODE_CALL */,
  9629. tag,
  9630. props,
  9631. children,
  9632. patchFlag,
  9633. dynamicProps,
  9634. directives,
  9635. isBlock,
  9636. disableTracking,
  9637. loc
  9638. };
  9639. }
  9640. function createArrayExpression(elements, loc = locStub) {
  9641. return {
  9642. type: 17 /* JS_ARRAY_EXPRESSION */,
  9643. loc,
  9644. elements
  9645. };
  9646. }
  9647. function createObjectExpression(properties, loc = locStub) {
  9648. return {
  9649. type: 15 /* JS_OBJECT_EXPRESSION */,
  9650. loc,
  9651. properties
  9652. };
  9653. }
  9654. function createObjectProperty(key, value) {
  9655. return {
  9656. type: 16 /* JS_PROPERTY */,
  9657. loc: locStub,
  9658. key: isString(key) ? createSimpleExpression(key, true) : key,
  9659. value
  9660. };
  9661. }
  9662. function createSimpleExpression(content, isStatic, loc = locStub, constType = 0 /* NOT_CONSTANT */) {
  9663. return {
  9664. type: 4 /* SIMPLE_EXPRESSION */,
  9665. loc,
  9666. content,
  9667. isStatic,
  9668. constType: isStatic ? 3 /* CAN_STRINGIFY */ : constType
  9669. };
  9670. }
  9671. function createCompoundExpression(children, loc = locStub) {
  9672. return {
  9673. type: 8 /* COMPOUND_EXPRESSION */,
  9674. loc,
  9675. children
  9676. };
  9677. }
  9678. function createCallExpression(callee, args = [], loc = locStub) {
  9679. return {
  9680. type: 14 /* JS_CALL_EXPRESSION */,
  9681. loc,
  9682. callee,
  9683. arguments: args
  9684. };
  9685. }
  9686. function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {
  9687. return {
  9688. type: 18 /* JS_FUNCTION_EXPRESSION */,
  9689. params,
  9690. returns,
  9691. newline,
  9692. isSlot,
  9693. loc
  9694. };
  9695. }
  9696. function createConditionalExpression(test, consequent, alternate, newline = true) {
  9697. return {
  9698. type: 19 /* JS_CONDITIONAL_EXPRESSION */,
  9699. test,
  9700. consequent,
  9701. alternate,
  9702. newline,
  9703. loc: locStub
  9704. };
  9705. }
  9706. function createCacheExpression(index, value, isVNode = false) {
  9707. return {
  9708. type: 20 /* JS_CACHE_EXPRESSION */,
  9709. index,
  9710. value,
  9711. isVNode,
  9712. loc: locStub
  9713. };
  9714. }
  9715. const isStaticExp = (p) => p.type === 4 /* SIMPLE_EXPRESSION */ && p.isStatic;
  9716. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  9717. function isCoreComponent(tag) {
  9718. if (isBuiltInType(tag, 'Teleport')) {
  9719. return TELEPORT;
  9720. }
  9721. else if (isBuiltInType(tag, 'Suspense')) {
  9722. return SUSPENSE;
  9723. }
  9724. else if (isBuiltInType(tag, 'KeepAlive')) {
  9725. return KEEP_ALIVE;
  9726. }
  9727. else if (isBuiltInType(tag, 'BaseTransition')) {
  9728. return BASE_TRANSITION;
  9729. }
  9730. }
  9731. const nonIdentifierRE = /^\d|[^\$\w]/;
  9732. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  9733. const memberExpRE = /^[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*|\[[^\]]+\])*$/;
  9734. const isMemberExpression = (path) => {
  9735. if (!path)
  9736. return false;
  9737. return memberExpRE.test(path.trim());
  9738. };
  9739. function getInnerRange(loc, offset, length) {
  9740. const source = loc.source.substr(offset, length);
  9741. const newLoc = {
  9742. source,
  9743. start: advancePositionWithClone(loc.start, loc.source, offset),
  9744. end: loc.end
  9745. };
  9746. if (length != null) {
  9747. newLoc.end = advancePositionWithClone(loc.start, loc.source, offset + length);
  9748. }
  9749. return newLoc;
  9750. }
  9751. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  9752. return advancePositionWithMutation(extend({}, pos), source, numberOfCharacters);
  9753. }
  9754. // advance by mutation without cloning (for performance reasons), since this
  9755. // gets called a lot in the parser
  9756. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  9757. let linesCount = 0;
  9758. let lastNewLinePos = -1;
  9759. for (let i = 0; i < numberOfCharacters; i++) {
  9760. if (source.charCodeAt(i) === 10 /* newline char code */) {
  9761. linesCount++;
  9762. lastNewLinePos = i;
  9763. }
  9764. }
  9765. pos.offset += numberOfCharacters;
  9766. pos.line += linesCount;
  9767. pos.column =
  9768. lastNewLinePos === -1
  9769. ? pos.column + numberOfCharacters
  9770. : numberOfCharacters - lastNewLinePos;
  9771. return pos;
  9772. }
  9773. function assert(condition, msg) {
  9774. /* istanbul ignore if */
  9775. if (!condition) {
  9776. throw new Error(msg || `unexpected compiler condition`);
  9777. }
  9778. }
  9779. function findDir(node, name, allowEmpty = false) {
  9780. for (let i = 0; i < node.props.length; i++) {
  9781. const p = node.props[i];
  9782. if (p.type === 7 /* DIRECTIVE */ &&
  9783. (allowEmpty || p.exp) &&
  9784. (isString(name) ? p.name === name : name.test(p.name))) {
  9785. return p;
  9786. }
  9787. }
  9788. }
  9789. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  9790. for (let i = 0; i < node.props.length; i++) {
  9791. const p = node.props[i];
  9792. if (p.type === 6 /* ATTRIBUTE */) {
  9793. if (dynamicOnly)
  9794. continue;
  9795. if (p.name === name && (p.value || allowEmpty)) {
  9796. return p;
  9797. }
  9798. }
  9799. else if (p.name === 'bind' &&
  9800. (p.exp || allowEmpty) &&
  9801. isBindKey(p.arg, name)) {
  9802. return p;
  9803. }
  9804. }
  9805. }
  9806. function isBindKey(arg, name) {
  9807. return !!(arg && isStaticExp(arg) && arg.content === name);
  9808. }
  9809. function hasDynamicKeyVBind(node) {
  9810. return node.props.some(p => p.type === 7 /* DIRECTIVE */ &&
  9811. p.name === 'bind' &&
  9812. (!p.arg || // v-bind="obj"
  9813. p.arg.type !== 4 /* SIMPLE_EXPRESSION */ || // v-bind:[_ctx.foo]
  9814. !p.arg.isStatic) // v-bind:[foo]
  9815. );
  9816. }
  9817. function isText(node) {
  9818. return node.type === 5 /* INTERPOLATION */ || node.type === 2 /* TEXT */;
  9819. }
  9820. function isVSlot(p) {
  9821. return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';
  9822. }
  9823. function isTemplateNode(node) {
  9824. return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);
  9825. }
  9826. function isSlotOutlet(node) {
  9827. return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;
  9828. }
  9829. function injectProp(node, prop, context) {
  9830. let propsWithInjection;
  9831. const props = node.type === 13 /* VNODE_CALL */ ? node.props : node.arguments[2];
  9832. if (props == null || isString(props)) {
  9833. propsWithInjection = createObjectExpression([prop]);
  9834. }
  9835. else if (props.type === 14 /* JS_CALL_EXPRESSION */) {
  9836. // merged props... add ours
  9837. // only inject key to object literal if it's the first argument so that
  9838. // if doesn't override user provided keys
  9839. const first = props.arguments[0];
  9840. if (!isString(first) && first.type === 15 /* JS_OBJECT_EXPRESSION */) {
  9841. first.properties.unshift(prop);
  9842. }
  9843. else {
  9844. if (props.callee === TO_HANDLERS) {
  9845. // #2366
  9846. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  9847. createObjectExpression([prop]),
  9848. props
  9849. ]);
  9850. }
  9851. else {
  9852. props.arguments.unshift(createObjectExpression([prop]));
  9853. }
  9854. }
  9855. !propsWithInjection && (propsWithInjection = props);
  9856. }
  9857. else if (props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  9858. let alreadyExists = false;
  9859. // check existing key to avoid overriding user provided keys
  9860. if (prop.key.type === 4 /* SIMPLE_EXPRESSION */) {
  9861. const propKeyName = prop.key.content;
  9862. alreadyExists = props.properties.some(p => p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  9863. p.key.content === propKeyName);
  9864. }
  9865. if (!alreadyExists) {
  9866. props.properties.unshift(prop);
  9867. }
  9868. propsWithInjection = props;
  9869. }
  9870. else {
  9871. // single v-bind with expression, return a merged replacement
  9872. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  9873. createObjectExpression([prop]),
  9874. props
  9875. ]);
  9876. }
  9877. if (node.type === 13 /* VNODE_CALL */) {
  9878. node.props = propsWithInjection;
  9879. }
  9880. else {
  9881. node.arguments[2] = propsWithInjection;
  9882. }
  9883. }
  9884. function toValidAssetId(name, type) {
  9885. return `_${type}_${name.replace(/[^\w]/g, '_')}`;
  9886. }
  9887. // The default decoder only provides escapes for characters reserved as part of
  9888. // the template syntax, and is only used if the custom renderer did not provide
  9889. // a platform-specific decoder.
  9890. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  9891. const decodeMap = {
  9892. gt: '>',
  9893. lt: '<',
  9894. amp: '&',
  9895. apos: "'",
  9896. quot: '"'
  9897. };
  9898. const defaultParserOptions = {
  9899. delimiters: [`{{`, `}}`],
  9900. getNamespace: () => 0 /* HTML */,
  9901. getTextMode: () => 0 /* DATA */,
  9902. isVoidTag: NO,
  9903. isPreTag: NO,
  9904. isCustomElement: NO,
  9905. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  9906. onError: defaultOnError,
  9907. comments: false
  9908. };
  9909. function baseParse(content, options = {}) {
  9910. const context = createParserContext(content, options);
  9911. const start = getCursor(context);
  9912. return createRoot(parseChildren(context, 0 /* DATA */, []), getSelection(context, start));
  9913. }
  9914. function createParserContext(content, rawOptions) {
  9915. const options = extend({}, defaultParserOptions);
  9916. for (const key in rawOptions) {
  9917. // @ts-ignore
  9918. options[key] = rawOptions[key] || defaultParserOptions[key];
  9919. }
  9920. return {
  9921. options,
  9922. column: 1,
  9923. line: 1,
  9924. offset: 0,
  9925. originalSource: content,
  9926. source: content,
  9927. inPre: false,
  9928. inVPre: false
  9929. };
  9930. }
  9931. function parseChildren(context, mode, ancestors) {
  9932. const parent = last(ancestors);
  9933. const ns = parent ? parent.ns : 0 /* HTML */;
  9934. const nodes = [];
  9935. while (!isEnd(context, mode, ancestors)) {
  9936. const s = context.source;
  9937. let node = undefined;
  9938. if (mode === 0 /* DATA */ || mode === 1 /* RCDATA */) {
  9939. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  9940. // '{{'
  9941. node = parseInterpolation(context, mode);
  9942. }
  9943. else if (mode === 0 /* DATA */ && s[0] === '<') {
  9944. // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
  9945. if (s.length === 1) {
  9946. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 1);
  9947. }
  9948. else if (s[1] === '!') {
  9949. // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
  9950. if (startsWith(s, '<!--')) {
  9951. node = parseComment(context);
  9952. }
  9953. else if (startsWith(s, '<!DOCTYPE')) {
  9954. // Ignore DOCTYPE by a limitation.
  9955. node = parseBogusComment(context);
  9956. }
  9957. else if (startsWith(s, '<![CDATA[')) {
  9958. if (ns !== 0 /* HTML */) {
  9959. node = parseCDATA(context, ancestors);
  9960. }
  9961. else {
  9962. emitError(context, 1 /* CDATA_IN_HTML_CONTENT */);
  9963. node = parseBogusComment(context);
  9964. }
  9965. }
  9966. else {
  9967. emitError(context, 11 /* INCORRECTLY_OPENED_COMMENT */);
  9968. node = parseBogusComment(context);
  9969. }
  9970. }
  9971. else if (s[1] === '/') {
  9972. // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
  9973. if (s.length === 2) {
  9974. emitError(context, 5 /* EOF_BEFORE_TAG_NAME */, 2);
  9975. }
  9976. else if (s[2] === '>') {
  9977. emitError(context, 14 /* MISSING_END_TAG_NAME */, 2);
  9978. advanceBy(context, 3);
  9979. continue;
  9980. }
  9981. else if (/[a-z]/i.test(s[2])) {
  9982. emitError(context, 23 /* X_INVALID_END_TAG */);
  9983. parseTag(context, 1 /* End */, parent);
  9984. continue;
  9985. }
  9986. else {
  9987. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 2);
  9988. node = parseBogusComment(context);
  9989. }
  9990. }
  9991. else if (/[a-z]/i.test(s[1])) {
  9992. node = parseElement(context, ancestors);
  9993. }
  9994. else if (s[1] === '?') {
  9995. emitError(context, 21 /* UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */, 1);
  9996. node = parseBogusComment(context);
  9997. }
  9998. else {
  9999. emitError(context, 12 /* INVALID_FIRST_CHARACTER_OF_TAG_NAME */, 1);
  10000. }
  10001. }
  10002. }
  10003. if (!node) {
  10004. node = parseText(context, mode);
  10005. }
  10006. if (isArray(node)) {
  10007. for (let i = 0; i < node.length; i++) {
  10008. pushNode(nodes, node[i]);
  10009. }
  10010. }
  10011. else {
  10012. pushNode(nodes, node);
  10013. }
  10014. }
  10015. // Whitespace management for more efficient output
  10016. // (same as v2 whitespace: 'condense')
  10017. let removedWhitespace = false;
  10018. if (mode !== 2 /* RAWTEXT */) {
  10019. for (let i = 0; i < nodes.length; i++) {
  10020. const node = nodes[i];
  10021. if (!context.inPre && node.type === 2 /* TEXT */) {
  10022. if (!/[^\t\r\n\f ]/.test(node.content)) {
  10023. const prev = nodes[i - 1];
  10024. const next = nodes[i + 1];
  10025. // If:
  10026. // - the whitespace is the first or last node, or:
  10027. // - the whitespace is adjacent to a comment, or:
  10028. // - the whitespace is between two elements AND contains newline
  10029. // Then the whitespace is ignored.
  10030. if (!prev ||
  10031. !next ||
  10032. prev.type === 3 /* COMMENT */ ||
  10033. next.type === 3 /* COMMENT */ ||
  10034. (prev.type === 1 /* ELEMENT */ &&
  10035. next.type === 1 /* ELEMENT */ &&
  10036. /[\r\n]/.test(node.content))) {
  10037. removedWhitespace = true;
  10038. nodes[i] = null;
  10039. }
  10040. else {
  10041. // Otherwise, condensed consecutive whitespace inside the text
  10042. // down to a single space
  10043. node.content = ' ';
  10044. }
  10045. }
  10046. else {
  10047. node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
  10048. }
  10049. }
  10050. }
  10051. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  10052. // remove leading newline per html spec
  10053. // https://html.spec.whatwg.org/multipage/grouping-content.html#the-pre-element
  10054. const first = nodes[0];
  10055. if (first && first.type === 2 /* TEXT */) {
  10056. first.content = first.content.replace(/^\r?\n/, '');
  10057. }
  10058. }
  10059. }
  10060. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  10061. }
  10062. function pushNode(nodes, node) {
  10063. if (node.type === 2 /* TEXT */) {
  10064. const prev = last(nodes);
  10065. // Merge if both this and the previous node are text and those are
  10066. // consecutive. This happens for cases like "a < b".
  10067. if (prev &&
  10068. prev.type === 2 /* TEXT */ &&
  10069. prev.loc.end.offset === node.loc.start.offset) {
  10070. prev.content += node.content;
  10071. prev.loc.end = node.loc.end;
  10072. prev.loc.source += node.loc.source;
  10073. return;
  10074. }
  10075. }
  10076. nodes.push(node);
  10077. }
  10078. function parseCDATA(context, ancestors) {
  10079. advanceBy(context, 9);
  10080. const nodes = parseChildren(context, 3 /* CDATA */, ancestors);
  10081. if (context.source.length === 0) {
  10082. emitError(context, 6 /* EOF_IN_CDATA */);
  10083. }
  10084. else {
  10085. advanceBy(context, 3);
  10086. }
  10087. return nodes;
  10088. }
  10089. function parseComment(context) {
  10090. const start = getCursor(context);
  10091. let content;
  10092. // Regular comment.
  10093. const match = /--(\!)?>/.exec(context.source);
  10094. if (!match) {
  10095. content = context.source.slice(4);
  10096. advanceBy(context, context.source.length);
  10097. emitError(context, 7 /* EOF_IN_COMMENT */);
  10098. }
  10099. else {
  10100. if (match.index <= 3) {
  10101. emitError(context, 0 /* ABRUPT_CLOSING_OF_EMPTY_COMMENT */);
  10102. }
  10103. if (match[1]) {
  10104. emitError(context, 10 /* INCORRECTLY_CLOSED_COMMENT */);
  10105. }
  10106. content = context.source.slice(4, match.index);
  10107. // Advancing with reporting nested comments.
  10108. const s = context.source.slice(0, match.index);
  10109. let prevIndex = 1, nestedIndex = 0;
  10110. while ((nestedIndex = s.indexOf('<!--', prevIndex)) !== -1) {
  10111. advanceBy(context, nestedIndex - prevIndex + 1);
  10112. if (nestedIndex + 4 < s.length) {
  10113. emitError(context, 16 /* NESTED_COMMENT */);
  10114. }
  10115. prevIndex = nestedIndex + 1;
  10116. }
  10117. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  10118. }
  10119. return {
  10120. type: 3 /* COMMENT */,
  10121. content,
  10122. loc: getSelection(context, start)
  10123. };
  10124. }
  10125. function parseBogusComment(context) {
  10126. const start = getCursor(context);
  10127. const contentStart = context.source[1] === '?' ? 1 : 2;
  10128. let content;
  10129. const closeIndex = context.source.indexOf('>');
  10130. if (closeIndex === -1) {
  10131. content = context.source.slice(contentStart);
  10132. advanceBy(context, context.source.length);
  10133. }
  10134. else {
  10135. content = context.source.slice(contentStart, closeIndex);
  10136. advanceBy(context, closeIndex + 1);
  10137. }
  10138. return {
  10139. type: 3 /* COMMENT */,
  10140. content,
  10141. loc: getSelection(context, start)
  10142. };
  10143. }
  10144. function parseElement(context, ancestors) {
  10145. // Start tag.
  10146. const wasInPre = context.inPre;
  10147. const wasInVPre = context.inVPre;
  10148. const parent = last(ancestors);
  10149. const element = parseTag(context, 0 /* Start */, parent);
  10150. const isPreBoundary = context.inPre && !wasInPre;
  10151. const isVPreBoundary = context.inVPre && !wasInVPre;
  10152. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  10153. return element;
  10154. }
  10155. // Children.
  10156. ancestors.push(element);
  10157. const mode = context.options.getTextMode(element, parent);
  10158. const children = parseChildren(context, mode, ancestors);
  10159. ancestors.pop();
  10160. element.children = children;
  10161. // End tag.
  10162. if (startsWithEndTagOpen(context.source, element.tag)) {
  10163. parseTag(context, 1 /* End */, parent);
  10164. }
  10165. else {
  10166. emitError(context, 24 /* X_MISSING_END_TAG */, 0, element.loc.start);
  10167. if (context.source.length === 0 && element.tag.toLowerCase() === 'script') {
  10168. const first = children[0];
  10169. if (first && startsWith(first.loc.source, '<!--')) {
  10170. emitError(context, 8 /* EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */);
  10171. }
  10172. }
  10173. }
  10174. element.loc = getSelection(context, element.loc.start);
  10175. if (isPreBoundary) {
  10176. context.inPre = false;
  10177. }
  10178. if (isVPreBoundary) {
  10179. context.inVPre = false;
  10180. }
  10181. return element;
  10182. }
  10183. const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(`if,else,else-if,for,slot`);
  10184. /**
  10185. * Parse a tag (E.g. `<div id=a>`) with that type (start tag or end tag).
  10186. */
  10187. function parseTag(context, type, parent) {
  10188. // Tag open.
  10189. const start = getCursor(context);
  10190. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  10191. const tag = match[1];
  10192. const ns = context.options.getNamespace(tag, parent);
  10193. advanceBy(context, match[0].length);
  10194. advanceSpaces(context);
  10195. // save current state in case we need to re-parse attributes with v-pre
  10196. const cursor = getCursor(context);
  10197. const currentSource = context.source;
  10198. // Attributes.
  10199. let props = parseAttributes(context, type);
  10200. // check <pre> tag
  10201. if (context.options.isPreTag(tag)) {
  10202. context.inPre = true;
  10203. }
  10204. // check v-pre
  10205. if (!context.inVPre &&
  10206. props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'pre')) {
  10207. context.inVPre = true;
  10208. // reset context
  10209. extend(context, cursor);
  10210. context.source = currentSource;
  10211. // re-parse attrs and filter out v-pre itself
  10212. props = parseAttributes(context, type).filter(p => p.name !== 'v-pre');
  10213. }
  10214. // Tag close.
  10215. let isSelfClosing = false;
  10216. if (context.source.length === 0) {
  10217. emitError(context, 9 /* EOF_IN_TAG */);
  10218. }
  10219. else {
  10220. isSelfClosing = startsWith(context.source, '/>');
  10221. if (type === 1 /* End */ && isSelfClosing) {
  10222. emitError(context, 4 /* END_TAG_WITH_TRAILING_SOLIDUS */);
  10223. }
  10224. advanceBy(context, isSelfClosing ? 2 : 1);
  10225. }
  10226. let tagType = 0 /* ELEMENT */;
  10227. const options = context.options;
  10228. if (!context.inVPre && !options.isCustomElement(tag)) {
  10229. const hasVIs = props.some(p => p.type === 7 /* DIRECTIVE */ && p.name === 'is');
  10230. if (options.isNativeTag && !hasVIs) {
  10231. if (!options.isNativeTag(tag))
  10232. tagType = 1 /* COMPONENT */;
  10233. }
  10234. else if (hasVIs ||
  10235. isCoreComponent(tag) ||
  10236. (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
  10237. /^[A-Z]/.test(tag) ||
  10238. tag === 'component') {
  10239. tagType = 1 /* COMPONENT */;
  10240. }
  10241. if (tag === 'slot') {
  10242. tagType = 2 /* SLOT */;
  10243. }
  10244. else if (tag === 'template' &&
  10245. props.some(p => {
  10246. return (p.type === 7 /* DIRECTIVE */ && isSpecialTemplateDirective(p.name));
  10247. })) {
  10248. tagType = 3 /* TEMPLATE */;
  10249. }
  10250. }
  10251. return {
  10252. type: 1 /* ELEMENT */,
  10253. ns,
  10254. tag,
  10255. tagType,
  10256. props,
  10257. isSelfClosing,
  10258. children: [],
  10259. loc: getSelection(context, start),
  10260. codegenNode: undefined // to be created during transform phase
  10261. };
  10262. }
  10263. function parseAttributes(context, type) {
  10264. const props = [];
  10265. const attributeNames = new Set();
  10266. while (context.source.length > 0 &&
  10267. !startsWith(context.source, '>') &&
  10268. !startsWith(context.source, '/>')) {
  10269. if (startsWith(context.source, '/')) {
  10270. emitError(context, 22 /* UNEXPECTED_SOLIDUS_IN_TAG */);
  10271. advanceBy(context, 1);
  10272. advanceSpaces(context);
  10273. continue;
  10274. }
  10275. if (type === 1 /* End */) {
  10276. emitError(context, 3 /* END_TAG_WITH_ATTRIBUTES */);
  10277. }
  10278. const attr = parseAttribute(context, attributeNames);
  10279. if (type === 0 /* Start */) {
  10280. props.push(attr);
  10281. }
  10282. if (/^[^\t\r\n\f />]/.test(context.source)) {
  10283. emitError(context, 15 /* MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */);
  10284. }
  10285. advanceSpaces(context);
  10286. }
  10287. return props;
  10288. }
  10289. function parseAttribute(context, nameSet) {
  10290. // Name.
  10291. const start = getCursor(context);
  10292. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  10293. const name = match[0];
  10294. if (nameSet.has(name)) {
  10295. emitError(context, 2 /* DUPLICATE_ATTRIBUTE */);
  10296. }
  10297. nameSet.add(name);
  10298. if (name[0] === '=') {
  10299. emitError(context, 19 /* UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */);
  10300. }
  10301. {
  10302. const pattern = /["'<]/g;
  10303. let m;
  10304. while ((m = pattern.exec(name))) {
  10305. emitError(context, 17 /* UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */, m.index);
  10306. }
  10307. }
  10308. advanceBy(context, name.length);
  10309. // Value
  10310. let value = undefined;
  10311. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  10312. advanceSpaces(context);
  10313. advanceBy(context, 1);
  10314. advanceSpaces(context);
  10315. value = parseAttributeValue(context);
  10316. if (!value) {
  10317. emitError(context, 13 /* MISSING_ATTRIBUTE_VALUE */);
  10318. }
  10319. }
  10320. const loc = getSelection(context, start);
  10321. if (!context.inVPre && /^(v-|:|@|#)/.test(name)) {
  10322. const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(name);
  10323. const dirName = match[1] ||
  10324. (startsWith(name, ':') ? 'bind' : startsWith(name, '@') ? 'on' : 'slot');
  10325. let arg;
  10326. if (match[2]) {
  10327. const isSlot = dirName === 'slot';
  10328. const startOffset = name.indexOf(match[2]);
  10329. const loc = getSelection(context, getNewPosition(context, start, startOffset), getNewPosition(context, start, startOffset + match[2].length + ((isSlot && match[3]) || '').length));
  10330. let content = match[2];
  10331. let isStatic = true;
  10332. if (content.startsWith('[')) {
  10333. isStatic = false;
  10334. if (!content.endsWith(']')) {
  10335. emitError(context, 26 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
  10336. }
  10337. content = content.substr(1, content.length - 2);
  10338. }
  10339. else if (isSlot) {
  10340. // #1241 special case for v-slot: vuetify relies extensively on slot
  10341. // names containing dots. v-slot doesn't have any modifiers and Vue 2.x
  10342. // supports such usage so we are keeping it consistent with 2.x.
  10343. content += match[3] || '';
  10344. }
  10345. arg = {
  10346. type: 4 /* SIMPLE_EXPRESSION */,
  10347. content,
  10348. isStatic,
  10349. constType: isStatic
  10350. ? 3 /* CAN_STRINGIFY */
  10351. : 0 /* NOT_CONSTANT */,
  10352. loc
  10353. };
  10354. }
  10355. if (value && value.isQuoted) {
  10356. const valueLoc = value.loc;
  10357. valueLoc.start.offset++;
  10358. valueLoc.start.column++;
  10359. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  10360. valueLoc.source = valueLoc.source.slice(1, -1);
  10361. }
  10362. return {
  10363. type: 7 /* DIRECTIVE */,
  10364. name: dirName,
  10365. exp: value && {
  10366. type: 4 /* SIMPLE_EXPRESSION */,
  10367. content: value.content,
  10368. isStatic: false,
  10369. // Treat as non-constant by default. This can be potentially set to
  10370. // other values by `transformExpression` to make it eligible for hoisting.
  10371. constType: 0 /* NOT_CONSTANT */,
  10372. loc: value.loc
  10373. },
  10374. arg,
  10375. modifiers: match[3] ? match[3].substr(1).split('.') : [],
  10376. loc
  10377. };
  10378. }
  10379. return {
  10380. type: 6 /* ATTRIBUTE */,
  10381. name,
  10382. value: value && {
  10383. type: 2 /* TEXT */,
  10384. content: value.content,
  10385. loc: value.loc
  10386. },
  10387. loc
  10388. };
  10389. }
  10390. function parseAttributeValue(context) {
  10391. const start = getCursor(context);
  10392. let content;
  10393. const quote = context.source[0];
  10394. const isQuoted = quote === `"` || quote === `'`;
  10395. if (isQuoted) {
  10396. // Quoted value.
  10397. advanceBy(context, 1);
  10398. const endIndex = context.source.indexOf(quote);
  10399. if (endIndex === -1) {
  10400. content = parseTextData(context, context.source.length, 4 /* ATTRIBUTE_VALUE */);
  10401. }
  10402. else {
  10403. content = parseTextData(context, endIndex, 4 /* ATTRIBUTE_VALUE */);
  10404. advanceBy(context, 1);
  10405. }
  10406. }
  10407. else {
  10408. // Unquoted
  10409. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  10410. if (!match) {
  10411. return undefined;
  10412. }
  10413. const unexpectedChars = /["'<=`]/g;
  10414. let m;
  10415. while ((m = unexpectedChars.exec(match[0]))) {
  10416. emitError(context, 18 /* UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */, m.index);
  10417. }
  10418. content = parseTextData(context, match[0].length, 4 /* ATTRIBUTE_VALUE */);
  10419. }
  10420. return { content, isQuoted, loc: getSelection(context, start) };
  10421. }
  10422. function parseInterpolation(context, mode) {
  10423. const [open, close] = context.options.delimiters;
  10424. const closeIndex = context.source.indexOf(close, open.length);
  10425. if (closeIndex === -1) {
  10426. emitError(context, 25 /* X_MISSING_INTERPOLATION_END */);
  10427. return undefined;
  10428. }
  10429. const start = getCursor(context);
  10430. advanceBy(context, open.length);
  10431. const innerStart = getCursor(context);
  10432. const innerEnd = getCursor(context);
  10433. const rawContentLength = closeIndex - open.length;
  10434. const rawContent = context.source.slice(0, rawContentLength);
  10435. const preTrimContent = parseTextData(context, rawContentLength, mode);
  10436. const content = preTrimContent.trim();
  10437. const startOffset = preTrimContent.indexOf(content);
  10438. if (startOffset > 0) {
  10439. advancePositionWithMutation(innerStart, rawContent, startOffset);
  10440. }
  10441. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  10442. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  10443. advanceBy(context, close.length);
  10444. return {
  10445. type: 5 /* INTERPOLATION */,
  10446. content: {
  10447. type: 4 /* SIMPLE_EXPRESSION */,
  10448. isStatic: false,
  10449. // Set `isConstant` to false by default and will decide in transformExpression
  10450. constType: 0 /* NOT_CONSTANT */,
  10451. content,
  10452. loc: getSelection(context, innerStart, innerEnd)
  10453. },
  10454. loc: getSelection(context, start)
  10455. };
  10456. }
  10457. function parseText(context, mode) {
  10458. const endTokens = ['<', context.options.delimiters[0]];
  10459. if (mode === 3 /* CDATA */) {
  10460. endTokens.push(']]>');
  10461. }
  10462. let endIndex = context.source.length;
  10463. for (let i = 0; i < endTokens.length; i++) {
  10464. const index = context.source.indexOf(endTokens[i], 1);
  10465. if (index !== -1 && endIndex > index) {
  10466. endIndex = index;
  10467. }
  10468. }
  10469. const start = getCursor(context);
  10470. const content = parseTextData(context, endIndex, mode);
  10471. return {
  10472. type: 2 /* TEXT */,
  10473. content,
  10474. loc: getSelection(context, start)
  10475. };
  10476. }
  10477. /**
  10478. * Get text data with a given length from the current location.
  10479. * This translates HTML entities in the text data.
  10480. */
  10481. function parseTextData(context, length, mode) {
  10482. const rawText = context.source.slice(0, length);
  10483. advanceBy(context, length);
  10484. if (mode === 2 /* RAWTEXT */ ||
  10485. mode === 3 /* CDATA */ ||
  10486. rawText.indexOf('&') === -1) {
  10487. return rawText;
  10488. }
  10489. else {
  10490. // DATA or RCDATA containing "&"". Entity decoding required.
  10491. return context.options.decodeEntities(rawText, mode === 4 /* ATTRIBUTE_VALUE */);
  10492. }
  10493. }
  10494. function getCursor(context) {
  10495. const { column, line, offset } = context;
  10496. return { column, line, offset };
  10497. }
  10498. function getSelection(context, start, end) {
  10499. end = end || getCursor(context);
  10500. return {
  10501. start,
  10502. end,
  10503. source: context.originalSource.slice(start.offset, end.offset)
  10504. };
  10505. }
  10506. function last(xs) {
  10507. return xs[xs.length - 1];
  10508. }
  10509. function startsWith(source, searchString) {
  10510. return source.startsWith(searchString);
  10511. }
  10512. function advanceBy(context, numberOfCharacters) {
  10513. const { source } = context;
  10514. advancePositionWithMutation(context, source, numberOfCharacters);
  10515. context.source = source.slice(numberOfCharacters);
  10516. }
  10517. function advanceSpaces(context) {
  10518. const match = /^[\t\r\n\f ]+/.exec(context.source);
  10519. if (match) {
  10520. advanceBy(context, match[0].length);
  10521. }
  10522. }
  10523. function getNewPosition(context, start, numberOfCharacters) {
  10524. return advancePositionWithClone(start, context.originalSource.slice(start.offset, numberOfCharacters), numberOfCharacters);
  10525. }
  10526. function emitError(context, code, offset, loc = getCursor(context)) {
  10527. if (offset) {
  10528. loc.offset += offset;
  10529. loc.column += offset;
  10530. }
  10531. context.options.onError(createCompilerError(code, {
  10532. start: loc,
  10533. end: loc,
  10534. source: ''
  10535. }));
  10536. }
  10537. function isEnd(context, mode, ancestors) {
  10538. const s = context.source;
  10539. switch (mode) {
  10540. case 0 /* DATA */:
  10541. if (startsWith(s, '</')) {
  10542. // TODO: probably bad performance
  10543. for (let i = ancestors.length - 1; i >= 0; --i) {
  10544. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  10545. return true;
  10546. }
  10547. }
  10548. }
  10549. break;
  10550. case 1 /* RCDATA */:
  10551. case 2 /* RAWTEXT */: {
  10552. const parent = last(ancestors);
  10553. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  10554. return true;
  10555. }
  10556. break;
  10557. }
  10558. case 3 /* CDATA */:
  10559. if (startsWith(s, ']]>')) {
  10560. return true;
  10561. }
  10562. break;
  10563. }
  10564. return !s;
  10565. }
  10566. function startsWithEndTagOpen(source, tag) {
  10567. return (startsWith(source, '</') &&
  10568. source.substr(2, tag.length).toLowerCase() === tag.toLowerCase() &&
  10569. /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
  10570. }
  10571. function hoistStatic(root, context) {
  10572. walk(root, context,
  10573. // Root node is unfortunately non-hoistable due to potential parent
  10574. // fallthrough attributes.
  10575. isSingleElementRoot(root, root.children[0]));
  10576. }
  10577. function isSingleElementRoot(root, child) {
  10578. const { children } = root;
  10579. return (children.length === 1 &&
  10580. child.type === 1 /* ELEMENT */ &&
  10581. !isSlotOutlet(child));
  10582. }
  10583. function walk(node, context, doNotHoistNode = false) {
  10584. let hasHoistedNode = false;
  10585. // Some transforms, e.g. transformAssetUrls from @vue/compiler-sfc, replaces
  10586. // static bindings with expressions. These expressions are guaranteed to be
  10587. // constant so they are still eligible for hoisting, but they are only
  10588. // available at runtime and therefore cannot be evaluated ahead of time.
  10589. // This is only a concern for pre-stringification (via transformHoist by
  10590. // @vue/compiler-dom), but doing it here allows us to perform only one full
  10591. // walk of the AST and allow `stringifyStatic` to stop walking as soon as its
  10592. // stringficiation threshold is met.
  10593. let canStringify = true;
  10594. const { children } = node;
  10595. for (let i = 0; i < children.length; i++) {
  10596. const child = children[i];
  10597. // only plain elements & text calls are eligible for hoisting.
  10598. if (child.type === 1 /* ELEMENT */ &&
  10599. child.tagType === 0 /* ELEMENT */) {
  10600. const constantType = doNotHoistNode
  10601. ? 0 /* NOT_CONSTANT */
  10602. : getConstantType(child, context);
  10603. if (constantType > 0 /* NOT_CONSTANT */) {
  10604. if (constantType < 3 /* CAN_STRINGIFY */) {
  10605. canStringify = false;
  10606. }
  10607. if (constantType >= 2 /* CAN_HOIST */) {
  10608. child.codegenNode.patchFlag =
  10609. -1 /* HOISTED */ + (` /* HOISTED */` );
  10610. child.codegenNode = context.hoist(child.codegenNode);
  10611. hasHoistedNode = true;
  10612. continue;
  10613. }
  10614. }
  10615. else {
  10616. // node may contain dynamic children, but its props may be eligible for
  10617. // hoisting.
  10618. const codegenNode = child.codegenNode;
  10619. if (codegenNode.type === 13 /* VNODE_CALL */) {
  10620. const flag = getPatchFlag(codegenNode);
  10621. if ((!flag ||
  10622. flag === 512 /* NEED_PATCH */ ||
  10623. flag === 1 /* TEXT */) &&
  10624. getGeneratedPropsConstantType(child, context) >=
  10625. 2 /* CAN_HOIST */) {
  10626. const props = getNodeProps(child);
  10627. if (props) {
  10628. codegenNode.props = context.hoist(props);
  10629. }
  10630. }
  10631. }
  10632. }
  10633. }
  10634. else if (child.type === 12 /* TEXT_CALL */) {
  10635. const contentType = getConstantType(child.content, context);
  10636. if (contentType > 0) {
  10637. if (contentType < 3 /* CAN_STRINGIFY */) {
  10638. canStringify = false;
  10639. }
  10640. if (contentType >= 2 /* CAN_HOIST */) {
  10641. child.codegenNode = context.hoist(child.codegenNode);
  10642. hasHoistedNode = true;
  10643. }
  10644. }
  10645. }
  10646. // walk further
  10647. if (child.type === 1 /* ELEMENT */) {
  10648. walk(child, context);
  10649. }
  10650. else if (child.type === 11 /* FOR */) {
  10651. // Do not hoist v-for single child because it has to be a block
  10652. walk(child, context, child.children.length === 1);
  10653. }
  10654. else if (child.type === 9 /* IF */) {
  10655. for (let i = 0; i < child.branches.length; i++) {
  10656. // Do not hoist v-if single child because it has to be a block
  10657. walk(child.branches[i], context, child.branches[i].children.length === 1);
  10658. }
  10659. }
  10660. }
  10661. if (canStringify && hasHoistedNode && context.transformHoist) {
  10662. context.transformHoist(children, context, node);
  10663. }
  10664. }
  10665. function getConstantType(node, context) {
  10666. const { constantCache } = context;
  10667. switch (node.type) {
  10668. case 1 /* ELEMENT */:
  10669. if (node.tagType !== 0 /* ELEMENT */) {
  10670. return 0 /* NOT_CONSTANT */;
  10671. }
  10672. const cached = constantCache.get(node);
  10673. if (cached !== undefined) {
  10674. return cached;
  10675. }
  10676. const codegenNode = node.codegenNode;
  10677. if (codegenNode.type !== 13 /* VNODE_CALL */) {
  10678. return 0 /* NOT_CONSTANT */;
  10679. }
  10680. const flag = getPatchFlag(codegenNode);
  10681. if (!flag) {
  10682. let returnType = 3 /* CAN_STRINGIFY */;
  10683. // Element itself has no patch flag. However we still need to check:
  10684. // 1. Even for a node with no patch flag, it is possible for it to contain
  10685. // non-hoistable expressions that refers to scope variables, e.g. compiler
  10686. // injected keys or cached event handlers. Therefore we need to always
  10687. // check the codegenNode's props to be sure.
  10688. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  10689. if (generatedPropsType === 0 /* NOT_CONSTANT */) {
  10690. constantCache.set(node, 0 /* NOT_CONSTANT */);
  10691. return 0 /* NOT_CONSTANT */;
  10692. }
  10693. if (generatedPropsType < returnType) {
  10694. returnType = generatedPropsType;
  10695. }
  10696. // 2. its children.
  10697. for (let i = 0; i < node.children.length; i++) {
  10698. const childType = getConstantType(node.children[i], context);
  10699. if (childType === 0 /* NOT_CONSTANT */) {
  10700. constantCache.set(node, 0 /* NOT_CONSTANT */);
  10701. return 0 /* NOT_CONSTANT */;
  10702. }
  10703. if (childType < returnType) {
  10704. returnType = childType;
  10705. }
  10706. }
  10707. // 3. if the type is not already CAN_SKIP_PATCH which is the lowest non-0
  10708. // type, check if any of the props can cause the type to be lowered
  10709. // we can skip can_patch because it's guaranteed by the absence of a
  10710. // patchFlag.
  10711. if (returnType > 1 /* CAN_SKIP_PATCH */) {
  10712. for (let i = 0; i < node.props.length; i++) {
  10713. const p = node.props[i];
  10714. if (p.type === 7 /* DIRECTIVE */ && p.name === 'bind' && p.exp) {
  10715. const expType = getConstantType(p.exp, context);
  10716. if (expType === 0 /* NOT_CONSTANT */) {
  10717. constantCache.set(node, 0 /* NOT_CONSTANT */);
  10718. return 0 /* NOT_CONSTANT */;
  10719. }
  10720. if (expType < returnType) {
  10721. returnType = expType;
  10722. }
  10723. }
  10724. }
  10725. }
  10726. // only svg/foreignObject could be block here, however if they are
  10727. // static then they don't need to be blocks since there will be no
  10728. // nested updates.
  10729. if (codegenNode.isBlock) {
  10730. codegenNode.isBlock = false;
  10731. context.helper(CREATE_VNODE);
  10732. }
  10733. constantCache.set(node, returnType);
  10734. return returnType;
  10735. }
  10736. else {
  10737. constantCache.set(node, 0 /* NOT_CONSTANT */);
  10738. return 0 /* NOT_CONSTANT */;
  10739. }
  10740. case 2 /* TEXT */:
  10741. case 3 /* COMMENT */:
  10742. return 3 /* CAN_STRINGIFY */;
  10743. case 9 /* IF */:
  10744. case 11 /* FOR */:
  10745. case 10 /* IF_BRANCH */:
  10746. return 0 /* NOT_CONSTANT */;
  10747. case 5 /* INTERPOLATION */:
  10748. case 12 /* TEXT_CALL */:
  10749. return getConstantType(node.content, context);
  10750. case 4 /* SIMPLE_EXPRESSION */:
  10751. return node.constType;
  10752. case 8 /* COMPOUND_EXPRESSION */:
  10753. let returnType = 3 /* CAN_STRINGIFY */;
  10754. for (let i = 0; i < node.children.length; i++) {
  10755. const child = node.children[i];
  10756. if (isString(child) || isSymbol(child)) {
  10757. continue;
  10758. }
  10759. const childType = getConstantType(child, context);
  10760. if (childType === 0 /* NOT_CONSTANT */) {
  10761. return 0 /* NOT_CONSTANT */;
  10762. }
  10763. else if (childType < returnType) {
  10764. returnType = childType;
  10765. }
  10766. }
  10767. return returnType;
  10768. default:
  10769. return 0 /* NOT_CONSTANT */;
  10770. }
  10771. }
  10772. function getGeneratedPropsConstantType(node, context) {
  10773. let returnType = 3 /* CAN_STRINGIFY */;
  10774. const props = getNodeProps(node);
  10775. if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {
  10776. const { properties } = props;
  10777. for (let i = 0; i < properties.length; i++) {
  10778. const { key, value } = properties[i];
  10779. const keyType = getConstantType(key, context);
  10780. if (keyType === 0 /* NOT_CONSTANT */) {
  10781. return keyType;
  10782. }
  10783. if (keyType < returnType) {
  10784. returnType = keyType;
  10785. }
  10786. if (value.type !== 4 /* SIMPLE_EXPRESSION */) {
  10787. return 0 /* NOT_CONSTANT */;
  10788. }
  10789. const valueType = getConstantType(value, context);
  10790. if (valueType === 0 /* NOT_CONSTANT */) {
  10791. return valueType;
  10792. }
  10793. if (valueType < returnType) {
  10794. returnType = valueType;
  10795. }
  10796. }
  10797. }
  10798. return returnType;
  10799. }
  10800. function getNodeProps(node) {
  10801. const codegenNode = node.codegenNode;
  10802. if (codegenNode.type === 13 /* VNODE_CALL */) {
  10803. return codegenNode.props;
  10804. }
  10805. }
  10806. function getPatchFlag(node) {
  10807. const flag = node.patchFlag;
  10808. return flag ? parseInt(flag, 10) : undefined;
  10809. }
  10810. 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 }) {
  10811. const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
  10812. const context = {
  10813. // options
  10814. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  10815. prefixIdentifiers,
  10816. hoistStatic,
  10817. cacheHandlers,
  10818. nodeTransforms,
  10819. directiveTransforms,
  10820. transformHoist,
  10821. isBuiltInComponent,
  10822. isCustomElement,
  10823. expressionPlugins,
  10824. scopeId,
  10825. ssr,
  10826. ssrCssVars,
  10827. bindingMetadata,
  10828. inline,
  10829. isTS,
  10830. onError,
  10831. // state
  10832. root,
  10833. helpers: new Set(),
  10834. components: new Set(),
  10835. directives: new Set(),
  10836. hoists: [],
  10837. imports: [],
  10838. constantCache: new Map(),
  10839. temps: 0,
  10840. cached: 0,
  10841. identifiers: Object.create(null),
  10842. scopes: {
  10843. vFor: 0,
  10844. vSlot: 0,
  10845. vPre: 0,
  10846. vOnce: 0
  10847. },
  10848. parent: null,
  10849. currentNode: root,
  10850. childIndex: 0,
  10851. // methods
  10852. helper(name) {
  10853. context.helpers.add(name);
  10854. return name;
  10855. },
  10856. helperString(name) {
  10857. return `_${helperNameMap[context.helper(name)]}`;
  10858. },
  10859. replaceNode(node) {
  10860. /* istanbul ignore if */
  10861. {
  10862. if (!context.currentNode) {
  10863. throw new Error(`Node being replaced is already removed.`);
  10864. }
  10865. if (!context.parent) {
  10866. throw new Error(`Cannot replace root node.`);
  10867. }
  10868. }
  10869. context.parent.children[context.childIndex] = context.currentNode = node;
  10870. },
  10871. removeNode(node) {
  10872. if (!context.parent) {
  10873. throw new Error(`Cannot remove root node.`);
  10874. }
  10875. const list = context.parent.children;
  10876. const removalIndex = node
  10877. ? list.indexOf(node)
  10878. : context.currentNode
  10879. ? context.childIndex
  10880. : -1;
  10881. /* istanbul ignore if */
  10882. if (removalIndex < 0) {
  10883. throw new Error(`node being removed is not a child of current parent`);
  10884. }
  10885. if (!node || node === context.currentNode) {
  10886. // current node removed
  10887. context.currentNode = null;
  10888. context.onNodeRemoved();
  10889. }
  10890. else {
  10891. // sibling node removed
  10892. if (context.childIndex > removalIndex) {
  10893. context.childIndex--;
  10894. context.onNodeRemoved();
  10895. }
  10896. }
  10897. context.parent.children.splice(removalIndex, 1);
  10898. },
  10899. onNodeRemoved: () => { },
  10900. addIdentifiers(exp) {
  10901. },
  10902. removeIdentifiers(exp) {
  10903. },
  10904. hoist(exp) {
  10905. context.hoists.push(exp);
  10906. const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2 /* CAN_HOIST */);
  10907. identifier.hoisted = exp;
  10908. return identifier;
  10909. },
  10910. cache(exp, isVNode = false) {
  10911. return createCacheExpression(++context.cached, exp, isVNode);
  10912. }
  10913. };
  10914. return context;
  10915. }
  10916. function transform(root, options) {
  10917. const context = createTransformContext(root, options);
  10918. traverseNode(root, context);
  10919. if (options.hoistStatic) {
  10920. hoistStatic(root, context);
  10921. }
  10922. if (!options.ssr) {
  10923. createRootCodegen(root, context);
  10924. }
  10925. // finalize meta information
  10926. root.helpers = [...context.helpers];
  10927. root.components = [...context.components];
  10928. root.directives = [...context.directives];
  10929. root.imports = context.imports;
  10930. root.hoists = context.hoists;
  10931. root.temps = context.temps;
  10932. root.cached = context.cached;
  10933. }
  10934. function createRootCodegen(root, context) {
  10935. const { helper } = context;
  10936. const { children } = root;
  10937. if (children.length === 1) {
  10938. const child = children[0];
  10939. // if the single child is an element, turn it into a block.
  10940. if (isSingleElementRoot(root, child) && child.codegenNode) {
  10941. // single element root is never hoisted so codegenNode will never be
  10942. // SimpleExpressionNode
  10943. const codegenNode = child.codegenNode;
  10944. if (codegenNode.type === 13 /* VNODE_CALL */) {
  10945. codegenNode.isBlock = true;
  10946. helper(OPEN_BLOCK);
  10947. helper(CREATE_BLOCK);
  10948. }
  10949. root.codegenNode = codegenNode;
  10950. }
  10951. else {
  10952. // - single <slot/>, IfNode, ForNode: already blocks.
  10953. // - single text node: always patched.
  10954. // root codegen falls through via genNode()
  10955. root.codegenNode = child;
  10956. }
  10957. }
  10958. else if (children.length > 1) {
  10959. // root has multiple nodes - return a fragment block.
  10960. let patchFlag = 64 /* STABLE_FRAGMENT */;
  10961. let patchFlagText = PatchFlagNames[64 /* STABLE_FRAGMENT */];
  10962. // check if the fragment actually contains a single valid child with
  10963. // the rest being comments
  10964. if (children.filter(c => c.type !== 3 /* COMMENT */).length === 1) {
  10965. patchFlag |= 2048 /* DEV_ROOT_FRAGMENT */;
  10966. patchFlagText += `, ${PatchFlagNames[2048 /* DEV_ROOT_FRAGMENT */]}`;
  10967. }
  10968. root.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, root.children, patchFlag + (` /* ${patchFlagText} */` ), undefined, undefined, true);
  10969. }
  10970. else ;
  10971. }
  10972. function traverseChildren(parent, context) {
  10973. let i = 0;
  10974. const nodeRemoved = () => {
  10975. i--;
  10976. };
  10977. for (; i < parent.children.length; i++) {
  10978. const child = parent.children[i];
  10979. if (isString(child))
  10980. continue;
  10981. context.parent = parent;
  10982. context.childIndex = i;
  10983. context.onNodeRemoved = nodeRemoved;
  10984. traverseNode(child, context);
  10985. }
  10986. }
  10987. function traverseNode(node, context) {
  10988. context.currentNode = node;
  10989. // apply transform plugins
  10990. const { nodeTransforms } = context;
  10991. const exitFns = [];
  10992. for (let i = 0; i < nodeTransforms.length; i++) {
  10993. const onExit = nodeTransforms[i](node, context);
  10994. if (onExit) {
  10995. if (isArray(onExit)) {
  10996. exitFns.push(...onExit);
  10997. }
  10998. else {
  10999. exitFns.push(onExit);
  11000. }
  11001. }
  11002. if (!context.currentNode) {
  11003. // node was removed
  11004. return;
  11005. }
  11006. else {
  11007. // node may have been replaced
  11008. node = context.currentNode;
  11009. }
  11010. }
  11011. switch (node.type) {
  11012. case 3 /* COMMENT */:
  11013. if (!context.ssr) {
  11014. // inject import for the Comment symbol, which is needed for creating
  11015. // comment nodes with `createVNode`
  11016. context.helper(CREATE_COMMENT);
  11017. }
  11018. break;
  11019. case 5 /* INTERPOLATION */:
  11020. // no need to traverse, but we need to inject toString helper
  11021. if (!context.ssr) {
  11022. context.helper(TO_DISPLAY_STRING);
  11023. }
  11024. break;
  11025. // for container types, further traverse downwards
  11026. case 9 /* IF */:
  11027. for (let i = 0; i < node.branches.length; i++) {
  11028. traverseNode(node.branches[i], context);
  11029. }
  11030. break;
  11031. case 10 /* IF_BRANCH */:
  11032. case 11 /* FOR */:
  11033. case 1 /* ELEMENT */:
  11034. case 0 /* ROOT */:
  11035. traverseChildren(node, context);
  11036. break;
  11037. }
  11038. // exit transforms
  11039. context.currentNode = node;
  11040. let i = exitFns.length;
  11041. while (i--) {
  11042. exitFns[i]();
  11043. }
  11044. }
  11045. function createStructuralDirectiveTransform(name, fn) {
  11046. const matches = isString(name)
  11047. ? (n) => n === name
  11048. : (n) => name.test(n);
  11049. return (node, context) => {
  11050. if (node.type === 1 /* ELEMENT */) {
  11051. const { props } = node;
  11052. // structural directive transforms are not concerned with slots
  11053. // as they are handled separately in vSlot.ts
  11054. if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {
  11055. return;
  11056. }
  11057. const exitFns = [];
  11058. for (let i = 0; i < props.length; i++) {
  11059. const prop = props[i];
  11060. if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {
  11061. // structural directives are removed to avoid infinite recursion
  11062. // also we remove them *before* applying so that it can further
  11063. // traverse itself in case it moves the node around
  11064. props.splice(i, 1);
  11065. i--;
  11066. const onExit = fn(node, prop, context);
  11067. if (onExit)
  11068. exitFns.push(onExit);
  11069. }
  11070. }
  11071. return exitFns;
  11072. }
  11073. };
  11074. }
  11075. const PURE_ANNOTATION = `/*#__PURE__*/`;
  11076. function createCodegenContext(ast, { mode = 'function', prefixIdentifiers = mode === 'module', sourceMap = false, filename = `template.vue.html`, scopeId = null, optimizeImports = false, runtimeGlobalName = `Vue`, runtimeModuleName = `vue`, ssr = false }) {
  11077. const context = {
  11078. mode,
  11079. prefixIdentifiers,
  11080. sourceMap,
  11081. filename,
  11082. scopeId,
  11083. optimizeImports,
  11084. runtimeGlobalName,
  11085. runtimeModuleName,
  11086. ssr,
  11087. source: ast.loc.source,
  11088. code: ``,
  11089. column: 1,
  11090. line: 1,
  11091. offset: 0,
  11092. indentLevel: 0,
  11093. pure: false,
  11094. map: undefined,
  11095. helper(key) {
  11096. return `_${helperNameMap[key]}`;
  11097. },
  11098. push(code, node) {
  11099. context.code += code;
  11100. },
  11101. indent() {
  11102. newline(++context.indentLevel);
  11103. },
  11104. deindent(withoutNewLine = false) {
  11105. if (withoutNewLine) {
  11106. --context.indentLevel;
  11107. }
  11108. else {
  11109. newline(--context.indentLevel);
  11110. }
  11111. },
  11112. newline() {
  11113. newline(context.indentLevel);
  11114. }
  11115. };
  11116. function newline(n) {
  11117. context.push('\n' + ` `.repeat(n));
  11118. }
  11119. return context;
  11120. }
  11121. function generate(ast, options = {}) {
  11122. const context = createCodegenContext(ast, options);
  11123. if (options.onContextCreated)
  11124. options.onContextCreated(context);
  11125. const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
  11126. const hasHelpers = ast.helpers.length > 0;
  11127. const useWithBlock = !prefixIdentifiers && mode !== 'module';
  11128. // preambles
  11129. // in setup() inline mode, the preamble is generated in a sub context
  11130. // and returned separately.
  11131. const preambleContext = context;
  11132. {
  11133. genFunctionPreamble(ast, preambleContext);
  11134. }
  11135. // enter render function
  11136. const functionName = ssr ? `ssrRender` : `render`;
  11137. const args = ssr ? ['_ctx', '_push', '_parent', '_attrs'] : ['_ctx', '_cache'];
  11138. const signature = args.join(', ');
  11139. {
  11140. push(`function ${functionName}(${signature}) {`);
  11141. }
  11142. indent();
  11143. if (useWithBlock) {
  11144. push(`with (_ctx) {`);
  11145. indent();
  11146. // function mode const declarations should be inside with block
  11147. // also they should be renamed to avoid collision with user properties
  11148. if (hasHelpers) {
  11149. push(`const { ${ast.helpers
  11150. .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
  11151. .join(', ')} } = _Vue`);
  11152. push(`\n`);
  11153. newline();
  11154. }
  11155. }
  11156. // generate asset resolution statements
  11157. if (ast.components.length) {
  11158. genAssets(ast.components, 'component', context);
  11159. if (ast.directives.length || ast.temps > 0) {
  11160. newline();
  11161. }
  11162. }
  11163. if (ast.directives.length) {
  11164. genAssets(ast.directives, 'directive', context);
  11165. if (ast.temps > 0) {
  11166. newline();
  11167. }
  11168. }
  11169. if (ast.temps > 0) {
  11170. push(`let `);
  11171. for (let i = 0; i < ast.temps; i++) {
  11172. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  11173. }
  11174. }
  11175. if (ast.components.length || ast.directives.length || ast.temps) {
  11176. push(`\n`);
  11177. newline();
  11178. }
  11179. // generate the VNode tree expression
  11180. if (!ssr) {
  11181. push(`return `);
  11182. }
  11183. if (ast.codegenNode) {
  11184. genNode(ast.codegenNode, context);
  11185. }
  11186. else {
  11187. push(`null`);
  11188. }
  11189. if (useWithBlock) {
  11190. deindent();
  11191. push(`}`);
  11192. }
  11193. deindent();
  11194. push(`}`);
  11195. return {
  11196. ast,
  11197. code: context.code,
  11198. preamble: ``,
  11199. // SourceMapGenerator does have toJSON() method but it's not in the types
  11200. map: context.map ? context.map.toJSON() : undefined
  11201. };
  11202. }
  11203. function genFunctionPreamble(ast, context) {
  11204. const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName } = context;
  11205. const VueBinding = runtimeGlobalName;
  11206. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  11207. // Generate const declaration for helpers
  11208. // In prefix mode, we place the const declaration at top so it's done
  11209. // only once; But if we not prefixing, we place the declaration inside the
  11210. // with block so it doesn't incur the `in` check cost for every helper access.
  11211. if (ast.helpers.length > 0) {
  11212. {
  11213. // "with" mode.
  11214. // save Vue in a separate variable to avoid collision
  11215. push(`const _Vue = ${VueBinding}\n`);
  11216. // in "with" mode, helpers are declared inside the with block to avoid
  11217. // has check cost, but hoists are lifted out of the function - we need
  11218. // to provide the helper here.
  11219. if (ast.hoists.length) {
  11220. const staticHelpers = [
  11221. CREATE_VNODE,
  11222. CREATE_COMMENT,
  11223. CREATE_TEXT,
  11224. CREATE_STATIC
  11225. ]
  11226. .filter(helper => ast.helpers.includes(helper))
  11227. .map(aliasHelper)
  11228. .join(', ');
  11229. push(`const { ${staticHelpers} } = _Vue\n`);
  11230. }
  11231. }
  11232. }
  11233. genHoists(ast.hoists, context);
  11234. newline();
  11235. push(`return `);
  11236. }
  11237. function genAssets(assets, type, { helper, push, newline }) {
  11238. const resolver = helper(type === 'component' ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE);
  11239. for (let i = 0; i < assets.length; i++) {
  11240. const id = assets[i];
  11241. push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)})`);
  11242. if (i < assets.length - 1) {
  11243. newline();
  11244. }
  11245. }
  11246. }
  11247. function genHoists(hoists, context) {
  11248. if (!hoists.length) {
  11249. return;
  11250. }
  11251. context.pure = true;
  11252. const { push, newline, helper, scopeId, mode } = context;
  11253. newline();
  11254. hoists.forEach((exp, i) => {
  11255. if (exp) {
  11256. push(`const _hoisted_${i + 1} = `);
  11257. genNode(exp, context);
  11258. newline();
  11259. }
  11260. });
  11261. context.pure = false;
  11262. }
  11263. function isText$1(n) {
  11264. return (isString(n) ||
  11265. n.type === 4 /* SIMPLE_EXPRESSION */ ||
  11266. n.type === 2 /* TEXT */ ||
  11267. n.type === 5 /* INTERPOLATION */ ||
  11268. n.type === 8 /* COMPOUND_EXPRESSION */);
  11269. }
  11270. function genNodeListAsArray(nodes, context) {
  11271. const multilines = nodes.length > 3 ||
  11272. (nodes.some(n => isArray(n) || !isText$1(n)));
  11273. context.push(`[`);
  11274. multilines && context.indent();
  11275. genNodeList(nodes, context, multilines);
  11276. multilines && context.deindent();
  11277. context.push(`]`);
  11278. }
  11279. function genNodeList(nodes, context, multilines = false, comma = true) {
  11280. const { push, newline } = context;
  11281. for (let i = 0; i < nodes.length; i++) {
  11282. const node = nodes[i];
  11283. if (isString(node)) {
  11284. push(node);
  11285. }
  11286. else if (isArray(node)) {
  11287. genNodeListAsArray(node, context);
  11288. }
  11289. else {
  11290. genNode(node, context);
  11291. }
  11292. if (i < nodes.length - 1) {
  11293. if (multilines) {
  11294. comma && push(',');
  11295. newline();
  11296. }
  11297. else {
  11298. comma && push(', ');
  11299. }
  11300. }
  11301. }
  11302. }
  11303. function genNode(node, context) {
  11304. if (isString(node)) {
  11305. context.push(node);
  11306. return;
  11307. }
  11308. if (isSymbol(node)) {
  11309. context.push(context.helper(node));
  11310. return;
  11311. }
  11312. switch (node.type) {
  11313. case 1 /* ELEMENT */:
  11314. case 9 /* IF */:
  11315. case 11 /* FOR */:
  11316. assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +
  11317. `Apply appropriate transforms first.`);
  11318. genNode(node.codegenNode, context);
  11319. break;
  11320. case 2 /* TEXT */:
  11321. genText(node, context);
  11322. break;
  11323. case 4 /* SIMPLE_EXPRESSION */:
  11324. genExpression(node, context);
  11325. break;
  11326. case 5 /* INTERPOLATION */:
  11327. genInterpolation(node, context);
  11328. break;
  11329. case 12 /* TEXT_CALL */:
  11330. genNode(node.codegenNode, context);
  11331. break;
  11332. case 8 /* COMPOUND_EXPRESSION */:
  11333. genCompoundExpression(node, context);
  11334. break;
  11335. case 3 /* COMMENT */:
  11336. genComment(node, context);
  11337. break;
  11338. case 13 /* VNODE_CALL */:
  11339. genVNodeCall(node, context);
  11340. break;
  11341. case 14 /* JS_CALL_EXPRESSION */:
  11342. genCallExpression(node, context);
  11343. break;
  11344. case 15 /* JS_OBJECT_EXPRESSION */:
  11345. genObjectExpression(node, context);
  11346. break;
  11347. case 17 /* JS_ARRAY_EXPRESSION */:
  11348. genArrayExpression(node, context);
  11349. break;
  11350. case 18 /* JS_FUNCTION_EXPRESSION */:
  11351. genFunctionExpression(node, context);
  11352. break;
  11353. case 19 /* JS_CONDITIONAL_EXPRESSION */:
  11354. genConditionalExpression(node, context);
  11355. break;
  11356. case 20 /* JS_CACHE_EXPRESSION */:
  11357. genCacheExpression(node, context);
  11358. break;
  11359. // SSR only types
  11360. case 21 /* JS_BLOCK_STATEMENT */:
  11361. break;
  11362. case 22 /* JS_TEMPLATE_LITERAL */:
  11363. break;
  11364. case 23 /* JS_IF_STATEMENT */:
  11365. break;
  11366. case 24 /* JS_ASSIGNMENT_EXPRESSION */:
  11367. break;
  11368. case 25 /* JS_SEQUENCE_EXPRESSION */:
  11369. break;
  11370. case 26 /* JS_RETURN_STATEMENT */:
  11371. break;
  11372. /* istanbul ignore next */
  11373. case 10 /* IF_BRANCH */:
  11374. // noop
  11375. break;
  11376. default:
  11377. {
  11378. assert(false, `unhandled codegen node type: ${node.type}`);
  11379. // make sure we exhaust all possible types
  11380. const exhaustiveCheck = node;
  11381. return exhaustiveCheck;
  11382. }
  11383. }
  11384. }
  11385. function genText(node, context) {
  11386. context.push(JSON.stringify(node.content), node);
  11387. }
  11388. function genExpression(node, context) {
  11389. const { content, isStatic } = node;
  11390. context.push(isStatic ? JSON.stringify(content) : content, node);
  11391. }
  11392. function genInterpolation(node, context) {
  11393. const { push, helper, pure } = context;
  11394. if (pure)
  11395. push(PURE_ANNOTATION);
  11396. push(`${helper(TO_DISPLAY_STRING)}(`);
  11397. genNode(node.content, context);
  11398. push(`)`);
  11399. }
  11400. function genCompoundExpression(node, context) {
  11401. for (let i = 0; i < node.children.length; i++) {
  11402. const child = node.children[i];
  11403. if (isString(child)) {
  11404. context.push(child);
  11405. }
  11406. else {
  11407. genNode(child, context);
  11408. }
  11409. }
  11410. }
  11411. function genExpressionAsPropertyKey(node, context) {
  11412. const { push } = context;
  11413. if (node.type === 8 /* COMPOUND_EXPRESSION */) {
  11414. push(`[`);
  11415. genCompoundExpression(node, context);
  11416. push(`]`);
  11417. }
  11418. else if (node.isStatic) {
  11419. // only quote keys if necessary
  11420. const text = isSimpleIdentifier(node.content)
  11421. ? node.content
  11422. : JSON.stringify(node.content);
  11423. push(text, node);
  11424. }
  11425. else {
  11426. push(`[${node.content}]`, node);
  11427. }
  11428. }
  11429. function genComment(node, context) {
  11430. {
  11431. const { push, helper, pure } = context;
  11432. if (pure) {
  11433. push(PURE_ANNOTATION);
  11434. }
  11435. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  11436. }
  11437. }
  11438. function genVNodeCall(node, context) {
  11439. const { push, helper, pure } = context;
  11440. const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking } = node;
  11441. if (directives) {
  11442. push(helper(WITH_DIRECTIVES) + `(`);
  11443. }
  11444. if (isBlock) {
  11445. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  11446. }
  11447. if (pure) {
  11448. push(PURE_ANNOTATION);
  11449. }
  11450. push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node);
  11451. genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
  11452. push(`)`);
  11453. if (isBlock) {
  11454. push(`)`);
  11455. }
  11456. if (directives) {
  11457. push(`, `);
  11458. genNode(directives, context);
  11459. push(`)`);
  11460. }
  11461. }
  11462. function genNullableArgs(args) {
  11463. let i = args.length;
  11464. while (i--) {
  11465. if (args[i] != null)
  11466. break;
  11467. }
  11468. return args.slice(0, i + 1).map(arg => arg || `null`);
  11469. }
  11470. // JavaScript
  11471. function genCallExpression(node, context) {
  11472. const { push, helper, pure } = context;
  11473. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  11474. if (pure) {
  11475. push(PURE_ANNOTATION);
  11476. }
  11477. push(callee + `(`, node);
  11478. genNodeList(node.arguments, context);
  11479. push(`)`);
  11480. }
  11481. function genObjectExpression(node, context) {
  11482. const { push, indent, deindent, newline } = context;
  11483. const { properties } = node;
  11484. if (!properties.length) {
  11485. push(`{}`, node);
  11486. return;
  11487. }
  11488. const multilines = properties.length > 1 ||
  11489. (properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));
  11490. push(multilines ? `{` : `{ `);
  11491. multilines && indent();
  11492. for (let i = 0; i < properties.length; i++) {
  11493. const { key, value } = properties[i];
  11494. // key
  11495. genExpressionAsPropertyKey(key, context);
  11496. push(`: `);
  11497. // value
  11498. genNode(value, context);
  11499. if (i < properties.length - 1) {
  11500. // will only reach this if it's multilines
  11501. push(`,`);
  11502. newline();
  11503. }
  11504. }
  11505. multilines && deindent();
  11506. push(multilines ? `}` : ` }`);
  11507. }
  11508. function genArrayExpression(node, context) {
  11509. genNodeListAsArray(node.elements, context);
  11510. }
  11511. function genFunctionExpression(node, context) {
  11512. const { push, indent, deindent, scopeId, mode } = context;
  11513. const { params, returns, body, newline, isSlot } = node;
  11514. if (isSlot) {
  11515. push(`_${helperNameMap[WITH_CTX]}(`);
  11516. }
  11517. push(`(`, node);
  11518. if (isArray(params)) {
  11519. genNodeList(params, context);
  11520. }
  11521. else if (params) {
  11522. genNode(params, context);
  11523. }
  11524. push(`) => `);
  11525. if (newline || body) {
  11526. push(`{`);
  11527. indent();
  11528. }
  11529. if (returns) {
  11530. if (newline) {
  11531. push(`return `);
  11532. }
  11533. if (isArray(returns)) {
  11534. genNodeListAsArray(returns, context);
  11535. }
  11536. else {
  11537. genNode(returns, context);
  11538. }
  11539. }
  11540. else if (body) {
  11541. genNode(body, context);
  11542. }
  11543. if (newline || body) {
  11544. deindent();
  11545. push(`}`);
  11546. }
  11547. if (isSlot) {
  11548. push(`)`);
  11549. }
  11550. }
  11551. function genConditionalExpression(node, context) {
  11552. const { test, consequent, alternate, newline: needNewline } = node;
  11553. const { push, indent, deindent, newline } = context;
  11554. if (test.type === 4 /* SIMPLE_EXPRESSION */) {
  11555. const needsParens = !isSimpleIdentifier(test.content);
  11556. needsParens && push(`(`);
  11557. genExpression(test, context);
  11558. needsParens && push(`)`);
  11559. }
  11560. else {
  11561. push(`(`);
  11562. genNode(test, context);
  11563. push(`)`);
  11564. }
  11565. needNewline && indent();
  11566. context.indentLevel++;
  11567. needNewline || push(` `);
  11568. push(`? `);
  11569. genNode(consequent, context);
  11570. context.indentLevel--;
  11571. needNewline && newline();
  11572. needNewline || push(` `);
  11573. push(`: `);
  11574. const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;
  11575. if (!isNested) {
  11576. context.indentLevel++;
  11577. }
  11578. genNode(alternate, context);
  11579. if (!isNested) {
  11580. context.indentLevel--;
  11581. }
  11582. needNewline && deindent(true /* without newline */);
  11583. }
  11584. function genCacheExpression(node, context) {
  11585. const { push, helper, indent, deindent, newline } = context;
  11586. push(`_cache[${node.index}] || (`);
  11587. if (node.isVNode) {
  11588. indent();
  11589. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  11590. newline();
  11591. }
  11592. push(`_cache[${node.index}] = `);
  11593. genNode(node.value, context);
  11594. if (node.isVNode) {
  11595. push(`,`);
  11596. newline();
  11597. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  11598. newline();
  11599. push(`_cache[${node.index}]`);
  11600. deindent();
  11601. }
  11602. push(`)`);
  11603. }
  11604. // these keywords should not appear inside expressions, but operators like
  11605. // typeof, instanceof and in are allowed
  11606. const prohibitedKeywordRE = new RegExp('\\b' +
  11607. ('do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
  11608. 'super,throw,while,yield,delete,export,import,return,switch,default,' +
  11609. 'extends,finally,continue,debugger,function,arguments,typeof,void')
  11610. .split(',')
  11611. .join('\\b|\\b') +
  11612. '\\b');
  11613. // strip strings in expressions
  11614. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  11615. /**
  11616. * Validate a non-prefixed expression.
  11617. * This is only called when using the in-browser runtime compiler since it
  11618. * doesn't prefix expressions.
  11619. */
  11620. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  11621. const exp = node.content;
  11622. // empty expressions are validated per-directive since some directives
  11623. // do allow empty expressions.
  11624. if (!exp.trim()) {
  11625. return;
  11626. }
  11627. try {
  11628. new Function(asRawStatements
  11629. ? ` ${exp} `
  11630. : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
  11631. }
  11632. catch (e) {
  11633. let message = e.message;
  11634. const keywordMatch = exp
  11635. .replace(stripStringRE, '')
  11636. .match(prohibitedKeywordRE);
  11637. if (keywordMatch) {
  11638. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  11639. }
  11640. context.onError(createCompilerError(43 /* X_INVALID_EXPRESSION */, node.loc, undefined, message));
  11641. }
  11642. }
  11643. const transformExpression = (node, context) => {
  11644. if (node.type === 5 /* INTERPOLATION */) {
  11645. node.content = processExpression(node.content, context);
  11646. }
  11647. else if (node.type === 1 /* ELEMENT */) {
  11648. // handle directives on element
  11649. for (let i = 0; i < node.props.length; i++) {
  11650. const dir = node.props[i];
  11651. // do not process for v-on & v-for since they are special handled
  11652. if (dir.type === 7 /* DIRECTIVE */ && dir.name !== 'for') {
  11653. const exp = dir.exp;
  11654. const arg = dir.arg;
  11655. // do not process exp if this is v-on:arg - we need special handling
  11656. // for wrapping inline statements.
  11657. if (exp &&
  11658. exp.type === 4 /* SIMPLE_EXPRESSION */ &&
  11659. !(dir.name === 'on' && arg)) {
  11660. dir.exp = processExpression(exp, context,
  11661. // slot args must be processed as function params
  11662. dir.name === 'slot');
  11663. }
  11664. if (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && !arg.isStatic) {
  11665. dir.arg = processExpression(arg, context);
  11666. }
  11667. }
  11668. }
  11669. }
  11670. };
  11671. // Important: since this function uses Node.js only dependencies, it should
  11672. // always be used with a leading !true check so that it can be
  11673. // tree-shaken from the browser build.
  11674. function processExpression(node, context,
  11675. // some expressions like v-slot props & v-for aliases should be parsed as
  11676. // function params
  11677. asParams = false,
  11678. // v-on handler values may contain multiple statements
  11679. asRawStatements = false) {
  11680. {
  11681. {
  11682. // simple in-browser validation (same logic in 2.x)
  11683. validateBrowserExpression(node, context, asParams, asRawStatements);
  11684. }
  11685. return node;
  11686. }
  11687. }
  11688. const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {
  11689. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  11690. // #1587: We need to dynamically increment the key based on the current
  11691. // node's sibling nodes, since chained v-if/else branches are
  11692. // rendered at the same depth
  11693. const siblings = context.parent.children;
  11694. let i = siblings.indexOf(ifNode);
  11695. let key = 0;
  11696. while (i-- >= 0) {
  11697. const sibling = siblings[i];
  11698. if (sibling && sibling.type === 9 /* IF */) {
  11699. key += sibling.branches.length;
  11700. }
  11701. }
  11702. // Exit callback. Complete the codegenNode when all children have been
  11703. // transformed.
  11704. return () => {
  11705. if (isRoot) {
  11706. ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
  11707. }
  11708. else {
  11709. // attach this branch's codegen node to the v-if root.
  11710. const parentCondition = getParentCondition(ifNode.codegenNode);
  11711. parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
  11712. }
  11713. };
  11714. });
  11715. });
  11716. // target-agnostic transform used for both Client and SSR
  11717. function processIf(node, dir, context, processCodegen) {
  11718. if (dir.name !== 'else' &&
  11719. (!dir.exp || !dir.exp.content.trim())) {
  11720. const loc = dir.exp ? dir.exp.loc : node.loc;
  11721. context.onError(createCompilerError(27 /* X_V_IF_NO_EXPRESSION */, dir.loc));
  11722. dir.exp = createSimpleExpression(`true`, false, loc);
  11723. }
  11724. if (dir.exp) {
  11725. validateBrowserExpression(dir.exp, context);
  11726. }
  11727. if (dir.name === 'if') {
  11728. const branch = createIfBranch(node, dir);
  11729. const ifNode = {
  11730. type: 9 /* IF */,
  11731. loc: node.loc,
  11732. branches: [branch]
  11733. };
  11734. context.replaceNode(ifNode);
  11735. if (processCodegen) {
  11736. return processCodegen(ifNode, branch, true);
  11737. }
  11738. }
  11739. else {
  11740. // locate the adjacent v-if
  11741. const siblings = context.parent.children;
  11742. const comments = [];
  11743. let i = siblings.indexOf(node);
  11744. while (i-- >= -1) {
  11745. const sibling = siblings[i];
  11746. if (sibling && sibling.type === 3 /* COMMENT */) {
  11747. context.removeNode(sibling);
  11748. comments.unshift(sibling);
  11749. continue;
  11750. }
  11751. if (sibling &&
  11752. sibling.type === 2 /* TEXT */ &&
  11753. !sibling.content.trim().length) {
  11754. context.removeNode(sibling);
  11755. continue;
  11756. }
  11757. if (sibling && sibling.type === 9 /* IF */) {
  11758. // move the node to the if node's branches
  11759. context.removeNode();
  11760. const branch = createIfBranch(node, dir);
  11761. if (comments.length) {
  11762. branch.children = [...comments, ...branch.children];
  11763. }
  11764. // check if user is forcing same key on different branches
  11765. {
  11766. const key = branch.userKey;
  11767. if (key) {
  11768. sibling.branches.forEach(({ userKey }) => {
  11769. if (isSameKey(userKey, key)) {
  11770. context.onError(createCompilerError(28 /* X_V_IF_SAME_KEY */, branch.userKey.loc));
  11771. }
  11772. });
  11773. }
  11774. }
  11775. sibling.branches.push(branch);
  11776. const onExit = processCodegen && processCodegen(sibling, branch, false);
  11777. // since the branch was removed, it will not be traversed.
  11778. // make sure to traverse here.
  11779. traverseNode(branch, context);
  11780. // call on exit
  11781. if (onExit)
  11782. onExit();
  11783. // make sure to reset currentNode after traversal to indicate this
  11784. // node has been removed.
  11785. context.currentNode = null;
  11786. }
  11787. else {
  11788. context.onError(createCompilerError(29 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc));
  11789. }
  11790. break;
  11791. }
  11792. }
  11793. }
  11794. function createIfBranch(node, dir) {
  11795. return {
  11796. type: 10 /* IF_BRANCH */,
  11797. loc: node.loc,
  11798. condition: dir.name === 'else' ? undefined : dir.exp,
  11799. children: node.tagType === 3 /* TEMPLATE */ && !findDir(node, 'for')
  11800. ? node.children
  11801. : [node],
  11802. userKey: findProp(node, `key`)
  11803. };
  11804. }
  11805. function createCodegenNodeForBranch(branch, keyIndex, context) {
  11806. if (branch.condition) {
  11807. return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
  11808. // make sure to pass in asBlock: true so that the comment node call
  11809. // closes the current block.
  11810. createCallExpression(context.helper(CREATE_COMMENT), [
  11811. '"v-if"' ,
  11812. 'true'
  11813. ]));
  11814. }
  11815. else {
  11816. return createChildrenCodegenNode(branch, keyIndex, context);
  11817. }
  11818. }
  11819. function createChildrenCodegenNode(branch, keyIndex, context) {
  11820. const { helper } = context;
  11821. const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2 /* CAN_HOIST */));
  11822. const { children } = branch;
  11823. const firstChild = children[0];
  11824. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */;
  11825. if (needFragmentWrapper) {
  11826. if (children.length === 1 && firstChild.type === 11 /* FOR */) {
  11827. // optimize away nested fragments when child is a ForNode
  11828. const vnodeCall = firstChild.codegenNode;
  11829. injectProp(vnodeCall, keyProperty, context);
  11830. return vnodeCall;
  11831. }
  11832. else {
  11833. return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, 64 /* STABLE_FRAGMENT */ +
  11834. (` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  11835. ), undefined, undefined, true, false, branch.loc);
  11836. }
  11837. }
  11838. else {
  11839. const vnodeCall = firstChild
  11840. .codegenNode;
  11841. // Change createVNode to createBlock.
  11842. if (vnodeCall.type === 13 /* VNODE_CALL */) {
  11843. vnodeCall.isBlock = true;
  11844. helper(OPEN_BLOCK);
  11845. helper(CREATE_BLOCK);
  11846. }
  11847. // inject branch key
  11848. injectProp(vnodeCall, keyProperty, context);
  11849. return vnodeCall;
  11850. }
  11851. }
  11852. function isSameKey(a, b) {
  11853. if (!a || a.type !== b.type) {
  11854. return false;
  11855. }
  11856. if (a.type === 6 /* ATTRIBUTE */) {
  11857. if (a.value.content !== b.value.content) {
  11858. return false;
  11859. }
  11860. }
  11861. else {
  11862. // directive
  11863. const exp = a.exp;
  11864. const branchExp = b.exp;
  11865. if (exp.type !== branchExp.type) {
  11866. return false;
  11867. }
  11868. if (exp.type !== 4 /* SIMPLE_EXPRESSION */ ||
  11869. (exp.isStatic !== branchExp.isStatic ||
  11870. exp.content !== branchExp.content)) {
  11871. return false;
  11872. }
  11873. }
  11874. return true;
  11875. }
  11876. function getParentCondition(node) {
  11877. while (true) {
  11878. if (node.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  11879. if (node.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  11880. node = node.alternate;
  11881. }
  11882. else {
  11883. return node;
  11884. }
  11885. }
  11886. else if (node.type === 20 /* JS_CACHE_EXPRESSION */) {
  11887. node = node.value;
  11888. }
  11889. }
  11890. }
  11891. const transformFor = createStructuralDirectiveTransform('for', (node, dir, context) => {
  11892. const { helper } = context;
  11893. return processFor(node, dir, context, forNode => {
  11894. // create the loop render function expression now, and add the
  11895. // iterator on exit after all children have been traversed
  11896. const renderExp = createCallExpression(helper(RENDER_LIST), [
  11897. forNode.source
  11898. ]);
  11899. const keyProp = findProp(node, `key`);
  11900. const keyProperty = keyProp
  11901. ? createObjectProperty(`key`, keyProp.type === 6 /* ATTRIBUTE */
  11902. ? createSimpleExpression(keyProp.value.content, true)
  11903. : keyProp.exp)
  11904. : null;
  11905. const isStableFragment = forNode.source.type === 4 /* SIMPLE_EXPRESSION */ &&
  11906. forNode.source.constType > 0 /* NOT_CONSTANT */;
  11907. const fragmentFlag = isStableFragment
  11908. ? 64 /* STABLE_FRAGMENT */
  11909. : keyProp
  11910. ? 128 /* KEYED_FRAGMENT */
  11911. : 256 /* UNKEYED_FRAGMENT */;
  11912. forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), undefined, renderExp, fragmentFlag +
  11913. (` /* ${PatchFlagNames[fragmentFlag]} */` ), undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, node.loc);
  11914. return () => {
  11915. // finish the codegen now that all children have been traversed
  11916. let childBlock;
  11917. const isTemplate = isTemplateNode(node);
  11918. const { children } = forNode;
  11919. // check <template v-for> key placement
  11920. if (isTemplate) {
  11921. node.children.some(c => {
  11922. if (c.type === 1 /* ELEMENT */) {
  11923. const key = findProp(c, 'key');
  11924. if (key) {
  11925. context.onError(createCompilerError(32 /* X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
  11926. return true;
  11927. }
  11928. }
  11929. });
  11930. }
  11931. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* ELEMENT */;
  11932. const slotOutlet = isSlotOutlet(node)
  11933. ? node
  11934. : isTemplate &&
  11935. node.children.length === 1 &&
  11936. isSlotOutlet(node.children[0])
  11937. ? node.children[0] // api-extractor somehow fails to infer this
  11938. : null;
  11939. if (slotOutlet) {
  11940. // <slot v-for="..."> or <template v-for="..."><slot/></template>
  11941. childBlock = slotOutlet.codegenNode;
  11942. if (isTemplate && keyProperty) {
  11943. // <template v-for="..." :key="..."><slot/></template>
  11944. // we need to inject the key to the renderSlot() call.
  11945. // the props for renderSlot is passed as the 3rd argument.
  11946. injectProp(childBlock, keyProperty, context);
  11947. }
  11948. }
  11949. else if (needFragmentWrapper) {
  11950. // <template v-for="..."> with text or multi-elements
  11951. // should generate a fragment block for each loop
  11952. childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : undefined, node.children, 64 /* STABLE_FRAGMENT */ +
  11953. (` /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`
  11954. ), undefined, undefined, true);
  11955. }
  11956. else {
  11957. // Normal element v-for. Directly use the child's codegenNode
  11958. // but mark it as a block.
  11959. childBlock = children[0]
  11960. .codegenNode;
  11961. if (isTemplate && keyProperty) {
  11962. injectProp(childBlock, keyProperty, context);
  11963. }
  11964. childBlock.isBlock = !isStableFragment;
  11965. if (childBlock.isBlock) {
  11966. helper(OPEN_BLOCK);
  11967. helper(CREATE_BLOCK);
  11968. }
  11969. else {
  11970. helper(CREATE_VNODE);
  11971. }
  11972. }
  11973. renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
  11974. };
  11975. });
  11976. });
  11977. // target-agnostic transform used for both Client and SSR
  11978. function processFor(node, dir, context, processCodegen) {
  11979. if (!dir.exp) {
  11980. context.onError(createCompilerError(30 /* X_V_FOR_NO_EXPRESSION */, dir.loc));
  11981. return;
  11982. }
  11983. const parseResult = parseForExpression(
  11984. // can only be simple expression because vFor transform is applied
  11985. // before expression transform.
  11986. dir.exp, context);
  11987. if (!parseResult) {
  11988. context.onError(createCompilerError(31 /* X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
  11989. return;
  11990. }
  11991. const { addIdentifiers, removeIdentifiers, scopes } = context;
  11992. const { source, value, key, index } = parseResult;
  11993. const forNode = {
  11994. type: 11 /* FOR */,
  11995. loc: dir.loc,
  11996. source,
  11997. valueAlias: value,
  11998. keyAlias: key,
  11999. objectIndexAlias: index,
  12000. parseResult,
  12001. children: isTemplateNode(node) ? node.children : [node]
  12002. };
  12003. context.replaceNode(forNode);
  12004. // bookkeeping
  12005. scopes.vFor++;
  12006. const onExit = processCodegen && processCodegen(forNode);
  12007. return () => {
  12008. scopes.vFor--;
  12009. if (onExit)
  12010. onExit();
  12011. };
  12012. }
  12013. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  12014. // This regex doesn't cover the case if key or index aliases have destructuring,
  12015. // but those do not make sense in the first place, so this works in practice.
  12016. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  12017. const stripParensRE = /^\(|\)$/g;
  12018. function parseForExpression(input, context) {
  12019. const loc = input.loc;
  12020. const exp = input.content;
  12021. const inMatch = exp.match(forAliasRE);
  12022. if (!inMatch)
  12023. return;
  12024. const [, LHS, RHS] = inMatch;
  12025. const result = {
  12026. source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
  12027. value: undefined,
  12028. key: undefined,
  12029. index: undefined
  12030. };
  12031. {
  12032. validateBrowserExpression(result.source, context);
  12033. }
  12034. let valueContent = LHS.trim()
  12035. .replace(stripParensRE, '')
  12036. .trim();
  12037. const trimmedOffset = LHS.indexOf(valueContent);
  12038. const iteratorMatch = valueContent.match(forIteratorRE);
  12039. if (iteratorMatch) {
  12040. valueContent = valueContent.replace(forIteratorRE, '').trim();
  12041. const keyContent = iteratorMatch[1].trim();
  12042. let keyOffset;
  12043. if (keyContent) {
  12044. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  12045. result.key = createAliasExpression(loc, keyContent, keyOffset);
  12046. {
  12047. validateBrowserExpression(result.key, context, true);
  12048. }
  12049. }
  12050. if (iteratorMatch[2]) {
  12051. const indexContent = iteratorMatch[2].trim();
  12052. if (indexContent) {
  12053. result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
  12054. ? keyOffset + keyContent.length
  12055. : trimmedOffset + valueContent.length));
  12056. {
  12057. validateBrowserExpression(result.index, context, true);
  12058. }
  12059. }
  12060. }
  12061. }
  12062. if (valueContent) {
  12063. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  12064. {
  12065. validateBrowserExpression(result.value, context, true);
  12066. }
  12067. }
  12068. return result;
  12069. }
  12070. function createAliasExpression(range, content, offset) {
  12071. return createSimpleExpression(content, false, getInnerRange(range, offset, content.length));
  12072. }
  12073. function createForLoopParams({ value, key, index }) {
  12074. const params = [];
  12075. if (value) {
  12076. params.push(value);
  12077. }
  12078. if (key) {
  12079. if (!value) {
  12080. params.push(createSimpleExpression(`_`, false));
  12081. }
  12082. params.push(key);
  12083. }
  12084. if (index) {
  12085. if (!key) {
  12086. if (!value) {
  12087. params.push(createSimpleExpression(`_`, false));
  12088. }
  12089. params.push(createSimpleExpression(`__`, false));
  12090. }
  12091. params.push(index);
  12092. }
  12093. return params;
  12094. }
  12095. const defaultFallback = createSimpleExpression(`undefined`, false);
  12096. // A NodeTransform that:
  12097. // 1. Tracks scope identifiers for scoped slots so that they don't get prefixed
  12098. // by transformExpression. This is only applied in non-browser builds with
  12099. // { prefixIdentifiers: true }.
  12100. // 2. Track v-slot depths so that we know a slot is inside another slot.
  12101. // Note the exit callback is executed before buildSlots() on the same node,
  12102. // so only nested slots see positive numbers.
  12103. const trackSlotScopes = (node, context) => {
  12104. if (node.type === 1 /* ELEMENT */ &&
  12105. (node.tagType === 1 /* COMPONENT */ ||
  12106. node.tagType === 3 /* TEMPLATE */)) {
  12107. // We are only checking non-empty v-slot here
  12108. // since we only care about slots that introduce scope variables.
  12109. const vSlot = findDir(node, 'slot');
  12110. if (vSlot) {
  12111. vSlot.exp;
  12112. context.scopes.vSlot++;
  12113. return () => {
  12114. context.scopes.vSlot--;
  12115. };
  12116. }
  12117. }
  12118. };
  12119. const buildClientSlotFn = (props, children, loc) => createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);
  12120. // Instead of being a DirectiveTransform, v-slot processing is called during
  12121. // transformElement to build the slots object for a component.
  12122. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  12123. context.helper(WITH_CTX);
  12124. const { children, loc } = node;
  12125. const slotsProperties = [];
  12126. const dynamicSlots = [];
  12127. const buildDefaultSlotProperty = (props, children) => createObjectProperty(`default`, buildSlotFn(props, children, loc));
  12128. // If the slot is inside a v-for or another v-slot, force it to be dynamic
  12129. // since it likely uses a scope variable.
  12130. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  12131. // 1. Check for slot with slotProps on component itself.
  12132. // <Comp v-slot="{ prop }"/>
  12133. const onComponentSlot = findDir(node, 'slot', true);
  12134. if (onComponentSlot) {
  12135. const { arg, exp } = onComponentSlot;
  12136. if (arg && !isStaticExp(arg)) {
  12137. hasDynamicSlots = true;
  12138. }
  12139. slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));
  12140. }
  12141. // 2. Iterate through children and check for template slots
  12142. // <template v-slot:foo="{ prop }">
  12143. let hasTemplateSlots = false;
  12144. let hasNamedDefaultSlot = false;
  12145. const implicitDefaultChildren = [];
  12146. const seenSlotNames = new Set();
  12147. for (let i = 0; i < children.length; i++) {
  12148. const slotElement = children[i];
  12149. let slotDir;
  12150. if (!isTemplateNode(slotElement) ||
  12151. !(slotDir = findDir(slotElement, 'slot', true))) {
  12152. // not a <template v-slot>, skip.
  12153. if (slotElement.type !== 3 /* COMMENT */) {
  12154. implicitDefaultChildren.push(slotElement);
  12155. }
  12156. continue;
  12157. }
  12158. if (onComponentSlot) {
  12159. // already has on-component slot - this is incorrect usage.
  12160. context.onError(createCompilerError(36 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));
  12161. break;
  12162. }
  12163. hasTemplateSlots = true;
  12164. const { children: slotChildren, loc: slotLoc } = slotElement;
  12165. const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
  12166. // check if name is dynamic.
  12167. let staticSlotName;
  12168. if (isStaticExp(slotName)) {
  12169. staticSlotName = slotName ? slotName.content : `default`;
  12170. }
  12171. else {
  12172. hasDynamicSlots = true;
  12173. }
  12174. const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);
  12175. // check if this slot is conditional (v-if/v-for)
  12176. let vIf;
  12177. let vElse;
  12178. let vFor;
  12179. if ((vIf = findDir(slotElement, 'if'))) {
  12180. hasDynamicSlots = true;
  12181. dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));
  12182. }
  12183. else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {
  12184. // find adjacent v-if
  12185. let j = i;
  12186. let prev;
  12187. while (j--) {
  12188. prev = children[j];
  12189. if (prev.type !== 3 /* COMMENT */) {
  12190. break;
  12191. }
  12192. }
  12193. if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {
  12194. // remove node
  12195. children.splice(i, 1);
  12196. i--;
  12197. // attach this slot to previous conditional
  12198. let conditional = dynamicSlots[dynamicSlots.length - 1];
  12199. while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {
  12200. conditional = conditional.alternate;
  12201. }
  12202. conditional.alternate = vElse.exp
  12203. ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)
  12204. : buildDynamicSlot(slotName, slotFunction);
  12205. }
  12206. else {
  12207. context.onError(createCompilerError(29 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));
  12208. }
  12209. }
  12210. else if ((vFor = findDir(slotElement, 'for'))) {
  12211. hasDynamicSlots = true;
  12212. const parseResult = vFor.parseResult ||
  12213. parseForExpression(vFor.exp, context);
  12214. if (parseResult) {
  12215. // Render the dynamic slots as an array and add it to the createSlot()
  12216. // args. The runtime knows how to handle it appropriately.
  12217. dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [
  12218. parseResult.source,
  12219. createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)
  12220. ]));
  12221. }
  12222. else {
  12223. context.onError(createCompilerError(31 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));
  12224. }
  12225. }
  12226. else {
  12227. // check duplicate static names
  12228. if (staticSlotName) {
  12229. if (seenSlotNames.has(staticSlotName)) {
  12230. context.onError(createCompilerError(37 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));
  12231. continue;
  12232. }
  12233. seenSlotNames.add(staticSlotName);
  12234. if (staticSlotName === 'default') {
  12235. hasNamedDefaultSlot = true;
  12236. }
  12237. }
  12238. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  12239. }
  12240. }
  12241. if (!onComponentSlot) {
  12242. if (!hasTemplateSlots) {
  12243. // implicit default slot (on component)
  12244. slotsProperties.push(buildDefaultSlotProperty(undefined, children));
  12245. }
  12246. else if (implicitDefaultChildren.length) {
  12247. // implicit default slot (mixed with named slots)
  12248. if (hasNamedDefaultSlot) {
  12249. context.onError(createCompilerError(38 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));
  12250. }
  12251. else {
  12252. slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));
  12253. }
  12254. }
  12255. }
  12256. const slotFlag = hasDynamicSlots
  12257. ? 2 /* DYNAMIC */
  12258. : hasForwardedSlots(node.children)
  12259. ? 3 /* FORWARDED */
  12260. : 1 /* STABLE */;
  12261. let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`,
  12262. // 2 = compiled but dynamic = can skip normalization, but must run diff
  12263. // 1 = compiled and static = can skip normalization AND diff as optimized
  12264. createSimpleExpression(slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ), false))), loc);
  12265. if (dynamicSlots.length) {
  12266. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  12267. slots,
  12268. createArrayExpression(dynamicSlots)
  12269. ]);
  12270. }
  12271. return {
  12272. slots,
  12273. hasDynamicSlots
  12274. };
  12275. }
  12276. function buildDynamicSlot(name, fn) {
  12277. return createObjectExpression([
  12278. createObjectProperty(`name`, name),
  12279. createObjectProperty(`fn`, fn)
  12280. ]);
  12281. }
  12282. function hasForwardedSlots(children) {
  12283. for (let i = 0; i < children.length; i++) {
  12284. const child = children[i];
  12285. if (child.type === 1 /* ELEMENT */) {
  12286. if (child.tagType === 2 /* SLOT */ ||
  12287. (child.tagType === 0 /* ELEMENT */ &&
  12288. hasForwardedSlots(child.children))) {
  12289. return true;
  12290. }
  12291. }
  12292. }
  12293. return false;
  12294. }
  12295. // some directive transforms (e.g. v-model) may return a symbol for runtime
  12296. // import, which should be used instead of a resolveDirective call.
  12297. const directiveImportMap = new WeakMap();
  12298. // generate a JavaScript AST for this element's codegen
  12299. const transformElement = (node, context) => {
  12300. if (!(node.type === 1 /* ELEMENT */ &&
  12301. (node.tagType === 0 /* ELEMENT */ ||
  12302. node.tagType === 1 /* COMPONENT */))) {
  12303. return;
  12304. }
  12305. // perform the work on exit, after all child expressions have been
  12306. // processed and merged.
  12307. return function postTransformElement() {
  12308. const { tag, props } = node;
  12309. const isComponent = node.tagType === 1 /* COMPONENT */;
  12310. // The goal of the transform is to create a codegenNode implementing the
  12311. // VNodeCall interface.
  12312. const vnodeTag = isComponent
  12313. ? resolveComponentType(node, context)
  12314. : `"${tag}"`;
  12315. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  12316. let vnodeProps;
  12317. let vnodeChildren;
  12318. let vnodePatchFlag;
  12319. let patchFlag = 0;
  12320. let vnodeDynamicProps;
  12321. let dynamicPropNames;
  12322. let vnodeDirectives;
  12323. let shouldUseBlock =
  12324. // dynamic component may resolve to plain elements
  12325. isDynamicComponent ||
  12326. vnodeTag === TELEPORT ||
  12327. vnodeTag === SUSPENSE ||
  12328. (!isComponent &&
  12329. // <svg> and <foreignObject> must be forced into blocks so that block
  12330. // updates inside get proper isSVG flag at runtime. (#639, #643)
  12331. // This is technically web-specific, but splitting the logic out of core
  12332. // leads to too much unnecessary complexity.
  12333. (tag === 'svg' ||
  12334. tag === 'foreignObject' ||
  12335. // #938: elements with dynamic keys should be forced into blocks
  12336. findProp(node, 'key', true)));
  12337. // props
  12338. if (props.length > 0) {
  12339. const propsBuildResult = buildProps(node, context);
  12340. vnodeProps = propsBuildResult.props;
  12341. patchFlag = propsBuildResult.patchFlag;
  12342. dynamicPropNames = propsBuildResult.dynamicPropNames;
  12343. const directives = propsBuildResult.directives;
  12344. vnodeDirectives =
  12345. directives && directives.length
  12346. ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))
  12347. : undefined;
  12348. }
  12349. // children
  12350. if (node.children.length > 0) {
  12351. if (vnodeTag === KEEP_ALIVE) {
  12352. // Although a built-in component, we compile KeepAlive with raw children
  12353. // instead of slot functions so that it can be used inside Transition
  12354. // or other Transition-wrapping HOCs.
  12355. // To ensure correct updates with block optimizations, we need to:
  12356. // 1. Force keep-alive into a block. This avoids its children being
  12357. // collected by a parent block.
  12358. shouldUseBlock = true;
  12359. // 2. Force keep-alive to always be updated, since it uses raw children.
  12360. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  12361. if (node.children.length > 1) {
  12362. context.onError(createCompilerError(44 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {
  12363. start: node.children[0].loc.start,
  12364. end: node.children[node.children.length - 1].loc.end,
  12365. source: ''
  12366. }));
  12367. }
  12368. }
  12369. const shouldBuildAsSlots = isComponent &&
  12370. // Teleport is not a real component and has dedicated runtime handling
  12371. vnodeTag !== TELEPORT &&
  12372. // explained above.
  12373. vnodeTag !== KEEP_ALIVE;
  12374. if (shouldBuildAsSlots) {
  12375. const { slots, hasDynamicSlots } = buildSlots(node, context);
  12376. vnodeChildren = slots;
  12377. if (hasDynamicSlots) {
  12378. patchFlag |= 1024 /* DYNAMIC_SLOTS */;
  12379. }
  12380. }
  12381. else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  12382. const child = node.children[0];
  12383. const type = child.type;
  12384. // check for dynamic text children
  12385. const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||
  12386. type === 8 /* COMPOUND_EXPRESSION */;
  12387. if (hasDynamicTextChild &&
  12388. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  12389. patchFlag |= 1 /* TEXT */;
  12390. }
  12391. // pass directly if the only child is a text node
  12392. // (plain / interpolation / expression)
  12393. if (hasDynamicTextChild || type === 2 /* TEXT */) {
  12394. vnodeChildren = child;
  12395. }
  12396. else {
  12397. vnodeChildren = node.children;
  12398. }
  12399. }
  12400. else {
  12401. vnodeChildren = node.children;
  12402. }
  12403. }
  12404. // patchFlag & dynamicPropNames
  12405. if (patchFlag !== 0) {
  12406. {
  12407. if (patchFlag < 0) {
  12408. // special flags (negative and mutually exclusive)
  12409. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  12410. }
  12411. else {
  12412. // bitwise flags
  12413. const flagNames = Object.keys(PatchFlagNames)
  12414. .map(Number)
  12415. .filter(n => n > 0 && patchFlag & n)
  12416. .map(n => PatchFlagNames[n])
  12417. .join(`, `);
  12418. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  12419. }
  12420. }
  12421. if (dynamicPropNames && dynamicPropNames.length) {
  12422. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  12423. }
  12424. }
  12425. node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, node.loc);
  12426. };
  12427. };
  12428. function resolveComponentType(node, context, ssr = false) {
  12429. const { tag } = node;
  12430. // 1. dynamic component
  12431. const isProp = node.tag === 'component' ? findProp(node, 'is') : findDir(node, 'is');
  12432. if (isProp) {
  12433. const exp = isProp.type === 6 /* ATTRIBUTE */
  12434. ? isProp.value && createSimpleExpression(isProp.value.content, true)
  12435. : isProp.exp;
  12436. if (exp) {
  12437. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  12438. exp
  12439. ]);
  12440. }
  12441. }
  12442. // 2. built-in components (Teleport, Transition, KeepAlive, Suspense...)
  12443. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  12444. if (builtIn) {
  12445. // built-ins are simply fallthroughs / have special handling during ssr
  12446. // so we don't need to import their runtime equivalents
  12447. if (!ssr)
  12448. context.helper(builtIn);
  12449. return builtIn;
  12450. }
  12451. // 5. user component (resolve)
  12452. context.helper(RESOLVE_COMPONENT);
  12453. context.components.add(tag);
  12454. return toValidAssetId(tag, `component`);
  12455. }
  12456. function buildProps(node, context, props = node.props, ssr = false) {
  12457. const { tag, loc: elementLoc } = node;
  12458. const isComponent = node.tagType === 1 /* COMPONENT */;
  12459. let properties = [];
  12460. const mergeArgs = [];
  12461. const runtimeDirectives = [];
  12462. // patchFlag analysis
  12463. let patchFlag = 0;
  12464. let hasRef = false;
  12465. let hasClassBinding = false;
  12466. let hasStyleBinding = false;
  12467. let hasHydrationEventBinding = false;
  12468. let hasDynamicKeys = false;
  12469. let hasVnodeHook = false;
  12470. const dynamicPropNames = [];
  12471. const analyzePatchFlag = ({ key, value }) => {
  12472. if (isStaticExp(key)) {
  12473. const name = key.content;
  12474. const isEventHandler = isOn(name);
  12475. if (!isComponent &&
  12476. isEventHandler &&
  12477. // omit the flag for click handlers because hydration gives click
  12478. // dedicated fast path.
  12479. name.toLowerCase() !== 'onclick' &&
  12480. // omit v-model handlers
  12481. name !== 'onUpdate:modelValue' &&
  12482. // omit onVnodeXXX hooks
  12483. !isReservedProp(name)) {
  12484. hasHydrationEventBinding = true;
  12485. }
  12486. if (isEventHandler && isReservedProp(name)) {
  12487. hasVnodeHook = true;
  12488. }
  12489. if (value.type === 20 /* JS_CACHE_EXPRESSION */ ||
  12490. ((value.type === 4 /* SIMPLE_EXPRESSION */ ||
  12491. value.type === 8 /* COMPOUND_EXPRESSION */) &&
  12492. getConstantType(value, context) > 0)) {
  12493. // skip if the prop is a cached handler or has constant value
  12494. return;
  12495. }
  12496. if (name === 'ref') {
  12497. hasRef = true;
  12498. }
  12499. else if (name === 'class' && !isComponent) {
  12500. hasClassBinding = true;
  12501. }
  12502. else if (name === 'style' && !isComponent) {
  12503. hasStyleBinding = true;
  12504. }
  12505. else if (name !== 'key' && !dynamicPropNames.includes(name)) {
  12506. dynamicPropNames.push(name);
  12507. }
  12508. }
  12509. else {
  12510. hasDynamicKeys = true;
  12511. }
  12512. };
  12513. for (let i = 0; i < props.length; i++) {
  12514. // static attribute
  12515. const prop = props[i];
  12516. if (prop.type === 6 /* ATTRIBUTE */) {
  12517. const { loc, name, value } = prop;
  12518. let isStatic = true;
  12519. if (name === 'ref') {
  12520. hasRef = true;
  12521. }
  12522. // skip :is on <component>
  12523. if (name === 'is' && tag === 'component') {
  12524. continue;
  12525. }
  12526. properties.push(createObjectProperty(createSimpleExpression(name, true, getInnerRange(loc, 0, name.length)), createSimpleExpression(value ? value.content : '', isStatic, value ? value.loc : loc)));
  12527. }
  12528. else {
  12529. // directives
  12530. const { name, arg, exp, loc } = prop;
  12531. const isBind = name === 'bind';
  12532. const isOn = name === 'on';
  12533. // skip v-slot - it is handled by its dedicated transform.
  12534. if (name === 'slot') {
  12535. if (!isComponent) {
  12536. context.onError(createCompilerError(39 /* X_V_SLOT_MISPLACED */, loc));
  12537. }
  12538. continue;
  12539. }
  12540. // skip v-once - it is handled by its dedicated transform.
  12541. if (name === 'once') {
  12542. continue;
  12543. }
  12544. // skip v-is and :is on <component>
  12545. if (name === 'is' ||
  12546. (isBind && tag === 'component' && isBindKey(arg, 'is'))) {
  12547. continue;
  12548. }
  12549. // skip v-on in SSR compilation
  12550. if (isOn && ssr) {
  12551. continue;
  12552. }
  12553. // special case for v-bind and v-on with no argument
  12554. if (!arg && (isBind || isOn)) {
  12555. hasDynamicKeys = true;
  12556. if (exp) {
  12557. if (properties.length) {
  12558. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  12559. properties = [];
  12560. }
  12561. if (isBind) {
  12562. mergeArgs.push(exp);
  12563. }
  12564. else {
  12565. // v-on="obj" -> toHandlers(obj)
  12566. mergeArgs.push({
  12567. type: 14 /* JS_CALL_EXPRESSION */,
  12568. loc,
  12569. callee: context.helper(TO_HANDLERS),
  12570. arguments: [exp]
  12571. });
  12572. }
  12573. }
  12574. else {
  12575. context.onError(createCompilerError(isBind
  12576. ? 33 /* X_V_BIND_NO_EXPRESSION */
  12577. : 34 /* X_V_ON_NO_EXPRESSION */, loc));
  12578. }
  12579. continue;
  12580. }
  12581. const directiveTransform = context.directiveTransforms[name];
  12582. if (directiveTransform) {
  12583. // has built-in directive transform.
  12584. const { props, needRuntime } = directiveTransform(prop, node, context);
  12585. !ssr && props.forEach(analyzePatchFlag);
  12586. properties.push(...props);
  12587. if (needRuntime) {
  12588. runtimeDirectives.push(prop);
  12589. if (isSymbol(needRuntime)) {
  12590. directiveImportMap.set(prop, needRuntime);
  12591. }
  12592. }
  12593. }
  12594. else {
  12595. // no built-in transform, this is a user custom directive.
  12596. runtimeDirectives.push(prop);
  12597. }
  12598. }
  12599. }
  12600. let propsExpression = undefined;
  12601. // has v-bind="object" or v-on="object", wrap with mergeProps
  12602. if (mergeArgs.length) {
  12603. if (properties.length) {
  12604. mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
  12605. }
  12606. if (mergeArgs.length > 1) {
  12607. propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
  12608. }
  12609. else {
  12610. // single v-bind with nothing else - no need for a mergeProps call
  12611. propsExpression = mergeArgs[0];
  12612. }
  12613. }
  12614. else if (properties.length) {
  12615. propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
  12616. }
  12617. // patchFlag analysis
  12618. if (hasDynamicKeys) {
  12619. patchFlag |= 16 /* FULL_PROPS */;
  12620. }
  12621. else {
  12622. if (hasClassBinding) {
  12623. patchFlag |= 2 /* CLASS */;
  12624. }
  12625. if (hasStyleBinding) {
  12626. patchFlag |= 4 /* STYLE */;
  12627. }
  12628. if (dynamicPropNames.length) {
  12629. patchFlag |= 8 /* PROPS */;
  12630. }
  12631. if (hasHydrationEventBinding) {
  12632. patchFlag |= 32 /* HYDRATE_EVENTS */;
  12633. }
  12634. }
  12635. if ((patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) &&
  12636. (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  12637. patchFlag |= 512 /* NEED_PATCH */;
  12638. }
  12639. return {
  12640. props: propsExpression,
  12641. directives: runtimeDirectives,
  12642. patchFlag,
  12643. dynamicPropNames
  12644. };
  12645. }
  12646. // Dedupe props in an object literal.
  12647. // Literal duplicated attributes would have been warned during the parse phase,
  12648. // however, it's possible to encounter duplicated `onXXX` handlers with different
  12649. // modifiers. We also need to merge static and dynamic class / style attributes.
  12650. // - onXXX handlers / style: merge into array
  12651. // - class: merge into single expression with concatenation
  12652. function dedupeProperties(properties) {
  12653. const knownProps = new Map();
  12654. const deduped = [];
  12655. for (let i = 0; i < properties.length; i++) {
  12656. const prop = properties[i];
  12657. // dynamic keys are always allowed
  12658. if (prop.key.type === 8 /* COMPOUND_EXPRESSION */ || !prop.key.isStatic) {
  12659. deduped.push(prop);
  12660. continue;
  12661. }
  12662. const name = prop.key.content;
  12663. const existing = knownProps.get(name);
  12664. if (existing) {
  12665. if (name === 'style' || name === 'class' || name.startsWith('on')) {
  12666. mergeAsArray(existing, prop);
  12667. }
  12668. // unexpected duplicate, should have emitted error during parse
  12669. }
  12670. else {
  12671. knownProps.set(name, prop);
  12672. deduped.push(prop);
  12673. }
  12674. }
  12675. return deduped;
  12676. }
  12677. function mergeAsArray(existing, incoming) {
  12678. if (existing.value.type === 17 /* JS_ARRAY_EXPRESSION */) {
  12679. existing.value.elements.push(incoming.value);
  12680. }
  12681. else {
  12682. existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
  12683. }
  12684. }
  12685. function buildDirectiveArgs(dir, context) {
  12686. const dirArgs = [];
  12687. const runtime = directiveImportMap.get(dir);
  12688. if (runtime) {
  12689. // built-in directive with runtime
  12690. dirArgs.push(context.helperString(runtime));
  12691. }
  12692. else {
  12693. {
  12694. // inject statement for resolving directive
  12695. context.helper(RESOLVE_DIRECTIVE);
  12696. context.directives.add(dir.name);
  12697. dirArgs.push(toValidAssetId(dir.name, `directive`));
  12698. }
  12699. }
  12700. const { loc } = dir;
  12701. if (dir.exp)
  12702. dirArgs.push(dir.exp);
  12703. if (dir.arg) {
  12704. if (!dir.exp) {
  12705. dirArgs.push(`void 0`);
  12706. }
  12707. dirArgs.push(dir.arg);
  12708. }
  12709. if (Object.keys(dir.modifiers).length) {
  12710. if (!dir.arg) {
  12711. if (!dir.exp) {
  12712. dirArgs.push(`void 0`);
  12713. }
  12714. dirArgs.push(`void 0`);
  12715. }
  12716. const trueExpression = createSimpleExpression(`true`, false, loc);
  12717. dirArgs.push(createObjectExpression(dir.modifiers.map(modifier => createObjectProperty(modifier, trueExpression)), loc));
  12718. }
  12719. return createArrayExpression(dirArgs, dir.loc);
  12720. }
  12721. function stringifyDynamicPropNames(props) {
  12722. let propsNamesString = `[`;
  12723. for (let i = 0, l = props.length; i < l; i++) {
  12724. propsNamesString += JSON.stringify(props[i]);
  12725. if (i < l - 1)
  12726. propsNamesString += ', ';
  12727. }
  12728. return propsNamesString + `]`;
  12729. }
  12730. const transformSlotOutlet = (node, context) => {
  12731. if (isSlotOutlet(node)) {
  12732. const { children, loc } = node;
  12733. const { slotName, slotProps } = processSlotOutlet(node, context);
  12734. const slotArgs = [
  12735. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  12736. slotName
  12737. ];
  12738. if (slotProps) {
  12739. slotArgs.push(slotProps);
  12740. }
  12741. if (children.length) {
  12742. if (!slotProps) {
  12743. slotArgs.push(`{}`);
  12744. }
  12745. slotArgs.push(createFunctionExpression([], children, false, false, loc));
  12746. }
  12747. node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
  12748. }
  12749. };
  12750. function processSlotOutlet(node, context) {
  12751. let slotName = `"default"`;
  12752. let slotProps = undefined;
  12753. const nonNameProps = [];
  12754. for (let i = 0; i < node.props.length; i++) {
  12755. const p = node.props[i];
  12756. if (p.type === 6 /* ATTRIBUTE */) {
  12757. if (p.value) {
  12758. if (p.name === 'name') {
  12759. slotName = JSON.stringify(p.value.content);
  12760. }
  12761. else {
  12762. p.name = camelize(p.name);
  12763. nonNameProps.push(p);
  12764. }
  12765. }
  12766. }
  12767. else {
  12768. if (p.name === 'bind' && isBindKey(p.arg, 'name')) {
  12769. if (p.exp)
  12770. slotName = p.exp;
  12771. }
  12772. else {
  12773. if (p.name === 'bind' && p.arg && isStaticExp(p.arg)) {
  12774. p.arg.content = camelize(p.arg.content);
  12775. }
  12776. nonNameProps.push(p);
  12777. }
  12778. }
  12779. }
  12780. if (nonNameProps.length > 0) {
  12781. const { props, directives } = buildProps(node, context, nonNameProps);
  12782. slotProps = props;
  12783. if (directives.length) {
  12784. context.onError(createCompilerError(35 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
  12785. }
  12786. }
  12787. return {
  12788. slotName,
  12789. slotProps
  12790. };
  12791. }
  12792. const fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^\s*function(?:\s+[\w$]+)?\s*\(/;
  12793. const transformOn = (dir, node, context, augmentor) => {
  12794. const { loc, modifiers, arg } = dir;
  12795. if (!dir.exp && !modifiers.length) {
  12796. context.onError(createCompilerError(34 /* X_V_ON_NO_EXPRESSION */, loc));
  12797. }
  12798. let eventName;
  12799. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12800. if (arg.isStatic) {
  12801. const rawName = arg.content;
  12802. // for all event listeners, auto convert it to camelCase. See issue #2249
  12803. eventName = createSimpleExpression(toHandlerKey(camelize(rawName)), true, arg.loc);
  12804. }
  12805. else {
  12806. // #2388
  12807. eventName = createCompoundExpression([
  12808. `${context.helperString(TO_HANDLER_KEY)}(`,
  12809. arg,
  12810. `)`
  12811. ]);
  12812. }
  12813. }
  12814. else {
  12815. // already a compound expression.
  12816. eventName = arg;
  12817. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  12818. eventName.children.push(`)`);
  12819. }
  12820. // handler processing
  12821. let exp = dir.exp;
  12822. if (exp && !exp.content.trim()) {
  12823. exp = undefined;
  12824. }
  12825. let shouldCache = context.cacheHandlers && !exp;
  12826. if (exp) {
  12827. const isMemberExp = isMemberExpression(exp.content);
  12828. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  12829. const hasMultipleStatements = exp.content.includes(`;`);
  12830. {
  12831. validateBrowserExpression(exp, context, false, hasMultipleStatements);
  12832. }
  12833. if (isInlineStatement || (shouldCache && isMemberExp)) {
  12834. // wrap inline statement in a function expression
  12835. exp = createCompoundExpression([
  12836. `${isInlineStatement
  12837. ? `$event`
  12838. : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  12839. exp,
  12840. hasMultipleStatements ? `}` : `)`
  12841. ]);
  12842. }
  12843. }
  12844. let ret = {
  12845. props: [
  12846. createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))
  12847. ]
  12848. };
  12849. // apply extended compiler augmentor
  12850. if (augmentor) {
  12851. ret = augmentor(ret);
  12852. }
  12853. if (shouldCache) {
  12854. // cache handlers so that it's always the same handler being passed down.
  12855. // this avoids unnecessary re-renders when users use inline handlers on
  12856. // components.
  12857. ret.props[0].value = context.cache(ret.props[0].value);
  12858. }
  12859. return ret;
  12860. };
  12861. // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
  12862. // codegen for the entire props object. This transform here is only for v-bind
  12863. // *with* args.
  12864. const transformBind = (dir, node, context) => {
  12865. const { exp, modifiers, loc } = dir;
  12866. const arg = dir.arg;
  12867. if (arg.type !== 4 /* SIMPLE_EXPRESSION */) {
  12868. arg.children.unshift(`(`);
  12869. arg.children.push(`) || ""`);
  12870. }
  12871. else if (!arg.isStatic) {
  12872. arg.content = `${arg.content} || ""`;
  12873. }
  12874. // .prop is no longer necessary due to new patch behavior
  12875. // .sync is replaced by v-model:arg
  12876. if (modifiers.includes('camel')) {
  12877. if (arg.type === 4 /* SIMPLE_EXPRESSION */) {
  12878. if (arg.isStatic) {
  12879. arg.content = camelize(arg.content);
  12880. }
  12881. else {
  12882. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  12883. }
  12884. }
  12885. else {
  12886. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  12887. arg.children.push(`)`);
  12888. }
  12889. }
  12890. if (!exp ||
  12891. (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  12892. context.onError(createCompilerError(33 /* X_V_BIND_NO_EXPRESSION */, loc));
  12893. return {
  12894. props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]
  12895. };
  12896. }
  12897. return {
  12898. props: [createObjectProperty(arg, exp)]
  12899. };
  12900. };
  12901. // Merge adjacent text nodes and expressions into a single expression
  12902. // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
  12903. const transformText = (node, context) => {
  12904. if (node.type === 0 /* ROOT */ ||
  12905. node.type === 1 /* ELEMENT */ ||
  12906. node.type === 11 /* FOR */ ||
  12907. node.type === 10 /* IF_BRANCH */) {
  12908. // perform the transform on node exit so that all expressions have already
  12909. // been processed.
  12910. return () => {
  12911. const children = node.children;
  12912. let currentContainer = undefined;
  12913. let hasText = false;
  12914. for (let i = 0; i < children.length; i++) {
  12915. const child = children[i];
  12916. if (isText(child)) {
  12917. hasText = true;
  12918. for (let j = i + 1; j < children.length; j++) {
  12919. const next = children[j];
  12920. if (isText(next)) {
  12921. if (!currentContainer) {
  12922. currentContainer = children[i] = {
  12923. type: 8 /* COMPOUND_EXPRESSION */,
  12924. loc: child.loc,
  12925. children: [child]
  12926. };
  12927. }
  12928. // merge adjacent text node into current
  12929. currentContainer.children.push(` + `, next);
  12930. children.splice(j, 1);
  12931. j--;
  12932. }
  12933. else {
  12934. currentContainer = undefined;
  12935. break;
  12936. }
  12937. }
  12938. }
  12939. }
  12940. if (!hasText ||
  12941. // if this is a plain element with a single text child, leave it
  12942. // as-is since the runtime has dedicated fast path for this by directly
  12943. // setting textContent of the element.
  12944. // for component root it's always normalized anyway.
  12945. (children.length === 1 &&
  12946. (node.type === 0 /* ROOT */ ||
  12947. (node.type === 1 /* ELEMENT */ &&
  12948. node.tagType === 0 /* ELEMENT */)))) {
  12949. return;
  12950. }
  12951. // pre-convert text nodes into createTextVNode(text) calls to avoid
  12952. // runtime normalization.
  12953. for (let i = 0; i < children.length; i++) {
  12954. const child = children[i];
  12955. if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {
  12956. const callArgs = [];
  12957. // createTextVNode defaults to single whitespace, so if it is a
  12958. // single space the code could be an empty call to save bytes.
  12959. if (child.type !== 2 /* TEXT */ || child.content !== ' ') {
  12960. callArgs.push(child);
  12961. }
  12962. // mark dynamic text with flag so it gets patched inside a block
  12963. if (!context.ssr &&
  12964. getConstantType(child, context) === 0 /* NOT_CONSTANT */) {
  12965. callArgs.push(1 /* TEXT */ +
  12966. (` /* ${PatchFlagNames[1 /* TEXT */]} */` ));
  12967. }
  12968. children[i] = {
  12969. type: 12 /* TEXT_CALL */,
  12970. content: child,
  12971. loc: child.loc,
  12972. codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
  12973. };
  12974. }
  12975. }
  12976. };
  12977. }
  12978. };
  12979. const seen = new WeakSet();
  12980. const transformOnce = (node, context) => {
  12981. if (node.type === 1 /* ELEMENT */ && findDir(node, 'once', true)) {
  12982. if (seen.has(node)) {
  12983. return;
  12984. }
  12985. seen.add(node);
  12986. context.helper(SET_BLOCK_TRACKING);
  12987. return () => {
  12988. const cur = context.currentNode;
  12989. if (cur.codegenNode) {
  12990. cur.codegenNode = context.cache(cur.codegenNode, true /* isVNode */);
  12991. }
  12992. };
  12993. }
  12994. };
  12995. const transformModel = (dir, node, context) => {
  12996. const { exp, arg } = dir;
  12997. if (!exp) {
  12998. context.onError(createCompilerError(40 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));
  12999. return createTransformProps();
  13000. }
  13001. const rawExp = exp.loc.source;
  13002. const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : rawExp;
  13003. // im SFC <script setup> inline mode, the exp may have been transformed into
  13004. // _unref(exp)
  13005. context.bindingMetadata[rawExp];
  13006. const maybeRef = !true /* SETUP_CONST */;
  13007. if (!isMemberExpression(expString) && !maybeRef) {
  13008. context.onError(createCompilerError(41 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));
  13009. return createTransformProps();
  13010. }
  13011. const propName = arg ? arg : createSimpleExpression('modelValue', true);
  13012. const eventName = arg
  13013. ? isStaticExp(arg)
  13014. ? `onUpdate:${arg.content}`
  13015. : createCompoundExpression(['"onUpdate:" + ', arg])
  13016. : `onUpdate:modelValue`;
  13017. let assignmentExp;
  13018. const eventArg = context.isTS ? `($event: any)` : `$event`;
  13019. {
  13020. assignmentExp = createCompoundExpression([
  13021. `${eventArg} => (`,
  13022. exp,
  13023. ` = $event)`
  13024. ]);
  13025. }
  13026. const props = [
  13027. // modelValue: foo
  13028. createObjectProperty(propName, dir.exp),
  13029. // "onUpdate:modelValue": $event => (foo = $event)
  13030. createObjectProperty(eventName, assignmentExp)
  13031. ];
  13032. // modelModifiers: { foo: true, "bar-baz": true }
  13033. if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {
  13034. const modifiers = dir.modifiers
  13035. .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)
  13036. .join(`, `);
  13037. const modifiersKey = arg
  13038. ? isStaticExp(arg)
  13039. ? `${arg.content}Modifiers`
  13040. : createCompoundExpression([arg, ' + "Modifiers"'])
  13041. : `modelModifiers`;
  13042. props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2 /* CAN_HOIST */)));
  13043. }
  13044. return createTransformProps(props);
  13045. };
  13046. function createTransformProps(props = []) {
  13047. return { props };
  13048. }
  13049. function getBaseTransformPreset(prefixIdentifiers) {
  13050. return [
  13051. [
  13052. transformOnce,
  13053. transformIf,
  13054. transformFor,
  13055. ...([transformExpression]
  13056. ),
  13057. transformSlotOutlet,
  13058. transformElement,
  13059. trackSlotScopes,
  13060. transformText
  13061. ],
  13062. {
  13063. on: transformOn,
  13064. bind: transformBind,
  13065. model: transformModel
  13066. }
  13067. ];
  13068. }
  13069. // we name it `baseCompile` so that higher order compilers like
  13070. // @vue/compiler-dom can export `compile` while re-exporting everything else.
  13071. function baseCompile(template, options = {}) {
  13072. const onError = options.onError || defaultOnError;
  13073. const isModuleMode = options.mode === 'module';
  13074. /* istanbul ignore if */
  13075. {
  13076. if (options.prefixIdentifiers === true) {
  13077. onError(createCompilerError(45 /* X_PREFIX_ID_NOT_SUPPORTED */));
  13078. }
  13079. else if (isModuleMode) {
  13080. onError(createCompilerError(46 /* X_MODULE_MODE_NOT_SUPPORTED */));
  13081. }
  13082. }
  13083. const prefixIdentifiers = !true ;
  13084. if (options.cacheHandlers) {
  13085. onError(createCompilerError(47 /* X_CACHE_HANDLER_NOT_SUPPORTED */));
  13086. }
  13087. if (options.scopeId && !isModuleMode) {
  13088. onError(createCompilerError(48 /* X_SCOPE_ID_NOT_SUPPORTED */));
  13089. }
  13090. const ast = isString(template) ? baseParse(template, options) : template;
  13091. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  13092. transform(ast, extend({}, options, {
  13093. prefixIdentifiers,
  13094. nodeTransforms: [
  13095. ...nodeTransforms,
  13096. ...(options.nodeTransforms || []) // user transforms
  13097. ],
  13098. directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms
  13099. )
  13100. }));
  13101. return generate(ast, extend({}, options, {
  13102. prefixIdentifiers
  13103. }));
  13104. }
  13105. const noopDirectiveTransform = () => ({ props: [] });
  13106. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  13107. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  13108. const V_MODEL_TEXT = Symbol(`vModelText` );
  13109. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  13110. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  13111. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  13112. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  13113. const V_SHOW = Symbol(`vShow` );
  13114. const TRANSITION$1 = Symbol(`Transition` );
  13115. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  13116. registerRuntimeHelpers({
  13117. [V_MODEL_RADIO]: `vModelRadio`,
  13118. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  13119. [V_MODEL_TEXT]: `vModelText`,
  13120. [V_MODEL_SELECT]: `vModelSelect`,
  13121. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  13122. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  13123. [V_ON_WITH_KEYS]: `withKeys`,
  13124. [V_SHOW]: `vShow`,
  13125. [TRANSITION$1]: `Transition`,
  13126. [TRANSITION_GROUP]: `TransitionGroup`
  13127. });
  13128. /* eslint-disable no-restricted-globals */
  13129. let decoder;
  13130. function decodeHtmlBrowser(raw) {
  13131. (decoder || (decoder = document.createElement('div'))).innerHTML = raw;
  13132. return decoder.textContent;
  13133. }
  13134. const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
  13135. const parserOptions = {
  13136. isVoidTag,
  13137. isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
  13138. isPreTag: tag => tag === 'pre',
  13139. decodeEntities: decodeHtmlBrowser ,
  13140. isBuiltInComponent: (tag) => {
  13141. if (isBuiltInType(tag, `Transition`)) {
  13142. return TRANSITION$1;
  13143. }
  13144. else if (isBuiltInType(tag, `TransitionGroup`)) {
  13145. return TRANSITION_GROUP;
  13146. }
  13147. },
  13148. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  13149. getNamespace(tag, parent) {
  13150. let ns = parent ? parent.ns : 0 /* HTML */;
  13151. if (parent && ns === 2 /* MATH_ML */) {
  13152. if (parent.tag === 'annotation-xml') {
  13153. if (tag === 'svg') {
  13154. return 1 /* SVG */;
  13155. }
  13156. if (parent.props.some(a => a.type === 6 /* ATTRIBUTE */ &&
  13157. a.name === 'encoding' &&
  13158. a.value != null &&
  13159. (a.value.content === 'text/html' ||
  13160. a.value.content === 'application/xhtml+xml'))) {
  13161. ns = 0 /* HTML */;
  13162. }
  13163. }
  13164. else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
  13165. tag !== 'mglyph' &&
  13166. tag !== 'malignmark') {
  13167. ns = 0 /* HTML */;
  13168. }
  13169. }
  13170. else if (parent && ns === 1 /* SVG */) {
  13171. if (parent.tag === 'foreignObject' ||
  13172. parent.tag === 'desc' ||
  13173. parent.tag === 'title') {
  13174. ns = 0 /* HTML */;
  13175. }
  13176. }
  13177. if (ns === 0 /* HTML */) {
  13178. if (tag === 'svg') {
  13179. return 1 /* SVG */;
  13180. }
  13181. if (tag === 'math') {
  13182. return 2 /* MATH_ML */;
  13183. }
  13184. }
  13185. return ns;
  13186. },
  13187. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  13188. getTextMode({ tag, ns }) {
  13189. if (ns === 0 /* HTML */) {
  13190. if (tag === 'textarea' || tag === 'title') {
  13191. return 1 /* RCDATA */;
  13192. }
  13193. if (isRawTextContainer(tag)) {
  13194. return 2 /* RAWTEXT */;
  13195. }
  13196. }
  13197. return 0 /* DATA */;
  13198. }
  13199. };
  13200. // Parse inline CSS strings for static style attributes into an object.
  13201. // This is a NodeTransform since it works on the static `style` attribute and
  13202. // converts it into a dynamic equivalent:
  13203. // style="color: red" -> :style='{ "color": "red" }'
  13204. // It is then processed by `transformElement` and included in the generated
  13205. // props.
  13206. const transformStyle = node => {
  13207. if (node.type === 1 /* ELEMENT */) {
  13208. node.props.forEach((p, i) => {
  13209. if (p.type === 6 /* ATTRIBUTE */ && p.name === 'style' && p.value) {
  13210. // replace p with an expression node
  13211. node.props[i] = {
  13212. type: 7 /* DIRECTIVE */,
  13213. name: `bind`,
  13214. arg: createSimpleExpression(`style`, true, p.loc),
  13215. exp: parseInlineCSS(p.value.content, p.loc),
  13216. modifiers: [],
  13217. loc: p.loc
  13218. };
  13219. }
  13220. });
  13221. }
  13222. };
  13223. const parseInlineCSS = (cssText, loc) => {
  13224. const normalized = parseStringStyle(cssText);
  13225. return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* CAN_STRINGIFY */);
  13226. };
  13227. function createDOMCompilerError(code, loc) {
  13228. return createCompilerError(code, loc, DOMErrorMessages );
  13229. }
  13230. const DOMErrorMessages = {
  13231. [49 /* X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
  13232. [50 /* X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
  13233. [51 /* X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
  13234. [52 /* X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
  13235. [53 /* X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  13236. [54 /* X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
  13237. [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.`,
  13238. [56 /* X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  13239. [57 /* X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
  13240. [58 /* X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
  13241. [59 /* X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  13242. };
  13243. const transformVHtml = (dir, node, context) => {
  13244. const { exp, loc } = dir;
  13245. if (!exp) {
  13246. context.onError(createDOMCompilerError(49 /* X_V_HTML_NO_EXPRESSION */, loc));
  13247. }
  13248. if (node.children.length) {
  13249. context.onError(createDOMCompilerError(50 /* X_V_HTML_WITH_CHILDREN */, loc));
  13250. node.children.length = 0;
  13251. }
  13252. return {
  13253. props: [
  13254. createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
  13255. ]
  13256. };
  13257. };
  13258. const transformVText = (dir, node, context) => {
  13259. const { exp, loc } = dir;
  13260. if (!exp) {
  13261. context.onError(createDOMCompilerError(51 /* X_V_TEXT_NO_EXPRESSION */, loc));
  13262. }
  13263. if (node.children.length) {
  13264. context.onError(createDOMCompilerError(52 /* X_V_TEXT_WITH_CHILDREN */, loc));
  13265. node.children.length = 0;
  13266. }
  13267. return {
  13268. props: [
  13269. createObjectProperty(createSimpleExpression(`textContent`, true), exp
  13270. ? createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
  13271. : createSimpleExpression('', true))
  13272. ]
  13273. };
  13274. };
  13275. const transformModel$1 = (dir, node, context) => {
  13276. const baseResult = transformModel(dir, node, context);
  13277. // base transform has errors OR component v-model (only need props)
  13278. if (!baseResult.props.length || node.tagType === 1 /* COMPONENT */) {
  13279. return baseResult;
  13280. }
  13281. if (dir.arg) {
  13282. context.onError(createDOMCompilerError(54 /* X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
  13283. }
  13284. function checkDuplicatedValue() {
  13285. const value = findProp(node, 'value');
  13286. if (value) {
  13287. context.onError(createDOMCompilerError(56 /* X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
  13288. }
  13289. }
  13290. const { tag } = node;
  13291. const isCustomElement = context.isCustomElement(tag);
  13292. if (tag === 'input' ||
  13293. tag === 'textarea' ||
  13294. tag === 'select' ||
  13295. isCustomElement) {
  13296. let directiveToUse = V_MODEL_TEXT;
  13297. let isInvalidType = false;
  13298. if (tag === 'input' || isCustomElement) {
  13299. const type = findProp(node, `type`);
  13300. if (type) {
  13301. if (type.type === 7 /* DIRECTIVE */) {
  13302. // :type="foo"
  13303. directiveToUse = V_MODEL_DYNAMIC;
  13304. }
  13305. else if (type.value) {
  13306. switch (type.value.content) {
  13307. case 'radio':
  13308. directiveToUse = V_MODEL_RADIO;
  13309. break;
  13310. case 'checkbox':
  13311. directiveToUse = V_MODEL_CHECKBOX;
  13312. break;
  13313. case 'file':
  13314. isInvalidType = true;
  13315. context.onError(createDOMCompilerError(55 /* X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
  13316. break;
  13317. default:
  13318. // text type
  13319. checkDuplicatedValue();
  13320. break;
  13321. }
  13322. }
  13323. }
  13324. else if (hasDynamicKeyVBind(node)) {
  13325. // element has bindings with dynamic keys, which can possibly contain
  13326. // "type".
  13327. directiveToUse = V_MODEL_DYNAMIC;
  13328. }
  13329. else {
  13330. // text type
  13331. checkDuplicatedValue();
  13332. }
  13333. }
  13334. else if (tag === 'select') {
  13335. directiveToUse = V_MODEL_SELECT;
  13336. }
  13337. else {
  13338. // textarea
  13339. checkDuplicatedValue();
  13340. }
  13341. // inject runtime directive
  13342. // by returning the helper symbol via needRuntime
  13343. // the import will replaced a resolveDirective call.
  13344. if (!isInvalidType) {
  13345. baseResult.needRuntime = context.helper(directiveToUse);
  13346. }
  13347. }
  13348. else {
  13349. context.onError(createDOMCompilerError(53 /* X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
  13350. }
  13351. // native vmodel doesn't need the `modelValue` props since they are also
  13352. // passed to the runtime as `binding.value`. removing it reduces code size.
  13353. baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* SIMPLE_EXPRESSION */ &&
  13354. p.key.content === 'modelValue'));
  13355. return baseResult;
  13356. };
  13357. const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
  13358. const isNonKeyModifier = /*#__PURE__*/ makeMap(
  13359. // event propagation management
  13360. `stop,prevent,self,` +
  13361. // system modifiers + exact
  13362. `ctrl,shift,alt,meta,exact,` +
  13363. // mouse
  13364. `middle`);
  13365. // left & right could be mouse or key modifiers based on event type
  13366. const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
  13367. const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
  13368. const resolveModifiers = (key, modifiers) => {
  13369. const keyModifiers = [];
  13370. const nonKeyModifiers = [];
  13371. const eventOptionModifiers = [];
  13372. for (let i = 0; i < modifiers.length; i++) {
  13373. const modifier = modifiers[i];
  13374. if (isEventOptionModifier(modifier)) {
  13375. // eventOptionModifiers: modifiers for addEventListener() options,
  13376. // e.g. .passive & .capture
  13377. eventOptionModifiers.push(modifier);
  13378. }
  13379. else {
  13380. // runtimeModifiers: modifiers that needs runtime guards
  13381. if (maybeKeyModifier(modifier)) {
  13382. if (isStaticExp(key)) {
  13383. if (isKeyboardEvent(key.content)) {
  13384. keyModifiers.push(modifier);
  13385. }
  13386. else {
  13387. nonKeyModifiers.push(modifier);
  13388. }
  13389. }
  13390. else {
  13391. keyModifiers.push(modifier);
  13392. nonKeyModifiers.push(modifier);
  13393. }
  13394. }
  13395. else {
  13396. if (isNonKeyModifier(modifier)) {
  13397. nonKeyModifiers.push(modifier);
  13398. }
  13399. else {
  13400. keyModifiers.push(modifier);
  13401. }
  13402. }
  13403. }
  13404. }
  13405. return {
  13406. keyModifiers,
  13407. nonKeyModifiers,
  13408. eventOptionModifiers
  13409. };
  13410. };
  13411. const transformClick = (key, event) => {
  13412. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
  13413. return isStaticClick
  13414. ? createSimpleExpression(event, true)
  13415. : key.type !== 4 /* SIMPLE_EXPRESSION */
  13416. ? createCompoundExpression([
  13417. `(`,
  13418. key,
  13419. `) === "onClick" ? "${event}" : (`,
  13420. key,
  13421. `)`
  13422. ])
  13423. : key;
  13424. };
  13425. const transformOn$1 = (dir, node, context) => {
  13426. return transformOn(dir, node, context, baseResult => {
  13427. const { modifiers } = dir;
  13428. if (!modifiers.length)
  13429. return baseResult;
  13430. let { key, value: handlerExp } = baseResult.props[0];
  13431. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers);
  13432. // normalize click.right and click.middle since they don't actually fire
  13433. if (nonKeyModifiers.includes('right')) {
  13434. key = transformClick(key, `onContextmenu`);
  13435. }
  13436. if (nonKeyModifiers.includes('middle')) {
  13437. key = transformClick(key, `onMouseup`);
  13438. }
  13439. if (nonKeyModifiers.length) {
  13440. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  13441. handlerExp,
  13442. JSON.stringify(nonKeyModifiers)
  13443. ]);
  13444. }
  13445. if (keyModifiers.length &&
  13446. // if event name is dynamic, always wrap with keys guard
  13447. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  13448. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  13449. handlerExp,
  13450. JSON.stringify(keyModifiers)
  13451. ]);
  13452. }
  13453. if (eventOptionModifiers.length) {
  13454. const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
  13455. key = isStaticExp(key)
  13456. ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
  13457. : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  13458. }
  13459. return {
  13460. props: [createObjectProperty(key, handlerExp)]
  13461. };
  13462. });
  13463. };
  13464. const transformShow = (dir, node, context) => {
  13465. const { exp, loc } = dir;
  13466. if (!exp) {
  13467. context.onError(createDOMCompilerError(57 /* X_V_SHOW_NO_EXPRESSION */, loc));
  13468. }
  13469. return {
  13470. props: [],
  13471. needRuntime: context.helper(V_SHOW)
  13472. };
  13473. };
  13474. const warnTransitionChildren = (node, context) => {
  13475. if (node.type === 1 /* ELEMENT */ &&
  13476. node.tagType === 1 /* COMPONENT */) {
  13477. const component = context.isBuiltInComponent(node.tag);
  13478. if (component === TRANSITION$1) {
  13479. return () => {
  13480. if (node.children.length && hasMultipleChildren(node)) {
  13481. context.onError(createDOMCompilerError(58 /* X_TRANSITION_INVALID_CHILDREN */, {
  13482. start: node.children[0].loc.start,
  13483. end: node.children[node.children.length - 1].loc.end,
  13484. source: ''
  13485. }));
  13486. }
  13487. };
  13488. }
  13489. }
  13490. };
  13491. function hasMultipleChildren(node) {
  13492. // #1352 filter out potential comment nodes.
  13493. const children = (node.children = node.children.filter(c => c.type !== 3 /* COMMENT */));
  13494. const child = children[0];
  13495. return (children.length !== 1 ||
  13496. child.type === 11 /* FOR */ ||
  13497. (child.type === 9 /* IF */ && child.branches.some(hasMultipleChildren)));
  13498. }
  13499. const ignoreSideEffectTags = (node, context) => {
  13500. if (node.type === 1 /* ELEMENT */ &&
  13501. node.tagType === 0 /* ELEMENT */ &&
  13502. (node.tag === 'script' || node.tag === 'style')) {
  13503. context.onError(createDOMCompilerError(59 /* X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
  13504. context.removeNode();
  13505. }
  13506. };
  13507. const DOMNodeTransforms = [
  13508. transformStyle,
  13509. ...([warnTransitionChildren] )
  13510. ];
  13511. const DOMDirectiveTransforms = {
  13512. cloak: noopDirectiveTransform,
  13513. html: transformVHtml,
  13514. text: transformVText,
  13515. model: transformModel$1,
  13516. on: transformOn$1,
  13517. show: transformShow
  13518. };
  13519. function compile$1(template, options = {}) {
  13520. return baseCompile(template, extend({}, parserOptions, options, {
  13521. nodeTransforms: [
  13522. // ignore <script> and <tag>
  13523. // this is not put inside DOMNodeTransforms because that list is used
  13524. // by compiler-ssr to generate vnode fallback branches
  13525. ignoreSideEffectTags,
  13526. ...DOMNodeTransforms,
  13527. ...(options.nodeTransforms || [])
  13528. ],
  13529. directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
  13530. transformHoist: null
  13531. }));
  13532. }
  13533. // This entry is the "full-build" that includes both the runtime
  13534. {
  13535. initDev();
  13536. }
  13537. const compileCache = Object.create(null);
  13538. function compileToFunction(template, options) {
  13539. if (!isString(template)) {
  13540. if (template.nodeType) {
  13541. template = template.innerHTML;
  13542. }
  13543. else {
  13544. warn(`invalid template option: `, template);
  13545. return NOOP;
  13546. }
  13547. }
  13548. const key = template;
  13549. const cached = compileCache[key];
  13550. if (cached) {
  13551. return cached;
  13552. }
  13553. if (template[0] === '#') {
  13554. const el = document.querySelector(template);
  13555. if (!el) {
  13556. warn(`Template element not found or is empty: ${template}`);
  13557. }
  13558. // __UNSAFE__
  13559. // Reason: potential execution of JS expressions in in-DOM template.
  13560. // The user must make sure the in-DOM template is trusted. If it's rendered
  13561. // by the server, the template should not contain any user data.
  13562. template = el ? el.innerHTML : ``;
  13563. }
  13564. const { code } = compile$1(template, extend({
  13565. hoistStatic: true,
  13566. onError(err) {
  13567. {
  13568. const message = `Template compilation error: ${err.message}`;
  13569. const codeFrame = err.loc &&
  13570. generateCodeFrame(template, err.loc.start.offset, err.loc.end.offset);
  13571. warn(codeFrame ? `${message}\n${codeFrame}` : message);
  13572. }
  13573. }
  13574. }, options));
  13575. // The wildcard import results in a huge object with every export
  13576. // with keys that cannot be mangled, and can be quite heavy size-wise.
  13577. // In the global build we know `Vue` is available globally so we can avoid
  13578. // the wildcard object.
  13579. const render = (new Function('Vue', code)(runtimeDom));
  13580. render._rc = true;
  13581. return (compileCache[key] = render);
  13582. }
  13583. registerRuntimeCompiler(compileToFunction);
  13584. export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compileToFunction as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, isProxy, isReactive, isReadonly, isRef, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toDisplayString, toHandlerKey, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };