compiler-dom.global.js 168 KB

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