build.js 222 KB

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