compiler-dom.esm-browser.js 155 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331
  1. function makeMap(str, expectsLowerCase) {
  2. const map = /* @__PURE__ */ Object.create(null);
  3. const list = str.split(",");
  4. for (let i = 0; i < list.length; i++) {
  5. map[list[i]] = true;
  6. }
  7. return expectsLowerCase ? (val) => !!map[val.toLowerCase()] : (val) => !!map[val];
  8. }
  9. const EMPTY_OBJ = Object.freeze({}) ;
  10. const NOOP = () => {
  11. };
  12. const NO = () => false;
  13. const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && // uppercase letter
  14. (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
  15. const extend = Object.assign;
  16. const isArray = Array.isArray;
  17. const isString = (val) => typeof val === "string";
  18. const isSymbol = (val) => typeof val === "symbol";
  19. const isObject = (val) => val !== null && typeof val === "object";
  20. const isReservedProp = /* @__PURE__ */ makeMap(
  21. // the leading comma is intentional so empty string "" is also included
  22. ",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"
  23. );
  24. const isBuiltInDirective = /* @__PURE__ */ makeMap(
  25. "bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"
  26. );
  27. const cacheStringFunction = (fn) => {
  28. const cache = /* @__PURE__ */ Object.create(null);
  29. return (str) => {
  30. const hit = cache[str];
  31. return hit || (cache[str] = fn(str));
  32. };
  33. };
  34. const camelizeRE = /-(\w)/g;
  35. const camelize = cacheStringFunction((str) => {
  36. return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
  37. });
  38. const hyphenateRE = /\B([A-Z])/g;
  39. const hyphenate = cacheStringFunction(
  40. (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
  41. );
  42. const capitalize = cacheStringFunction((str) => {
  43. return str.charAt(0).toUpperCase() + str.slice(1);
  44. });
  45. const toHandlerKey = cacheStringFunction((str) => {
  46. const s = str ? `on${capitalize(str)}` : ``;
  47. return s;
  48. });
  49. const PatchFlagNames = {
  50. [1]: `TEXT`,
  51. [2]: `CLASS`,
  52. [4]: `STYLE`,
  53. [8]: `PROPS`,
  54. [16]: `FULL_PROPS`,
  55. [32]: `NEED_HYDRATION`,
  56. [64]: `STABLE_FRAGMENT`,
  57. [128]: `KEYED_FRAGMENT`,
  58. [256]: `UNKEYED_FRAGMENT`,
  59. [512]: `NEED_PATCH`,
  60. [1024]: `DYNAMIC_SLOTS`,
  61. [2048]: `DEV_ROOT_FRAGMENT`,
  62. [-1]: `HOISTED`,
  63. [-2]: `BAIL`
  64. };
  65. const slotFlagsText = {
  66. [1]: "STABLE",
  67. [2]: "DYNAMIC",
  68. [3]: "FORWARDED"
  69. };
  70. const range = 2;
  71. function generateCodeFrame(source, start = 0, end = source.length) {
  72. let lines = source.split(/(\r?\n)/);
  73. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  74. lines = lines.filter((_, idx) => idx % 2 === 0);
  75. let count = 0;
  76. const res = [];
  77. for (let i = 0; i < lines.length; i++) {
  78. count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
  79. if (count >= start) {
  80. for (let j = i - range; j <= i + range || end > count; j++) {
  81. if (j < 0 || j >= lines.length)
  82. continue;
  83. const line = j + 1;
  84. res.push(
  85. `${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
  86. );
  87. const lineLength = lines[j].length;
  88. const newLineSeqLength = newlineSequences[j] && newlineSequences[j].length || 0;
  89. if (j === i) {
  90. const pad = start - (count - (lineLength + newLineSeqLength));
  91. const length = Math.max(
  92. 1,
  93. end > count ? lineLength - pad : end - start
  94. );
  95. res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
  96. } else if (j > i) {
  97. if (end > count) {
  98. const length = Math.max(Math.min(end - count, lineLength), 1);
  99. res.push(` | ` + "^".repeat(length));
  100. }
  101. count += lineLength + newLineSeqLength;
  102. }
  103. }
  104. break;
  105. }
  106. }
  107. return res.join("\n");
  108. }
  109. const listDelimiterRE = /;(?![^(]*\))/g;
  110. const propertyDelimiterRE = /:([^]+)/;
  111. const styleCommentRE = /\/\*[^]*?\*\//g;
  112. function parseStringStyle(cssText) {
  113. const ret = {};
  114. cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
  115. if (item) {
  116. const tmp = item.split(propertyDelimiterRE);
  117. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  118. }
  119. });
  120. return ret;
  121. }
  122. const HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot";
  123. const SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
  124. const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
  125. const isHTMLTag = /* @__PURE__ */ makeMap(HTML_TAGS);
  126. const isSVGTag = /* @__PURE__ */ makeMap(SVG_TAGS);
  127. const isVoidTag = /* @__PURE__ */ makeMap(VOID_TAGS);
  128. function defaultOnError(error) {
  129. throw error;
  130. }
  131. function defaultOnWarn(msg) {
  132. console.warn(`[Vue warn] ${msg.message}`);
  133. }
  134. function createCompilerError(code, loc, messages, additionalMessage) {
  135. const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
  136. const error = new SyntaxError(String(msg));
  137. error.code = code;
  138. error.loc = loc;
  139. return error;
  140. }
  141. const errorMessages = {
  142. // parse errors
  143. [0]: "Illegal comment.",
  144. [1]: "CDATA section is allowed only in XML context.",
  145. [2]: "Duplicate attribute.",
  146. [3]: "End tag cannot have attributes.",
  147. [4]: "Illegal '/' in tags.",
  148. [5]: "Unexpected EOF in tag.",
  149. [6]: "Unexpected EOF in CDATA section.",
  150. [7]: "Unexpected EOF in comment.",
  151. [8]: "Unexpected EOF in script.",
  152. [9]: "Unexpected EOF in tag.",
  153. [10]: "Incorrectly closed comment.",
  154. [11]: "Incorrectly opened comment.",
  155. [12]: "Illegal tag name. Use '&lt;' to print '<'.",
  156. [13]: "Attribute value was expected.",
  157. [14]: "End tag name was expected.",
  158. [15]: "Whitespace was expected.",
  159. [16]: "Unexpected '<!--' in comment.",
  160. [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
  161. [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
  162. [19]: "Attribute name cannot start with '='.",
  163. [21]: "'<?' is allowed only in XML context.",
  164. [20]: `Unexpected null character.`,
  165. [22]: "Illegal '/' in tags.",
  166. // Vue-specific parse errors
  167. [23]: "Invalid end tag.",
  168. [24]: "Element is missing end tag.",
  169. [25]: "Interpolation end sign was not found.",
  170. [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
  171. [26]: "Legal directive name was expected.",
  172. // transform errors
  173. [28]: `v-if/v-else-if is missing expression.`,
  174. [29]: `v-if/else branches must use unique keys.`,
  175. [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  176. [31]: `v-for is missing expression.`,
  177. [32]: `v-for has invalid expression.`,
  178. [33]: `<template v-for> key should be placed on the <template> tag.`,
  179. [34]: `v-bind is missing expression.`,
  180. [35]: `v-on is missing expression.`,
  181. [36]: `Unexpected custom directive on <slot> outlet.`,
  182. [37]: `Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.`,
  183. [38]: `Duplicate slot names found. `,
  184. [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
  185. [40]: `v-slot can only be used on components or <template> tags.`,
  186. [41]: `v-model is missing expression.`,
  187. [42]: `v-model value must be a valid JavaScript member expression.`,
  188. [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  189. [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
  190. Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  191. [45]: `Error parsing JavaScript expression: `,
  192. [46]: `<KeepAlive> expects exactly one child component.`,
  193. // generic errors
  194. [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  195. [48]: `ES module mode is not supported in this build of compiler.`,
  196. [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  197. [50]: `"scopeId" option is only supported in module mode.`,
  198. // deprecations
  199. [51]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`,
  200. [52]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`,
  201. // just to fulfill types
  202. [53]: ``
  203. };
  204. const FRAGMENT = Symbol(`Fragment` );
  205. const TELEPORT = Symbol(`Teleport` );
  206. const SUSPENSE = Symbol(`Suspense` );
  207. const KEEP_ALIVE = Symbol(`KeepAlive` );
  208. const BASE_TRANSITION = Symbol(`BaseTransition` );
  209. const OPEN_BLOCK = Symbol(`openBlock` );
  210. const CREATE_BLOCK = Symbol(`createBlock` );
  211. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  212. const CREATE_VNODE = Symbol(`createVNode` );
  213. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  214. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  215. const CREATE_TEXT = Symbol(`createTextVNode` );
  216. const CREATE_STATIC = Symbol(`createStaticVNode` );
  217. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  218. const RESOLVE_DYNAMIC_COMPONENT = Symbol(
  219. `resolveDynamicComponent`
  220. );
  221. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  222. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  223. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  224. const RENDER_LIST = Symbol(`renderList` );
  225. const RENDER_SLOT = Symbol(`renderSlot` );
  226. const CREATE_SLOTS = Symbol(`createSlots` );
  227. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  228. const MERGE_PROPS = Symbol(`mergeProps` );
  229. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  230. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  231. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  232. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  233. const TO_HANDLERS = Symbol(`toHandlers` );
  234. const CAMELIZE = Symbol(`camelize` );
  235. const CAPITALIZE = Symbol(`capitalize` );
  236. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  237. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  238. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  239. const POP_SCOPE_ID = Symbol(`popScopeId` );
  240. const WITH_CTX = Symbol(`withCtx` );
  241. const UNREF = Symbol(`unref` );
  242. const IS_REF = Symbol(`isRef` );
  243. const WITH_MEMO = Symbol(`withMemo` );
  244. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  245. const helperNameMap = {
  246. [FRAGMENT]: `Fragment`,
  247. [TELEPORT]: `Teleport`,
  248. [SUSPENSE]: `Suspense`,
  249. [KEEP_ALIVE]: `KeepAlive`,
  250. [BASE_TRANSITION]: `BaseTransition`,
  251. [OPEN_BLOCK]: `openBlock`,
  252. [CREATE_BLOCK]: `createBlock`,
  253. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  254. [CREATE_VNODE]: `createVNode`,
  255. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  256. [CREATE_COMMENT]: `createCommentVNode`,
  257. [CREATE_TEXT]: `createTextVNode`,
  258. [CREATE_STATIC]: `createStaticVNode`,
  259. [RESOLVE_COMPONENT]: `resolveComponent`,
  260. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  261. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  262. [RESOLVE_FILTER]: `resolveFilter`,
  263. [WITH_DIRECTIVES]: `withDirectives`,
  264. [RENDER_LIST]: `renderList`,
  265. [RENDER_SLOT]: `renderSlot`,
  266. [CREATE_SLOTS]: `createSlots`,
  267. [TO_DISPLAY_STRING]: `toDisplayString`,
  268. [MERGE_PROPS]: `mergeProps`,
  269. [NORMALIZE_CLASS]: `normalizeClass`,
  270. [NORMALIZE_STYLE]: `normalizeStyle`,
  271. [NORMALIZE_PROPS]: `normalizeProps`,
  272. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  273. [TO_HANDLERS]: `toHandlers`,
  274. [CAMELIZE]: `camelize`,
  275. [CAPITALIZE]: `capitalize`,
  276. [TO_HANDLER_KEY]: `toHandlerKey`,
  277. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  278. [PUSH_SCOPE_ID]: `pushScopeId`,
  279. [POP_SCOPE_ID]: `popScopeId`,
  280. [WITH_CTX]: `withCtx`,
  281. [UNREF]: `unref`,
  282. [IS_REF]: `isRef`,
  283. [WITH_MEMO]: `withMemo`,
  284. [IS_MEMO_SAME]: `isMemoSame`
  285. };
  286. function registerRuntimeHelpers(helpers) {
  287. Object.getOwnPropertySymbols(helpers).forEach((s) => {
  288. helperNameMap[s] = helpers[s];
  289. });
  290. }
  291. const locStub = {
  292. source: "",
  293. start: { line: 1, column: 1, offset: 0 },
  294. end: { line: 1, column: 1, offset: 0 }
  295. };
  296. function createRoot(children, loc = locStub) {
  297. return {
  298. type: 0,
  299. children,
  300. helpers: /* @__PURE__ */ new Set(),
  301. components: [],
  302. directives: [],
  303. hoists: [],
  304. imports: [],
  305. cached: 0,
  306. temps: 0,
  307. codegenNode: void 0,
  308. loc
  309. };
  310. }
  311. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  312. if (context) {
  313. if (isBlock) {
  314. context.helper(OPEN_BLOCK);
  315. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  316. } else {
  317. context.helper(getVNodeHelper(context.inSSR, isComponent));
  318. }
  319. if (directives) {
  320. context.helper(WITH_DIRECTIVES);
  321. }
  322. }
  323. return {
  324. type: 13,
  325. tag,
  326. props,
  327. children,
  328. patchFlag,
  329. dynamicProps,
  330. directives,
  331. isBlock,
  332. disableTracking,
  333. isComponent,
  334. loc
  335. };
  336. }
  337. function createArrayExpression(elements, loc = locStub) {
  338. return {
  339. type: 17,
  340. loc,
  341. elements
  342. };
  343. }
  344. function createObjectExpression(properties, loc = locStub) {
  345. return {
  346. type: 15,
  347. loc,
  348. properties
  349. };
  350. }
  351. function createObjectProperty(key, value) {
  352. return {
  353. type: 16,
  354. loc: locStub,
  355. key: isString(key) ? createSimpleExpression(key, true) : key,
  356. value
  357. };
  358. }
  359. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
  360. return {
  361. type: 4,
  362. loc,
  363. content,
  364. isStatic,
  365. constType: isStatic ? 3 : constType
  366. };
  367. }
  368. function createInterpolation(content, loc) {
  369. return {
  370. type: 5,
  371. loc,
  372. content: isString(content) ? createSimpleExpression(content, false, loc) : content
  373. };
  374. }
  375. function createCompoundExpression(children, loc = locStub) {
  376. return {
  377. type: 8,
  378. loc,
  379. children
  380. };
  381. }
  382. function createCallExpression(callee, args = [], loc = locStub) {
  383. return {
  384. type: 14,
  385. loc,
  386. callee,
  387. arguments: args
  388. };
  389. }
  390. function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
  391. return {
  392. type: 18,
  393. params,
  394. returns,
  395. newline,
  396. isSlot,
  397. loc
  398. };
  399. }
  400. function createConditionalExpression(test, consequent, alternate, newline = true) {
  401. return {
  402. type: 19,
  403. test,
  404. consequent,
  405. alternate,
  406. newline,
  407. loc: locStub
  408. };
  409. }
  410. function createCacheExpression(index, value, isVNode = false) {
  411. return {
  412. type: 20,
  413. index,
  414. value,
  415. isVNode,
  416. loc: locStub
  417. };
  418. }
  419. function createBlockStatement(body) {
  420. return {
  421. type: 21,
  422. body,
  423. loc: locStub
  424. };
  425. }
  426. function createTemplateLiteral(elements) {
  427. return {
  428. type: 22,
  429. elements,
  430. loc: locStub
  431. };
  432. }
  433. function createIfStatement(test, consequent, alternate) {
  434. return {
  435. type: 23,
  436. test,
  437. consequent,
  438. alternate,
  439. loc: locStub
  440. };
  441. }
  442. function createAssignmentExpression(left, right) {
  443. return {
  444. type: 24,
  445. left,
  446. right,
  447. loc: locStub
  448. };
  449. }
  450. function createSequenceExpression(expressions) {
  451. return {
  452. type: 25,
  453. expressions,
  454. loc: locStub
  455. };
  456. }
  457. function createReturnStatement(returns) {
  458. return {
  459. type: 26,
  460. returns,
  461. loc: locStub
  462. };
  463. }
  464. function getVNodeHelper(ssr, isComponent) {
  465. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  466. }
  467. function getVNodeBlockHelper(ssr, isComponent) {
  468. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  469. }
  470. function convertToBlock(node, { helper, removeHelper, inSSR }) {
  471. if (!node.isBlock) {
  472. node.isBlock = true;
  473. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  474. helper(OPEN_BLOCK);
  475. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  476. }
  477. }
  478. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  479. const isBuiltInType = (tag, expected) => tag === expected || tag === hyphenate(expected);
  480. function isCoreComponent(tag) {
  481. if (isBuiltInType(tag, "Teleport")) {
  482. return TELEPORT;
  483. } else if (isBuiltInType(tag, "Suspense")) {
  484. return SUSPENSE;
  485. } else if (isBuiltInType(tag, "KeepAlive")) {
  486. return KEEP_ALIVE;
  487. } else if (isBuiltInType(tag, "BaseTransition")) {
  488. return BASE_TRANSITION;
  489. }
  490. }
  491. const nonIdentifierRE = /^\d|[^\$\w]/;
  492. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  493. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  494. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  495. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  496. const isMemberExpressionBrowser = (path) => {
  497. path = path.trim().replace(whitespaceRE, (s) => s.trim());
  498. let state = 0 /* inMemberExp */;
  499. let stateStack = [];
  500. let currentOpenBracketCount = 0;
  501. let currentOpenParensCount = 0;
  502. let currentStringType = null;
  503. for (let i = 0; i < path.length; i++) {
  504. const char = path.charAt(i);
  505. switch (state) {
  506. case 0 /* inMemberExp */:
  507. if (char === "[") {
  508. stateStack.push(state);
  509. state = 1 /* inBrackets */;
  510. currentOpenBracketCount++;
  511. } else if (char === "(") {
  512. stateStack.push(state);
  513. state = 2 /* inParens */;
  514. currentOpenParensCount++;
  515. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  516. return false;
  517. }
  518. break;
  519. case 1 /* inBrackets */:
  520. if (char === `'` || char === `"` || char === "`") {
  521. stateStack.push(state);
  522. state = 3 /* inString */;
  523. currentStringType = char;
  524. } else if (char === `[`) {
  525. currentOpenBracketCount++;
  526. } else if (char === `]`) {
  527. if (!--currentOpenBracketCount) {
  528. state = stateStack.pop();
  529. }
  530. }
  531. break;
  532. case 2 /* inParens */:
  533. if (char === `'` || char === `"` || char === "`") {
  534. stateStack.push(state);
  535. state = 3 /* inString */;
  536. currentStringType = char;
  537. } else if (char === `(`) {
  538. currentOpenParensCount++;
  539. } else if (char === `)`) {
  540. if (i === path.length - 1) {
  541. return false;
  542. }
  543. if (!--currentOpenParensCount) {
  544. state = stateStack.pop();
  545. }
  546. }
  547. break;
  548. case 3 /* inString */:
  549. if (char === currentStringType) {
  550. state = stateStack.pop();
  551. currentStringType = null;
  552. }
  553. break;
  554. }
  555. }
  556. return !currentOpenBracketCount && !currentOpenParensCount;
  557. };
  558. const isMemberExpressionNode = NOOP ;
  559. const isMemberExpression = isMemberExpressionBrowser ;
  560. function getInnerRange(loc, offset, length) {
  561. const source = loc.source.slice(offset, offset + length);
  562. const newLoc = {
  563. source,
  564. start: advancePositionWithClone(loc.start, loc.source, offset),
  565. end: loc.end
  566. };
  567. if (length != null) {
  568. newLoc.end = advancePositionWithClone(
  569. loc.start,
  570. loc.source,
  571. offset + length
  572. );
  573. }
  574. return newLoc;
  575. }
  576. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  577. return advancePositionWithMutation(
  578. extend({}, pos),
  579. source,
  580. numberOfCharacters
  581. );
  582. }
  583. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  584. let linesCount = 0;
  585. let lastNewLinePos = -1;
  586. for (let i = 0; i < numberOfCharacters; i++) {
  587. if (source.charCodeAt(i) === 10) {
  588. linesCount++;
  589. lastNewLinePos = i;
  590. }
  591. }
  592. pos.offset += numberOfCharacters;
  593. pos.line += linesCount;
  594. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  595. return pos;
  596. }
  597. function assert(condition, msg) {
  598. if (!condition) {
  599. throw new Error(msg || `unexpected compiler condition`);
  600. }
  601. }
  602. function findDir(node, name, allowEmpty = false) {
  603. for (let i = 0; i < node.props.length; i++) {
  604. const p = node.props[i];
  605. if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) {
  606. return p;
  607. }
  608. }
  609. }
  610. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  611. for (let i = 0; i < node.props.length; i++) {
  612. const p = node.props[i];
  613. if (p.type === 6) {
  614. if (dynamicOnly)
  615. continue;
  616. if (p.name === name && (p.value || allowEmpty)) {
  617. return p;
  618. }
  619. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  620. return p;
  621. }
  622. }
  623. }
  624. function isStaticArgOf(arg, name) {
  625. return !!(arg && isStaticExp(arg) && arg.content === name);
  626. }
  627. function hasDynamicKeyVBind(node) {
  628. return node.props.some(
  629. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  630. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  631. !p.arg.isStatic)
  632. // v-bind:[foo]
  633. );
  634. }
  635. function isText$1(node) {
  636. return node.type === 5 || node.type === 2;
  637. }
  638. function isVSlot(p) {
  639. return p.type === 7 && p.name === "slot";
  640. }
  641. function isTemplateNode(node) {
  642. return node.type === 1 && node.tagType === 3;
  643. }
  644. function isSlotOutlet(node) {
  645. return node.type === 1 && node.tagType === 2;
  646. }
  647. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  648. function getUnnormalizedProps(props, callPath = []) {
  649. if (props && !isString(props) && props.type === 14) {
  650. const callee = props.callee;
  651. if (!isString(callee) && propsHelperSet.has(callee)) {
  652. return getUnnormalizedProps(
  653. props.arguments[0],
  654. callPath.concat(props)
  655. );
  656. }
  657. }
  658. return [props, callPath];
  659. }
  660. function injectProp(node, prop, context) {
  661. let propsWithInjection;
  662. let props = node.type === 13 ? node.props : node.arguments[2];
  663. let callPath = [];
  664. let parentCall;
  665. if (props && !isString(props) && props.type === 14) {
  666. const ret = getUnnormalizedProps(props);
  667. props = ret[0];
  668. callPath = ret[1];
  669. parentCall = callPath[callPath.length - 1];
  670. }
  671. if (props == null || isString(props)) {
  672. propsWithInjection = createObjectExpression([prop]);
  673. } else if (props.type === 14) {
  674. const first = props.arguments[0];
  675. if (!isString(first) && first.type === 15) {
  676. if (!hasProp(prop, first)) {
  677. first.properties.unshift(prop);
  678. }
  679. } else {
  680. if (props.callee === TO_HANDLERS) {
  681. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  682. createObjectExpression([prop]),
  683. props
  684. ]);
  685. } else {
  686. props.arguments.unshift(createObjectExpression([prop]));
  687. }
  688. }
  689. !propsWithInjection && (propsWithInjection = props);
  690. } else if (props.type === 15) {
  691. if (!hasProp(prop, props)) {
  692. props.properties.unshift(prop);
  693. }
  694. propsWithInjection = props;
  695. } else {
  696. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  697. createObjectExpression([prop]),
  698. props
  699. ]);
  700. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  701. parentCall = callPath[callPath.length - 2];
  702. }
  703. }
  704. if (node.type === 13) {
  705. if (parentCall) {
  706. parentCall.arguments[0] = propsWithInjection;
  707. } else {
  708. node.props = propsWithInjection;
  709. }
  710. } else {
  711. if (parentCall) {
  712. parentCall.arguments[0] = propsWithInjection;
  713. } else {
  714. node.arguments[2] = propsWithInjection;
  715. }
  716. }
  717. }
  718. function hasProp(prop, props) {
  719. let result = false;
  720. if (prop.key.type === 4) {
  721. const propKeyName = prop.key.content;
  722. result = props.properties.some(
  723. (p) => p.key.type === 4 && p.key.content === propKeyName
  724. );
  725. }
  726. return result;
  727. }
  728. function toValidAssetId(name, type) {
  729. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  730. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  731. })}`;
  732. }
  733. function hasScopeRef(node, ids) {
  734. if (!node || Object.keys(ids).length === 0) {
  735. return false;
  736. }
  737. switch (node.type) {
  738. case 1:
  739. for (let i = 0; i < node.props.length; i++) {
  740. const p = node.props[i];
  741. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  742. return true;
  743. }
  744. }
  745. return node.children.some((c) => hasScopeRef(c, ids));
  746. case 11:
  747. if (hasScopeRef(node.source, ids)) {
  748. return true;
  749. }
  750. return node.children.some((c) => hasScopeRef(c, ids));
  751. case 9:
  752. return node.branches.some((b) => hasScopeRef(b, ids));
  753. case 10:
  754. if (hasScopeRef(node.condition, ids)) {
  755. return true;
  756. }
  757. return node.children.some((c) => hasScopeRef(c, ids));
  758. case 4:
  759. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  760. case 8:
  761. return node.children.some((c) => isObject(c) && hasScopeRef(c, ids));
  762. case 5:
  763. case 12:
  764. return hasScopeRef(node.content, ids);
  765. case 2:
  766. case 3:
  767. return false;
  768. default:
  769. return false;
  770. }
  771. }
  772. function getMemoedVNodeCall(node) {
  773. if (node.type === 14 && node.callee === WITH_MEMO) {
  774. return node.arguments[1].returns;
  775. } else {
  776. return node;
  777. }
  778. }
  779. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  780. const deprecationData = {
  781. ["COMPILER_IS_ON_ELEMENT"]: {
  782. message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`,
  783. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  784. },
  785. ["COMPILER_V_BIND_SYNC"]: {
  786. message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`,
  787. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  788. },
  789. ["COMPILER_V_BIND_PROP"]: {
  790. message: `.prop modifier for v-bind has been removed and no longer necessary. Vue 3 will automatically set a binding as DOM property when appropriate.`
  791. },
  792. ["COMPILER_V_BIND_OBJECT_ORDER"]: {
  793. message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.`,
  794. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  795. },
  796. ["COMPILER_V_ON_NATIVE"]: {
  797. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  798. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  799. },
  800. ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
  801. message: `v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.`,
  802. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  803. },
  804. ["COMPILER_NATIVE_TEMPLATE"]: {
  805. message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
  806. },
  807. ["COMPILER_INLINE_TEMPLATE"]: {
  808. message: `"inline-template" has been removed in Vue 3.`,
  809. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  810. },
  811. ["COMPILER_FILTER"]: {
  812. message: `filters have been removed in Vue 3. The "|" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.`,
  813. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  814. }
  815. };
  816. function getCompatValue(key, context) {
  817. const config = context.options ? context.options.compatConfig : context.compatConfig;
  818. const value = config && config[key];
  819. if (key === "MODE") {
  820. return value || 3;
  821. } else {
  822. return value;
  823. }
  824. }
  825. function isCompatEnabled(key, context) {
  826. const mode = getCompatValue("MODE", context);
  827. const value = getCompatValue(key, context);
  828. return mode === 3 ? value === true : value !== false;
  829. }
  830. function checkCompatEnabled(key, context, loc, ...args) {
  831. const enabled = isCompatEnabled(key, context);
  832. if (enabled) {
  833. warnDeprecation(key, context, loc, ...args);
  834. }
  835. return enabled;
  836. }
  837. function warnDeprecation(key, context, loc, ...args) {
  838. const val = getCompatValue(key, context);
  839. if (val === "suppress-warning") {
  840. return;
  841. }
  842. const { message, link } = deprecationData[key];
  843. const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
  844. Details: ${link}` : ``}`;
  845. const err = new SyntaxError(msg);
  846. err.code = key;
  847. if (loc)
  848. err.loc = loc;
  849. context.onWarn(err);
  850. }
  851. const decodeRE = /&(gt|lt|amp|apos|quot);/g;
  852. const decodeMap = {
  853. gt: ">",
  854. lt: "<",
  855. amp: "&",
  856. apos: "'",
  857. quot: '"'
  858. };
  859. const defaultParserOptions = {
  860. delimiters: [`{{`, `}}`],
  861. getNamespace: () => 0,
  862. getTextMode: () => 0,
  863. isVoidTag: NO,
  864. isPreTag: NO,
  865. isCustomElement: NO,
  866. decodeEntities: (rawText) => rawText.replace(decodeRE, (_, p1) => decodeMap[p1]),
  867. onError: defaultOnError,
  868. onWarn: defaultOnWarn,
  869. comments: true
  870. };
  871. function baseParse(content, options = {}) {
  872. const context = createParserContext(content, options);
  873. const start = getCursor(context);
  874. return createRoot(
  875. parseChildren(context, 0, []),
  876. getSelection(context, start)
  877. );
  878. }
  879. function createParserContext(content, rawOptions) {
  880. const options = extend({}, defaultParserOptions);
  881. let key;
  882. for (key in rawOptions) {
  883. options[key] = rawOptions[key] === void 0 ? defaultParserOptions[key] : rawOptions[key];
  884. }
  885. return {
  886. options,
  887. column: 1,
  888. line: 1,
  889. offset: 0,
  890. originalSource: content,
  891. source: content,
  892. inPre: false,
  893. inVPre: false,
  894. onWarn: options.onWarn
  895. };
  896. }
  897. function parseChildren(context, mode, ancestors) {
  898. const parent = last(ancestors);
  899. const ns = parent ? parent.ns : 0;
  900. const nodes = [];
  901. while (!isEnd(context, mode, ancestors)) {
  902. const s = context.source;
  903. let node = void 0;
  904. if (mode === 0 || mode === 1) {
  905. if (!context.inVPre && startsWith(s, context.options.delimiters[0])) {
  906. node = parseInterpolation(context, mode);
  907. } else if (mode === 0 && s[0] === "<") {
  908. if (s.length === 1) {
  909. emitError(context, 5, 1);
  910. } else if (s[1] === "!") {
  911. if (startsWith(s, "<!--")) {
  912. node = parseComment(context);
  913. } else if (startsWith(s, "<!DOCTYPE")) {
  914. node = parseBogusComment(context);
  915. } else if (startsWith(s, "<![CDATA[")) {
  916. if (ns !== 0) {
  917. node = parseCDATA(context, ancestors);
  918. } else {
  919. emitError(context, 1);
  920. node = parseBogusComment(context);
  921. }
  922. } else {
  923. emitError(context, 11);
  924. node = parseBogusComment(context);
  925. }
  926. } else if (s[1] === "/") {
  927. if (s.length === 2) {
  928. emitError(context, 5, 2);
  929. } else if (s[2] === ">") {
  930. emitError(context, 14, 2);
  931. advanceBy(context, 3);
  932. continue;
  933. } else if (/[a-z]/i.test(s[2])) {
  934. emitError(context, 23);
  935. parseTag(context, 1 /* End */, parent);
  936. continue;
  937. } else {
  938. emitError(
  939. context,
  940. 12,
  941. 2
  942. );
  943. node = parseBogusComment(context);
  944. }
  945. } else if (/[a-z]/i.test(s[1])) {
  946. node = parseElement(context, ancestors);
  947. if (isCompatEnabled(
  948. "COMPILER_NATIVE_TEMPLATE",
  949. context
  950. ) && node && node.tag === "template" && !node.props.some(
  951. (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
  952. )) {
  953. warnDeprecation(
  954. "COMPILER_NATIVE_TEMPLATE",
  955. context,
  956. node.loc
  957. );
  958. node = node.children;
  959. }
  960. } else if (s[1] === "?") {
  961. emitError(
  962. context,
  963. 21,
  964. 1
  965. );
  966. node = parseBogusComment(context);
  967. } else {
  968. emitError(context, 12, 1);
  969. }
  970. }
  971. }
  972. if (!node) {
  973. node = parseText(context, mode);
  974. }
  975. if (isArray(node)) {
  976. for (let i = 0; i < node.length; i++) {
  977. pushNode(nodes, node[i]);
  978. }
  979. } else {
  980. pushNode(nodes, node);
  981. }
  982. }
  983. let removedWhitespace = false;
  984. if (mode !== 2 && mode !== 1) {
  985. const shouldCondense = context.options.whitespace !== "preserve";
  986. for (let i = 0; i < nodes.length; i++) {
  987. const node = nodes[i];
  988. if (node.type === 2) {
  989. if (!context.inPre) {
  990. if (!/[^\t\r\n\f ]/.test(node.content)) {
  991. const prev = nodes[i - 1];
  992. const next = nodes[i + 1];
  993. if (!prev || !next || shouldCondense && (prev.type === 3 && next.type === 3 || prev.type === 3 && next.type === 1 || prev.type === 1 && next.type === 3 || prev.type === 1 && next.type === 1 && /[\r\n]/.test(node.content))) {
  994. removedWhitespace = true;
  995. nodes[i] = null;
  996. } else {
  997. node.content = " ";
  998. }
  999. } else if (shouldCondense) {
  1000. node.content = node.content.replace(/[\t\r\n\f ]+/g, " ");
  1001. }
  1002. } else {
  1003. node.content = node.content.replace(/\r\n/g, "\n");
  1004. }
  1005. } else if (node.type === 3 && !context.options.comments) {
  1006. removedWhitespace = true;
  1007. nodes[i] = null;
  1008. }
  1009. }
  1010. if (context.inPre && parent && context.options.isPreTag(parent.tag)) {
  1011. const first = nodes[0];
  1012. if (first && first.type === 2) {
  1013. first.content = first.content.replace(/^\r?\n/, "");
  1014. }
  1015. }
  1016. }
  1017. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  1018. }
  1019. function pushNode(nodes, node) {
  1020. if (node.type === 2) {
  1021. const prev = last(nodes);
  1022. if (prev && prev.type === 2 && prev.loc.end.offset === node.loc.start.offset) {
  1023. prev.content += node.content;
  1024. prev.loc.end = node.loc.end;
  1025. prev.loc.source += node.loc.source;
  1026. return;
  1027. }
  1028. }
  1029. nodes.push(node);
  1030. }
  1031. function parseCDATA(context, ancestors) {
  1032. advanceBy(context, 9);
  1033. const nodes = parseChildren(context, 3, ancestors);
  1034. if (context.source.length === 0) {
  1035. emitError(context, 6);
  1036. } else {
  1037. advanceBy(context, 3);
  1038. }
  1039. return nodes;
  1040. }
  1041. function parseComment(context) {
  1042. const start = getCursor(context);
  1043. let content;
  1044. const match = /--(\!)?>/.exec(context.source);
  1045. if (!match) {
  1046. content = context.source.slice(4);
  1047. advanceBy(context, context.source.length);
  1048. emitError(context, 7);
  1049. } else {
  1050. if (match.index <= 3) {
  1051. emitError(context, 0);
  1052. }
  1053. if (match[1]) {
  1054. emitError(context, 10);
  1055. }
  1056. content = context.source.slice(4, match.index);
  1057. const s = context.source.slice(0, match.index);
  1058. let prevIndex = 1, nestedIndex = 0;
  1059. while ((nestedIndex = s.indexOf("<!--", prevIndex)) !== -1) {
  1060. advanceBy(context, nestedIndex - prevIndex + 1);
  1061. if (nestedIndex + 4 < s.length) {
  1062. emitError(context, 16);
  1063. }
  1064. prevIndex = nestedIndex + 1;
  1065. }
  1066. advanceBy(context, match.index + match[0].length - prevIndex + 1);
  1067. }
  1068. return {
  1069. type: 3,
  1070. content,
  1071. loc: getSelection(context, start)
  1072. };
  1073. }
  1074. function parseBogusComment(context) {
  1075. const start = getCursor(context);
  1076. const contentStart = context.source[1] === "?" ? 1 : 2;
  1077. let content;
  1078. const closeIndex = context.source.indexOf(">");
  1079. if (closeIndex === -1) {
  1080. content = context.source.slice(contentStart);
  1081. advanceBy(context, context.source.length);
  1082. } else {
  1083. content = context.source.slice(contentStart, closeIndex);
  1084. advanceBy(context, closeIndex + 1);
  1085. }
  1086. return {
  1087. type: 3,
  1088. content,
  1089. loc: getSelection(context, start)
  1090. };
  1091. }
  1092. function parseElement(context, ancestors) {
  1093. const wasInPre = context.inPre;
  1094. const wasInVPre = context.inVPre;
  1095. const parent = last(ancestors);
  1096. const element = parseTag(context, 0 /* Start */, parent);
  1097. const isPreBoundary = context.inPre && !wasInPre;
  1098. const isVPreBoundary = context.inVPre && !wasInVPre;
  1099. if (element.isSelfClosing || context.options.isVoidTag(element.tag)) {
  1100. if (isPreBoundary) {
  1101. context.inPre = false;
  1102. }
  1103. if (isVPreBoundary) {
  1104. context.inVPre = false;
  1105. }
  1106. return element;
  1107. }
  1108. ancestors.push(element);
  1109. const mode = context.options.getTextMode(element, parent);
  1110. const children = parseChildren(context, mode, ancestors);
  1111. ancestors.pop();
  1112. {
  1113. const inlineTemplateProp = element.props.find(
  1114. (p) => p.type === 6 && p.name === "inline-template"
  1115. );
  1116. if (inlineTemplateProp && checkCompatEnabled(
  1117. "COMPILER_INLINE_TEMPLATE",
  1118. context,
  1119. inlineTemplateProp.loc
  1120. )) {
  1121. const loc = getSelection(context, element.loc.end);
  1122. inlineTemplateProp.value = {
  1123. type: 2,
  1124. content: loc.source,
  1125. loc
  1126. };
  1127. }
  1128. }
  1129. element.children = children;
  1130. if (startsWithEndTagOpen(context.source, element.tag)) {
  1131. parseTag(context, 1 /* End */, parent);
  1132. } else {
  1133. emitError(context, 24, 0, element.loc.start);
  1134. if (context.source.length === 0 && element.tag.toLowerCase() === "script") {
  1135. const first = children[0];
  1136. if (first && startsWith(first.loc.source, "<!--")) {
  1137. emitError(context, 8);
  1138. }
  1139. }
  1140. }
  1141. element.loc = getSelection(context, element.loc.start);
  1142. if (isPreBoundary) {
  1143. context.inPre = false;
  1144. }
  1145. if (isVPreBoundary) {
  1146. context.inVPre = false;
  1147. }
  1148. return element;
  1149. }
  1150. const isSpecialTemplateDirective = /* @__PURE__ */ makeMap(
  1151. `if,else,else-if,for,slot`
  1152. );
  1153. function parseTag(context, type, parent) {
  1154. const start = getCursor(context);
  1155. const match = /^<\/?([a-z][^\t\r\n\f />]*)/i.exec(context.source);
  1156. const tag = match[1];
  1157. const ns = context.options.getNamespace(tag, parent);
  1158. advanceBy(context, match[0].length);
  1159. advanceSpaces(context);
  1160. const cursor = getCursor(context);
  1161. const currentSource = context.source;
  1162. if (context.options.isPreTag(tag)) {
  1163. context.inPre = true;
  1164. }
  1165. let props = parseAttributes(context, type);
  1166. if (type === 0 /* Start */ && !context.inVPre && props.some((p) => p.type === 7 && p.name === "pre")) {
  1167. context.inVPre = true;
  1168. extend(context, cursor);
  1169. context.source = currentSource;
  1170. props = parseAttributes(context, type).filter((p) => p.name !== "v-pre");
  1171. }
  1172. let isSelfClosing = false;
  1173. if (context.source.length === 0) {
  1174. emitError(context, 9);
  1175. } else {
  1176. isSelfClosing = startsWith(context.source, "/>");
  1177. if (type === 1 /* End */ && isSelfClosing) {
  1178. emitError(context, 4);
  1179. }
  1180. advanceBy(context, isSelfClosing ? 2 : 1);
  1181. }
  1182. if (type === 1 /* End */) {
  1183. return;
  1184. }
  1185. if (isCompatEnabled(
  1186. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  1187. context
  1188. )) {
  1189. let hasIf = false;
  1190. let hasFor = false;
  1191. for (let i = 0; i < props.length; i++) {
  1192. const p = props[i];
  1193. if (p.type === 7) {
  1194. if (p.name === "if") {
  1195. hasIf = true;
  1196. } else if (p.name === "for") {
  1197. hasFor = true;
  1198. }
  1199. }
  1200. if (hasIf && hasFor) {
  1201. warnDeprecation(
  1202. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  1203. context,
  1204. getSelection(context, start)
  1205. );
  1206. break;
  1207. }
  1208. }
  1209. }
  1210. let tagType = 0;
  1211. if (!context.inVPre) {
  1212. if (tag === "slot") {
  1213. tagType = 2;
  1214. } else if (tag === "template") {
  1215. if (props.some(
  1216. (p) => p.type === 7 && isSpecialTemplateDirective(p.name)
  1217. )) {
  1218. tagType = 3;
  1219. }
  1220. } else if (isComponent(tag, props, context)) {
  1221. tagType = 1;
  1222. }
  1223. }
  1224. return {
  1225. type: 1,
  1226. ns,
  1227. tag,
  1228. tagType,
  1229. props,
  1230. isSelfClosing,
  1231. children: [],
  1232. loc: getSelection(context, start),
  1233. codegenNode: void 0
  1234. // to be created during transform phase
  1235. };
  1236. }
  1237. function isComponent(tag, props, context) {
  1238. const options = context.options;
  1239. if (options.isCustomElement(tag)) {
  1240. return false;
  1241. }
  1242. if (tag === "component" || /^[A-Z]/.test(tag) || isCoreComponent(tag) || options.isBuiltInComponent && options.isBuiltInComponent(tag) || options.isNativeTag && !options.isNativeTag(tag)) {
  1243. return true;
  1244. }
  1245. for (let i = 0; i < props.length; i++) {
  1246. const p = props[i];
  1247. if (p.type === 6) {
  1248. if (p.name === "is" && p.value) {
  1249. if (p.value.content.startsWith("vue:")) {
  1250. return true;
  1251. } else if (checkCompatEnabled(
  1252. "COMPILER_IS_ON_ELEMENT",
  1253. context,
  1254. p.loc
  1255. )) {
  1256. return true;
  1257. }
  1258. }
  1259. } else {
  1260. if (p.name === "is") {
  1261. return true;
  1262. } else if (
  1263. // :is on plain element - only treat as component in compat mode
  1264. p.name === "bind" && isStaticArgOf(p.arg, "is") && true && checkCompatEnabled(
  1265. "COMPILER_IS_ON_ELEMENT",
  1266. context,
  1267. p.loc
  1268. )
  1269. ) {
  1270. return true;
  1271. }
  1272. }
  1273. }
  1274. }
  1275. function parseAttributes(context, type) {
  1276. const props = [];
  1277. const attributeNames = /* @__PURE__ */ new Set();
  1278. while (context.source.length > 0 && !startsWith(context.source, ">") && !startsWith(context.source, "/>")) {
  1279. if (startsWith(context.source, "/")) {
  1280. emitError(context, 22);
  1281. advanceBy(context, 1);
  1282. advanceSpaces(context);
  1283. continue;
  1284. }
  1285. if (type === 1 /* End */) {
  1286. emitError(context, 3);
  1287. }
  1288. const attr = parseAttribute(context, attributeNames);
  1289. if (attr.type === 6 && attr.value && attr.name === "class") {
  1290. attr.value.content = attr.value.content.replace(/\s+/g, " ").trim();
  1291. }
  1292. if (type === 0 /* Start */) {
  1293. props.push(attr);
  1294. }
  1295. if (/^[^\t\r\n\f />]/.test(context.source)) {
  1296. emitError(context, 15);
  1297. }
  1298. advanceSpaces(context);
  1299. }
  1300. return props;
  1301. }
  1302. function parseAttribute(context, nameSet) {
  1303. var _a;
  1304. const start = getCursor(context);
  1305. const match = /^[^\t\r\n\f />][^\t\r\n\f />=]*/.exec(context.source);
  1306. const name = match[0];
  1307. if (nameSet.has(name)) {
  1308. emitError(context, 2);
  1309. }
  1310. nameSet.add(name);
  1311. if (name[0] === "=") {
  1312. emitError(context, 19);
  1313. }
  1314. {
  1315. const pattern = /["'<]/g;
  1316. let m;
  1317. while (m = pattern.exec(name)) {
  1318. emitError(
  1319. context,
  1320. 17,
  1321. m.index
  1322. );
  1323. }
  1324. }
  1325. advanceBy(context, name.length);
  1326. let value = void 0;
  1327. if (/^[\t\r\n\f ]*=/.test(context.source)) {
  1328. advanceSpaces(context);
  1329. advanceBy(context, 1);
  1330. advanceSpaces(context);
  1331. value = parseAttributeValue(context);
  1332. if (!value) {
  1333. emitError(context, 13);
  1334. }
  1335. }
  1336. const loc = getSelection(context, start);
  1337. if (!context.inVPre && /^(v-[A-Za-z0-9-]|:|\.|@|#)/.test(name)) {
  1338. const match2 = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
  1339. name
  1340. );
  1341. let isPropShorthand = startsWith(name, ".");
  1342. let dirName = match2[1] || (isPropShorthand || startsWith(name, ":") ? "bind" : startsWith(name, "@") ? "on" : "slot");
  1343. let arg;
  1344. if (match2[2]) {
  1345. const isSlot = dirName === "slot";
  1346. const startOffset = name.lastIndexOf(
  1347. match2[2],
  1348. name.length - (((_a = match2[3]) == null ? void 0 : _a.length) || 0)
  1349. );
  1350. const loc2 = getSelection(
  1351. context,
  1352. getNewPosition(context, start, startOffset),
  1353. getNewPosition(
  1354. context,
  1355. start,
  1356. startOffset + match2[2].length + (isSlot && match2[3] || "").length
  1357. )
  1358. );
  1359. let content = match2[2];
  1360. let isStatic = true;
  1361. if (content.startsWith("[")) {
  1362. isStatic = false;
  1363. if (!content.endsWith("]")) {
  1364. emitError(
  1365. context,
  1366. 27
  1367. );
  1368. content = content.slice(1);
  1369. } else {
  1370. content = content.slice(1, content.length - 1);
  1371. }
  1372. } else if (isSlot) {
  1373. content += match2[3] || "";
  1374. }
  1375. arg = {
  1376. type: 4,
  1377. content,
  1378. isStatic,
  1379. constType: isStatic ? 3 : 0,
  1380. loc: loc2
  1381. };
  1382. }
  1383. if (value && value.isQuoted) {
  1384. const valueLoc = value.loc;
  1385. valueLoc.start.offset++;
  1386. valueLoc.start.column++;
  1387. valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
  1388. valueLoc.source = valueLoc.source.slice(1, -1);
  1389. }
  1390. const modifiers = match2[3] ? match2[3].slice(1).split(".") : [];
  1391. if (isPropShorthand)
  1392. modifiers.push("prop");
  1393. if (dirName === "bind" && arg) {
  1394. if (modifiers.includes("sync") && checkCompatEnabled(
  1395. "COMPILER_V_BIND_SYNC",
  1396. context,
  1397. loc,
  1398. arg.loc.source
  1399. )) {
  1400. dirName = "model";
  1401. modifiers.splice(modifiers.indexOf("sync"), 1);
  1402. }
  1403. if (modifiers.includes("prop")) {
  1404. checkCompatEnabled(
  1405. "COMPILER_V_BIND_PROP",
  1406. context,
  1407. loc
  1408. );
  1409. }
  1410. }
  1411. return {
  1412. type: 7,
  1413. name: dirName,
  1414. exp: value && {
  1415. type: 4,
  1416. content: value.content,
  1417. isStatic: false,
  1418. // Treat as non-constant by default. This can be potentially set to
  1419. // other values by `transformExpression` to make it eligible for hoisting.
  1420. constType: 0,
  1421. loc: value.loc
  1422. },
  1423. arg,
  1424. modifiers,
  1425. loc
  1426. };
  1427. }
  1428. if (!context.inVPre && startsWith(name, "v-")) {
  1429. emitError(context, 26);
  1430. }
  1431. return {
  1432. type: 6,
  1433. name,
  1434. value: value && {
  1435. type: 2,
  1436. content: value.content,
  1437. loc: value.loc
  1438. },
  1439. loc
  1440. };
  1441. }
  1442. function parseAttributeValue(context) {
  1443. const start = getCursor(context);
  1444. let content;
  1445. const quote = context.source[0];
  1446. const isQuoted = quote === `"` || quote === `'`;
  1447. if (isQuoted) {
  1448. advanceBy(context, 1);
  1449. const endIndex = context.source.indexOf(quote);
  1450. if (endIndex === -1) {
  1451. content = parseTextData(
  1452. context,
  1453. context.source.length,
  1454. 4
  1455. );
  1456. } else {
  1457. content = parseTextData(context, endIndex, 4);
  1458. advanceBy(context, 1);
  1459. }
  1460. } else {
  1461. const match = /^[^\t\r\n\f >]+/.exec(context.source);
  1462. if (!match) {
  1463. return void 0;
  1464. }
  1465. const unexpectedChars = /["'<=`]/g;
  1466. let m;
  1467. while (m = unexpectedChars.exec(match[0])) {
  1468. emitError(
  1469. context,
  1470. 18,
  1471. m.index
  1472. );
  1473. }
  1474. content = parseTextData(context, match[0].length, 4);
  1475. }
  1476. return { content, isQuoted, loc: getSelection(context, start) };
  1477. }
  1478. function parseInterpolation(context, mode) {
  1479. const [open, close] = context.options.delimiters;
  1480. const closeIndex = context.source.indexOf(close, open.length);
  1481. if (closeIndex === -1) {
  1482. emitError(context, 25);
  1483. return void 0;
  1484. }
  1485. const start = getCursor(context);
  1486. advanceBy(context, open.length);
  1487. const innerStart = getCursor(context);
  1488. const innerEnd = getCursor(context);
  1489. const rawContentLength = closeIndex - open.length;
  1490. const rawContent = context.source.slice(0, rawContentLength);
  1491. const preTrimContent = parseTextData(context, rawContentLength, mode);
  1492. const content = preTrimContent.trim();
  1493. const startOffset = preTrimContent.indexOf(content);
  1494. if (startOffset > 0) {
  1495. advancePositionWithMutation(innerStart, rawContent, startOffset);
  1496. }
  1497. const endOffset = rawContentLength - (preTrimContent.length - content.length - startOffset);
  1498. advancePositionWithMutation(innerEnd, rawContent, endOffset);
  1499. advanceBy(context, close.length);
  1500. return {
  1501. type: 5,
  1502. content: {
  1503. type: 4,
  1504. isStatic: false,
  1505. // Set `isConstant` to false by default and will decide in transformExpression
  1506. constType: 0,
  1507. content,
  1508. loc: getSelection(context, innerStart, innerEnd)
  1509. },
  1510. loc: getSelection(context, start)
  1511. };
  1512. }
  1513. function parseText(context, mode) {
  1514. const endTokens = mode === 3 ? ["]]>"] : ["<", context.options.delimiters[0]];
  1515. let endIndex = context.source.length;
  1516. for (let i = 0; i < endTokens.length; i++) {
  1517. const index = context.source.indexOf(endTokens[i], 1);
  1518. if (index !== -1 && endIndex > index) {
  1519. endIndex = index;
  1520. }
  1521. }
  1522. const start = getCursor(context);
  1523. const content = parseTextData(context, endIndex, mode);
  1524. return {
  1525. type: 2,
  1526. content,
  1527. loc: getSelection(context, start)
  1528. };
  1529. }
  1530. function parseTextData(context, length, mode) {
  1531. const rawText = context.source.slice(0, length);
  1532. advanceBy(context, length);
  1533. if (mode === 2 || mode === 3 || !rawText.includes("&")) {
  1534. return rawText;
  1535. } else {
  1536. return context.options.decodeEntities(
  1537. rawText,
  1538. mode === 4
  1539. );
  1540. }
  1541. }
  1542. function getCursor(context) {
  1543. const { column, line, offset } = context;
  1544. return { column, line, offset };
  1545. }
  1546. function getSelection(context, start, end) {
  1547. end = end || getCursor(context);
  1548. return {
  1549. start,
  1550. end,
  1551. source: context.originalSource.slice(start.offset, end.offset)
  1552. };
  1553. }
  1554. function last(xs) {
  1555. return xs[xs.length - 1];
  1556. }
  1557. function startsWith(source, searchString) {
  1558. return source.startsWith(searchString);
  1559. }
  1560. function advanceBy(context, numberOfCharacters) {
  1561. const { source } = context;
  1562. advancePositionWithMutation(context, source, numberOfCharacters);
  1563. context.source = source.slice(numberOfCharacters);
  1564. }
  1565. function advanceSpaces(context) {
  1566. const match = /^[\t\r\n\f ]+/.exec(context.source);
  1567. if (match) {
  1568. advanceBy(context, match[0].length);
  1569. }
  1570. }
  1571. function getNewPosition(context, start, numberOfCharacters) {
  1572. return advancePositionWithClone(
  1573. start,
  1574. context.originalSource.slice(start.offset, numberOfCharacters),
  1575. numberOfCharacters
  1576. );
  1577. }
  1578. function emitError(context, code, offset, loc = getCursor(context)) {
  1579. if (offset) {
  1580. loc.offset += offset;
  1581. loc.column += offset;
  1582. }
  1583. context.options.onError(
  1584. createCompilerError(code, {
  1585. start: loc,
  1586. end: loc,
  1587. source: ""
  1588. })
  1589. );
  1590. }
  1591. function isEnd(context, mode, ancestors) {
  1592. const s = context.source;
  1593. switch (mode) {
  1594. case 0:
  1595. if (startsWith(s, "</")) {
  1596. for (let i = ancestors.length - 1; i >= 0; --i) {
  1597. if (startsWithEndTagOpen(s, ancestors[i].tag)) {
  1598. return true;
  1599. }
  1600. }
  1601. }
  1602. break;
  1603. case 1:
  1604. case 2: {
  1605. const parent = last(ancestors);
  1606. if (parent && startsWithEndTagOpen(s, parent.tag)) {
  1607. return true;
  1608. }
  1609. break;
  1610. }
  1611. case 3:
  1612. if (startsWith(s, "]]>")) {
  1613. return true;
  1614. }
  1615. break;
  1616. }
  1617. return !s;
  1618. }
  1619. function startsWithEndTagOpen(source, tag) {
  1620. return startsWith(source, "</") && source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() && /[\t\r\n\f />]/.test(source[2 + tag.length] || ">");
  1621. }
  1622. function hoistStatic(root, context) {
  1623. walk(
  1624. root,
  1625. context,
  1626. // Root node is unfortunately non-hoistable due to potential parent
  1627. // fallthrough attributes.
  1628. isSingleElementRoot(root, root.children[0])
  1629. );
  1630. }
  1631. function isSingleElementRoot(root, child) {
  1632. const { children } = root;
  1633. return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
  1634. }
  1635. function walk(node, context, doNotHoistNode = false) {
  1636. const { children } = node;
  1637. const originalCount = children.length;
  1638. let hoistedCount = 0;
  1639. for (let i = 0; i < children.length; i++) {
  1640. const child = children[i];
  1641. if (child.type === 1 && child.tagType === 0) {
  1642. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  1643. if (constantType > 0) {
  1644. if (constantType >= 2) {
  1645. child.codegenNode.patchFlag = -1 + (` /* HOISTED */` );
  1646. child.codegenNode = context.hoist(child.codegenNode);
  1647. hoistedCount++;
  1648. continue;
  1649. }
  1650. } else {
  1651. const codegenNode = child.codegenNode;
  1652. if (codegenNode.type === 13) {
  1653. const flag = getPatchFlag(codegenNode);
  1654. if ((!flag || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  1655. const props = getNodeProps(child);
  1656. if (props) {
  1657. codegenNode.props = context.hoist(props);
  1658. }
  1659. }
  1660. if (codegenNode.dynamicProps) {
  1661. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  1662. }
  1663. }
  1664. }
  1665. }
  1666. if (child.type === 1) {
  1667. const isComponent = child.tagType === 1;
  1668. if (isComponent) {
  1669. context.scopes.vSlot++;
  1670. }
  1671. walk(child, context);
  1672. if (isComponent) {
  1673. context.scopes.vSlot--;
  1674. }
  1675. } else if (child.type === 11) {
  1676. walk(child, context, child.children.length === 1);
  1677. } else if (child.type === 9) {
  1678. for (let i2 = 0; i2 < child.branches.length; i2++) {
  1679. walk(
  1680. child.branches[i2],
  1681. context,
  1682. child.branches[i2].children.length === 1
  1683. );
  1684. }
  1685. }
  1686. }
  1687. if (hoistedCount && context.transformHoist) {
  1688. context.transformHoist(children, context, node);
  1689. }
  1690. if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
  1691. const hoisted = context.hoist(
  1692. createArrayExpression(node.codegenNode.children)
  1693. );
  1694. if (context.hmr) {
  1695. hoisted.content = `[...${hoisted.content}]`;
  1696. }
  1697. node.codegenNode.children = hoisted;
  1698. }
  1699. }
  1700. function getConstantType(node, context) {
  1701. const { constantCache } = context;
  1702. switch (node.type) {
  1703. case 1:
  1704. if (node.tagType !== 0) {
  1705. return 0;
  1706. }
  1707. const cached = constantCache.get(node);
  1708. if (cached !== void 0) {
  1709. return cached;
  1710. }
  1711. const codegenNode = node.codegenNode;
  1712. if (codegenNode.type !== 13) {
  1713. return 0;
  1714. }
  1715. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
  1716. return 0;
  1717. }
  1718. const flag = getPatchFlag(codegenNode);
  1719. if (!flag) {
  1720. let returnType2 = 3;
  1721. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  1722. if (generatedPropsType === 0) {
  1723. constantCache.set(node, 0);
  1724. return 0;
  1725. }
  1726. if (generatedPropsType < returnType2) {
  1727. returnType2 = generatedPropsType;
  1728. }
  1729. for (let i = 0; i < node.children.length; i++) {
  1730. const childType = getConstantType(node.children[i], context);
  1731. if (childType === 0) {
  1732. constantCache.set(node, 0);
  1733. return 0;
  1734. }
  1735. if (childType < returnType2) {
  1736. returnType2 = childType;
  1737. }
  1738. }
  1739. if (returnType2 > 1) {
  1740. for (let i = 0; i < node.props.length; i++) {
  1741. const p = node.props[i];
  1742. if (p.type === 7 && p.name === "bind" && p.exp) {
  1743. const expType = getConstantType(p.exp, context);
  1744. if (expType === 0) {
  1745. constantCache.set(node, 0);
  1746. return 0;
  1747. }
  1748. if (expType < returnType2) {
  1749. returnType2 = expType;
  1750. }
  1751. }
  1752. }
  1753. }
  1754. if (codegenNode.isBlock) {
  1755. for (let i = 0; i < node.props.length; i++) {
  1756. const p = node.props[i];
  1757. if (p.type === 7) {
  1758. constantCache.set(node, 0);
  1759. return 0;
  1760. }
  1761. }
  1762. context.removeHelper(OPEN_BLOCK);
  1763. context.removeHelper(
  1764. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  1765. );
  1766. codegenNode.isBlock = false;
  1767. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  1768. }
  1769. constantCache.set(node, returnType2);
  1770. return returnType2;
  1771. } else {
  1772. constantCache.set(node, 0);
  1773. return 0;
  1774. }
  1775. case 2:
  1776. case 3:
  1777. return 3;
  1778. case 9:
  1779. case 11:
  1780. case 10:
  1781. return 0;
  1782. case 5:
  1783. case 12:
  1784. return getConstantType(node.content, context);
  1785. case 4:
  1786. return node.constType;
  1787. case 8:
  1788. let returnType = 3;
  1789. for (let i = 0; i < node.children.length; i++) {
  1790. const child = node.children[i];
  1791. if (isString(child) || isSymbol(child)) {
  1792. continue;
  1793. }
  1794. const childType = getConstantType(child, context);
  1795. if (childType === 0) {
  1796. return 0;
  1797. } else if (childType < returnType) {
  1798. returnType = childType;
  1799. }
  1800. }
  1801. return returnType;
  1802. default:
  1803. return 0;
  1804. }
  1805. }
  1806. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  1807. NORMALIZE_CLASS,
  1808. NORMALIZE_STYLE,
  1809. NORMALIZE_PROPS,
  1810. GUARD_REACTIVE_PROPS
  1811. ]);
  1812. function getConstantTypeOfHelperCall(value, context) {
  1813. if (value.type === 14 && !isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  1814. const arg = value.arguments[0];
  1815. if (arg.type === 4) {
  1816. return getConstantType(arg, context);
  1817. } else if (arg.type === 14) {
  1818. return getConstantTypeOfHelperCall(arg, context);
  1819. }
  1820. }
  1821. return 0;
  1822. }
  1823. function getGeneratedPropsConstantType(node, context) {
  1824. let returnType = 3;
  1825. const props = getNodeProps(node);
  1826. if (props && props.type === 15) {
  1827. const { properties } = props;
  1828. for (let i = 0; i < properties.length; i++) {
  1829. const { key, value } = properties[i];
  1830. const keyType = getConstantType(key, context);
  1831. if (keyType === 0) {
  1832. return keyType;
  1833. }
  1834. if (keyType < returnType) {
  1835. returnType = keyType;
  1836. }
  1837. let valueType;
  1838. if (value.type === 4) {
  1839. valueType = getConstantType(value, context);
  1840. } else if (value.type === 14) {
  1841. valueType = getConstantTypeOfHelperCall(value, context);
  1842. } else {
  1843. valueType = 0;
  1844. }
  1845. if (valueType === 0) {
  1846. return valueType;
  1847. }
  1848. if (valueType < returnType) {
  1849. returnType = valueType;
  1850. }
  1851. }
  1852. }
  1853. return returnType;
  1854. }
  1855. function getNodeProps(node) {
  1856. const codegenNode = node.codegenNode;
  1857. if (codegenNode.type === 13) {
  1858. return codegenNode.props;
  1859. }
  1860. }
  1861. function getPatchFlag(node) {
  1862. const flag = node.patchFlag;
  1863. return flag ? parseInt(flag, 10) : void 0;
  1864. }
  1865. function createTransformContext(root, {
  1866. filename = "",
  1867. prefixIdentifiers = false,
  1868. hoistStatic: hoistStatic2 = false,
  1869. hmr = false,
  1870. cacheHandlers = false,
  1871. nodeTransforms = [],
  1872. directiveTransforms = {},
  1873. transformHoist = null,
  1874. isBuiltInComponent = NOOP,
  1875. isCustomElement = NOOP,
  1876. expressionPlugins = [],
  1877. scopeId = null,
  1878. slotted = true,
  1879. ssr = false,
  1880. inSSR = false,
  1881. ssrCssVars = ``,
  1882. bindingMetadata = EMPTY_OBJ,
  1883. inline = false,
  1884. isTS = false,
  1885. onError = defaultOnError,
  1886. onWarn = defaultOnWarn,
  1887. compatConfig
  1888. }) {
  1889. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  1890. const context = {
  1891. // options
  1892. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  1893. prefixIdentifiers,
  1894. hoistStatic: hoistStatic2,
  1895. hmr,
  1896. cacheHandlers,
  1897. nodeTransforms,
  1898. directiveTransforms,
  1899. transformHoist,
  1900. isBuiltInComponent,
  1901. isCustomElement,
  1902. expressionPlugins,
  1903. scopeId,
  1904. slotted,
  1905. ssr,
  1906. inSSR,
  1907. ssrCssVars,
  1908. bindingMetadata,
  1909. inline,
  1910. isTS,
  1911. onError,
  1912. onWarn,
  1913. compatConfig,
  1914. // state
  1915. root,
  1916. helpers: /* @__PURE__ */ new Map(),
  1917. components: /* @__PURE__ */ new Set(),
  1918. directives: /* @__PURE__ */ new Set(),
  1919. hoists: [],
  1920. imports: [],
  1921. constantCache: /* @__PURE__ */ new WeakMap(),
  1922. temps: 0,
  1923. cached: 0,
  1924. identifiers: /* @__PURE__ */ Object.create(null),
  1925. scopes: {
  1926. vFor: 0,
  1927. vSlot: 0,
  1928. vPre: 0,
  1929. vOnce: 0
  1930. },
  1931. parent: null,
  1932. currentNode: root,
  1933. childIndex: 0,
  1934. inVOnce: false,
  1935. // methods
  1936. helper(name) {
  1937. const count = context.helpers.get(name) || 0;
  1938. context.helpers.set(name, count + 1);
  1939. return name;
  1940. },
  1941. removeHelper(name) {
  1942. const count = context.helpers.get(name);
  1943. if (count) {
  1944. const currentCount = count - 1;
  1945. if (!currentCount) {
  1946. context.helpers.delete(name);
  1947. } else {
  1948. context.helpers.set(name, currentCount);
  1949. }
  1950. }
  1951. },
  1952. helperString(name) {
  1953. return `_${helperNameMap[context.helper(name)]}`;
  1954. },
  1955. replaceNode(node) {
  1956. {
  1957. if (!context.currentNode) {
  1958. throw new Error(`Node being replaced is already removed.`);
  1959. }
  1960. if (!context.parent) {
  1961. throw new Error(`Cannot replace root node.`);
  1962. }
  1963. }
  1964. context.parent.children[context.childIndex] = context.currentNode = node;
  1965. },
  1966. removeNode(node) {
  1967. if (!context.parent) {
  1968. throw new Error(`Cannot remove root node.`);
  1969. }
  1970. const list = context.parent.children;
  1971. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  1972. if (removalIndex < 0) {
  1973. throw new Error(`node being removed is not a child of current parent`);
  1974. }
  1975. if (!node || node === context.currentNode) {
  1976. context.currentNode = null;
  1977. context.onNodeRemoved();
  1978. } else {
  1979. if (context.childIndex > removalIndex) {
  1980. context.childIndex--;
  1981. context.onNodeRemoved();
  1982. }
  1983. }
  1984. context.parent.children.splice(removalIndex, 1);
  1985. },
  1986. onNodeRemoved: () => {
  1987. },
  1988. addIdentifiers(exp) {
  1989. },
  1990. removeIdentifiers(exp) {
  1991. },
  1992. hoist(exp) {
  1993. if (isString(exp))
  1994. exp = createSimpleExpression(exp);
  1995. context.hoists.push(exp);
  1996. const identifier = createSimpleExpression(
  1997. `_hoisted_${context.hoists.length}`,
  1998. false,
  1999. exp.loc,
  2000. 2
  2001. );
  2002. identifier.hoisted = exp;
  2003. return identifier;
  2004. },
  2005. cache(exp, isVNode = false) {
  2006. return createCacheExpression(context.cached++, exp, isVNode);
  2007. }
  2008. };
  2009. {
  2010. context.filters = /* @__PURE__ */ new Set();
  2011. }
  2012. return context;
  2013. }
  2014. function transform(root, options) {
  2015. const context = createTransformContext(root, options);
  2016. traverseNode(root, context);
  2017. if (options.hoistStatic) {
  2018. hoistStatic(root, context);
  2019. }
  2020. if (!options.ssr) {
  2021. createRootCodegen(root, context);
  2022. }
  2023. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  2024. root.components = [...context.components];
  2025. root.directives = [...context.directives];
  2026. root.imports = context.imports;
  2027. root.hoists = context.hoists;
  2028. root.temps = context.temps;
  2029. root.cached = context.cached;
  2030. {
  2031. root.filters = [...context.filters];
  2032. }
  2033. }
  2034. function createRootCodegen(root, context) {
  2035. const { helper } = context;
  2036. const { children } = root;
  2037. if (children.length === 1) {
  2038. const child = children[0];
  2039. if (isSingleElementRoot(root, child) && child.codegenNode) {
  2040. const codegenNode = child.codegenNode;
  2041. if (codegenNode.type === 13) {
  2042. convertToBlock(codegenNode, context);
  2043. }
  2044. root.codegenNode = codegenNode;
  2045. } else {
  2046. root.codegenNode = child;
  2047. }
  2048. } else if (children.length > 1) {
  2049. let patchFlag = 64;
  2050. let patchFlagText = PatchFlagNames[64];
  2051. if (children.filter((c) => c.type !== 3).length === 1) {
  2052. patchFlag |= 2048;
  2053. patchFlagText += `, ${PatchFlagNames[2048]}`;
  2054. }
  2055. root.codegenNode = createVNodeCall(
  2056. context,
  2057. helper(FRAGMENT),
  2058. void 0,
  2059. root.children,
  2060. patchFlag + (` /* ${patchFlagText} */` ),
  2061. void 0,
  2062. void 0,
  2063. true,
  2064. void 0,
  2065. false
  2066. /* isComponent */
  2067. );
  2068. } else ;
  2069. }
  2070. function traverseChildren(parent, context) {
  2071. let i = 0;
  2072. const nodeRemoved = () => {
  2073. i--;
  2074. };
  2075. for (; i < parent.children.length; i++) {
  2076. const child = parent.children[i];
  2077. if (isString(child))
  2078. continue;
  2079. context.parent = parent;
  2080. context.childIndex = i;
  2081. context.onNodeRemoved = nodeRemoved;
  2082. traverseNode(child, context);
  2083. }
  2084. }
  2085. function traverseNode(node, context) {
  2086. context.currentNode = node;
  2087. const { nodeTransforms } = context;
  2088. const exitFns = [];
  2089. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  2090. const onExit = nodeTransforms[i2](node, context);
  2091. if (onExit) {
  2092. if (isArray(onExit)) {
  2093. exitFns.push(...onExit);
  2094. } else {
  2095. exitFns.push(onExit);
  2096. }
  2097. }
  2098. if (!context.currentNode) {
  2099. return;
  2100. } else {
  2101. node = context.currentNode;
  2102. }
  2103. }
  2104. switch (node.type) {
  2105. case 3:
  2106. if (!context.ssr) {
  2107. context.helper(CREATE_COMMENT);
  2108. }
  2109. break;
  2110. case 5:
  2111. if (!context.ssr) {
  2112. context.helper(TO_DISPLAY_STRING);
  2113. }
  2114. break;
  2115. case 9:
  2116. for (let i2 = 0; i2 < node.branches.length; i2++) {
  2117. traverseNode(node.branches[i2], context);
  2118. }
  2119. break;
  2120. case 10:
  2121. case 11:
  2122. case 1:
  2123. case 0:
  2124. traverseChildren(node, context);
  2125. break;
  2126. }
  2127. context.currentNode = node;
  2128. let i = exitFns.length;
  2129. while (i--) {
  2130. exitFns[i]();
  2131. }
  2132. }
  2133. function createStructuralDirectiveTransform(name, fn) {
  2134. const matches = isString(name) ? (n) => n === name : (n) => name.test(n);
  2135. return (node, context) => {
  2136. if (node.type === 1) {
  2137. const { props } = node;
  2138. if (node.tagType === 3 && props.some(isVSlot)) {
  2139. return;
  2140. }
  2141. const exitFns = [];
  2142. for (let i = 0; i < props.length; i++) {
  2143. const prop = props[i];
  2144. if (prop.type === 7 && matches(prop.name)) {
  2145. props.splice(i, 1);
  2146. i--;
  2147. const onExit = fn(node, prop, context);
  2148. if (onExit)
  2149. exitFns.push(onExit);
  2150. }
  2151. }
  2152. return exitFns;
  2153. }
  2154. };
  2155. }
  2156. const PURE_ANNOTATION = `/*#__PURE__*/`;
  2157. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  2158. function createCodegenContext(ast, {
  2159. mode = "function",
  2160. prefixIdentifiers = mode === "module",
  2161. sourceMap = false,
  2162. filename = `template.vue.html`,
  2163. scopeId = null,
  2164. optimizeImports = false,
  2165. runtimeGlobalName = `Vue`,
  2166. runtimeModuleName = `vue`,
  2167. ssrRuntimeModuleName = "vue/server-renderer",
  2168. ssr = false,
  2169. isTS = false,
  2170. inSSR = false
  2171. }) {
  2172. const context = {
  2173. mode,
  2174. prefixIdentifiers,
  2175. sourceMap,
  2176. filename,
  2177. scopeId,
  2178. optimizeImports,
  2179. runtimeGlobalName,
  2180. runtimeModuleName,
  2181. ssrRuntimeModuleName,
  2182. ssr,
  2183. isTS,
  2184. inSSR,
  2185. source: ast.loc.source,
  2186. code: ``,
  2187. column: 1,
  2188. line: 1,
  2189. offset: 0,
  2190. indentLevel: 0,
  2191. pure: false,
  2192. map: void 0,
  2193. helper(key) {
  2194. return `_${helperNameMap[key]}`;
  2195. },
  2196. push(code, node) {
  2197. context.code += code;
  2198. },
  2199. indent() {
  2200. newline(++context.indentLevel);
  2201. },
  2202. deindent(withoutNewLine = false) {
  2203. if (withoutNewLine) {
  2204. --context.indentLevel;
  2205. } else {
  2206. newline(--context.indentLevel);
  2207. }
  2208. },
  2209. newline() {
  2210. newline(context.indentLevel);
  2211. }
  2212. };
  2213. function newline(n) {
  2214. context.push("\n" + ` `.repeat(n));
  2215. }
  2216. return context;
  2217. }
  2218. function generate(ast, options = {}) {
  2219. const context = createCodegenContext(ast, options);
  2220. if (options.onContextCreated)
  2221. options.onContextCreated(context);
  2222. const {
  2223. mode,
  2224. push,
  2225. prefixIdentifiers,
  2226. indent,
  2227. deindent,
  2228. newline,
  2229. scopeId,
  2230. ssr
  2231. } = context;
  2232. const helpers = Array.from(ast.helpers);
  2233. const hasHelpers = helpers.length > 0;
  2234. const useWithBlock = !prefixIdentifiers && mode !== "module";
  2235. const isSetupInlined = false;
  2236. const preambleContext = isSetupInlined ? createCodegenContext(ast, options) : context;
  2237. {
  2238. genFunctionPreamble(ast, preambleContext);
  2239. }
  2240. const functionName = ssr ? `ssrRender` : `render`;
  2241. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  2242. const signature = args.join(", ");
  2243. {
  2244. push(`function ${functionName}(${signature}) {`);
  2245. }
  2246. indent();
  2247. if (useWithBlock) {
  2248. push(`with (_ctx) {`);
  2249. indent();
  2250. if (hasHelpers) {
  2251. push(`const { ${helpers.map(aliasHelper).join(", ")} } = _Vue`);
  2252. push(`
  2253. `);
  2254. newline();
  2255. }
  2256. }
  2257. if (ast.components.length) {
  2258. genAssets(ast.components, "component", context);
  2259. if (ast.directives.length || ast.temps > 0) {
  2260. newline();
  2261. }
  2262. }
  2263. if (ast.directives.length) {
  2264. genAssets(ast.directives, "directive", context);
  2265. if (ast.temps > 0) {
  2266. newline();
  2267. }
  2268. }
  2269. if (ast.filters && ast.filters.length) {
  2270. newline();
  2271. genAssets(ast.filters, "filter", context);
  2272. newline();
  2273. }
  2274. if (ast.temps > 0) {
  2275. push(`let `);
  2276. for (let i = 0; i < ast.temps; i++) {
  2277. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  2278. }
  2279. }
  2280. if (ast.components.length || ast.directives.length || ast.temps) {
  2281. push(`
  2282. `);
  2283. newline();
  2284. }
  2285. if (!ssr) {
  2286. push(`return `);
  2287. }
  2288. if (ast.codegenNode) {
  2289. genNode(ast.codegenNode, context);
  2290. } else {
  2291. push(`null`);
  2292. }
  2293. if (useWithBlock) {
  2294. deindent();
  2295. push(`}`);
  2296. }
  2297. deindent();
  2298. push(`}`);
  2299. return {
  2300. ast,
  2301. code: context.code,
  2302. preamble: isSetupInlined ? preambleContext.code : ``,
  2303. // SourceMapGenerator does have toJSON() method but it's not in the types
  2304. map: context.map ? context.map.toJSON() : void 0
  2305. };
  2306. }
  2307. function genFunctionPreamble(ast, context) {
  2308. const {
  2309. ssr,
  2310. prefixIdentifiers,
  2311. push,
  2312. newline,
  2313. runtimeModuleName,
  2314. runtimeGlobalName,
  2315. ssrRuntimeModuleName
  2316. } = context;
  2317. const VueBinding = runtimeGlobalName;
  2318. const helpers = Array.from(ast.helpers);
  2319. if (helpers.length > 0) {
  2320. {
  2321. push(`const _Vue = ${VueBinding}
  2322. `);
  2323. if (ast.hoists.length) {
  2324. const staticHelpers = [
  2325. CREATE_VNODE,
  2326. CREATE_ELEMENT_VNODE,
  2327. CREATE_COMMENT,
  2328. CREATE_TEXT,
  2329. CREATE_STATIC
  2330. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  2331. push(`const { ${staticHelpers} } = _Vue
  2332. `);
  2333. }
  2334. }
  2335. }
  2336. genHoists(ast.hoists, context);
  2337. newline();
  2338. push(`return `);
  2339. }
  2340. function genAssets(assets, type, { helper, push, newline, isTS }) {
  2341. const resolver = helper(
  2342. type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  2343. );
  2344. for (let i = 0; i < assets.length; i++) {
  2345. let id = assets[i];
  2346. const maybeSelfReference = id.endsWith("__self");
  2347. if (maybeSelfReference) {
  2348. id = id.slice(0, -6);
  2349. }
  2350. push(
  2351. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  2352. );
  2353. if (i < assets.length - 1) {
  2354. newline();
  2355. }
  2356. }
  2357. }
  2358. function genHoists(hoists, context) {
  2359. if (!hoists.length) {
  2360. return;
  2361. }
  2362. context.pure = true;
  2363. const { push, newline, helper, scopeId, mode } = context;
  2364. newline();
  2365. for (let i = 0; i < hoists.length; i++) {
  2366. const exp = hoists[i];
  2367. if (exp) {
  2368. push(
  2369. `const _hoisted_${i + 1} = ${``}`
  2370. );
  2371. genNode(exp, context);
  2372. newline();
  2373. }
  2374. }
  2375. context.pure = false;
  2376. }
  2377. function isText(n) {
  2378. return isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  2379. }
  2380. function genNodeListAsArray(nodes, context) {
  2381. const multilines = nodes.length > 3 || nodes.some((n) => isArray(n) || !isText(n));
  2382. context.push(`[`);
  2383. multilines && context.indent();
  2384. genNodeList(nodes, context, multilines);
  2385. multilines && context.deindent();
  2386. context.push(`]`);
  2387. }
  2388. function genNodeList(nodes, context, multilines = false, comma = true) {
  2389. const { push, newline } = context;
  2390. for (let i = 0; i < nodes.length; i++) {
  2391. const node = nodes[i];
  2392. if (isString(node)) {
  2393. push(node);
  2394. } else if (isArray(node)) {
  2395. genNodeListAsArray(node, context);
  2396. } else {
  2397. genNode(node, context);
  2398. }
  2399. if (i < nodes.length - 1) {
  2400. if (multilines) {
  2401. comma && push(",");
  2402. newline();
  2403. } else {
  2404. comma && push(", ");
  2405. }
  2406. }
  2407. }
  2408. }
  2409. function genNode(node, context) {
  2410. if (isString(node)) {
  2411. context.push(node);
  2412. return;
  2413. }
  2414. if (isSymbol(node)) {
  2415. context.push(context.helper(node));
  2416. return;
  2417. }
  2418. switch (node.type) {
  2419. case 1:
  2420. case 9:
  2421. case 11:
  2422. assert(
  2423. node.codegenNode != null,
  2424. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  2425. );
  2426. genNode(node.codegenNode, context);
  2427. break;
  2428. case 2:
  2429. genText(node, context);
  2430. break;
  2431. case 4:
  2432. genExpression(node, context);
  2433. break;
  2434. case 5:
  2435. genInterpolation(node, context);
  2436. break;
  2437. case 12:
  2438. genNode(node.codegenNode, context);
  2439. break;
  2440. case 8:
  2441. genCompoundExpression(node, context);
  2442. break;
  2443. case 3:
  2444. genComment(node, context);
  2445. break;
  2446. case 13:
  2447. genVNodeCall(node, context);
  2448. break;
  2449. case 14:
  2450. genCallExpression(node, context);
  2451. break;
  2452. case 15:
  2453. genObjectExpression(node, context);
  2454. break;
  2455. case 17:
  2456. genArrayExpression(node, context);
  2457. break;
  2458. case 18:
  2459. genFunctionExpression(node, context);
  2460. break;
  2461. case 19:
  2462. genConditionalExpression(node, context);
  2463. break;
  2464. case 20:
  2465. genCacheExpression(node, context);
  2466. break;
  2467. case 21:
  2468. genNodeList(node.body, context, true, false);
  2469. break;
  2470. case 22:
  2471. break;
  2472. case 23:
  2473. break;
  2474. case 24:
  2475. break;
  2476. case 25:
  2477. break;
  2478. case 26:
  2479. break;
  2480. case 10:
  2481. break;
  2482. default:
  2483. {
  2484. assert(false, `unhandled codegen node type: ${node.type}`);
  2485. const exhaustiveCheck = node;
  2486. return exhaustiveCheck;
  2487. }
  2488. }
  2489. }
  2490. function genText(node, context) {
  2491. context.push(JSON.stringify(node.content), node);
  2492. }
  2493. function genExpression(node, context) {
  2494. const { content, isStatic } = node;
  2495. context.push(isStatic ? JSON.stringify(content) : content, node);
  2496. }
  2497. function genInterpolation(node, context) {
  2498. const { push, helper, pure } = context;
  2499. if (pure)
  2500. push(PURE_ANNOTATION);
  2501. push(`${helper(TO_DISPLAY_STRING)}(`);
  2502. genNode(node.content, context);
  2503. push(`)`);
  2504. }
  2505. function genCompoundExpression(node, context) {
  2506. for (let i = 0; i < node.children.length; i++) {
  2507. const child = node.children[i];
  2508. if (isString(child)) {
  2509. context.push(child);
  2510. } else {
  2511. genNode(child, context);
  2512. }
  2513. }
  2514. }
  2515. function genExpressionAsPropertyKey(node, context) {
  2516. const { push } = context;
  2517. if (node.type === 8) {
  2518. push(`[`);
  2519. genCompoundExpression(node, context);
  2520. push(`]`);
  2521. } else if (node.isStatic) {
  2522. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  2523. push(text, node);
  2524. } else {
  2525. push(`[${node.content}]`, node);
  2526. }
  2527. }
  2528. function genComment(node, context) {
  2529. const { push, helper, pure } = context;
  2530. if (pure) {
  2531. push(PURE_ANNOTATION);
  2532. }
  2533. push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
  2534. }
  2535. function genVNodeCall(node, context) {
  2536. const { push, helper, pure } = context;
  2537. const {
  2538. tag,
  2539. props,
  2540. children,
  2541. patchFlag,
  2542. dynamicProps,
  2543. directives,
  2544. isBlock,
  2545. disableTracking,
  2546. isComponent
  2547. } = node;
  2548. if (directives) {
  2549. push(helper(WITH_DIRECTIVES) + `(`);
  2550. }
  2551. if (isBlock) {
  2552. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  2553. }
  2554. if (pure) {
  2555. push(PURE_ANNOTATION);
  2556. }
  2557. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  2558. push(helper(callHelper) + `(`, node);
  2559. genNodeList(
  2560. genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
  2561. context
  2562. );
  2563. push(`)`);
  2564. if (isBlock) {
  2565. push(`)`);
  2566. }
  2567. if (directives) {
  2568. push(`, `);
  2569. genNode(directives, context);
  2570. push(`)`);
  2571. }
  2572. }
  2573. function genNullableArgs(args) {
  2574. let i = args.length;
  2575. while (i--) {
  2576. if (args[i] != null)
  2577. break;
  2578. }
  2579. return args.slice(0, i + 1).map((arg) => arg || `null`);
  2580. }
  2581. function genCallExpression(node, context) {
  2582. const { push, helper, pure } = context;
  2583. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  2584. if (pure) {
  2585. push(PURE_ANNOTATION);
  2586. }
  2587. push(callee + `(`, node);
  2588. genNodeList(node.arguments, context);
  2589. push(`)`);
  2590. }
  2591. function genObjectExpression(node, context) {
  2592. const { push, indent, deindent, newline } = context;
  2593. const { properties } = node;
  2594. if (!properties.length) {
  2595. push(`{}`, node);
  2596. return;
  2597. }
  2598. const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
  2599. push(multilines ? `{` : `{ `);
  2600. multilines && indent();
  2601. for (let i = 0; i < properties.length; i++) {
  2602. const { key, value } = properties[i];
  2603. genExpressionAsPropertyKey(key, context);
  2604. push(`: `);
  2605. genNode(value, context);
  2606. if (i < properties.length - 1) {
  2607. push(`,`);
  2608. newline();
  2609. }
  2610. }
  2611. multilines && deindent();
  2612. push(multilines ? `}` : ` }`);
  2613. }
  2614. function genArrayExpression(node, context) {
  2615. genNodeListAsArray(node.elements, context);
  2616. }
  2617. function genFunctionExpression(node, context) {
  2618. const { push, indent, deindent } = context;
  2619. const { params, returns, body, newline, isSlot } = node;
  2620. if (isSlot) {
  2621. push(`_${helperNameMap[WITH_CTX]}(`);
  2622. }
  2623. push(`(`, node);
  2624. if (isArray(params)) {
  2625. genNodeList(params, context);
  2626. } else if (params) {
  2627. genNode(params, context);
  2628. }
  2629. push(`) => `);
  2630. if (newline || body) {
  2631. push(`{`);
  2632. indent();
  2633. }
  2634. if (returns) {
  2635. if (newline) {
  2636. push(`return `);
  2637. }
  2638. if (isArray(returns)) {
  2639. genNodeListAsArray(returns, context);
  2640. } else {
  2641. genNode(returns, context);
  2642. }
  2643. } else if (body) {
  2644. genNode(body, context);
  2645. }
  2646. if (newline || body) {
  2647. deindent();
  2648. push(`}`);
  2649. }
  2650. if (isSlot) {
  2651. if (node.isNonScopedSlot) {
  2652. push(`, undefined, true`);
  2653. }
  2654. push(`)`);
  2655. }
  2656. }
  2657. function genConditionalExpression(node, context) {
  2658. const { test, consequent, alternate, newline: needNewline } = node;
  2659. const { push, indent, deindent, newline } = context;
  2660. if (test.type === 4) {
  2661. const needsParens = !isSimpleIdentifier(test.content);
  2662. needsParens && push(`(`);
  2663. genExpression(test, context);
  2664. needsParens && push(`)`);
  2665. } else {
  2666. push(`(`);
  2667. genNode(test, context);
  2668. push(`)`);
  2669. }
  2670. needNewline && indent();
  2671. context.indentLevel++;
  2672. needNewline || push(` `);
  2673. push(`? `);
  2674. genNode(consequent, context);
  2675. context.indentLevel--;
  2676. needNewline && newline();
  2677. needNewline || push(` `);
  2678. push(`: `);
  2679. const isNested = alternate.type === 19;
  2680. if (!isNested) {
  2681. context.indentLevel++;
  2682. }
  2683. genNode(alternate, context);
  2684. if (!isNested) {
  2685. context.indentLevel--;
  2686. }
  2687. needNewline && deindent(
  2688. true
  2689. /* without newline */
  2690. );
  2691. }
  2692. function genCacheExpression(node, context) {
  2693. const { push, helper, indent, deindent, newline } = context;
  2694. push(`_cache[${node.index}] || (`);
  2695. if (node.isVNode) {
  2696. indent();
  2697. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  2698. newline();
  2699. }
  2700. push(`_cache[${node.index}] = `);
  2701. genNode(node.value, context);
  2702. if (node.isVNode) {
  2703. push(`,`);
  2704. newline();
  2705. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  2706. newline();
  2707. push(`_cache[${node.index}]`);
  2708. deindent();
  2709. }
  2710. push(`)`);
  2711. }
  2712. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
  2713. {
  2714. return;
  2715. }
  2716. }
  2717. function isReferencedIdentifier(id, parent, parentStack) {
  2718. {
  2719. return false;
  2720. }
  2721. }
  2722. function isInDestructureAssignment(parent, parentStack) {
  2723. if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
  2724. let i = parentStack.length;
  2725. while (i--) {
  2726. const p = parentStack[i];
  2727. if (p.type === "AssignmentExpression") {
  2728. return true;
  2729. } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
  2730. break;
  2731. }
  2732. }
  2733. }
  2734. return false;
  2735. }
  2736. function walkFunctionParams(node, onIdent) {
  2737. for (const p of node.params) {
  2738. for (const id of extractIdentifiers(p)) {
  2739. onIdent(id);
  2740. }
  2741. }
  2742. }
  2743. function walkBlockDeclarations(block, onIdent) {
  2744. for (const stmt of block.body) {
  2745. if (stmt.type === "VariableDeclaration") {
  2746. if (stmt.declare)
  2747. continue;
  2748. for (const decl of stmt.declarations) {
  2749. for (const id of extractIdentifiers(decl.id)) {
  2750. onIdent(id);
  2751. }
  2752. }
  2753. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  2754. if (stmt.declare || !stmt.id)
  2755. continue;
  2756. onIdent(stmt.id);
  2757. } else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
  2758. const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
  2759. if (variable && variable.type === "VariableDeclaration") {
  2760. for (const decl of variable.declarations) {
  2761. for (const id of extractIdentifiers(decl.id)) {
  2762. onIdent(id);
  2763. }
  2764. }
  2765. }
  2766. }
  2767. }
  2768. }
  2769. function extractIdentifiers(param, nodes = []) {
  2770. switch (param.type) {
  2771. case "Identifier":
  2772. nodes.push(param);
  2773. break;
  2774. case "MemberExpression":
  2775. let object = param;
  2776. while (object.type === "MemberExpression") {
  2777. object = object.object;
  2778. }
  2779. nodes.push(object);
  2780. break;
  2781. case "ObjectPattern":
  2782. for (const prop of param.properties) {
  2783. if (prop.type === "RestElement") {
  2784. extractIdentifiers(prop.argument, nodes);
  2785. } else {
  2786. extractIdentifiers(prop.value, nodes);
  2787. }
  2788. }
  2789. break;
  2790. case "ArrayPattern":
  2791. param.elements.forEach((element) => {
  2792. if (element)
  2793. extractIdentifiers(element, nodes);
  2794. });
  2795. break;
  2796. case "RestElement":
  2797. extractIdentifiers(param.argument, nodes);
  2798. break;
  2799. case "AssignmentPattern":
  2800. extractIdentifiers(param.left, nodes);
  2801. break;
  2802. }
  2803. return nodes;
  2804. }
  2805. const isFunctionType = (node) => {
  2806. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  2807. };
  2808. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  2809. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  2810. const TS_NODE_TYPES = [
  2811. "TSAsExpression",
  2812. // foo as number
  2813. "TSTypeAssertion",
  2814. // (<number>foo)
  2815. "TSNonNullExpression",
  2816. // foo!
  2817. "TSInstantiationExpression",
  2818. // foo<string>
  2819. "TSSatisfiesExpression"
  2820. // foo satisfies T
  2821. ];
  2822. const prohibitedKeywordRE = new RegExp(
  2823. "\\b" + "arguments,await,break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,finally,for,function,if,import,let,new,return,super,switch,throw,try,var,void,while,with,yield".split(",").join("\\b|\\b") + "\\b"
  2824. );
  2825. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  2826. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  2827. const exp = node.content;
  2828. if (!exp.trim()) {
  2829. return;
  2830. }
  2831. try {
  2832. new Function(
  2833. asRawStatements ? ` ${exp} ` : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`
  2834. );
  2835. } catch (e) {
  2836. let message = e.message;
  2837. const keywordMatch = exp.replace(stripStringRE, "").match(prohibitedKeywordRE);
  2838. if (keywordMatch) {
  2839. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  2840. }
  2841. context.onError(
  2842. createCompilerError(
  2843. 45,
  2844. node.loc,
  2845. void 0,
  2846. message
  2847. )
  2848. );
  2849. }
  2850. }
  2851. const transformExpression = (node, context) => {
  2852. if (node.type === 5) {
  2853. node.content = processExpression(
  2854. node.content,
  2855. context
  2856. );
  2857. } else if (node.type === 1) {
  2858. for (let i = 0; i < node.props.length; i++) {
  2859. const dir = node.props[i];
  2860. if (dir.type === 7 && dir.name !== "for") {
  2861. const exp = dir.exp;
  2862. const arg = dir.arg;
  2863. if (exp && exp.type === 4 && !(dir.name === "on" && arg)) {
  2864. dir.exp = processExpression(
  2865. exp,
  2866. context,
  2867. // slot args must be processed as function params
  2868. dir.name === "slot"
  2869. );
  2870. }
  2871. if (arg && arg.type === 4 && !arg.isStatic) {
  2872. dir.arg = processExpression(arg, context);
  2873. }
  2874. }
  2875. }
  2876. }
  2877. };
  2878. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  2879. {
  2880. {
  2881. validateBrowserExpression(node, context, asParams, asRawStatements);
  2882. }
  2883. return node;
  2884. }
  2885. }
  2886. function stringifyExpression(exp) {
  2887. if (isString(exp)) {
  2888. return exp;
  2889. } else if (exp.type === 4) {
  2890. return exp.content;
  2891. } else {
  2892. return exp.children.map(stringifyExpression).join("");
  2893. }
  2894. }
  2895. const transformIf = createStructuralDirectiveTransform(
  2896. /^(if|else|else-if)$/,
  2897. (node, dir, context) => {
  2898. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  2899. const siblings = context.parent.children;
  2900. let i = siblings.indexOf(ifNode);
  2901. let key = 0;
  2902. while (i-- >= 0) {
  2903. const sibling = siblings[i];
  2904. if (sibling && sibling.type === 9) {
  2905. key += sibling.branches.length;
  2906. }
  2907. }
  2908. return () => {
  2909. if (isRoot) {
  2910. ifNode.codegenNode = createCodegenNodeForBranch(
  2911. branch,
  2912. key,
  2913. context
  2914. );
  2915. } else {
  2916. const parentCondition = getParentCondition(ifNode.codegenNode);
  2917. parentCondition.alternate = createCodegenNodeForBranch(
  2918. branch,
  2919. key + ifNode.branches.length - 1,
  2920. context
  2921. );
  2922. }
  2923. };
  2924. });
  2925. }
  2926. );
  2927. function processIf(node, dir, context, processCodegen) {
  2928. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  2929. const loc = dir.exp ? dir.exp.loc : node.loc;
  2930. context.onError(
  2931. createCompilerError(28, dir.loc)
  2932. );
  2933. dir.exp = createSimpleExpression(`true`, false, loc);
  2934. }
  2935. if (dir.exp) {
  2936. validateBrowserExpression(dir.exp, context);
  2937. }
  2938. if (dir.name === "if") {
  2939. const branch = createIfBranch(node, dir);
  2940. const ifNode = {
  2941. type: 9,
  2942. loc: node.loc,
  2943. branches: [branch]
  2944. };
  2945. context.replaceNode(ifNode);
  2946. if (processCodegen) {
  2947. return processCodegen(ifNode, branch, true);
  2948. }
  2949. } else {
  2950. const siblings = context.parent.children;
  2951. const comments = [];
  2952. let i = siblings.indexOf(node);
  2953. while (i-- >= -1) {
  2954. const sibling = siblings[i];
  2955. if (sibling && sibling.type === 3) {
  2956. context.removeNode(sibling);
  2957. comments.unshift(sibling);
  2958. continue;
  2959. }
  2960. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  2961. context.removeNode(sibling);
  2962. continue;
  2963. }
  2964. if (sibling && sibling.type === 9) {
  2965. if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  2966. context.onError(
  2967. createCompilerError(30, node.loc)
  2968. );
  2969. }
  2970. context.removeNode();
  2971. const branch = createIfBranch(node, dir);
  2972. if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  2973. !(context.parent && context.parent.type === 1 && isBuiltInType(context.parent.tag, "transition"))) {
  2974. branch.children = [...comments, ...branch.children];
  2975. }
  2976. {
  2977. const key = branch.userKey;
  2978. if (key) {
  2979. sibling.branches.forEach(({ userKey }) => {
  2980. if (isSameKey(userKey, key)) {
  2981. context.onError(
  2982. createCompilerError(
  2983. 29,
  2984. branch.userKey.loc
  2985. )
  2986. );
  2987. }
  2988. });
  2989. }
  2990. }
  2991. sibling.branches.push(branch);
  2992. const onExit = processCodegen && processCodegen(sibling, branch, false);
  2993. traverseNode(branch, context);
  2994. if (onExit)
  2995. onExit();
  2996. context.currentNode = null;
  2997. } else {
  2998. context.onError(
  2999. createCompilerError(30, node.loc)
  3000. );
  3001. }
  3002. break;
  3003. }
  3004. }
  3005. }
  3006. function createIfBranch(node, dir) {
  3007. const isTemplateIf = node.tagType === 3;
  3008. return {
  3009. type: 10,
  3010. loc: node.loc,
  3011. condition: dir.name === "else" ? void 0 : dir.exp,
  3012. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  3013. userKey: findProp(node, `key`),
  3014. isTemplateIf
  3015. };
  3016. }
  3017. function createCodegenNodeForBranch(branch, keyIndex, context) {
  3018. if (branch.condition) {
  3019. return createConditionalExpression(
  3020. branch.condition,
  3021. createChildrenCodegenNode(branch, keyIndex, context),
  3022. // make sure to pass in asBlock: true so that the comment node call
  3023. // closes the current block.
  3024. createCallExpression(context.helper(CREATE_COMMENT), [
  3025. '"v-if"' ,
  3026. "true"
  3027. ])
  3028. );
  3029. } else {
  3030. return createChildrenCodegenNode(branch, keyIndex, context);
  3031. }
  3032. }
  3033. function createChildrenCodegenNode(branch, keyIndex, context) {
  3034. const { helper } = context;
  3035. const keyProperty = createObjectProperty(
  3036. `key`,
  3037. createSimpleExpression(
  3038. `${keyIndex}`,
  3039. false,
  3040. locStub,
  3041. 2
  3042. )
  3043. );
  3044. const { children } = branch;
  3045. const firstChild = children[0];
  3046. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  3047. if (needFragmentWrapper) {
  3048. if (children.length === 1 && firstChild.type === 11) {
  3049. const vnodeCall = firstChild.codegenNode;
  3050. injectProp(vnodeCall, keyProperty, context);
  3051. return vnodeCall;
  3052. } else {
  3053. let patchFlag = 64;
  3054. let patchFlagText = PatchFlagNames[64];
  3055. if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  3056. patchFlag |= 2048;
  3057. patchFlagText += `, ${PatchFlagNames[2048]}`;
  3058. }
  3059. return createVNodeCall(
  3060. context,
  3061. helper(FRAGMENT),
  3062. createObjectExpression([keyProperty]),
  3063. children,
  3064. patchFlag + (` /* ${patchFlagText} */` ),
  3065. void 0,
  3066. void 0,
  3067. true,
  3068. false,
  3069. false,
  3070. branch.loc
  3071. );
  3072. }
  3073. } else {
  3074. const ret = firstChild.codegenNode;
  3075. const vnodeCall = getMemoedVNodeCall(ret);
  3076. if (vnodeCall.type === 13) {
  3077. convertToBlock(vnodeCall, context);
  3078. }
  3079. injectProp(vnodeCall, keyProperty, context);
  3080. return ret;
  3081. }
  3082. }
  3083. function isSameKey(a, b) {
  3084. if (!a || a.type !== b.type) {
  3085. return false;
  3086. }
  3087. if (a.type === 6) {
  3088. if (a.value.content !== b.value.content) {
  3089. return false;
  3090. }
  3091. } else {
  3092. const exp = a.exp;
  3093. const branchExp = b.exp;
  3094. if (exp.type !== branchExp.type) {
  3095. return false;
  3096. }
  3097. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  3098. return false;
  3099. }
  3100. }
  3101. return true;
  3102. }
  3103. function getParentCondition(node) {
  3104. while (true) {
  3105. if (node.type === 19) {
  3106. if (node.alternate.type === 19) {
  3107. node = node.alternate;
  3108. } else {
  3109. return node;
  3110. }
  3111. } else if (node.type === 20) {
  3112. node = node.value;
  3113. }
  3114. }
  3115. }
  3116. const transformFor = createStructuralDirectiveTransform(
  3117. "for",
  3118. (node, dir, context) => {
  3119. const { helper, removeHelper } = context;
  3120. return processFor(node, dir, context, (forNode) => {
  3121. const renderExp = createCallExpression(helper(RENDER_LIST), [
  3122. forNode.source
  3123. ]);
  3124. const isTemplate = isTemplateNode(node);
  3125. const memo = findDir(node, "memo");
  3126. const keyProp = findProp(node, `key`);
  3127. const keyExp = keyProp && (keyProp.type === 6 ? createSimpleExpression(keyProp.value.content, true) : keyProp.exp);
  3128. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  3129. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  3130. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  3131. forNode.codegenNode = createVNodeCall(
  3132. context,
  3133. helper(FRAGMENT),
  3134. void 0,
  3135. renderExp,
  3136. fragmentFlag + (` /* ${PatchFlagNames[fragmentFlag]} */` ),
  3137. void 0,
  3138. void 0,
  3139. true,
  3140. !isStableFragment,
  3141. false,
  3142. node.loc
  3143. );
  3144. return () => {
  3145. let childBlock;
  3146. const { children } = forNode;
  3147. if (isTemplate) {
  3148. node.children.some((c) => {
  3149. if (c.type === 1) {
  3150. const key = findProp(c, "key");
  3151. if (key) {
  3152. context.onError(
  3153. createCompilerError(
  3154. 33,
  3155. key.loc
  3156. )
  3157. );
  3158. return true;
  3159. }
  3160. }
  3161. });
  3162. }
  3163. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  3164. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  3165. if (slotOutlet) {
  3166. childBlock = slotOutlet.codegenNode;
  3167. if (isTemplate && keyProperty) {
  3168. injectProp(childBlock, keyProperty, context);
  3169. }
  3170. } else if (needFragmentWrapper) {
  3171. childBlock = createVNodeCall(
  3172. context,
  3173. helper(FRAGMENT),
  3174. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  3175. node.children,
  3176. 64 + (` /* ${PatchFlagNames[64]} */` ),
  3177. void 0,
  3178. void 0,
  3179. true,
  3180. void 0,
  3181. false
  3182. /* isComponent */
  3183. );
  3184. } else {
  3185. childBlock = children[0].codegenNode;
  3186. if (isTemplate && keyProperty) {
  3187. injectProp(childBlock, keyProperty, context);
  3188. }
  3189. if (childBlock.isBlock !== !isStableFragment) {
  3190. if (childBlock.isBlock) {
  3191. removeHelper(OPEN_BLOCK);
  3192. removeHelper(
  3193. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  3194. );
  3195. } else {
  3196. removeHelper(
  3197. getVNodeHelper(context.inSSR, childBlock.isComponent)
  3198. );
  3199. }
  3200. }
  3201. childBlock.isBlock = !isStableFragment;
  3202. if (childBlock.isBlock) {
  3203. helper(OPEN_BLOCK);
  3204. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  3205. } else {
  3206. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  3207. }
  3208. }
  3209. if (memo) {
  3210. const loop = createFunctionExpression(
  3211. createForLoopParams(forNode.parseResult, [
  3212. createSimpleExpression(`_cached`)
  3213. ])
  3214. );
  3215. loop.body = createBlockStatement([
  3216. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  3217. createCompoundExpression([
  3218. `if (_cached`,
  3219. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  3220. ` && ${context.helperString(
  3221. IS_MEMO_SAME
  3222. )}(_cached, _memo)) return _cached`
  3223. ]),
  3224. createCompoundExpression([`const _item = `, childBlock]),
  3225. createSimpleExpression(`_item.memo = _memo`),
  3226. createSimpleExpression(`return _item`)
  3227. ]);
  3228. renderExp.arguments.push(
  3229. loop,
  3230. createSimpleExpression(`_cache`),
  3231. createSimpleExpression(String(context.cached++))
  3232. );
  3233. } else {
  3234. renderExp.arguments.push(
  3235. createFunctionExpression(
  3236. createForLoopParams(forNode.parseResult),
  3237. childBlock,
  3238. true
  3239. /* force newline */
  3240. )
  3241. );
  3242. }
  3243. };
  3244. });
  3245. }
  3246. );
  3247. function processFor(node, dir, context, processCodegen) {
  3248. if (!dir.exp) {
  3249. context.onError(
  3250. createCompilerError(31, dir.loc)
  3251. );
  3252. return;
  3253. }
  3254. const parseResult = parseForExpression(
  3255. // can only be simple expression because vFor transform is applied
  3256. // before expression transform.
  3257. dir.exp,
  3258. context
  3259. );
  3260. if (!parseResult) {
  3261. context.onError(
  3262. createCompilerError(32, dir.loc)
  3263. );
  3264. return;
  3265. }
  3266. const { addIdentifiers, removeIdentifiers, scopes } = context;
  3267. const { source, value, key, index } = parseResult;
  3268. const forNode = {
  3269. type: 11,
  3270. loc: dir.loc,
  3271. source,
  3272. valueAlias: value,
  3273. keyAlias: key,
  3274. objectIndexAlias: index,
  3275. parseResult,
  3276. children: isTemplateNode(node) ? node.children : [node]
  3277. };
  3278. context.replaceNode(forNode);
  3279. scopes.vFor++;
  3280. const onExit = processCodegen && processCodegen(forNode);
  3281. return () => {
  3282. scopes.vFor--;
  3283. if (onExit)
  3284. onExit();
  3285. };
  3286. }
  3287. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  3288. const stripParensRE = /^\(|\)$/g;
  3289. function parseForExpression(input, context) {
  3290. const loc = input.loc;
  3291. const exp = input.content;
  3292. const inMatch = exp.match(forAliasRE);
  3293. if (!inMatch)
  3294. return;
  3295. const [, LHS, RHS] = inMatch;
  3296. const result = {
  3297. source: createAliasExpression(
  3298. loc,
  3299. RHS.trim(),
  3300. exp.indexOf(RHS, LHS.length)
  3301. ),
  3302. value: void 0,
  3303. key: void 0,
  3304. index: void 0
  3305. };
  3306. {
  3307. validateBrowserExpression(result.source, context);
  3308. }
  3309. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  3310. const trimmedOffset = LHS.indexOf(valueContent);
  3311. const iteratorMatch = valueContent.match(forIteratorRE);
  3312. if (iteratorMatch) {
  3313. valueContent = valueContent.replace(forIteratorRE, "").trim();
  3314. const keyContent = iteratorMatch[1].trim();
  3315. let keyOffset;
  3316. if (keyContent) {
  3317. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  3318. result.key = createAliasExpression(loc, keyContent, keyOffset);
  3319. {
  3320. validateBrowserExpression(
  3321. result.key,
  3322. context,
  3323. true
  3324. );
  3325. }
  3326. }
  3327. if (iteratorMatch[2]) {
  3328. const indexContent = iteratorMatch[2].trim();
  3329. if (indexContent) {
  3330. result.index = createAliasExpression(
  3331. loc,
  3332. indexContent,
  3333. exp.indexOf(
  3334. indexContent,
  3335. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  3336. )
  3337. );
  3338. {
  3339. validateBrowserExpression(
  3340. result.index,
  3341. context,
  3342. true
  3343. );
  3344. }
  3345. }
  3346. }
  3347. }
  3348. if (valueContent) {
  3349. result.value = createAliasExpression(loc, valueContent, trimmedOffset);
  3350. {
  3351. validateBrowserExpression(
  3352. result.value,
  3353. context,
  3354. true
  3355. );
  3356. }
  3357. }
  3358. return result;
  3359. }
  3360. function createAliasExpression(range, content, offset) {
  3361. return createSimpleExpression(
  3362. content,
  3363. false,
  3364. getInnerRange(range, offset, content.length)
  3365. );
  3366. }
  3367. function createForLoopParams({ value, key, index }, memoArgs = []) {
  3368. return createParamsList([value, key, index, ...memoArgs]);
  3369. }
  3370. function createParamsList(args) {
  3371. let i = args.length;
  3372. while (i--) {
  3373. if (args[i])
  3374. break;
  3375. }
  3376. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  3377. }
  3378. const defaultFallback = createSimpleExpression(`undefined`, false);
  3379. const trackSlotScopes = (node, context) => {
  3380. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  3381. const vSlot = findDir(node, "slot");
  3382. if (vSlot) {
  3383. vSlot.exp;
  3384. context.scopes.vSlot++;
  3385. return () => {
  3386. context.scopes.vSlot--;
  3387. };
  3388. }
  3389. }
  3390. };
  3391. const trackVForSlotScopes = (node, context) => {
  3392. let vFor;
  3393. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  3394. const result = vFor.parseResult = parseForExpression(
  3395. vFor.exp,
  3396. context
  3397. );
  3398. if (result) {
  3399. const { value, key, index } = result;
  3400. const { addIdentifiers, removeIdentifiers } = context;
  3401. value && addIdentifiers(value);
  3402. key && addIdentifiers(key);
  3403. index && addIdentifiers(index);
  3404. return () => {
  3405. value && removeIdentifiers(value);
  3406. key && removeIdentifiers(key);
  3407. index && removeIdentifiers(index);
  3408. };
  3409. }
  3410. }
  3411. };
  3412. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  3413. props,
  3414. children,
  3415. false,
  3416. true,
  3417. children.length ? children[0].loc : loc
  3418. );
  3419. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  3420. context.helper(WITH_CTX);
  3421. const { children, loc } = node;
  3422. const slotsProperties = [];
  3423. const dynamicSlots = [];
  3424. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  3425. const onComponentSlot = findDir(node, "slot", true);
  3426. if (onComponentSlot) {
  3427. const { arg, exp } = onComponentSlot;
  3428. if (arg && !isStaticExp(arg)) {
  3429. hasDynamicSlots = true;
  3430. }
  3431. slotsProperties.push(
  3432. createObjectProperty(
  3433. arg || createSimpleExpression("default", true),
  3434. buildSlotFn(exp, void 0, children, loc)
  3435. )
  3436. );
  3437. }
  3438. let hasTemplateSlots = false;
  3439. let hasNamedDefaultSlot = false;
  3440. const implicitDefaultChildren = [];
  3441. const seenSlotNames = /* @__PURE__ */ new Set();
  3442. let conditionalBranchIndex = 0;
  3443. for (let i = 0; i < children.length; i++) {
  3444. const slotElement = children[i];
  3445. let slotDir;
  3446. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  3447. if (slotElement.type !== 3) {
  3448. implicitDefaultChildren.push(slotElement);
  3449. }
  3450. continue;
  3451. }
  3452. if (onComponentSlot) {
  3453. context.onError(
  3454. createCompilerError(37, slotDir.loc)
  3455. );
  3456. break;
  3457. }
  3458. hasTemplateSlots = true;
  3459. const { children: slotChildren, loc: slotLoc } = slotElement;
  3460. const {
  3461. arg: slotName = createSimpleExpression(`default`, true),
  3462. exp: slotProps,
  3463. loc: dirLoc
  3464. } = slotDir;
  3465. let staticSlotName;
  3466. if (isStaticExp(slotName)) {
  3467. staticSlotName = slotName ? slotName.content : `default`;
  3468. } else {
  3469. hasDynamicSlots = true;
  3470. }
  3471. const vFor = findDir(slotElement, "for");
  3472. const slotFunction = buildSlotFn(
  3473. slotProps,
  3474. vFor == null ? void 0 : vFor.exp,
  3475. slotChildren,
  3476. slotLoc
  3477. );
  3478. let vIf;
  3479. let vElse;
  3480. if (vIf = findDir(slotElement, "if")) {
  3481. hasDynamicSlots = true;
  3482. dynamicSlots.push(
  3483. createConditionalExpression(
  3484. vIf.exp,
  3485. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  3486. defaultFallback
  3487. )
  3488. );
  3489. } else if (vElse = findDir(
  3490. slotElement,
  3491. /^else(-if)?$/,
  3492. true
  3493. /* allowEmpty */
  3494. )) {
  3495. let j = i;
  3496. let prev;
  3497. while (j--) {
  3498. prev = children[j];
  3499. if (prev.type !== 3) {
  3500. break;
  3501. }
  3502. }
  3503. if (prev && isTemplateNode(prev) && findDir(prev, "if")) {
  3504. children.splice(i, 1);
  3505. i--;
  3506. let conditional = dynamicSlots[dynamicSlots.length - 1];
  3507. while (conditional.alternate.type === 19) {
  3508. conditional = conditional.alternate;
  3509. }
  3510. conditional.alternate = vElse.exp ? createConditionalExpression(
  3511. vElse.exp,
  3512. buildDynamicSlot(
  3513. slotName,
  3514. slotFunction,
  3515. conditionalBranchIndex++
  3516. ),
  3517. defaultFallback
  3518. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  3519. } else {
  3520. context.onError(
  3521. createCompilerError(30, vElse.loc)
  3522. );
  3523. }
  3524. } else if (vFor) {
  3525. hasDynamicSlots = true;
  3526. const parseResult = vFor.parseResult || parseForExpression(vFor.exp, context);
  3527. if (parseResult) {
  3528. dynamicSlots.push(
  3529. createCallExpression(context.helper(RENDER_LIST), [
  3530. parseResult.source,
  3531. createFunctionExpression(
  3532. createForLoopParams(parseResult),
  3533. buildDynamicSlot(slotName, slotFunction),
  3534. true
  3535. /* force newline */
  3536. )
  3537. ])
  3538. );
  3539. } else {
  3540. context.onError(
  3541. createCompilerError(32, vFor.loc)
  3542. );
  3543. }
  3544. } else {
  3545. if (staticSlotName) {
  3546. if (seenSlotNames.has(staticSlotName)) {
  3547. context.onError(
  3548. createCompilerError(
  3549. 38,
  3550. dirLoc
  3551. )
  3552. );
  3553. continue;
  3554. }
  3555. seenSlotNames.add(staticSlotName);
  3556. if (staticSlotName === "default") {
  3557. hasNamedDefaultSlot = true;
  3558. }
  3559. }
  3560. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  3561. }
  3562. }
  3563. if (!onComponentSlot) {
  3564. const buildDefaultSlotProperty = (props, children2) => {
  3565. const fn = buildSlotFn(props, void 0, children2, loc);
  3566. if (context.compatConfig) {
  3567. fn.isNonScopedSlot = true;
  3568. }
  3569. return createObjectProperty(`default`, fn);
  3570. };
  3571. if (!hasTemplateSlots) {
  3572. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  3573. } else if (implicitDefaultChildren.length && // #3766
  3574. // with whitespace: 'preserve', whitespaces between slots will end up in
  3575. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  3576. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  3577. if (hasNamedDefaultSlot) {
  3578. context.onError(
  3579. createCompilerError(
  3580. 39,
  3581. implicitDefaultChildren[0].loc
  3582. )
  3583. );
  3584. } else {
  3585. slotsProperties.push(
  3586. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  3587. );
  3588. }
  3589. }
  3590. }
  3591. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  3592. let slots = createObjectExpression(
  3593. slotsProperties.concat(
  3594. createObjectProperty(
  3595. `_`,
  3596. // 2 = compiled but dynamic = can skip normalization, but must run diff
  3597. // 1 = compiled and static = can skip normalization AND diff as optimized
  3598. createSimpleExpression(
  3599. slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
  3600. false
  3601. )
  3602. )
  3603. ),
  3604. loc
  3605. );
  3606. if (dynamicSlots.length) {
  3607. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  3608. slots,
  3609. createArrayExpression(dynamicSlots)
  3610. ]);
  3611. }
  3612. return {
  3613. slots,
  3614. hasDynamicSlots
  3615. };
  3616. }
  3617. function buildDynamicSlot(name, fn, index) {
  3618. const props = [
  3619. createObjectProperty(`name`, name),
  3620. createObjectProperty(`fn`, fn)
  3621. ];
  3622. if (index != null) {
  3623. props.push(
  3624. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  3625. );
  3626. }
  3627. return createObjectExpression(props);
  3628. }
  3629. function hasForwardedSlots(children) {
  3630. for (let i = 0; i < children.length; i++) {
  3631. const child = children[i];
  3632. switch (child.type) {
  3633. case 1:
  3634. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  3635. return true;
  3636. }
  3637. break;
  3638. case 9:
  3639. if (hasForwardedSlots(child.branches))
  3640. return true;
  3641. break;
  3642. case 10:
  3643. case 11:
  3644. if (hasForwardedSlots(child.children))
  3645. return true;
  3646. break;
  3647. }
  3648. }
  3649. return false;
  3650. }
  3651. function isNonWhitespaceContent(node) {
  3652. if (node.type !== 2 && node.type !== 12)
  3653. return true;
  3654. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  3655. }
  3656. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  3657. const transformElement = (node, context) => {
  3658. return function postTransformElement() {
  3659. node = context.currentNode;
  3660. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  3661. return;
  3662. }
  3663. const { tag, props } = node;
  3664. const isComponent = node.tagType === 1;
  3665. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  3666. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  3667. let vnodeProps;
  3668. let vnodeChildren;
  3669. let vnodePatchFlag;
  3670. let patchFlag = 0;
  3671. let vnodeDynamicProps;
  3672. let dynamicPropNames;
  3673. let vnodeDirectives;
  3674. let shouldUseBlock = (
  3675. // dynamic component may resolve to plain elements
  3676. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  3677. // updates inside get proper isSVG flag at runtime. (#639, #643)
  3678. // This is technically web-specific, but splitting the logic out of core
  3679. // leads to too much unnecessary complexity.
  3680. (tag === "svg" || tag === "foreignObject")
  3681. );
  3682. if (props.length > 0) {
  3683. const propsBuildResult = buildProps(
  3684. node,
  3685. context,
  3686. void 0,
  3687. isComponent,
  3688. isDynamicComponent
  3689. );
  3690. vnodeProps = propsBuildResult.props;
  3691. patchFlag = propsBuildResult.patchFlag;
  3692. dynamicPropNames = propsBuildResult.dynamicPropNames;
  3693. const directives = propsBuildResult.directives;
  3694. vnodeDirectives = directives && directives.length ? createArrayExpression(
  3695. directives.map((dir) => buildDirectiveArgs(dir, context))
  3696. ) : void 0;
  3697. if (propsBuildResult.shouldUseBlock) {
  3698. shouldUseBlock = true;
  3699. }
  3700. }
  3701. if (node.children.length > 0) {
  3702. if (vnodeTag === KEEP_ALIVE) {
  3703. shouldUseBlock = true;
  3704. patchFlag |= 1024;
  3705. if (node.children.length > 1) {
  3706. context.onError(
  3707. createCompilerError(46, {
  3708. start: node.children[0].loc.start,
  3709. end: node.children[node.children.length - 1].loc.end,
  3710. source: ""
  3711. })
  3712. );
  3713. }
  3714. }
  3715. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  3716. vnodeTag !== TELEPORT && // explained above.
  3717. vnodeTag !== KEEP_ALIVE;
  3718. if (shouldBuildAsSlots) {
  3719. const { slots, hasDynamicSlots } = buildSlots(node, context);
  3720. vnodeChildren = slots;
  3721. if (hasDynamicSlots) {
  3722. patchFlag |= 1024;
  3723. }
  3724. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  3725. const child = node.children[0];
  3726. const type = child.type;
  3727. const hasDynamicTextChild = type === 5 || type === 8;
  3728. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  3729. patchFlag |= 1;
  3730. }
  3731. if (hasDynamicTextChild || type === 2) {
  3732. vnodeChildren = child;
  3733. } else {
  3734. vnodeChildren = node.children;
  3735. }
  3736. } else {
  3737. vnodeChildren = node.children;
  3738. }
  3739. }
  3740. if (patchFlag !== 0) {
  3741. {
  3742. if (patchFlag < 0) {
  3743. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  3744. } else {
  3745. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  3746. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  3747. }
  3748. }
  3749. if (dynamicPropNames && dynamicPropNames.length) {
  3750. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  3751. }
  3752. }
  3753. node.codegenNode = createVNodeCall(
  3754. context,
  3755. vnodeTag,
  3756. vnodeProps,
  3757. vnodeChildren,
  3758. vnodePatchFlag,
  3759. vnodeDynamicProps,
  3760. vnodeDirectives,
  3761. !!shouldUseBlock,
  3762. false,
  3763. isComponent,
  3764. node.loc
  3765. );
  3766. };
  3767. };
  3768. function resolveComponentType(node, context, ssr = false) {
  3769. let { tag } = node;
  3770. const isExplicitDynamic = isComponentTag(tag);
  3771. const isProp = findProp(node, "is");
  3772. if (isProp) {
  3773. if (isExplicitDynamic || isCompatEnabled(
  3774. "COMPILER_IS_ON_ELEMENT",
  3775. context
  3776. )) {
  3777. const exp = isProp.type === 6 ? isProp.value && createSimpleExpression(isProp.value.content, true) : isProp.exp;
  3778. if (exp) {
  3779. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  3780. exp
  3781. ]);
  3782. }
  3783. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  3784. tag = isProp.value.content.slice(4);
  3785. }
  3786. }
  3787. const isDir = !isExplicitDynamic && findDir(node, "is");
  3788. if (isDir && isDir.exp) {
  3789. {
  3790. context.onWarn(
  3791. createCompilerError(52, isDir.loc)
  3792. );
  3793. }
  3794. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  3795. isDir.exp
  3796. ]);
  3797. }
  3798. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  3799. if (builtIn) {
  3800. if (!ssr)
  3801. context.helper(builtIn);
  3802. return builtIn;
  3803. }
  3804. context.helper(RESOLVE_COMPONENT);
  3805. context.components.add(tag);
  3806. return toValidAssetId(tag, `component`);
  3807. }
  3808. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  3809. const { tag, loc: elementLoc, children } = node;
  3810. let properties = [];
  3811. const mergeArgs = [];
  3812. const runtimeDirectives = [];
  3813. const hasChildren = children.length > 0;
  3814. let shouldUseBlock = false;
  3815. let patchFlag = 0;
  3816. let hasRef = false;
  3817. let hasClassBinding = false;
  3818. let hasStyleBinding = false;
  3819. let hasHydrationEventBinding = false;
  3820. let hasDynamicKeys = false;
  3821. let hasVnodeHook = false;
  3822. const dynamicPropNames = [];
  3823. const pushMergeArg = (arg) => {
  3824. if (properties.length) {
  3825. mergeArgs.push(
  3826. createObjectExpression(dedupeProperties(properties), elementLoc)
  3827. );
  3828. properties = [];
  3829. }
  3830. if (arg)
  3831. mergeArgs.push(arg);
  3832. };
  3833. const analyzePatchFlag = ({ key, value }) => {
  3834. if (isStaticExp(key)) {
  3835. const name = key.content;
  3836. const isEventHandler = isOn(name);
  3837. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  3838. // dedicated fast path.
  3839. name.toLowerCase() !== "onclick" && // omit v-model handlers
  3840. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  3841. !isReservedProp(name)) {
  3842. hasHydrationEventBinding = true;
  3843. }
  3844. if (isEventHandler && isReservedProp(name)) {
  3845. hasVnodeHook = true;
  3846. }
  3847. if (isEventHandler && value.type === 14) {
  3848. value = value.arguments[0];
  3849. }
  3850. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  3851. return;
  3852. }
  3853. if (name === "ref") {
  3854. hasRef = true;
  3855. } else if (name === "class") {
  3856. hasClassBinding = true;
  3857. } else if (name === "style") {
  3858. hasStyleBinding = true;
  3859. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  3860. dynamicPropNames.push(name);
  3861. }
  3862. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  3863. dynamicPropNames.push(name);
  3864. }
  3865. } else {
  3866. hasDynamicKeys = true;
  3867. }
  3868. };
  3869. for (let i = 0; i < props.length; i++) {
  3870. const prop = props[i];
  3871. if (prop.type === 6) {
  3872. const { loc, name, value } = prop;
  3873. let isStatic = true;
  3874. if (name === "ref") {
  3875. hasRef = true;
  3876. if (context.scopes.vFor > 0) {
  3877. properties.push(
  3878. createObjectProperty(
  3879. createSimpleExpression("ref_for", true),
  3880. createSimpleExpression("true")
  3881. )
  3882. );
  3883. }
  3884. }
  3885. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
  3886. "COMPILER_IS_ON_ELEMENT",
  3887. context
  3888. ))) {
  3889. continue;
  3890. }
  3891. properties.push(
  3892. createObjectProperty(
  3893. createSimpleExpression(
  3894. name,
  3895. true,
  3896. getInnerRange(loc, 0, name.length)
  3897. ),
  3898. createSimpleExpression(
  3899. value ? value.content : "",
  3900. isStatic,
  3901. value ? value.loc : loc
  3902. )
  3903. )
  3904. );
  3905. } else {
  3906. const { name, arg, exp, loc, modifiers } = prop;
  3907. const isVBind = name === "bind";
  3908. const isVOn = name === "on";
  3909. if (name === "slot") {
  3910. if (!isComponent) {
  3911. context.onError(
  3912. createCompilerError(40, loc)
  3913. );
  3914. }
  3915. continue;
  3916. }
  3917. if (name === "once" || name === "memo") {
  3918. continue;
  3919. }
  3920. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
  3921. "COMPILER_IS_ON_ELEMENT",
  3922. context
  3923. ))) {
  3924. continue;
  3925. }
  3926. if (isVOn && ssr) {
  3927. continue;
  3928. }
  3929. if (
  3930. // #938: elements with dynamic keys should be forced into blocks
  3931. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  3932. // before children
  3933. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  3934. ) {
  3935. shouldUseBlock = true;
  3936. }
  3937. if (isVBind && isStaticArgOf(arg, "ref") && context.scopes.vFor > 0) {
  3938. properties.push(
  3939. createObjectProperty(
  3940. createSimpleExpression("ref_for", true),
  3941. createSimpleExpression("true")
  3942. )
  3943. );
  3944. }
  3945. if (!arg && (isVBind || isVOn)) {
  3946. hasDynamicKeys = true;
  3947. if (exp) {
  3948. if (isVBind) {
  3949. pushMergeArg();
  3950. {
  3951. {
  3952. const hasOverridableKeys = mergeArgs.some((arg2) => {
  3953. if (arg2.type === 15) {
  3954. return arg2.properties.some(({ key }) => {
  3955. if (key.type !== 4 || !key.isStatic) {
  3956. return true;
  3957. }
  3958. return key.content !== "class" && key.content !== "style" && !isOn(key.content);
  3959. });
  3960. } else {
  3961. return true;
  3962. }
  3963. });
  3964. if (hasOverridableKeys) {
  3965. checkCompatEnabled(
  3966. "COMPILER_V_BIND_OBJECT_ORDER",
  3967. context,
  3968. loc
  3969. );
  3970. }
  3971. }
  3972. if (isCompatEnabled(
  3973. "COMPILER_V_BIND_OBJECT_ORDER",
  3974. context
  3975. )) {
  3976. mergeArgs.unshift(exp);
  3977. continue;
  3978. }
  3979. }
  3980. mergeArgs.push(exp);
  3981. } else {
  3982. pushMergeArg({
  3983. type: 14,
  3984. loc,
  3985. callee: context.helper(TO_HANDLERS),
  3986. arguments: isComponent ? [exp] : [exp, `true`]
  3987. });
  3988. }
  3989. } else {
  3990. context.onError(
  3991. createCompilerError(
  3992. isVBind ? 34 : 35,
  3993. loc
  3994. )
  3995. );
  3996. }
  3997. continue;
  3998. }
  3999. if (isVBind && modifiers.includes("prop")) {
  4000. patchFlag |= 32;
  4001. }
  4002. const directiveTransform = context.directiveTransforms[name];
  4003. if (directiveTransform) {
  4004. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  4005. !ssr && props2.forEach(analyzePatchFlag);
  4006. if (isVOn && arg && !isStaticExp(arg)) {
  4007. pushMergeArg(createObjectExpression(props2, elementLoc));
  4008. } else {
  4009. properties.push(...props2);
  4010. }
  4011. if (needRuntime) {
  4012. runtimeDirectives.push(prop);
  4013. if (isSymbol(needRuntime)) {
  4014. directiveImportMap.set(prop, needRuntime);
  4015. }
  4016. }
  4017. } else if (!isBuiltInDirective(name)) {
  4018. runtimeDirectives.push(prop);
  4019. if (hasChildren) {
  4020. shouldUseBlock = true;
  4021. }
  4022. }
  4023. }
  4024. }
  4025. let propsExpression = void 0;
  4026. if (mergeArgs.length) {
  4027. pushMergeArg();
  4028. if (mergeArgs.length > 1) {
  4029. propsExpression = createCallExpression(
  4030. context.helper(MERGE_PROPS),
  4031. mergeArgs,
  4032. elementLoc
  4033. );
  4034. } else {
  4035. propsExpression = mergeArgs[0];
  4036. }
  4037. } else if (properties.length) {
  4038. propsExpression = createObjectExpression(
  4039. dedupeProperties(properties),
  4040. elementLoc
  4041. );
  4042. }
  4043. if (hasDynamicKeys) {
  4044. patchFlag |= 16;
  4045. } else {
  4046. if (hasClassBinding && !isComponent) {
  4047. patchFlag |= 2;
  4048. }
  4049. if (hasStyleBinding && !isComponent) {
  4050. patchFlag |= 4;
  4051. }
  4052. if (dynamicPropNames.length) {
  4053. patchFlag |= 8;
  4054. }
  4055. if (hasHydrationEventBinding) {
  4056. patchFlag |= 32;
  4057. }
  4058. }
  4059. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  4060. patchFlag |= 512;
  4061. }
  4062. if (!context.inSSR && propsExpression) {
  4063. switch (propsExpression.type) {
  4064. case 15:
  4065. let classKeyIndex = -1;
  4066. let styleKeyIndex = -1;
  4067. let hasDynamicKey = false;
  4068. for (let i = 0; i < propsExpression.properties.length; i++) {
  4069. const key = propsExpression.properties[i].key;
  4070. if (isStaticExp(key)) {
  4071. if (key.content === "class") {
  4072. classKeyIndex = i;
  4073. } else if (key.content === "style") {
  4074. styleKeyIndex = i;
  4075. }
  4076. } else if (!key.isHandlerKey) {
  4077. hasDynamicKey = true;
  4078. }
  4079. }
  4080. const classProp = propsExpression.properties[classKeyIndex];
  4081. const styleProp = propsExpression.properties[styleKeyIndex];
  4082. if (!hasDynamicKey) {
  4083. if (classProp && !isStaticExp(classProp.value)) {
  4084. classProp.value = createCallExpression(
  4085. context.helper(NORMALIZE_CLASS),
  4086. [classProp.value]
  4087. );
  4088. }
  4089. if (styleProp && // the static style is compiled into an object,
  4090. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  4091. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  4092. // v-bind:style with static literal object
  4093. styleProp.value.type === 17)) {
  4094. styleProp.value = createCallExpression(
  4095. context.helper(NORMALIZE_STYLE),
  4096. [styleProp.value]
  4097. );
  4098. }
  4099. } else {
  4100. propsExpression = createCallExpression(
  4101. context.helper(NORMALIZE_PROPS),
  4102. [propsExpression]
  4103. );
  4104. }
  4105. break;
  4106. case 14:
  4107. break;
  4108. default:
  4109. propsExpression = createCallExpression(
  4110. context.helper(NORMALIZE_PROPS),
  4111. [
  4112. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  4113. propsExpression
  4114. ])
  4115. ]
  4116. );
  4117. break;
  4118. }
  4119. }
  4120. return {
  4121. props: propsExpression,
  4122. directives: runtimeDirectives,
  4123. patchFlag,
  4124. dynamicPropNames,
  4125. shouldUseBlock
  4126. };
  4127. }
  4128. function dedupeProperties(properties) {
  4129. const knownProps = /* @__PURE__ */ new Map();
  4130. const deduped = [];
  4131. for (let i = 0; i < properties.length; i++) {
  4132. const prop = properties[i];
  4133. if (prop.key.type === 8 || !prop.key.isStatic) {
  4134. deduped.push(prop);
  4135. continue;
  4136. }
  4137. const name = prop.key.content;
  4138. const existing = knownProps.get(name);
  4139. if (existing) {
  4140. if (name === "style" || name === "class" || isOn(name)) {
  4141. mergeAsArray(existing, prop);
  4142. }
  4143. } else {
  4144. knownProps.set(name, prop);
  4145. deduped.push(prop);
  4146. }
  4147. }
  4148. return deduped;
  4149. }
  4150. function mergeAsArray(existing, incoming) {
  4151. if (existing.value.type === 17) {
  4152. existing.value.elements.push(incoming.value);
  4153. } else {
  4154. existing.value = createArrayExpression(
  4155. [existing.value, incoming.value],
  4156. existing.loc
  4157. );
  4158. }
  4159. }
  4160. function buildDirectiveArgs(dir, context) {
  4161. const dirArgs = [];
  4162. const runtime = directiveImportMap.get(dir);
  4163. if (runtime) {
  4164. dirArgs.push(context.helperString(runtime));
  4165. } else {
  4166. {
  4167. context.helper(RESOLVE_DIRECTIVE);
  4168. context.directives.add(dir.name);
  4169. dirArgs.push(toValidAssetId(dir.name, `directive`));
  4170. }
  4171. }
  4172. const { loc } = dir;
  4173. if (dir.exp)
  4174. dirArgs.push(dir.exp);
  4175. if (dir.arg) {
  4176. if (!dir.exp) {
  4177. dirArgs.push(`void 0`);
  4178. }
  4179. dirArgs.push(dir.arg);
  4180. }
  4181. if (Object.keys(dir.modifiers).length) {
  4182. if (!dir.arg) {
  4183. if (!dir.exp) {
  4184. dirArgs.push(`void 0`);
  4185. }
  4186. dirArgs.push(`void 0`);
  4187. }
  4188. const trueExpression = createSimpleExpression(`true`, false, loc);
  4189. dirArgs.push(
  4190. createObjectExpression(
  4191. dir.modifiers.map(
  4192. (modifier) => createObjectProperty(modifier, trueExpression)
  4193. ),
  4194. loc
  4195. )
  4196. );
  4197. }
  4198. return createArrayExpression(dirArgs, dir.loc);
  4199. }
  4200. function stringifyDynamicPropNames(props) {
  4201. let propsNamesString = `[`;
  4202. for (let i = 0, l = props.length; i < l; i++) {
  4203. propsNamesString += JSON.stringify(props[i]);
  4204. if (i < l - 1)
  4205. propsNamesString += ", ";
  4206. }
  4207. return propsNamesString + `]`;
  4208. }
  4209. function isComponentTag(tag) {
  4210. return tag === "component" || tag === "Component";
  4211. }
  4212. const transformSlotOutlet = (node, context) => {
  4213. if (isSlotOutlet(node)) {
  4214. const { children, loc } = node;
  4215. const { slotName, slotProps } = processSlotOutlet(node, context);
  4216. const slotArgs = [
  4217. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  4218. slotName,
  4219. "{}",
  4220. "undefined",
  4221. "true"
  4222. ];
  4223. let expectedLen = 2;
  4224. if (slotProps) {
  4225. slotArgs[2] = slotProps;
  4226. expectedLen = 3;
  4227. }
  4228. if (children.length) {
  4229. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  4230. expectedLen = 4;
  4231. }
  4232. if (context.scopeId && !context.slotted) {
  4233. expectedLen = 5;
  4234. }
  4235. slotArgs.splice(expectedLen);
  4236. node.codegenNode = createCallExpression(
  4237. context.helper(RENDER_SLOT),
  4238. slotArgs,
  4239. loc
  4240. );
  4241. }
  4242. };
  4243. function processSlotOutlet(node, context) {
  4244. let slotName = `"default"`;
  4245. let slotProps = void 0;
  4246. const nonNameProps = [];
  4247. for (let i = 0; i < node.props.length; i++) {
  4248. const p = node.props[i];
  4249. if (p.type === 6) {
  4250. if (p.value) {
  4251. if (p.name === "name") {
  4252. slotName = JSON.stringify(p.value.content);
  4253. } else {
  4254. p.name = camelize(p.name);
  4255. nonNameProps.push(p);
  4256. }
  4257. }
  4258. } else {
  4259. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  4260. if (p.exp)
  4261. slotName = p.exp;
  4262. } else {
  4263. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  4264. p.arg.content = camelize(p.arg.content);
  4265. }
  4266. nonNameProps.push(p);
  4267. }
  4268. }
  4269. }
  4270. if (nonNameProps.length > 0) {
  4271. const { props, directives } = buildProps(
  4272. node,
  4273. context,
  4274. nonNameProps,
  4275. false,
  4276. false
  4277. );
  4278. slotProps = props;
  4279. if (directives.length) {
  4280. context.onError(
  4281. createCompilerError(
  4282. 36,
  4283. directives[0].loc
  4284. )
  4285. );
  4286. }
  4287. }
  4288. return {
  4289. slotName,
  4290. slotProps
  4291. };
  4292. }
  4293. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  4294. const transformOn$1 = (dir, node, context, augmentor) => {
  4295. const { loc, modifiers, arg } = dir;
  4296. if (!dir.exp && !modifiers.length) {
  4297. context.onError(createCompilerError(35, loc));
  4298. }
  4299. let eventName;
  4300. if (arg.type === 4) {
  4301. if (arg.isStatic) {
  4302. let rawName = arg.content;
  4303. if (rawName.startsWith("vnode")) {
  4304. context.onWarn(
  4305. createCompilerError(51, arg.loc)
  4306. );
  4307. }
  4308. if (rawName.startsWith("vue:")) {
  4309. rawName = `vnode-${rawName.slice(4)}`;
  4310. }
  4311. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  4312. // for non-element and vnode lifecycle event listeners, auto convert
  4313. // it to camelCase. See issue #2249
  4314. toHandlerKey(camelize(rawName))
  4315. ) : (
  4316. // preserve case for plain element listeners that have uppercase
  4317. // letters, as these may be custom elements' custom events
  4318. `on:${rawName}`
  4319. );
  4320. eventName = createSimpleExpression(eventString, true, arg.loc);
  4321. } else {
  4322. eventName = createCompoundExpression([
  4323. `${context.helperString(TO_HANDLER_KEY)}(`,
  4324. arg,
  4325. `)`
  4326. ]);
  4327. }
  4328. } else {
  4329. eventName = arg;
  4330. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  4331. eventName.children.push(`)`);
  4332. }
  4333. let exp = dir.exp;
  4334. if (exp && !exp.content.trim()) {
  4335. exp = void 0;
  4336. }
  4337. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  4338. if (exp) {
  4339. const isMemberExp = isMemberExpression(exp.content);
  4340. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  4341. const hasMultipleStatements = exp.content.includes(`;`);
  4342. {
  4343. validateBrowserExpression(
  4344. exp,
  4345. context,
  4346. false,
  4347. hasMultipleStatements
  4348. );
  4349. }
  4350. if (isInlineStatement || shouldCache && isMemberExp) {
  4351. exp = createCompoundExpression([
  4352. `${isInlineStatement ? `$event` : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  4353. exp,
  4354. hasMultipleStatements ? `}` : `)`
  4355. ]);
  4356. }
  4357. }
  4358. let ret = {
  4359. props: [
  4360. createObjectProperty(
  4361. eventName,
  4362. exp || createSimpleExpression(`() => {}`, false, loc)
  4363. )
  4364. ]
  4365. };
  4366. if (augmentor) {
  4367. ret = augmentor(ret);
  4368. }
  4369. if (shouldCache) {
  4370. ret.props[0].value = context.cache(ret.props[0].value);
  4371. }
  4372. ret.props.forEach((p) => p.key.isHandlerKey = true);
  4373. return ret;
  4374. };
  4375. const transformBind = (dir, _node, context) => {
  4376. const { exp, modifiers, loc } = dir;
  4377. const arg = dir.arg;
  4378. if (arg.type !== 4) {
  4379. arg.children.unshift(`(`);
  4380. arg.children.push(`) || ""`);
  4381. } else if (!arg.isStatic) {
  4382. arg.content = `${arg.content} || ""`;
  4383. }
  4384. if (modifiers.includes("camel")) {
  4385. if (arg.type === 4) {
  4386. if (arg.isStatic) {
  4387. arg.content = camelize(arg.content);
  4388. } else {
  4389. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  4390. }
  4391. } else {
  4392. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  4393. arg.children.push(`)`);
  4394. }
  4395. }
  4396. if (!context.inSSR) {
  4397. if (modifiers.includes("prop")) {
  4398. injectPrefix(arg, ".");
  4399. }
  4400. if (modifiers.includes("attr")) {
  4401. injectPrefix(arg, "^");
  4402. }
  4403. }
  4404. if (!exp || exp.type === 4 && !exp.content.trim()) {
  4405. context.onError(createCompilerError(34, loc));
  4406. return {
  4407. props: [createObjectProperty(arg, createSimpleExpression("", true, loc))]
  4408. };
  4409. }
  4410. return {
  4411. props: [createObjectProperty(arg, exp)]
  4412. };
  4413. };
  4414. const injectPrefix = (arg, prefix) => {
  4415. if (arg.type === 4) {
  4416. if (arg.isStatic) {
  4417. arg.content = prefix + arg.content;
  4418. } else {
  4419. arg.content = `\`${prefix}\${${arg.content}}\``;
  4420. }
  4421. } else {
  4422. arg.children.unshift(`'${prefix}' + (`);
  4423. arg.children.push(`)`);
  4424. }
  4425. };
  4426. const transformText = (node, context) => {
  4427. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  4428. return () => {
  4429. const children = node.children;
  4430. let currentContainer = void 0;
  4431. let hasText = false;
  4432. for (let i = 0; i < children.length; i++) {
  4433. const child = children[i];
  4434. if (isText$1(child)) {
  4435. hasText = true;
  4436. for (let j = i + 1; j < children.length; j++) {
  4437. const next = children[j];
  4438. if (isText$1(next)) {
  4439. if (!currentContainer) {
  4440. currentContainer = children[i] = createCompoundExpression(
  4441. [child],
  4442. child.loc
  4443. );
  4444. }
  4445. currentContainer.children.push(` + `, next);
  4446. children.splice(j, 1);
  4447. j--;
  4448. } else {
  4449. currentContainer = void 0;
  4450. break;
  4451. }
  4452. }
  4453. }
  4454. }
  4455. if (!hasText || // if this is a plain element with a single text child, leave it
  4456. // as-is since the runtime has dedicated fast path for this by directly
  4457. // setting textContent of the element.
  4458. // for component root it's always normalized anyway.
  4459. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  4460. // custom directives can potentially add DOM elements arbitrarily,
  4461. // we need to avoid setting textContent of the element at runtime
  4462. // to avoid accidentally overwriting the DOM elements added
  4463. // by the user through custom directives.
  4464. !node.props.find(
  4465. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  4466. ) && // in compat mode, <template> tags with no special directives
  4467. // will be rendered as a fragment so its children must be
  4468. // converted into vnodes.
  4469. !(node.tag === "template"))) {
  4470. return;
  4471. }
  4472. for (let i = 0; i < children.length; i++) {
  4473. const child = children[i];
  4474. if (isText$1(child) || child.type === 8) {
  4475. const callArgs = [];
  4476. if (child.type !== 2 || child.content !== " ") {
  4477. callArgs.push(child);
  4478. }
  4479. if (!context.ssr && getConstantType(child, context) === 0) {
  4480. callArgs.push(
  4481. 1 + (` /* ${PatchFlagNames[1]} */` )
  4482. );
  4483. }
  4484. children[i] = {
  4485. type: 12,
  4486. content: child,
  4487. loc: child.loc,
  4488. codegenNode: createCallExpression(
  4489. context.helper(CREATE_TEXT),
  4490. callArgs
  4491. )
  4492. };
  4493. }
  4494. }
  4495. };
  4496. }
  4497. };
  4498. const seen$1 = /* @__PURE__ */ new WeakSet();
  4499. const transformOnce = (node, context) => {
  4500. if (node.type === 1 && findDir(node, "once", true)) {
  4501. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  4502. return;
  4503. }
  4504. seen$1.add(node);
  4505. context.inVOnce = true;
  4506. context.helper(SET_BLOCK_TRACKING);
  4507. return () => {
  4508. context.inVOnce = false;
  4509. const cur = context.currentNode;
  4510. if (cur.codegenNode) {
  4511. cur.codegenNode = context.cache(
  4512. cur.codegenNode,
  4513. true
  4514. /* isVNode */
  4515. );
  4516. }
  4517. };
  4518. }
  4519. };
  4520. const transformModel$1 = (dir, node, context) => {
  4521. const { exp, arg } = dir;
  4522. if (!exp) {
  4523. context.onError(
  4524. createCompilerError(41, dir.loc)
  4525. );
  4526. return createTransformProps();
  4527. }
  4528. const rawExp = exp.loc.source;
  4529. const expString = exp.type === 4 ? exp.content : rawExp;
  4530. const bindingType = context.bindingMetadata[rawExp];
  4531. if (bindingType === "props" || bindingType === "props-aliased") {
  4532. context.onError(createCompilerError(44, exp.loc));
  4533. return createTransformProps();
  4534. }
  4535. const maybeRef = false;
  4536. if (!expString.trim() || !isMemberExpression(expString) && !maybeRef) {
  4537. context.onError(
  4538. createCompilerError(42, exp.loc)
  4539. );
  4540. return createTransformProps();
  4541. }
  4542. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  4543. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  4544. let assignmentExp;
  4545. const eventArg = context.isTS ? `($event: any)` : `$event`;
  4546. {
  4547. assignmentExp = createCompoundExpression([
  4548. `${eventArg} => ((`,
  4549. exp,
  4550. `) = $event)`
  4551. ]);
  4552. }
  4553. const props = [
  4554. // modelValue: foo
  4555. createObjectProperty(propName, dir.exp),
  4556. // "onUpdate:modelValue": $event => (foo = $event)
  4557. createObjectProperty(eventName, assignmentExp)
  4558. ];
  4559. if (dir.modifiers.length && node.tagType === 1) {
  4560. const modifiers = dir.modifiers.map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  4561. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  4562. props.push(
  4563. createObjectProperty(
  4564. modifiersKey,
  4565. createSimpleExpression(
  4566. `{ ${modifiers} }`,
  4567. false,
  4568. dir.loc,
  4569. 2
  4570. )
  4571. )
  4572. );
  4573. }
  4574. return createTransformProps(props);
  4575. };
  4576. function createTransformProps(props = []) {
  4577. return { props };
  4578. }
  4579. const validDivisionCharRE = /[\w).+\-_$\]]/;
  4580. const transformFilter = (node, context) => {
  4581. if (!isCompatEnabled("COMPILER_FILTER", context)) {
  4582. return;
  4583. }
  4584. if (node.type === 5) {
  4585. rewriteFilter(node.content, context);
  4586. }
  4587. if (node.type === 1) {
  4588. node.props.forEach((prop) => {
  4589. if (prop.type === 7 && prop.name !== "for" && prop.exp) {
  4590. rewriteFilter(prop.exp, context);
  4591. }
  4592. });
  4593. }
  4594. };
  4595. function rewriteFilter(node, context) {
  4596. if (node.type === 4) {
  4597. parseFilter(node, context);
  4598. } else {
  4599. for (let i = 0; i < node.children.length; i++) {
  4600. const child = node.children[i];
  4601. if (typeof child !== "object")
  4602. continue;
  4603. if (child.type === 4) {
  4604. parseFilter(child, context);
  4605. } else if (child.type === 8) {
  4606. rewriteFilter(node, context);
  4607. } else if (child.type === 5) {
  4608. rewriteFilter(child.content, context);
  4609. }
  4610. }
  4611. }
  4612. }
  4613. function parseFilter(node, context) {
  4614. const exp = node.content;
  4615. let inSingle = false;
  4616. let inDouble = false;
  4617. let inTemplateString = false;
  4618. let inRegex = false;
  4619. let curly = 0;
  4620. let square = 0;
  4621. let paren = 0;
  4622. let lastFilterIndex = 0;
  4623. let c, prev, i, expression, filters = [];
  4624. for (i = 0; i < exp.length; i++) {
  4625. prev = c;
  4626. c = exp.charCodeAt(i);
  4627. if (inSingle) {
  4628. if (c === 39 && prev !== 92)
  4629. inSingle = false;
  4630. } else if (inDouble) {
  4631. if (c === 34 && prev !== 92)
  4632. inDouble = false;
  4633. } else if (inTemplateString) {
  4634. if (c === 96 && prev !== 92)
  4635. inTemplateString = false;
  4636. } else if (inRegex) {
  4637. if (c === 47 && prev !== 92)
  4638. inRegex = false;
  4639. } else if (c === 124 && // pipe
  4640. exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
  4641. if (expression === void 0) {
  4642. lastFilterIndex = i + 1;
  4643. expression = exp.slice(0, i).trim();
  4644. } else {
  4645. pushFilter();
  4646. }
  4647. } else {
  4648. switch (c) {
  4649. case 34:
  4650. inDouble = true;
  4651. break;
  4652. case 39:
  4653. inSingle = true;
  4654. break;
  4655. case 96:
  4656. inTemplateString = true;
  4657. break;
  4658. case 40:
  4659. paren++;
  4660. break;
  4661. case 41:
  4662. paren--;
  4663. break;
  4664. case 91:
  4665. square++;
  4666. break;
  4667. case 93:
  4668. square--;
  4669. break;
  4670. case 123:
  4671. curly++;
  4672. break;
  4673. case 125:
  4674. curly--;
  4675. break;
  4676. }
  4677. if (c === 47) {
  4678. let j = i - 1;
  4679. let p;
  4680. for (; j >= 0; j--) {
  4681. p = exp.charAt(j);
  4682. if (p !== " ")
  4683. break;
  4684. }
  4685. if (!p || !validDivisionCharRE.test(p)) {
  4686. inRegex = true;
  4687. }
  4688. }
  4689. }
  4690. }
  4691. if (expression === void 0) {
  4692. expression = exp.slice(0, i).trim();
  4693. } else if (lastFilterIndex !== 0) {
  4694. pushFilter();
  4695. }
  4696. function pushFilter() {
  4697. filters.push(exp.slice(lastFilterIndex, i).trim());
  4698. lastFilterIndex = i + 1;
  4699. }
  4700. if (filters.length) {
  4701. warnDeprecation(
  4702. "COMPILER_FILTER",
  4703. context,
  4704. node.loc
  4705. );
  4706. for (i = 0; i < filters.length; i++) {
  4707. expression = wrapFilter(expression, filters[i], context);
  4708. }
  4709. node.content = expression;
  4710. }
  4711. }
  4712. function wrapFilter(exp, filter, context) {
  4713. context.helper(RESOLVE_FILTER);
  4714. const i = filter.indexOf("(");
  4715. if (i < 0) {
  4716. context.filters.add(filter);
  4717. return `${toValidAssetId(filter, "filter")}(${exp})`;
  4718. } else {
  4719. const name = filter.slice(0, i);
  4720. const args = filter.slice(i + 1);
  4721. context.filters.add(name);
  4722. return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
  4723. }
  4724. }
  4725. const seen = /* @__PURE__ */ new WeakSet();
  4726. const transformMemo = (node, context) => {
  4727. if (node.type === 1) {
  4728. const dir = findDir(node, "memo");
  4729. if (!dir || seen.has(node)) {
  4730. return;
  4731. }
  4732. seen.add(node);
  4733. return () => {
  4734. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  4735. if (codegenNode && codegenNode.type === 13) {
  4736. if (node.tagType !== 1) {
  4737. convertToBlock(codegenNode, context);
  4738. }
  4739. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  4740. dir.exp,
  4741. createFunctionExpression(void 0, codegenNode),
  4742. `_cache`,
  4743. String(context.cached++)
  4744. ]);
  4745. }
  4746. };
  4747. }
  4748. };
  4749. function getBaseTransformPreset(prefixIdentifiers) {
  4750. return [
  4751. [
  4752. transformOnce,
  4753. transformIf,
  4754. transformMemo,
  4755. transformFor,
  4756. ...[transformFilter] ,
  4757. ...[transformExpression] ,
  4758. transformSlotOutlet,
  4759. transformElement,
  4760. trackSlotScopes,
  4761. transformText
  4762. ],
  4763. {
  4764. on: transformOn$1,
  4765. bind: transformBind,
  4766. model: transformModel$1
  4767. }
  4768. ];
  4769. }
  4770. function baseCompile(template, options = {}) {
  4771. const onError = options.onError || defaultOnError;
  4772. const isModuleMode = options.mode === "module";
  4773. {
  4774. if (options.prefixIdentifiers === true) {
  4775. onError(createCompilerError(47));
  4776. } else if (isModuleMode) {
  4777. onError(createCompilerError(48));
  4778. }
  4779. }
  4780. const prefixIdentifiers = false;
  4781. if (options.cacheHandlers) {
  4782. onError(createCompilerError(49));
  4783. }
  4784. if (options.scopeId && !isModuleMode) {
  4785. onError(createCompilerError(50));
  4786. }
  4787. const ast = isString(template) ? baseParse(template, options) : template;
  4788. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  4789. transform(
  4790. ast,
  4791. extend({}, options, {
  4792. prefixIdentifiers,
  4793. nodeTransforms: [
  4794. ...nodeTransforms,
  4795. ...options.nodeTransforms || []
  4796. // user transforms
  4797. ],
  4798. directiveTransforms: extend(
  4799. {},
  4800. directiveTransforms,
  4801. options.directiveTransforms || {}
  4802. // user transforms
  4803. )
  4804. })
  4805. );
  4806. return generate(
  4807. ast,
  4808. extend({}, options, {
  4809. prefixIdentifiers
  4810. })
  4811. );
  4812. }
  4813. const noopDirectiveTransform = () => ({ props: [] });
  4814. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  4815. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  4816. const V_MODEL_TEXT = Symbol(`vModelText` );
  4817. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  4818. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  4819. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  4820. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  4821. const V_SHOW = Symbol(`vShow` );
  4822. const TRANSITION = Symbol(`Transition` );
  4823. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  4824. registerRuntimeHelpers({
  4825. [V_MODEL_RADIO]: `vModelRadio`,
  4826. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  4827. [V_MODEL_TEXT]: `vModelText`,
  4828. [V_MODEL_SELECT]: `vModelSelect`,
  4829. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  4830. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  4831. [V_ON_WITH_KEYS]: `withKeys`,
  4832. [V_SHOW]: `vShow`,
  4833. [TRANSITION]: `Transition`,
  4834. [TRANSITION_GROUP]: `TransitionGroup`
  4835. });
  4836. let decoder;
  4837. function decodeHtmlBrowser(raw, asAttr = false) {
  4838. if (!decoder) {
  4839. decoder = document.createElement("div");
  4840. }
  4841. if (asAttr) {
  4842. decoder.innerHTML = `<div foo="${raw.replace(/"/g, "&quot;")}">`;
  4843. return decoder.children[0].getAttribute("foo");
  4844. } else {
  4845. decoder.innerHTML = raw;
  4846. return decoder.textContent;
  4847. }
  4848. }
  4849. const isRawTextContainer = /* @__PURE__ */ makeMap(
  4850. "style,iframe,script,noscript",
  4851. true
  4852. );
  4853. const parserOptions = {
  4854. isVoidTag,
  4855. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag),
  4856. isPreTag: (tag) => tag === "pre",
  4857. decodeEntities: decodeHtmlBrowser ,
  4858. isBuiltInComponent: (tag) => {
  4859. if (isBuiltInType(tag, `Transition`)) {
  4860. return TRANSITION;
  4861. } else if (isBuiltInType(tag, `TransitionGroup`)) {
  4862. return TRANSITION_GROUP;
  4863. }
  4864. },
  4865. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  4866. getNamespace(tag, parent) {
  4867. let ns = parent ? parent.ns : 0;
  4868. if (parent && ns === 2) {
  4869. if (parent.tag === "annotation-xml") {
  4870. if (tag === "svg") {
  4871. return 1;
  4872. }
  4873. if (parent.props.some(
  4874. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  4875. )) {
  4876. ns = 0;
  4877. }
  4878. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  4879. ns = 0;
  4880. }
  4881. } else if (parent && ns === 1) {
  4882. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  4883. ns = 0;
  4884. }
  4885. }
  4886. if (ns === 0) {
  4887. if (tag === "svg") {
  4888. return 1;
  4889. }
  4890. if (tag === "math") {
  4891. return 2;
  4892. }
  4893. }
  4894. return ns;
  4895. },
  4896. // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
  4897. getTextMode({ tag, ns }) {
  4898. if (ns === 0) {
  4899. if (tag === "textarea" || tag === "title") {
  4900. return 1;
  4901. }
  4902. if (isRawTextContainer(tag)) {
  4903. return 2;
  4904. }
  4905. }
  4906. return 0;
  4907. }
  4908. };
  4909. const transformStyle = (node) => {
  4910. if (node.type === 1) {
  4911. node.props.forEach((p, i) => {
  4912. if (p.type === 6 && p.name === "style" && p.value) {
  4913. node.props[i] = {
  4914. type: 7,
  4915. name: `bind`,
  4916. arg: createSimpleExpression(`style`, true, p.loc),
  4917. exp: parseInlineCSS(p.value.content, p.loc),
  4918. modifiers: [],
  4919. loc: p.loc
  4920. };
  4921. }
  4922. });
  4923. }
  4924. };
  4925. const parseInlineCSS = (cssText, loc) => {
  4926. const normalized = parseStringStyle(cssText);
  4927. return createSimpleExpression(
  4928. JSON.stringify(normalized),
  4929. false,
  4930. loc,
  4931. 3
  4932. );
  4933. };
  4934. function createDOMCompilerError(code, loc) {
  4935. return createCompilerError(
  4936. code,
  4937. loc,
  4938. DOMErrorMessages
  4939. );
  4940. }
  4941. const DOMErrorMessages = {
  4942. [53]: `v-html is missing expression.`,
  4943. [54]: `v-html will override element children.`,
  4944. [55]: `v-text is missing expression.`,
  4945. [56]: `v-text will override element children.`,
  4946. [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  4947. [58]: `v-model argument is not supported on plain elements.`,
  4948. [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  4949. [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  4950. [61]: `v-show is missing expression.`,
  4951. [62]: `<Transition> expects exactly one child element or component.`,
  4952. [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  4953. };
  4954. const transformVHtml = (dir, node, context) => {
  4955. const { exp, loc } = dir;
  4956. if (!exp) {
  4957. context.onError(
  4958. createDOMCompilerError(53, loc)
  4959. );
  4960. }
  4961. if (node.children.length) {
  4962. context.onError(
  4963. createDOMCompilerError(54, loc)
  4964. );
  4965. node.children.length = 0;
  4966. }
  4967. return {
  4968. props: [
  4969. createObjectProperty(
  4970. createSimpleExpression(`innerHTML`, true, loc),
  4971. exp || createSimpleExpression("", true)
  4972. )
  4973. ]
  4974. };
  4975. };
  4976. const transformVText = (dir, node, context) => {
  4977. const { exp, loc } = dir;
  4978. if (!exp) {
  4979. context.onError(
  4980. createDOMCompilerError(55, loc)
  4981. );
  4982. }
  4983. if (node.children.length) {
  4984. context.onError(
  4985. createDOMCompilerError(56, loc)
  4986. );
  4987. node.children.length = 0;
  4988. }
  4989. return {
  4990. props: [
  4991. createObjectProperty(
  4992. createSimpleExpression(`textContent`, true),
  4993. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  4994. context.helperString(TO_DISPLAY_STRING),
  4995. [exp],
  4996. loc
  4997. ) : createSimpleExpression("", true)
  4998. )
  4999. ]
  5000. };
  5001. };
  5002. const transformModel = (dir, node, context) => {
  5003. const baseResult = transformModel$1(dir, node, context);
  5004. if (!baseResult.props.length || node.tagType === 1) {
  5005. return baseResult;
  5006. }
  5007. if (dir.arg) {
  5008. context.onError(
  5009. createDOMCompilerError(
  5010. 58,
  5011. dir.arg.loc
  5012. )
  5013. );
  5014. }
  5015. function checkDuplicatedValue() {
  5016. const value = findDir(node, "bind");
  5017. if (value && isStaticArgOf(value.arg, "value")) {
  5018. context.onError(
  5019. createDOMCompilerError(
  5020. 60,
  5021. value.loc
  5022. )
  5023. );
  5024. }
  5025. }
  5026. const { tag } = node;
  5027. const isCustomElement = context.isCustomElement(tag);
  5028. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  5029. let directiveToUse = V_MODEL_TEXT;
  5030. let isInvalidType = false;
  5031. if (tag === "input" || isCustomElement) {
  5032. const type = findProp(node, `type`);
  5033. if (type) {
  5034. if (type.type === 7) {
  5035. directiveToUse = V_MODEL_DYNAMIC;
  5036. } else if (type.value) {
  5037. switch (type.value.content) {
  5038. case "radio":
  5039. directiveToUse = V_MODEL_RADIO;
  5040. break;
  5041. case "checkbox":
  5042. directiveToUse = V_MODEL_CHECKBOX;
  5043. break;
  5044. case "file":
  5045. isInvalidType = true;
  5046. context.onError(
  5047. createDOMCompilerError(
  5048. 59,
  5049. dir.loc
  5050. )
  5051. );
  5052. break;
  5053. default:
  5054. checkDuplicatedValue();
  5055. break;
  5056. }
  5057. }
  5058. } else if (hasDynamicKeyVBind(node)) {
  5059. directiveToUse = V_MODEL_DYNAMIC;
  5060. } else {
  5061. checkDuplicatedValue();
  5062. }
  5063. } else if (tag === "select") {
  5064. directiveToUse = V_MODEL_SELECT;
  5065. } else {
  5066. checkDuplicatedValue();
  5067. }
  5068. if (!isInvalidType) {
  5069. baseResult.needRuntime = context.helper(directiveToUse);
  5070. }
  5071. } else {
  5072. context.onError(
  5073. createDOMCompilerError(
  5074. 57,
  5075. dir.loc
  5076. )
  5077. );
  5078. }
  5079. baseResult.props = baseResult.props.filter(
  5080. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  5081. );
  5082. return baseResult;
  5083. };
  5084. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  5085. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  5086. // event propagation management
  5087. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  5088. );
  5089. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  5090. const isKeyboardEvent = /* @__PURE__ */ makeMap(
  5091. `onkeyup,onkeydown,onkeypress`,
  5092. true
  5093. );
  5094. const resolveModifiers = (key, modifiers, context, loc) => {
  5095. const keyModifiers = [];
  5096. const nonKeyModifiers = [];
  5097. const eventOptionModifiers = [];
  5098. for (let i = 0; i < modifiers.length; i++) {
  5099. const modifier = modifiers[i];
  5100. if (modifier === "native" && checkCompatEnabled(
  5101. "COMPILER_V_ON_NATIVE",
  5102. context,
  5103. loc
  5104. )) {
  5105. eventOptionModifiers.push(modifier);
  5106. } else if (isEventOptionModifier(modifier)) {
  5107. eventOptionModifiers.push(modifier);
  5108. } else {
  5109. if (maybeKeyModifier(modifier)) {
  5110. if (isStaticExp(key)) {
  5111. if (isKeyboardEvent(key.content)) {
  5112. keyModifiers.push(modifier);
  5113. } else {
  5114. nonKeyModifiers.push(modifier);
  5115. }
  5116. } else {
  5117. keyModifiers.push(modifier);
  5118. nonKeyModifiers.push(modifier);
  5119. }
  5120. } else {
  5121. if (isNonKeyModifier(modifier)) {
  5122. nonKeyModifiers.push(modifier);
  5123. } else {
  5124. keyModifiers.push(modifier);
  5125. }
  5126. }
  5127. }
  5128. }
  5129. return {
  5130. keyModifiers,
  5131. nonKeyModifiers,
  5132. eventOptionModifiers
  5133. };
  5134. };
  5135. const transformClick = (key, event) => {
  5136. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  5137. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  5138. `(`,
  5139. key,
  5140. `) === "onClick" ? "${event}" : (`,
  5141. key,
  5142. `)`
  5143. ]) : key;
  5144. };
  5145. const transformOn = (dir, node, context) => {
  5146. return transformOn$1(dir, node, context, (baseResult) => {
  5147. const { modifiers } = dir;
  5148. if (!modifiers.length)
  5149. return baseResult;
  5150. let { key, value: handlerExp } = baseResult.props[0];
  5151. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  5152. if (nonKeyModifiers.includes("right")) {
  5153. key = transformClick(key, `onContextmenu`);
  5154. }
  5155. if (nonKeyModifiers.includes("middle")) {
  5156. key = transformClick(key, `onMouseup`);
  5157. }
  5158. if (nonKeyModifiers.length) {
  5159. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  5160. handlerExp,
  5161. JSON.stringify(nonKeyModifiers)
  5162. ]);
  5163. }
  5164. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  5165. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  5166. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  5167. handlerExp,
  5168. JSON.stringify(keyModifiers)
  5169. ]);
  5170. }
  5171. if (eventOptionModifiers.length) {
  5172. const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
  5173. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  5174. }
  5175. return {
  5176. props: [createObjectProperty(key, handlerExp)]
  5177. };
  5178. });
  5179. };
  5180. const transformShow = (dir, node, context) => {
  5181. const { exp, loc } = dir;
  5182. if (!exp) {
  5183. context.onError(
  5184. createDOMCompilerError(61, loc)
  5185. );
  5186. }
  5187. return {
  5188. props: [],
  5189. needRuntime: context.helper(V_SHOW)
  5190. };
  5191. };
  5192. const transformTransition = (node, context) => {
  5193. if (node.type === 1 && node.tagType === 1) {
  5194. const component = context.isBuiltInComponent(node.tag);
  5195. if (component === TRANSITION) {
  5196. return () => {
  5197. if (!node.children.length) {
  5198. return;
  5199. }
  5200. if (hasMultipleChildren(node)) {
  5201. context.onError(
  5202. createDOMCompilerError(
  5203. 62,
  5204. {
  5205. start: node.children[0].loc.start,
  5206. end: node.children[node.children.length - 1].loc.end,
  5207. source: ""
  5208. }
  5209. )
  5210. );
  5211. }
  5212. const child = node.children[0];
  5213. if (child.type === 1) {
  5214. for (const p of child.props) {
  5215. if (p.type === 7 && p.name === "show") {
  5216. node.props.push({
  5217. type: 6,
  5218. name: "persisted",
  5219. value: void 0,
  5220. loc: node.loc
  5221. });
  5222. }
  5223. }
  5224. }
  5225. };
  5226. }
  5227. }
  5228. };
  5229. function hasMultipleChildren(node) {
  5230. const children = node.children = node.children.filter(
  5231. (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
  5232. );
  5233. const child = children[0];
  5234. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  5235. }
  5236. const ignoreSideEffectTags = (node, context) => {
  5237. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  5238. context.onError(
  5239. createDOMCompilerError(
  5240. 63,
  5241. node.loc
  5242. )
  5243. );
  5244. context.removeNode();
  5245. }
  5246. };
  5247. const DOMNodeTransforms = [
  5248. transformStyle,
  5249. ...[transformTransition]
  5250. ];
  5251. const DOMDirectiveTransforms = {
  5252. cloak: noopDirectiveTransform,
  5253. html: transformVHtml,
  5254. text: transformVText,
  5255. model: transformModel,
  5256. // override compiler-core
  5257. on: transformOn,
  5258. // override compiler-core
  5259. show: transformShow
  5260. };
  5261. function compile(template, options = {}) {
  5262. return baseCompile(
  5263. template,
  5264. extend({}, parserOptions, options, {
  5265. nodeTransforms: [
  5266. // ignore <script> and <tag>
  5267. // this is not put inside DOMNodeTransforms because that list is used
  5268. // by compiler-ssr to generate vnode fallback branches
  5269. ignoreSideEffectTags,
  5270. ...DOMNodeTransforms,
  5271. ...options.nodeTransforms || []
  5272. ],
  5273. directiveTransforms: extend(
  5274. {},
  5275. DOMDirectiveTransforms,
  5276. options.directiveTransforms || {}
  5277. ),
  5278. transformHoist: null
  5279. })
  5280. );
  5281. }
  5282. function parse(template, options = {}) {
  5283. return baseParse(template, extend({}, parserOptions, options));
  5284. }
  5285. export { BASE_TRANSITION, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, DOMDirectiveTransforms, DOMNodeTransforms, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TRANSITION, TRANSITION_GROUP, TS_NODE_TYPES, UNREF, V_MODEL_CHECKBOX, V_MODEL_DYNAMIC, V_MODEL_RADIO, V_MODEL_SELECT, V_MODEL_TEXT, V_ON_WITH_KEYS, V_ON_WITH_MODIFIERS, V_SHOW, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, compile, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createDOMCompilerError, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, extractIdentifiers, findDir, findProp, forAliasRE, generate, generateCodeFrame, getBaseTransformPreset, getConstantType, getInnerRange, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isBuiltInType, isCoreComponent, isFunctionType, isInDestructureAssignment, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText$1 as isText, isVSlot, locStub, noopDirectiveTransform, parse, parserOptions, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel$1 as transformModel, transformOn$1 as transformOn, transformStyle, traverseNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };