build.js 222 KB

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