compiler-dom.esm-browser.js 154 KB

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