build.js 222 KB

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