e68725d6660636856dd025d8cfc6f81a9f156e8093d6ba174369c294163151a97d084cd6715a7b03fbf514a4ba670fdb8b62166b009940f59ffd7ddde9692b 206 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770
  1. /**
  2. * @vue/compiler-dom v3.5.21
  3. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  4. * @license MIT
  5. **/
  6. var VueCompilerDOM = (function (exports) {
  7. 'use strict';
  8. // @__NO_SIDE_EFFECTS__
  9. function makeMap(str) {
  10. const map = /* @__PURE__ */ Object.create(null);
  11. for (const key of str.split(",")) map[key] = 1;
  12. return (val) => val in map;
  13. }
  14. const EMPTY_OBJ = Object.freeze({}) ;
  15. const NOOP = () => {
  16. };
  17. const NO = () => false;
  18. const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && // uppercase letter
  19. (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
  20. const extend = Object.assign;
  21. const isArray = Array.isArray;
  22. const isString = (val) => typeof val === "string";
  23. const isSymbol = (val) => typeof val === "symbol";
  24. const isObject = (val) => val !== null && typeof val === "object";
  25. const isReservedProp = /* @__PURE__ */ makeMap(
  26. // the leading comma is intentional so empty string "" is also included
  27. ",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"
  28. );
  29. const isBuiltInDirective = /* @__PURE__ */ makeMap(
  30. "bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"
  31. );
  32. const cacheStringFunction = (fn) => {
  33. const cache = /* @__PURE__ */ Object.create(null);
  34. return ((str) => {
  35. const hit = cache[str];
  36. return hit || (cache[str] = fn(str));
  37. });
  38. };
  39. const camelizeRE = /-\w/g;
  40. const camelize = cacheStringFunction(
  41. (str) => {
  42. return str.replace(camelizeRE, (c) => c.slice(1).toUpperCase());
  43. }
  44. );
  45. const capitalize = cacheStringFunction((str) => {
  46. return str.charAt(0).toUpperCase() + str.slice(1);
  47. });
  48. const toHandlerKey = cacheStringFunction(
  49. (str) => {
  50. const s = str ? `on${capitalize(str)}` : ``;
  51. return s;
  52. }
  53. );
  54. const PatchFlagNames = {
  55. [1]: `TEXT`,
  56. [2]: `CLASS`,
  57. [4]: `STYLE`,
  58. [8]: `PROPS`,
  59. [16]: `FULL_PROPS`,
  60. [32]: `NEED_HYDRATION`,
  61. [64]: `STABLE_FRAGMENT`,
  62. [128]: `KEYED_FRAGMENT`,
  63. [256]: `UNKEYED_FRAGMENT`,
  64. [512]: `NEED_PATCH`,
  65. [1024]: `DYNAMIC_SLOTS`,
  66. [2048]: `DEV_ROOT_FRAGMENT`,
  67. [-1]: `CACHED`,
  68. [-2]: `BAIL`
  69. };
  70. const slotFlagsText = {
  71. [1]: "STABLE",
  72. [2]: "DYNAMIC",
  73. [3]: "FORWARDED"
  74. };
  75. const range = 2;
  76. function generateCodeFrame(source, start = 0, end = source.length) {
  77. start = Math.max(0, Math.min(start, source.length));
  78. end = Math.max(0, Math.min(end, source.length));
  79. if (start > end) return "";
  80. let lines = source.split(/(\r?\n)/);
  81. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  82. lines = lines.filter((_, idx) => idx % 2 === 0);
  83. let count = 0;
  84. const res = [];
  85. for (let i = 0; i < lines.length; i++) {
  86. count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
  87. if (count >= start) {
  88. for (let j = i - range; j <= i + range || end > count; j++) {
  89. if (j < 0 || j >= lines.length) continue;
  90. const line = j + 1;
  91. res.push(
  92. `${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
  93. );
  94. const lineLength = lines[j].length;
  95. const newLineSeqLength = newlineSequences[j] && newlineSequences[j].length || 0;
  96. if (j === i) {
  97. const pad = start - (count - (lineLength + newLineSeqLength));
  98. const length = Math.max(
  99. 1,
  100. end > count ? lineLength - pad : end - start
  101. );
  102. res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
  103. } else if (j > i) {
  104. if (end > count) {
  105. const length = Math.max(Math.min(end - count, lineLength), 1);
  106. res.push(` | ` + "^".repeat(length));
  107. }
  108. count += lineLength + newLineSeqLength;
  109. }
  110. }
  111. break;
  112. }
  113. }
  114. return res.join("\n");
  115. }
  116. const listDelimiterRE = /;(?![^(]*\))/g;
  117. const propertyDelimiterRE = /:([^]+)/;
  118. const styleCommentRE = /\/\*[^]*?\*\//g;
  119. function parseStringStyle(cssText) {
  120. const ret = {};
  121. cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
  122. if (item) {
  123. const tmp = item.split(propertyDelimiterRE);
  124. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  125. }
  126. });
  127. return ret;
  128. }
  129. 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";
  130. 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";
  131. const MATH_TAGS = "annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics";
  132. const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
  133. const isHTMLTag = /* @__PURE__ */ makeMap(HTML_TAGS);
  134. const isSVGTag = /* @__PURE__ */ makeMap(SVG_TAGS);
  135. const isMathMLTag = /* @__PURE__ */ makeMap(MATH_TAGS);
  136. const isVoidTag = /* @__PURE__ */ makeMap(VOID_TAGS);
  137. const FRAGMENT = Symbol(`Fragment` );
  138. const TELEPORT = Symbol(`Teleport` );
  139. const SUSPENSE = Symbol(`Suspense` );
  140. const KEEP_ALIVE = Symbol(`KeepAlive` );
  141. const BASE_TRANSITION = Symbol(
  142. `BaseTransition`
  143. );
  144. const OPEN_BLOCK = Symbol(`openBlock` );
  145. const CREATE_BLOCK = Symbol(`createBlock` );
  146. const CREATE_ELEMENT_BLOCK = Symbol(
  147. `createElementBlock`
  148. );
  149. const CREATE_VNODE = Symbol(`createVNode` );
  150. const CREATE_ELEMENT_VNODE = Symbol(
  151. `createElementVNode`
  152. );
  153. const CREATE_COMMENT = Symbol(
  154. `createCommentVNode`
  155. );
  156. const CREATE_TEXT = Symbol(
  157. `createTextVNode`
  158. );
  159. const CREATE_STATIC = Symbol(
  160. `createStaticVNode`
  161. );
  162. const RESOLVE_COMPONENT = Symbol(
  163. `resolveComponent`
  164. );
  165. const RESOLVE_DYNAMIC_COMPONENT = Symbol(
  166. `resolveDynamicComponent`
  167. );
  168. const RESOLVE_DIRECTIVE = Symbol(
  169. `resolveDirective`
  170. );
  171. const RESOLVE_FILTER = Symbol(
  172. `resolveFilter`
  173. );
  174. const WITH_DIRECTIVES = Symbol(
  175. `withDirectives`
  176. );
  177. const RENDER_LIST = Symbol(`renderList` );
  178. const RENDER_SLOT = Symbol(`renderSlot` );
  179. const CREATE_SLOTS = Symbol(`createSlots` );
  180. const TO_DISPLAY_STRING = Symbol(
  181. `toDisplayString`
  182. );
  183. const MERGE_PROPS = Symbol(`mergeProps` );
  184. const NORMALIZE_CLASS = Symbol(
  185. `normalizeClass`
  186. );
  187. const NORMALIZE_STYLE = Symbol(
  188. `normalizeStyle`
  189. );
  190. const NORMALIZE_PROPS = Symbol(
  191. `normalizeProps`
  192. );
  193. const GUARD_REACTIVE_PROPS = Symbol(
  194. `guardReactiveProps`
  195. );
  196. const TO_HANDLERS = Symbol(`toHandlers` );
  197. const CAMELIZE = Symbol(`camelize` );
  198. const CAPITALIZE = Symbol(`capitalize` );
  199. const TO_HANDLER_KEY = Symbol(
  200. `toHandlerKey`
  201. );
  202. const SET_BLOCK_TRACKING = Symbol(
  203. `setBlockTracking`
  204. );
  205. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  206. const POP_SCOPE_ID = Symbol(`popScopeId` );
  207. const WITH_CTX = Symbol(`withCtx` );
  208. const UNREF = Symbol(`unref` );
  209. const IS_REF = Symbol(`isRef` );
  210. const WITH_MEMO = Symbol(`withMemo` );
  211. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  212. const helperNameMap = {
  213. [FRAGMENT]: `Fragment`,
  214. [TELEPORT]: `Teleport`,
  215. [SUSPENSE]: `Suspense`,
  216. [KEEP_ALIVE]: `KeepAlive`,
  217. [BASE_TRANSITION]: `BaseTransition`,
  218. [OPEN_BLOCK]: `openBlock`,
  219. [CREATE_BLOCK]: `createBlock`,
  220. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  221. [CREATE_VNODE]: `createVNode`,
  222. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  223. [CREATE_COMMENT]: `createCommentVNode`,
  224. [CREATE_TEXT]: `createTextVNode`,
  225. [CREATE_STATIC]: `createStaticVNode`,
  226. [RESOLVE_COMPONENT]: `resolveComponent`,
  227. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  228. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  229. [RESOLVE_FILTER]: `resolveFilter`,
  230. [WITH_DIRECTIVES]: `withDirectives`,
  231. [RENDER_LIST]: `renderList`,
  232. [RENDER_SLOT]: `renderSlot`,
  233. [CREATE_SLOTS]: `createSlots`,
  234. [TO_DISPLAY_STRING]: `toDisplayString`,
  235. [MERGE_PROPS]: `mergeProps`,
  236. [NORMALIZE_CLASS]: `normalizeClass`,
  237. [NORMALIZE_STYLE]: `normalizeStyle`,
  238. [NORMALIZE_PROPS]: `normalizeProps`,
  239. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  240. [TO_HANDLERS]: `toHandlers`,
  241. [CAMELIZE]: `camelize`,
  242. [CAPITALIZE]: `capitalize`,
  243. [TO_HANDLER_KEY]: `toHandlerKey`,
  244. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  245. [PUSH_SCOPE_ID]: `pushScopeId`,
  246. [POP_SCOPE_ID]: `popScopeId`,
  247. [WITH_CTX]: `withCtx`,
  248. [UNREF]: `unref`,
  249. [IS_REF]: `isRef`,
  250. [WITH_MEMO]: `withMemo`,
  251. [IS_MEMO_SAME]: `isMemoSame`
  252. };
  253. function registerRuntimeHelpers(helpers) {
  254. Object.getOwnPropertySymbols(helpers).forEach((s) => {
  255. helperNameMap[s] = helpers[s];
  256. });
  257. }
  258. const Namespaces = {
  259. "HTML": 0,
  260. "0": "HTML",
  261. "SVG": 1,
  262. "1": "SVG",
  263. "MATH_ML": 2,
  264. "2": "MATH_ML"
  265. };
  266. const NodeTypes = {
  267. "ROOT": 0,
  268. "0": "ROOT",
  269. "ELEMENT": 1,
  270. "1": "ELEMENT",
  271. "TEXT": 2,
  272. "2": "TEXT",
  273. "COMMENT": 3,
  274. "3": "COMMENT",
  275. "SIMPLE_EXPRESSION": 4,
  276. "4": "SIMPLE_EXPRESSION",
  277. "INTERPOLATION": 5,
  278. "5": "INTERPOLATION",
  279. "ATTRIBUTE": 6,
  280. "6": "ATTRIBUTE",
  281. "DIRECTIVE": 7,
  282. "7": "DIRECTIVE",
  283. "COMPOUND_EXPRESSION": 8,
  284. "8": "COMPOUND_EXPRESSION",
  285. "IF": 9,
  286. "9": "IF",
  287. "IF_BRANCH": 10,
  288. "10": "IF_BRANCH",
  289. "FOR": 11,
  290. "11": "FOR",
  291. "TEXT_CALL": 12,
  292. "12": "TEXT_CALL",
  293. "VNODE_CALL": 13,
  294. "13": "VNODE_CALL",
  295. "JS_CALL_EXPRESSION": 14,
  296. "14": "JS_CALL_EXPRESSION",
  297. "JS_OBJECT_EXPRESSION": 15,
  298. "15": "JS_OBJECT_EXPRESSION",
  299. "JS_PROPERTY": 16,
  300. "16": "JS_PROPERTY",
  301. "JS_ARRAY_EXPRESSION": 17,
  302. "17": "JS_ARRAY_EXPRESSION",
  303. "JS_FUNCTION_EXPRESSION": 18,
  304. "18": "JS_FUNCTION_EXPRESSION",
  305. "JS_CONDITIONAL_EXPRESSION": 19,
  306. "19": "JS_CONDITIONAL_EXPRESSION",
  307. "JS_CACHE_EXPRESSION": 20,
  308. "20": "JS_CACHE_EXPRESSION",
  309. "JS_BLOCK_STATEMENT": 21,
  310. "21": "JS_BLOCK_STATEMENT",
  311. "JS_TEMPLATE_LITERAL": 22,
  312. "22": "JS_TEMPLATE_LITERAL",
  313. "JS_IF_STATEMENT": 23,
  314. "23": "JS_IF_STATEMENT",
  315. "JS_ASSIGNMENT_EXPRESSION": 24,
  316. "24": "JS_ASSIGNMENT_EXPRESSION",
  317. "JS_SEQUENCE_EXPRESSION": 25,
  318. "25": "JS_SEQUENCE_EXPRESSION",
  319. "JS_RETURN_STATEMENT": 26,
  320. "26": "JS_RETURN_STATEMENT"
  321. };
  322. const ElementTypes = {
  323. "ELEMENT": 0,
  324. "0": "ELEMENT",
  325. "COMPONENT": 1,
  326. "1": "COMPONENT",
  327. "SLOT": 2,
  328. "2": "SLOT",
  329. "TEMPLATE": 3,
  330. "3": "TEMPLATE"
  331. };
  332. const ConstantTypes = {
  333. "NOT_CONSTANT": 0,
  334. "0": "NOT_CONSTANT",
  335. "CAN_SKIP_PATCH": 1,
  336. "1": "CAN_SKIP_PATCH",
  337. "CAN_CACHE": 2,
  338. "2": "CAN_CACHE",
  339. "CAN_STRINGIFY": 3,
  340. "3": "CAN_STRINGIFY"
  341. };
  342. const locStub = {
  343. start: { line: 1, column: 1, offset: 0 },
  344. end: { line: 1, column: 1, offset: 0 },
  345. source: ""
  346. };
  347. function createRoot(children, source = "") {
  348. return {
  349. type: 0,
  350. source,
  351. children,
  352. helpers: /* @__PURE__ */ new Set(),
  353. components: [],
  354. directives: [],
  355. hoists: [],
  356. imports: [],
  357. cached: [],
  358. temps: 0,
  359. codegenNode: void 0,
  360. loc: locStub
  361. };
  362. }
  363. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  364. if (context) {
  365. if (isBlock) {
  366. context.helper(OPEN_BLOCK);
  367. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  368. } else {
  369. context.helper(getVNodeHelper(context.inSSR, isComponent));
  370. }
  371. if (directives) {
  372. context.helper(WITH_DIRECTIVES);
  373. }
  374. }
  375. return {
  376. type: 13,
  377. tag,
  378. props,
  379. children,
  380. patchFlag,
  381. dynamicProps,
  382. directives,
  383. isBlock,
  384. disableTracking,
  385. isComponent,
  386. loc
  387. };
  388. }
  389. function createArrayExpression(elements, loc = locStub) {
  390. return {
  391. type: 17,
  392. loc,
  393. elements
  394. };
  395. }
  396. function createObjectExpression(properties, loc = locStub) {
  397. return {
  398. type: 15,
  399. loc,
  400. properties
  401. };
  402. }
  403. function createObjectProperty(key, value) {
  404. return {
  405. type: 16,
  406. loc: locStub,
  407. key: isString(key) ? createSimpleExpression(key, true) : key,
  408. value
  409. };
  410. }
  411. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
  412. return {
  413. type: 4,
  414. loc,
  415. content,
  416. isStatic,
  417. constType: isStatic ? 3 : constType
  418. };
  419. }
  420. function createInterpolation(content, loc) {
  421. return {
  422. type: 5,
  423. loc,
  424. content: isString(content) ? createSimpleExpression(content, false, loc) : content
  425. };
  426. }
  427. function createCompoundExpression(children, loc = locStub) {
  428. return {
  429. type: 8,
  430. loc,
  431. children
  432. };
  433. }
  434. function createCallExpression(callee, args = [], loc = locStub) {
  435. return {
  436. type: 14,
  437. loc,
  438. callee,
  439. arguments: args
  440. };
  441. }
  442. function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
  443. return {
  444. type: 18,
  445. params,
  446. returns,
  447. newline,
  448. isSlot,
  449. loc
  450. };
  451. }
  452. function createConditionalExpression(test, consequent, alternate, newline = true) {
  453. return {
  454. type: 19,
  455. test,
  456. consequent,
  457. alternate,
  458. newline,
  459. loc: locStub
  460. };
  461. }
  462. function createCacheExpression(index, value, needPauseTracking = false, inVOnce = false) {
  463. return {
  464. type: 20,
  465. index,
  466. value,
  467. needPauseTracking,
  468. inVOnce,
  469. needArraySpread: false,
  470. loc: locStub
  471. };
  472. }
  473. function createBlockStatement(body) {
  474. return {
  475. type: 21,
  476. body,
  477. loc: locStub
  478. };
  479. }
  480. function createTemplateLiteral(elements) {
  481. return {
  482. type: 22,
  483. elements,
  484. loc: locStub
  485. };
  486. }
  487. function createIfStatement(test, consequent, alternate) {
  488. return {
  489. type: 23,
  490. test,
  491. consequent,
  492. alternate,
  493. loc: locStub
  494. };
  495. }
  496. function createAssignmentExpression(left, right) {
  497. return {
  498. type: 24,
  499. left,
  500. right,
  501. loc: locStub
  502. };
  503. }
  504. function createSequenceExpression(expressions) {
  505. return {
  506. type: 25,
  507. expressions,
  508. loc: locStub
  509. };
  510. }
  511. function createReturnStatement(returns) {
  512. return {
  513. type: 26,
  514. returns,
  515. loc: locStub
  516. };
  517. }
  518. function getVNodeHelper(ssr, isComponent) {
  519. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  520. }
  521. function getVNodeBlockHelper(ssr, isComponent) {
  522. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  523. }
  524. function convertToBlock(node, { helper, removeHelper, inSSR }) {
  525. if (!node.isBlock) {
  526. node.isBlock = true;
  527. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  528. helper(OPEN_BLOCK);
  529. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  530. }
  531. }
  532. const defaultDelimitersOpen = new Uint8Array([123, 123]);
  533. const defaultDelimitersClose = new Uint8Array([125, 125]);
  534. function isTagStartChar(c) {
  535. return c >= 97 && c <= 122 || c >= 65 && c <= 90;
  536. }
  537. function isWhitespace(c) {
  538. return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
  539. }
  540. function isEndOfTagSection(c) {
  541. return c === 47 || c === 62 || isWhitespace(c);
  542. }
  543. function toCharCodes(str) {
  544. const ret = new Uint8Array(str.length);
  545. for (let i = 0; i < str.length; i++) {
  546. ret[i] = str.charCodeAt(i);
  547. }
  548. return ret;
  549. }
  550. const Sequences = {
  551. Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
  552. // CDATA[
  553. CdataEnd: new Uint8Array([93, 93, 62]),
  554. // ]]>
  555. CommentEnd: new Uint8Array([45, 45, 62]),
  556. // `-->`
  557. ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
  558. // `<\/script`
  559. StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
  560. // `</style`
  561. TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
  562. // `</title`
  563. TextareaEnd: new Uint8Array([
  564. 60,
  565. 47,
  566. 116,
  567. 101,
  568. 120,
  569. 116,
  570. 97,
  571. 114,
  572. 101,
  573. 97
  574. ])
  575. // `</textarea
  576. };
  577. class Tokenizer {
  578. constructor(stack, cbs) {
  579. this.stack = stack;
  580. this.cbs = cbs;
  581. /** The current state the tokenizer is in. */
  582. this.state = 1;
  583. /** The read buffer. */
  584. this.buffer = "";
  585. /** The beginning of the section that is currently being read. */
  586. this.sectionStart = 0;
  587. /** The index within the buffer that we are currently looking at. */
  588. this.index = 0;
  589. /** The start of the last entity. */
  590. this.entityStart = 0;
  591. /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
  592. this.baseState = 1;
  593. /** For special parsing behavior inside of script and style tags. */
  594. this.inRCDATA = false;
  595. /** For disabling RCDATA tags handling */
  596. this.inXML = false;
  597. /** For disabling interpolation parsing in v-pre */
  598. this.inVPre = false;
  599. /** Record newline positions for fast line / column calculation */
  600. this.newlines = [];
  601. this.mode = 0;
  602. this.delimiterOpen = defaultDelimitersOpen;
  603. this.delimiterClose = defaultDelimitersClose;
  604. this.delimiterIndex = -1;
  605. this.currentSequence = void 0;
  606. this.sequenceIndex = 0;
  607. }
  608. get inSFCRoot() {
  609. return this.mode === 2 && this.stack.length === 0;
  610. }
  611. reset() {
  612. this.state = 1;
  613. this.mode = 0;
  614. this.buffer = "";
  615. this.sectionStart = 0;
  616. this.index = 0;
  617. this.baseState = 1;
  618. this.inRCDATA = false;
  619. this.currentSequence = void 0;
  620. this.newlines.length = 0;
  621. this.delimiterOpen = defaultDelimitersOpen;
  622. this.delimiterClose = defaultDelimitersClose;
  623. }
  624. /**
  625. * Generate Position object with line / column information using recorded
  626. * newline positions. We know the index is always going to be an already
  627. * processed index, so all the newlines up to this index should have been
  628. * recorded.
  629. */
  630. getPos(index) {
  631. let line = 1;
  632. let column = index + 1;
  633. for (let i = this.newlines.length - 1; i >= 0; i--) {
  634. const newlineIndex = this.newlines[i];
  635. if (index > newlineIndex) {
  636. line = i + 2;
  637. column = index - newlineIndex;
  638. break;
  639. }
  640. }
  641. return {
  642. column,
  643. line,
  644. offset: index
  645. };
  646. }
  647. peek() {
  648. return this.buffer.charCodeAt(this.index + 1);
  649. }
  650. stateText(c) {
  651. if (c === 60) {
  652. if (this.index > this.sectionStart) {
  653. this.cbs.ontext(this.sectionStart, this.index);
  654. }
  655. this.state = 5;
  656. this.sectionStart = this.index;
  657. } else if (!this.inVPre && c === this.delimiterOpen[0]) {
  658. this.state = 2;
  659. this.delimiterIndex = 0;
  660. this.stateInterpolationOpen(c);
  661. }
  662. }
  663. stateInterpolationOpen(c) {
  664. if (c === this.delimiterOpen[this.delimiterIndex]) {
  665. if (this.delimiterIndex === this.delimiterOpen.length - 1) {
  666. const start = this.index + 1 - this.delimiterOpen.length;
  667. if (start > this.sectionStart) {
  668. this.cbs.ontext(this.sectionStart, start);
  669. }
  670. this.state = 3;
  671. this.sectionStart = start;
  672. } else {
  673. this.delimiterIndex++;
  674. }
  675. } else if (this.inRCDATA) {
  676. this.state = 32;
  677. this.stateInRCDATA(c);
  678. } else {
  679. this.state = 1;
  680. this.stateText(c);
  681. }
  682. }
  683. stateInterpolation(c) {
  684. if (c === this.delimiterClose[0]) {
  685. this.state = 4;
  686. this.delimiterIndex = 0;
  687. this.stateInterpolationClose(c);
  688. }
  689. }
  690. stateInterpolationClose(c) {
  691. if (c === this.delimiterClose[this.delimiterIndex]) {
  692. if (this.delimiterIndex === this.delimiterClose.length - 1) {
  693. this.cbs.oninterpolation(this.sectionStart, this.index + 1);
  694. if (this.inRCDATA) {
  695. this.state = 32;
  696. } else {
  697. this.state = 1;
  698. }
  699. this.sectionStart = this.index + 1;
  700. } else {
  701. this.delimiterIndex++;
  702. }
  703. } else {
  704. this.state = 3;
  705. this.stateInterpolation(c);
  706. }
  707. }
  708. stateSpecialStartSequence(c) {
  709. const isEnd = this.sequenceIndex === this.currentSequence.length;
  710. const isMatch = isEnd ? (
  711. // If we are at the end of the sequence, make sure the tag name has ended
  712. isEndOfTagSection(c)
  713. ) : (
  714. // Otherwise, do a case-insensitive comparison
  715. (c | 32) === this.currentSequence[this.sequenceIndex]
  716. );
  717. if (!isMatch) {
  718. this.inRCDATA = false;
  719. } else if (!isEnd) {
  720. this.sequenceIndex++;
  721. return;
  722. }
  723. this.sequenceIndex = 0;
  724. this.state = 6;
  725. this.stateInTagName(c);
  726. }
  727. /** Look for an end tag. For <title> and <textarea>, also decode entities. */
  728. stateInRCDATA(c) {
  729. if (this.sequenceIndex === this.currentSequence.length) {
  730. if (c === 62 || isWhitespace(c)) {
  731. const endOfText = this.index - this.currentSequence.length;
  732. if (this.sectionStart < endOfText) {
  733. const actualIndex = this.index;
  734. this.index = endOfText;
  735. this.cbs.ontext(this.sectionStart, endOfText);
  736. this.index = actualIndex;
  737. }
  738. this.sectionStart = endOfText + 2;
  739. this.stateInClosingTagName(c);
  740. this.inRCDATA = false;
  741. return;
  742. }
  743. this.sequenceIndex = 0;
  744. }
  745. if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
  746. this.sequenceIndex += 1;
  747. } else if (this.sequenceIndex === 0) {
  748. if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
  749. if (!this.inVPre && c === this.delimiterOpen[0]) {
  750. this.state = 2;
  751. this.delimiterIndex = 0;
  752. this.stateInterpolationOpen(c);
  753. }
  754. } else if (this.fastForwardTo(60)) {
  755. this.sequenceIndex = 1;
  756. }
  757. } else {
  758. this.sequenceIndex = Number(c === 60);
  759. }
  760. }
  761. stateCDATASequence(c) {
  762. if (c === Sequences.Cdata[this.sequenceIndex]) {
  763. if (++this.sequenceIndex === Sequences.Cdata.length) {
  764. this.state = 28;
  765. this.currentSequence = Sequences.CdataEnd;
  766. this.sequenceIndex = 0;
  767. this.sectionStart = this.index + 1;
  768. }
  769. } else {
  770. this.sequenceIndex = 0;
  771. this.state = 23;
  772. this.stateInDeclaration(c);
  773. }
  774. }
  775. /**
  776. * When we wait for one specific character, we can speed things up
  777. * by skipping through the buffer until we find it.
  778. *
  779. * @returns Whether the character was found.
  780. */
  781. fastForwardTo(c) {
  782. while (++this.index < this.buffer.length) {
  783. const cc = this.buffer.charCodeAt(this.index);
  784. if (cc === 10) {
  785. this.newlines.push(this.index);
  786. }
  787. if (cc === c) {
  788. return true;
  789. }
  790. }
  791. this.index = this.buffer.length - 1;
  792. return false;
  793. }
  794. /**
  795. * Comments and CDATA end with `-->` and `]]>`.
  796. *
  797. * Their common qualities are:
  798. * - Their end sequences have a distinct character they start with.
  799. * - That character is then repeated, so we have to check multiple repeats.
  800. * - All characters but the start character of the sequence can be skipped.
  801. */
  802. stateInCommentLike(c) {
  803. if (c === this.currentSequence[this.sequenceIndex]) {
  804. if (++this.sequenceIndex === this.currentSequence.length) {
  805. if (this.currentSequence === Sequences.CdataEnd) {
  806. this.cbs.oncdata(this.sectionStart, this.index - 2);
  807. } else {
  808. this.cbs.oncomment(this.sectionStart, this.index - 2);
  809. }
  810. this.sequenceIndex = 0;
  811. this.sectionStart = this.index + 1;
  812. this.state = 1;
  813. }
  814. } else if (this.sequenceIndex === 0) {
  815. if (this.fastForwardTo(this.currentSequence[0])) {
  816. this.sequenceIndex = 1;
  817. }
  818. } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
  819. this.sequenceIndex = 0;
  820. }
  821. }
  822. startSpecial(sequence, offset) {
  823. this.enterRCDATA(sequence, offset);
  824. this.state = 31;
  825. }
  826. enterRCDATA(sequence, offset) {
  827. this.inRCDATA = true;
  828. this.currentSequence = sequence;
  829. this.sequenceIndex = offset;
  830. }
  831. stateBeforeTagName(c) {
  832. if (c === 33) {
  833. this.state = 22;
  834. this.sectionStart = this.index + 1;
  835. } else if (c === 63) {
  836. this.state = 24;
  837. this.sectionStart = this.index + 1;
  838. } else if (isTagStartChar(c)) {
  839. this.sectionStart = this.index;
  840. if (this.mode === 0) {
  841. this.state = 6;
  842. } else if (this.inSFCRoot) {
  843. this.state = 34;
  844. } else if (!this.inXML) {
  845. if (c === 116) {
  846. this.state = 30;
  847. } else {
  848. this.state = c === 115 ? 29 : 6;
  849. }
  850. } else {
  851. this.state = 6;
  852. }
  853. } else if (c === 47) {
  854. this.state = 8;
  855. } else {
  856. this.state = 1;
  857. this.stateText(c);
  858. }
  859. }
  860. stateInTagName(c) {
  861. if (isEndOfTagSection(c)) {
  862. this.handleTagName(c);
  863. }
  864. }
  865. stateInSFCRootTagName(c) {
  866. if (isEndOfTagSection(c)) {
  867. const tag = this.buffer.slice(this.sectionStart, this.index);
  868. if (tag !== "template") {
  869. this.enterRCDATA(toCharCodes(`</` + tag), 0);
  870. }
  871. this.handleTagName(c);
  872. }
  873. }
  874. handleTagName(c) {
  875. this.cbs.onopentagname(this.sectionStart, this.index);
  876. this.sectionStart = -1;
  877. this.state = 11;
  878. this.stateBeforeAttrName(c);
  879. }
  880. stateBeforeClosingTagName(c) {
  881. if (isWhitespace(c)) ; else if (c === 62) {
  882. {
  883. this.cbs.onerr(14, this.index);
  884. }
  885. this.state = 1;
  886. this.sectionStart = this.index + 1;
  887. } else {
  888. this.state = isTagStartChar(c) ? 9 : 27;
  889. this.sectionStart = this.index;
  890. }
  891. }
  892. stateInClosingTagName(c) {
  893. if (c === 62 || isWhitespace(c)) {
  894. this.cbs.onclosetag(this.sectionStart, this.index);
  895. this.sectionStart = -1;
  896. this.state = 10;
  897. this.stateAfterClosingTagName(c);
  898. }
  899. }
  900. stateAfterClosingTagName(c) {
  901. if (c === 62) {
  902. this.state = 1;
  903. this.sectionStart = this.index + 1;
  904. }
  905. }
  906. stateBeforeAttrName(c) {
  907. if (c === 62) {
  908. this.cbs.onopentagend(this.index);
  909. if (this.inRCDATA) {
  910. this.state = 32;
  911. } else {
  912. this.state = 1;
  913. }
  914. this.sectionStart = this.index + 1;
  915. } else if (c === 47) {
  916. this.state = 7;
  917. if (this.peek() !== 62) {
  918. this.cbs.onerr(22, this.index);
  919. }
  920. } else if (c === 60 && this.peek() === 47) {
  921. this.cbs.onopentagend(this.index);
  922. this.state = 5;
  923. this.sectionStart = this.index;
  924. } else if (!isWhitespace(c)) {
  925. if (c === 61) {
  926. this.cbs.onerr(
  927. 19,
  928. this.index
  929. );
  930. }
  931. this.handleAttrStart(c);
  932. }
  933. }
  934. handleAttrStart(c) {
  935. if (c === 118 && this.peek() === 45) {
  936. this.state = 13;
  937. this.sectionStart = this.index;
  938. } else if (c === 46 || c === 58 || c === 64 || c === 35) {
  939. this.cbs.ondirname(this.index, this.index + 1);
  940. this.state = 14;
  941. this.sectionStart = this.index + 1;
  942. } else {
  943. this.state = 12;
  944. this.sectionStart = this.index;
  945. }
  946. }
  947. stateInSelfClosingTag(c) {
  948. if (c === 62) {
  949. this.cbs.onselfclosingtag(this.index);
  950. this.state = 1;
  951. this.sectionStart = this.index + 1;
  952. this.inRCDATA = false;
  953. } else if (!isWhitespace(c)) {
  954. this.state = 11;
  955. this.stateBeforeAttrName(c);
  956. }
  957. }
  958. stateInAttrName(c) {
  959. if (c === 61 || isEndOfTagSection(c)) {
  960. this.cbs.onattribname(this.sectionStart, this.index);
  961. this.handleAttrNameEnd(c);
  962. } else if (c === 34 || c === 39 || c === 60) {
  963. this.cbs.onerr(
  964. 17,
  965. this.index
  966. );
  967. }
  968. }
  969. stateInDirName(c) {
  970. if (c === 61 || isEndOfTagSection(c)) {
  971. this.cbs.ondirname(this.sectionStart, this.index);
  972. this.handleAttrNameEnd(c);
  973. } else if (c === 58) {
  974. this.cbs.ondirname(this.sectionStart, this.index);
  975. this.state = 14;
  976. this.sectionStart = this.index + 1;
  977. } else if (c === 46) {
  978. this.cbs.ondirname(this.sectionStart, this.index);
  979. this.state = 16;
  980. this.sectionStart = this.index + 1;
  981. }
  982. }
  983. stateInDirArg(c) {
  984. if (c === 61 || isEndOfTagSection(c)) {
  985. this.cbs.ondirarg(this.sectionStart, this.index);
  986. this.handleAttrNameEnd(c);
  987. } else if (c === 91) {
  988. this.state = 15;
  989. } else if (c === 46) {
  990. this.cbs.ondirarg(this.sectionStart, this.index);
  991. this.state = 16;
  992. this.sectionStart = this.index + 1;
  993. }
  994. }
  995. stateInDynamicDirArg(c) {
  996. if (c === 93) {
  997. this.state = 14;
  998. } else if (c === 61 || isEndOfTagSection(c)) {
  999. this.cbs.ondirarg(this.sectionStart, this.index + 1);
  1000. this.handleAttrNameEnd(c);
  1001. {
  1002. this.cbs.onerr(
  1003. 27,
  1004. this.index
  1005. );
  1006. }
  1007. }
  1008. }
  1009. stateInDirModifier(c) {
  1010. if (c === 61 || isEndOfTagSection(c)) {
  1011. this.cbs.ondirmodifier(this.sectionStart, this.index);
  1012. this.handleAttrNameEnd(c);
  1013. } else if (c === 46) {
  1014. this.cbs.ondirmodifier(this.sectionStart, this.index);
  1015. this.sectionStart = this.index + 1;
  1016. }
  1017. }
  1018. handleAttrNameEnd(c) {
  1019. this.sectionStart = this.index;
  1020. this.state = 17;
  1021. this.cbs.onattribnameend(this.index);
  1022. this.stateAfterAttrName(c);
  1023. }
  1024. stateAfterAttrName(c) {
  1025. if (c === 61) {
  1026. this.state = 18;
  1027. } else if (c === 47 || c === 62) {
  1028. this.cbs.onattribend(0, this.sectionStart);
  1029. this.sectionStart = -1;
  1030. this.state = 11;
  1031. this.stateBeforeAttrName(c);
  1032. } else if (!isWhitespace(c)) {
  1033. this.cbs.onattribend(0, this.sectionStart);
  1034. this.handleAttrStart(c);
  1035. }
  1036. }
  1037. stateBeforeAttrValue(c) {
  1038. if (c === 34) {
  1039. this.state = 19;
  1040. this.sectionStart = this.index + 1;
  1041. } else if (c === 39) {
  1042. this.state = 20;
  1043. this.sectionStart = this.index + 1;
  1044. } else if (!isWhitespace(c)) {
  1045. this.sectionStart = this.index;
  1046. this.state = 21;
  1047. this.stateInAttrValueNoQuotes(c);
  1048. }
  1049. }
  1050. handleInAttrValue(c, quote) {
  1051. if (c === quote || this.fastForwardTo(quote)) {
  1052. this.cbs.onattribdata(this.sectionStart, this.index);
  1053. this.sectionStart = -1;
  1054. this.cbs.onattribend(
  1055. quote === 34 ? 3 : 2,
  1056. this.index + 1
  1057. );
  1058. this.state = 11;
  1059. }
  1060. }
  1061. stateInAttrValueDoubleQuotes(c) {
  1062. this.handleInAttrValue(c, 34);
  1063. }
  1064. stateInAttrValueSingleQuotes(c) {
  1065. this.handleInAttrValue(c, 39);
  1066. }
  1067. stateInAttrValueNoQuotes(c) {
  1068. if (isWhitespace(c) || c === 62) {
  1069. this.cbs.onattribdata(this.sectionStart, this.index);
  1070. this.sectionStart = -1;
  1071. this.cbs.onattribend(1, this.index);
  1072. this.state = 11;
  1073. this.stateBeforeAttrName(c);
  1074. } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
  1075. this.cbs.onerr(
  1076. 18,
  1077. this.index
  1078. );
  1079. } else ;
  1080. }
  1081. stateBeforeDeclaration(c) {
  1082. if (c === 91) {
  1083. this.state = 26;
  1084. this.sequenceIndex = 0;
  1085. } else {
  1086. this.state = c === 45 ? 25 : 23;
  1087. }
  1088. }
  1089. stateInDeclaration(c) {
  1090. if (c === 62 || this.fastForwardTo(62)) {
  1091. this.state = 1;
  1092. this.sectionStart = this.index + 1;
  1093. }
  1094. }
  1095. stateInProcessingInstruction(c) {
  1096. if (c === 62 || this.fastForwardTo(62)) {
  1097. this.cbs.onprocessinginstruction(this.sectionStart, this.index);
  1098. this.state = 1;
  1099. this.sectionStart = this.index + 1;
  1100. }
  1101. }
  1102. stateBeforeComment(c) {
  1103. if (c === 45) {
  1104. this.state = 28;
  1105. this.currentSequence = Sequences.CommentEnd;
  1106. this.sequenceIndex = 2;
  1107. this.sectionStart = this.index + 1;
  1108. } else {
  1109. this.state = 23;
  1110. }
  1111. }
  1112. stateInSpecialComment(c) {
  1113. if (c === 62 || this.fastForwardTo(62)) {
  1114. this.cbs.oncomment(this.sectionStart, this.index);
  1115. this.state = 1;
  1116. this.sectionStart = this.index + 1;
  1117. }
  1118. }
  1119. stateBeforeSpecialS(c) {
  1120. if (c === Sequences.ScriptEnd[3]) {
  1121. this.startSpecial(Sequences.ScriptEnd, 4);
  1122. } else if (c === Sequences.StyleEnd[3]) {
  1123. this.startSpecial(Sequences.StyleEnd, 4);
  1124. } else {
  1125. this.state = 6;
  1126. this.stateInTagName(c);
  1127. }
  1128. }
  1129. stateBeforeSpecialT(c) {
  1130. if (c === Sequences.TitleEnd[3]) {
  1131. this.startSpecial(Sequences.TitleEnd, 4);
  1132. } else if (c === Sequences.TextareaEnd[3]) {
  1133. this.startSpecial(Sequences.TextareaEnd, 4);
  1134. } else {
  1135. this.state = 6;
  1136. this.stateInTagName(c);
  1137. }
  1138. }
  1139. startEntity() {
  1140. }
  1141. stateInEntity() {
  1142. }
  1143. /**
  1144. * Iterates through the buffer, calling the function corresponding to the current state.
  1145. *
  1146. * States that are more likely to be hit are higher up, as a performance improvement.
  1147. */
  1148. parse(input) {
  1149. this.buffer = input;
  1150. while (this.index < this.buffer.length) {
  1151. const c = this.buffer.charCodeAt(this.index);
  1152. if (c === 10 && this.state !== 33) {
  1153. this.newlines.push(this.index);
  1154. }
  1155. switch (this.state) {
  1156. case 1: {
  1157. this.stateText(c);
  1158. break;
  1159. }
  1160. case 2: {
  1161. this.stateInterpolationOpen(c);
  1162. break;
  1163. }
  1164. case 3: {
  1165. this.stateInterpolation(c);
  1166. break;
  1167. }
  1168. case 4: {
  1169. this.stateInterpolationClose(c);
  1170. break;
  1171. }
  1172. case 31: {
  1173. this.stateSpecialStartSequence(c);
  1174. break;
  1175. }
  1176. case 32: {
  1177. this.stateInRCDATA(c);
  1178. break;
  1179. }
  1180. case 26: {
  1181. this.stateCDATASequence(c);
  1182. break;
  1183. }
  1184. case 19: {
  1185. this.stateInAttrValueDoubleQuotes(c);
  1186. break;
  1187. }
  1188. case 12: {
  1189. this.stateInAttrName(c);
  1190. break;
  1191. }
  1192. case 13: {
  1193. this.stateInDirName(c);
  1194. break;
  1195. }
  1196. case 14: {
  1197. this.stateInDirArg(c);
  1198. break;
  1199. }
  1200. case 15: {
  1201. this.stateInDynamicDirArg(c);
  1202. break;
  1203. }
  1204. case 16: {
  1205. this.stateInDirModifier(c);
  1206. break;
  1207. }
  1208. case 28: {
  1209. this.stateInCommentLike(c);
  1210. break;
  1211. }
  1212. case 27: {
  1213. this.stateInSpecialComment(c);
  1214. break;
  1215. }
  1216. case 11: {
  1217. this.stateBeforeAttrName(c);
  1218. break;
  1219. }
  1220. case 6: {
  1221. this.stateInTagName(c);
  1222. break;
  1223. }
  1224. case 34: {
  1225. this.stateInSFCRootTagName(c);
  1226. break;
  1227. }
  1228. case 9: {
  1229. this.stateInClosingTagName(c);
  1230. break;
  1231. }
  1232. case 5: {
  1233. this.stateBeforeTagName(c);
  1234. break;
  1235. }
  1236. case 17: {
  1237. this.stateAfterAttrName(c);
  1238. break;
  1239. }
  1240. case 20: {
  1241. this.stateInAttrValueSingleQuotes(c);
  1242. break;
  1243. }
  1244. case 18: {
  1245. this.stateBeforeAttrValue(c);
  1246. break;
  1247. }
  1248. case 8: {
  1249. this.stateBeforeClosingTagName(c);
  1250. break;
  1251. }
  1252. case 10: {
  1253. this.stateAfterClosingTagName(c);
  1254. break;
  1255. }
  1256. case 29: {
  1257. this.stateBeforeSpecialS(c);
  1258. break;
  1259. }
  1260. case 30: {
  1261. this.stateBeforeSpecialT(c);
  1262. break;
  1263. }
  1264. case 21: {
  1265. this.stateInAttrValueNoQuotes(c);
  1266. break;
  1267. }
  1268. case 7: {
  1269. this.stateInSelfClosingTag(c);
  1270. break;
  1271. }
  1272. case 23: {
  1273. this.stateInDeclaration(c);
  1274. break;
  1275. }
  1276. case 22: {
  1277. this.stateBeforeDeclaration(c);
  1278. break;
  1279. }
  1280. case 25: {
  1281. this.stateBeforeComment(c);
  1282. break;
  1283. }
  1284. case 24: {
  1285. this.stateInProcessingInstruction(c);
  1286. break;
  1287. }
  1288. case 33: {
  1289. this.stateInEntity();
  1290. break;
  1291. }
  1292. }
  1293. this.index++;
  1294. }
  1295. this.cleanup();
  1296. this.finish();
  1297. }
  1298. /**
  1299. * Remove data that has already been consumed from the buffer.
  1300. */
  1301. cleanup() {
  1302. if (this.sectionStart !== this.index) {
  1303. if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
  1304. this.cbs.ontext(this.sectionStart, this.index);
  1305. this.sectionStart = this.index;
  1306. } else if (this.state === 19 || this.state === 20 || this.state === 21) {
  1307. this.cbs.onattribdata(this.sectionStart, this.index);
  1308. this.sectionStart = this.index;
  1309. }
  1310. }
  1311. }
  1312. finish() {
  1313. this.handleTrailingData();
  1314. this.cbs.onend();
  1315. }
  1316. /** Handle any trailing data. */
  1317. handleTrailingData() {
  1318. const endIndex = this.buffer.length;
  1319. if (this.sectionStart >= endIndex) {
  1320. return;
  1321. }
  1322. if (this.state === 28) {
  1323. if (this.currentSequence === Sequences.CdataEnd) {
  1324. this.cbs.oncdata(this.sectionStart, endIndex);
  1325. } else {
  1326. this.cbs.oncomment(this.sectionStart, endIndex);
  1327. }
  1328. } else if (this.state === 6 || this.state === 11 || this.state === 18 || this.state === 17 || this.state === 12 || this.state === 13 || this.state === 14 || this.state === 15 || this.state === 16 || this.state === 20 || this.state === 19 || this.state === 21 || this.state === 9) ; else {
  1329. this.cbs.ontext(this.sectionStart, endIndex);
  1330. }
  1331. }
  1332. emitCodePoint(cp, consumed) {
  1333. }
  1334. }
  1335. const CompilerDeprecationTypes = {
  1336. "COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT",
  1337. "COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC",
  1338. "COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER",
  1339. "COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE",
  1340. "COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE",
  1341. "COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE",
  1342. "COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE",
  1343. "COMPILER_FILTERS": "COMPILER_FILTERS"
  1344. };
  1345. const deprecationData = {
  1346. ["COMPILER_IS_ON_ELEMENT"]: {
  1347. 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:".`,
  1348. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  1349. },
  1350. ["COMPILER_V_BIND_SYNC"]: {
  1351. 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}\`.`,
  1352. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  1353. },
  1354. ["COMPILER_V_BIND_OBJECT_ORDER"]: {
  1355. 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.`,
  1356. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  1357. },
  1358. ["COMPILER_V_ON_NATIVE"]: {
  1359. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  1360. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  1361. },
  1362. ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
  1363. 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.`,
  1364. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  1365. },
  1366. ["COMPILER_NATIVE_TEMPLATE"]: {
  1367. message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
  1368. },
  1369. ["COMPILER_INLINE_TEMPLATE"]: {
  1370. message: `"inline-template" has been removed in Vue 3.`,
  1371. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  1372. },
  1373. ["COMPILER_FILTERS"]: {
  1374. 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.`,
  1375. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  1376. }
  1377. };
  1378. function getCompatValue(key, { compatConfig }) {
  1379. const value = compatConfig && compatConfig[key];
  1380. if (key === "MODE") {
  1381. return value || 3;
  1382. } else {
  1383. return value;
  1384. }
  1385. }
  1386. function isCompatEnabled(key, context) {
  1387. const mode = getCompatValue("MODE", context);
  1388. const value = getCompatValue(key, context);
  1389. return mode === 3 ? value === true : value !== false;
  1390. }
  1391. function checkCompatEnabled(key, context, loc, ...args) {
  1392. const enabled = isCompatEnabled(key, context);
  1393. if (enabled) {
  1394. warnDeprecation(key, context, loc, ...args);
  1395. }
  1396. return enabled;
  1397. }
  1398. function warnDeprecation(key, context, loc, ...args) {
  1399. const val = getCompatValue(key, context);
  1400. if (val === "suppress-warning") {
  1401. return;
  1402. }
  1403. const { message, link } = deprecationData[key];
  1404. const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
  1405. Details: ${link}` : ``}`;
  1406. const err = new SyntaxError(msg);
  1407. err.code = key;
  1408. if (loc) err.loc = loc;
  1409. context.onWarn(err);
  1410. }
  1411. function defaultOnError(error) {
  1412. throw error;
  1413. }
  1414. function defaultOnWarn(msg) {
  1415. console.warn(`[Vue warn] ${msg.message}`);
  1416. }
  1417. function createCompilerError(code, loc, messages, additionalMessage) {
  1418. const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
  1419. const error = new SyntaxError(String(msg));
  1420. error.code = code;
  1421. error.loc = loc;
  1422. return error;
  1423. }
  1424. const ErrorCodes = {
  1425. "ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
  1426. "0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
  1427. "CDATA_IN_HTML_CONTENT": 1,
  1428. "1": "CDATA_IN_HTML_CONTENT",
  1429. "DUPLICATE_ATTRIBUTE": 2,
  1430. "2": "DUPLICATE_ATTRIBUTE",
  1431. "END_TAG_WITH_ATTRIBUTES": 3,
  1432. "3": "END_TAG_WITH_ATTRIBUTES",
  1433. "END_TAG_WITH_TRAILING_SOLIDUS": 4,
  1434. "4": "END_TAG_WITH_TRAILING_SOLIDUS",
  1435. "EOF_BEFORE_TAG_NAME": 5,
  1436. "5": "EOF_BEFORE_TAG_NAME",
  1437. "EOF_IN_CDATA": 6,
  1438. "6": "EOF_IN_CDATA",
  1439. "EOF_IN_COMMENT": 7,
  1440. "7": "EOF_IN_COMMENT",
  1441. "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
  1442. "8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
  1443. "EOF_IN_TAG": 9,
  1444. "9": "EOF_IN_TAG",
  1445. "INCORRECTLY_CLOSED_COMMENT": 10,
  1446. "10": "INCORRECTLY_CLOSED_COMMENT",
  1447. "INCORRECTLY_OPENED_COMMENT": 11,
  1448. "11": "INCORRECTLY_OPENED_COMMENT",
  1449. "INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
  1450. "12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
  1451. "MISSING_ATTRIBUTE_VALUE": 13,
  1452. "13": "MISSING_ATTRIBUTE_VALUE",
  1453. "MISSING_END_TAG_NAME": 14,
  1454. "14": "MISSING_END_TAG_NAME",
  1455. "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
  1456. "15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
  1457. "NESTED_COMMENT": 16,
  1458. "16": "NESTED_COMMENT",
  1459. "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
  1460. "17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
  1461. "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
  1462. "18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
  1463. "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
  1464. "19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
  1465. "UNEXPECTED_NULL_CHARACTER": 20,
  1466. "20": "UNEXPECTED_NULL_CHARACTER",
  1467. "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
  1468. "21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
  1469. "UNEXPECTED_SOLIDUS_IN_TAG": 22,
  1470. "22": "UNEXPECTED_SOLIDUS_IN_TAG",
  1471. "X_INVALID_END_TAG": 23,
  1472. "23": "X_INVALID_END_TAG",
  1473. "X_MISSING_END_TAG": 24,
  1474. "24": "X_MISSING_END_TAG",
  1475. "X_MISSING_INTERPOLATION_END": 25,
  1476. "25": "X_MISSING_INTERPOLATION_END",
  1477. "X_MISSING_DIRECTIVE_NAME": 26,
  1478. "26": "X_MISSING_DIRECTIVE_NAME",
  1479. "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
  1480. "27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
  1481. "X_V_IF_NO_EXPRESSION": 28,
  1482. "28": "X_V_IF_NO_EXPRESSION",
  1483. "X_V_IF_SAME_KEY": 29,
  1484. "29": "X_V_IF_SAME_KEY",
  1485. "X_V_ELSE_NO_ADJACENT_IF": 30,
  1486. "30": "X_V_ELSE_NO_ADJACENT_IF",
  1487. "X_V_FOR_NO_EXPRESSION": 31,
  1488. "31": "X_V_FOR_NO_EXPRESSION",
  1489. "X_V_FOR_MALFORMED_EXPRESSION": 32,
  1490. "32": "X_V_FOR_MALFORMED_EXPRESSION",
  1491. "X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
  1492. "33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
  1493. "X_V_BIND_NO_EXPRESSION": 34,
  1494. "34": "X_V_BIND_NO_EXPRESSION",
  1495. "X_V_ON_NO_EXPRESSION": 35,
  1496. "35": "X_V_ON_NO_EXPRESSION",
  1497. "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
  1498. "36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
  1499. "X_V_SLOT_MIXED_SLOT_USAGE": 37,
  1500. "37": "X_V_SLOT_MIXED_SLOT_USAGE",
  1501. "X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
  1502. "38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
  1503. "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
  1504. "39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
  1505. "X_V_SLOT_MISPLACED": 40,
  1506. "40": "X_V_SLOT_MISPLACED",
  1507. "X_V_MODEL_NO_EXPRESSION": 41,
  1508. "41": "X_V_MODEL_NO_EXPRESSION",
  1509. "X_V_MODEL_MALFORMED_EXPRESSION": 42,
  1510. "42": "X_V_MODEL_MALFORMED_EXPRESSION",
  1511. "X_V_MODEL_ON_SCOPE_VARIABLE": 43,
  1512. "43": "X_V_MODEL_ON_SCOPE_VARIABLE",
  1513. "X_V_MODEL_ON_PROPS": 44,
  1514. "44": "X_V_MODEL_ON_PROPS",
  1515. "X_INVALID_EXPRESSION": 45,
  1516. "45": "X_INVALID_EXPRESSION",
  1517. "X_KEEP_ALIVE_INVALID_CHILDREN": 46,
  1518. "46": "X_KEEP_ALIVE_INVALID_CHILDREN",
  1519. "X_PREFIX_ID_NOT_SUPPORTED": 47,
  1520. "47": "X_PREFIX_ID_NOT_SUPPORTED",
  1521. "X_MODULE_MODE_NOT_SUPPORTED": 48,
  1522. "48": "X_MODULE_MODE_NOT_SUPPORTED",
  1523. "X_CACHE_HANDLER_NOT_SUPPORTED": 49,
  1524. "49": "X_CACHE_HANDLER_NOT_SUPPORTED",
  1525. "X_SCOPE_ID_NOT_SUPPORTED": 50,
  1526. "50": "X_SCOPE_ID_NOT_SUPPORTED",
  1527. "X_VNODE_HOOKS": 51,
  1528. "51": "X_VNODE_HOOKS",
  1529. "X_V_BIND_INVALID_SAME_NAME_ARGUMENT": 52,
  1530. "52": "X_V_BIND_INVALID_SAME_NAME_ARGUMENT",
  1531. "__EXTEND_POINT__": 53,
  1532. "53": "__EXTEND_POINT__"
  1533. };
  1534. const errorMessages = {
  1535. // parse errors
  1536. [0]: "Illegal comment.",
  1537. [1]: "CDATA section is allowed only in XML context.",
  1538. [2]: "Duplicate attribute.",
  1539. [3]: "End tag cannot have attributes.",
  1540. [4]: "Illegal '/' in tags.",
  1541. [5]: "Unexpected EOF in tag.",
  1542. [6]: "Unexpected EOF in CDATA section.",
  1543. [7]: "Unexpected EOF in comment.",
  1544. [8]: "Unexpected EOF in script.",
  1545. [9]: "Unexpected EOF in tag.",
  1546. [10]: "Incorrectly closed comment.",
  1547. [11]: "Incorrectly opened comment.",
  1548. [12]: "Illegal tag name. Use '&lt;' to print '<'.",
  1549. [13]: "Attribute value was expected.",
  1550. [14]: "End tag name was expected.",
  1551. [15]: "Whitespace was expected.",
  1552. [16]: "Unexpected '<!--' in comment.",
  1553. [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
  1554. [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
  1555. [19]: "Attribute name cannot start with '='.",
  1556. [21]: "'<?' is allowed only in XML context.",
  1557. [20]: `Unexpected null character.`,
  1558. [22]: "Illegal '/' in tags.",
  1559. // Vue-specific parse errors
  1560. [23]: "Invalid end tag.",
  1561. [24]: "Element is missing end tag.",
  1562. [25]: "Interpolation end sign was not found.",
  1563. [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
  1564. [26]: "Legal directive name was expected.",
  1565. // transform errors
  1566. [28]: `v-if/v-else-if is missing expression.`,
  1567. [29]: `v-if/else branches must use unique keys.`,
  1568. [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  1569. [31]: `v-for is missing expression.`,
  1570. [32]: `v-for has invalid expression.`,
  1571. [33]: `<template v-for> key should be placed on the <template> tag.`,
  1572. [34]: `v-bind is missing expression.`,
  1573. [52]: `v-bind with same-name shorthand only allows static argument.`,
  1574. [35]: `v-on is missing expression.`,
  1575. [36]: `Unexpected custom directive on <slot> outlet.`,
  1576. [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.`,
  1577. [38]: `Duplicate slot names found. `,
  1578. [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
  1579. [40]: `v-slot can only be used on components or <template> tags.`,
  1580. [41]: `v-model is missing expression.`,
  1581. [42]: `v-model value must be a valid JavaScript member expression.`,
  1582. [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  1583. [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
  1584. Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  1585. [45]: `Error parsing JavaScript expression: `,
  1586. [46]: `<KeepAlive> expects exactly one child component.`,
  1587. [51]: `@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.`,
  1588. // generic errors
  1589. [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  1590. [48]: `ES module mode is not supported in this build of compiler.`,
  1591. [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  1592. [50]: `"scopeId" option is only supported in module mode.`,
  1593. // just to fulfill types
  1594. [53]: ``
  1595. };
  1596. function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
  1597. {
  1598. return;
  1599. }
  1600. }
  1601. function isReferencedIdentifier(id, parent, parentStack) {
  1602. {
  1603. return false;
  1604. }
  1605. }
  1606. function isInDestructureAssignment(parent, parentStack) {
  1607. if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
  1608. let i = parentStack.length;
  1609. while (i--) {
  1610. const p = parentStack[i];
  1611. if (p.type === "AssignmentExpression") {
  1612. return true;
  1613. } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
  1614. break;
  1615. }
  1616. }
  1617. }
  1618. return false;
  1619. }
  1620. function isInNewExpression(parentStack) {
  1621. let i = parentStack.length;
  1622. while (i--) {
  1623. const p = parentStack[i];
  1624. if (p.type === "NewExpression") {
  1625. return true;
  1626. } else if (p.type !== "MemberExpression") {
  1627. break;
  1628. }
  1629. }
  1630. return false;
  1631. }
  1632. function walkFunctionParams(node, onIdent) {
  1633. for (const p of node.params) {
  1634. for (const id of extractIdentifiers(p)) {
  1635. onIdent(id);
  1636. }
  1637. }
  1638. }
  1639. function walkBlockDeclarations(block, onIdent) {
  1640. for (const stmt of block.body) {
  1641. if (stmt.type === "VariableDeclaration") {
  1642. if (stmt.declare) continue;
  1643. for (const decl of stmt.declarations) {
  1644. for (const id of extractIdentifiers(decl.id)) {
  1645. onIdent(id);
  1646. }
  1647. }
  1648. } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
  1649. if (stmt.declare || !stmt.id) continue;
  1650. onIdent(stmt.id);
  1651. } else if (isForStatement(stmt)) {
  1652. walkForStatement(stmt, true, onIdent);
  1653. }
  1654. }
  1655. }
  1656. function isForStatement(stmt) {
  1657. return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
  1658. }
  1659. function walkForStatement(stmt, isVar, onIdent) {
  1660. const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
  1661. if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) {
  1662. for (const decl of variable.declarations) {
  1663. for (const id of extractIdentifiers(decl.id)) {
  1664. onIdent(id);
  1665. }
  1666. }
  1667. }
  1668. }
  1669. function extractIdentifiers(param, nodes = []) {
  1670. switch (param.type) {
  1671. case "Identifier":
  1672. nodes.push(param);
  1673. break;
  1674. case "MemberExpression":
  1675. let object = param;
  1676. while (object.type === "MemberExpression") {
  1677. object = object.object;
  1678. }
  1679. nodes.push(object);
  1680. break;
  1681. case "ObjectPattern":
  1682. for (const prop of param.properties) {
  1683. if (prop.type === "RestElement") {
  1684. extractIdentifiers(prop.argument, nodes);
  1685. } else {
  1686. extractIdentifiers(prop.value, nodes);
  1687. }
  1688. }
  1689. break;
  1690. case "ArrayPattern":
  1691. param.elements.forEach((element) => {
  1692. if (element) extractIdentifiers(element, nodes);
  1693. });
  1694. break;
  1695. case "RestElement":
  1696. extractIdentifiers(param.argument, nodes);
  1697. break;
  1698. case "AssignmentPattern":
  1699. extractIdentifiers(param.left, nodes);
  1700. break;
  1701. }
  1702. return nodes;
  1703. }
  1704. const isFunctionType = (node) => {
  1705. return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
  1706. };
  1707. const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
  1708. const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
  1709. const TS_NODE_TYPES = [
  1710. "TSAsExpression",
  1711. // foo as number
  1712. "TSTypeAssertion",
  1713. // (<number>foo)
  1714. "TSNonNullExpression",
  1715. // foo!
  1716. "TSInstantiationExpression",
  1717. // foo<string>
  1718. "TSSatisfiesExpression"
  1719. // foo satisfies T
  1720. ];
  1721. function unwrapTSNode(node) {
  1722. if (TS_NODE_TYPES.includes(node.type)) {
  1723. return unwrapTSNode(node.expression);
  1724. } else {
  1725. return node;
  1726. }
  1727. }
  1728. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  1729. function isCoreComponent(tag) {
  1730. switch (tag) {
  1731. case "Teleport":
  1732. case "teleport":
  1733. return TELEPORT;
  1734. case "Suspense":
  1735. case "suspense":
  1736. return SUSPENSE;
  1737. case "KeepAlive":
  1738. case "keep-alive":
  1739. return KEEP_ALIVE;
  1740. case "BaseTransition":
  1741. case "base-transition":
  1742. return BASE_TRANSITION;
  1743. }
  1744. }
  1745. const nonIdentifierRE = /^$|^\d|[^\$\w\xA0-\uFFFF]/;
  1746. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  1747. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  1748. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  1749. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  1750. const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
  1751. const isMemberExpressionBrowser = (exp) => {
  1752. const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
  1753. let state = 0 /* inMemberExp */;
  1754. let stateStack = [];
  1755. let currentOpenBracketCount = 0;
  1756. let currentOpenParensCount = 0;
  1757. let currentStringType = null;
  1758. for (let i = 0; i < path.length; i++) {
  1759. const char = path.charAt(i);
  1760. switch (state) {
  1761. case 0 /* inMemberExp */:
  1762. if (char === "[") {
  1763. stateStack.push(state);
  1764. state = 1 /* inBrackets */;
  1765. currentOpenBracketCount++;
  1766. } else if (char === "(") {
  1767. stateStack.push(state);
  1768. state = 2 /* inParens */;
  1769. currentOpenParensCount++;
  1770. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  1771. return false;
  1772. }
  1773. break;
  1774. case 1 /* inBrackets */:
  1775. if (char === `'` || char === `"` || char === "`") {
  1776. stateStack.push(state);
  1777. state = 3 /* inString */;
  1778. currentStringType = char;
  1779. } else if (char === `[`) {
  1780. currentOpenBracketCount++;
  1781. } else if (char === `]`) {
  1782. if (!--currentOpenBracketCount) {
  1783. state = stateStack.pop();
  1784. }
  1785. }
  1786. break;
  1787. case 2 /* inParens */:
  1788. if (char === `'` || char === `"` || char === "`") {
  1789. stateStack.push(state);
  1790. state = 3 /* inString */;
  1791. currentStringType = char;
  1792. } else if (char === `(`) {
  1793. currentOpenParensCount++;
  1794. } else if (char === `)`) {
  1795. if (i === path.length - 1) {
  1796. return false;
  1797. }
  1798. if (!--currentOpenParensCount) {
  1799. state = stateStack.pop();
  1800. }
  1801. }
  1802. break;
  1803. case 3 /* inString */:
  1804. if (char === currentStringType) {
  1805. state = stateStack.pop();
  1806. currentStringType = null;
  1807. }
  1808. break;
  1809. }
  1810. }
  1811. return !currentOpenBracketCount && !currentOpenParensCount;
  1812. };
  1813. const isMemberExpressionNode = NOOP ;
  1814. const isMemberExpression = isMemberExpressionBrowser ;
  1815. const fnExpRE = /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  1816. const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
  1817. const isFnExpressionNode = NOOP ;
  1818. const isFnExpression = isFnExpressionBrowser ;
  1819. function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
  1820. return advancePositionWithMutation(
  1821. {
  1822. offset: pos.offset,
  1823. line: pos.line,
  1824. column: pos.column
  1825. },
  1826. source,
  1827. numberOfCharacters
  1828. );
  1829. }
  1830. function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
  1831. let linesCount = 0;
  1832. let lastNewLinePos = -1;
  1833. for (let i = 0; i < numberOfCharacters; i++) {
  1834. if (source.charCodeAt(i) === 10) {
  1835. linesCount++;
  1836. lastNewLinePos = i;
  1837. }
  1838. }
  1839. pos.offset += numberOfCharacters;
  1840. pos.line += linesCount;
  1841. pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
  1842. return pos;
  1843. }
  1844. function assert(condition, msg) {
  1845. if (!condition) {
  1846. throw new Error(msg || `unexpected compiler condition`);
  1847. }
  1848. }
  1849. function findDir(node, name, allowEmpty = false) {
  1850. for (let i = 0; i < node.props.length; i++) {
  1851. const p = node.props[i];
  1852. if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) {
  1853. return p;
  1854. }
  1855. }
  1856. }
  1857. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  1858. for (let i = 0; i < node.props.length; i++) {
  1859. const p = node.props[i];
  1860. if (p.type === 6) {
  1861. if (dynamicOnly) continue;
  1862. if (p.name === name && (p.value || allowEmpty)) {
  1863. return p;
  1864. }
  1865. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  1866. return p;
  1867. }
  1868. }
  1869. }
  1870. function isStaticArgOf(arg, name) {
  1871. return !!(arg && isStaticExp(arg) && arg.content === name);
  1872. }
  1873. function hasDynamicKeyVBind(node) {
  1874. return node.props.some(
  1875. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  1876. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  1877. !p.arg.isStatic)
  1878. // v-bind:[foo]
  1879. );
  1880. }
  1881. function isText$1(node) {
  1882. return node.type === 5 || node.type === 2;
  1883. }
  1884. function isVPre(p) {
  1885. return p.type === 7 && p.name === "pre";
  1886. }
  1887. function isVSlot(p) {
  1888. return p.type === 7 && p.name === "slot";
  1889. }
  1890. function isTemplateNode(node) {
  1891. return node.type === 1 && node.tagType === 3;
  1892. }
  1893. function isSlotOutlet(node) {
  1894. return node.type === 1 && node.tagType === 2;
  1895. }
  1896. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  1897. function getUnnormalizedProps(props, callPath = []) {
  1898. if (props && !isString(props) && props.type === 14) {
  1899. const callee = props.callee;
  1900. if (!isString(callee) && propsHelperSet.has(callee)) {
  1901. return getUnnormalizedProps(
  1902. props.arguments[0],
  1903. callPath.concat(props)
  1904. );
  1905. }
  1906. }
  1907. return [props, callPath];
  1908. }
  1909. function injectProp(node, prop, context) {
  1910. let propsWithInjection;
  1911. let props = node.type === 13 ? node.props : node.arguments[2];
  1912. let callPath = [];
  1913. let parentCall;
  1914. if (props && !isString(props) && props.type === 14) {
  1915. const ret = getUnnormalizedProps(props);
  1916. props = ret[0];
  1917. callPath = ret[1];
  1918. parentCall = callPath[callPath.length - 1];
  1919. }
  1920. if (props == null || isString(props)) {
  1921. propsWithInjection = createObjectExpression([prop]);
  1922. } else if (props.type === 14) {
  1923. const first = props.arguments[0];
  1924. if (!isString(first) && first.type === 15) {
  1925. if (!hasProp(prop, first)) {
  1926. first.properties.unshift(prop);
  1927. }
  1928. } else {
  1929. if (props.callee === TO_HANDLERS) {
  1930. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  1931. createObjectExpression([prop]),
  1932. props
  1933. ]);
  1934. } else {
  1935. props.arguments.unshift(createObjectExpression([prop]));
  1936. }
  1937. }
  1938. !propsWithInjection && (propsWithInjection = props);
  1939. } else if (props.type === 15) {
  1940. if (!hasProp(prop, props)) {
  1941. props.properties.unshift(prop);
  1942. }
  1943. propsWithInjection = props;
  1944. } else {
  1945. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  1946. createObjectExpression([prop]),
  1947. props
  1948. ]);
  1949. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  1950. parentCall = callPath[callPath.length - 2];
  1951. }
  1952. }
  1953. if (node.type === 13) {
  1954. if (parentCall) {
  1955. parentCall.arguments[0] = propsWithInjection;
  1956. } else {
  1957. node.props = propsWithInjection;
  1958. }
  1959. } else {
  1960. if (parentCall) {
  1961. parentCall.arguments[0] = propsWithInjection;
  1962. } else {
  1963. node.arguments[2] = propsWithInjection;
  1964. }
  1965. }
  1966. }
  1967. function hasProp(prop, props) {
  1968. let result = false;
  1969. if (prop.key.type === 4) {
  1970. const propKeyName = prop.key.content;
  1971. result = props.properties.some(
  1972. (p) => p.key.type === 4 && p.key.content === propKeyName
  1973. );
  1974. }
  1975. return result;
  1976. }
  1977. function toValidAssetId(name, type) {
  1978. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  1979. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  1980. })}`;
  1981. }
  1982. function hasScopeRef(node, ids) {
  1983. if (!node || Object.keys(ids).length === 0) {
  1984. return false;
  1985. }
  1986. switch (node.type) {
  1987. case 1:
  1988. for (let i = 0; i < node.props.length; i++) {
  1989. const p = node.props[i];
  1990. if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
  1991. return true;
  1992. }
  1993. }
  1994. return node.children.some((c) => hasScopeRef(c, ids));
  1995. case 11:
  1996. if (hasScopeRef(node.source, ids)) {
  1997. return true;
  1998. }
  1999. return node.children.some((c) => hasScopeRef(c, ids));
  2000. case 9:
  2001. return node.branches.some((b) => hasScopeRef(b, ids));
  2002. case 10:
  2003. if (hasScopeRef(node.condition, ids)) {
  2004. return true;
  2005. }
  2006. return node.children.some((c) => hasScopeRef(c, ids));
  2007. case 4:
  2008. return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
  2009. case 8:
  2010. return node.children.some((c) => isObject(c) && hasScopeRef(c, ids));
  2011. case 5:
  2012. case 12:
  2013. return hasScopeRef(node.content, ids);
  2014. case 2:
  2015. case 3:
  2016. case 20:
  2017. return false;
  2018. default:
  2019. return false;
  2020. }
  2021. }
  2022. function getMemoedVNodeCall(node) {
  2023. if (node.type === 14 && node.callee === WITH_MEMO) {
  2024. return node.arguments[1].returns;
  2025. } else {
  2026. return node;
  2027. }
  2028. }
  2029. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
  2030. const defaultParserOptions = {
  2031. parseMode: "base",
  2032. ns: 0,
  2033. delimiters: [`{{`, `}}`],
  2034. getNamespace: () => 0,
  2035. isVoidTag: NO,
  2036. isPreTag: NO,
  2037. isIgnoreNewlineTag: NO,
  2038. isCustomElement: NO,
  2039. onError: defaultOnError,
  2040. onWarn: defaultOnWarn,
  2041. comments: true,
  2042. prefixIdentifiers: false
  2043. };
  2044. let currentOptions = defaultParserOptions;
  2045. let currentRoot = null;
  2046. let currentInput = "";
  2047. let currentOpenTag = null;
  2048. let currentProp = null;
  2049. let currentAttrValue = "";
  2050. let currentAttrStartIndex = -1;
  2051. let currentAttrEndIndex = -1;
  2052. let inPre = 0;
  2053. let inVPre = false;
  2054. let currentVPreBoundary = null;
  2055. const stack = [];
  2056. const tokenizer = new Tokenizer(stack, {
  2057. onerr: emitError,
  2058. ontext(start, end) {
  2059. onText(getSlice(start, end), start, end);
  2060. },
  2061. ontextentity(char, start, end) {
  2062. onText(char, start, end);
  2063. },
  2064. oninterpolation(start, end) {
  2065. if (inVPre) {
  2066. return onText(getSlice(start, end), start, end);
  2067. }
  2068. let innerStart = start + tokenizer.delimiterOpen.length;
  2069. let innerEnd = end - tokenizer.delimiterClose.length;
  2070. while (isWhitespace(currentInput.charCodeAt(innerStart))) {
  2071. innerStart++;
  2072. }
  2073. while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
  2074. innerEnd--;
  2075. }
  2076. let exp = getSlice(innerStart, innerEnd);
  2077. if (exp.includes("&")) {
  2078. {
  2079. exp = currentOptions.decodeEntities(exp, false);
  2080. }
  2081. }
  2082. addNode({
  2083. type: 5,
  2084. content: createExp(exp, false, getLoc(innerStart, innerEnd)),
  2085. loc: getLoc(start, end)
  2086. });
  2087. },
  2088. onopentagname(start, end) {
  2089. const name = getSlice(start, end);
  2090. currentOpenTag = {
  2091. type: 1,
  2092. tag: name,
  2093. ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
  2094. tagType: 0,
  2095. // will be refined on tag close
  2096. props: [],
  2097. children: [],
  2098. loc: getLoc(start - 1, end),
  2099. codegenNode: void 0
  2100. };
  2101. },
  2102. onopentagend(end) {
  2103. endOpenTag(end);
  2104. },
  2105. onclosetag(start, end) {
  2106. const name = getSlice(start, end);
  2107. if (!currentOptions.isVoidTag(name)) {
  2108. let found = false;
  2109. for (let i = 0; i < stack.length; i++) {
  2110. const e = stack[i];
  2111. if (e.tag.toLowerCase() === name.toLowerCase()) {
  2112. found = true;
  2113. if (i > 0) {
  2114. emitError(24, stack[0].loc.start.offset);
  2115. }
  2116. for (let j = 0; j <= i; j++) {
  2117. const el = stack.shift();
  2118. onCloseTag(el, end, j < i);
  2119. }
  2120. break;
  2121. }
  2122. }
  2123. if (!found) {
  2124. emitError(23, backTrack(start, 60));
  2125. }
  2126. }
  2127. },
  2128. onselfclosingtag(end) {
  2129. const name = currentOpenTag.tag;
  2130. currentOpenTag.isSelfClosing = true;
  2131. endOpenTag(end);
  2132. if (stack[0] && stack[0].tag === name) {
  2133. onCloseTag(stack.shift(), end);
  2134. }
  2135. },
  2136. onattribname(start, end) {
  2137. currentProp = {
  2138. type: 6,
  2139. name: getSlice(start, end),
  2140. nameLoc: getLoc(start, end),
  2141. value: void 0,
  2142. loc: getLoc(start)
  2143. };
  2144. },
  2145. ondirname(start, end) {
  2146. const raw = getSlice(start, end);
  2147. const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
  2148. if (!inVPre && name === "") {
  2149. emitError(26, start);
  2150. }
  2151. if (inVPre || name === "") {
  2152. currentProp = {
  2153. type: 6,
  2154. name: raw,
  2155. nameLoc: getLoc(start, end),
  2156. value: void 0,
  2157. loc: getLoc(start)
  2158. };
  2159. } else {
  2160. currentProp = {
  2161. type: 7,
  2162. name,
  2163. rawName: raw,
  2164. exp: void 0,
  2165. arg: void 0,
  2166. modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
  2167. loc: getLoc(start)
  2168. };
  2169. if (name === "pre") {
  2170. inVPre = tokenizer.inVPre = true;
  2171. currentVPreBoundary = currentOpenTag;
  2172. const props = currentOpenTag.props;
  2173. for (let i = 0; i < props.length; i++) {
  2174. if (props[i].type === 7) {
  2175. props[i] = dirToAttr(props[i]);
  2176. }
  2177. }
  2178. }
  2179. }
  2180. },
  2181. ondirarg(start, end) {
  2182. if (start === end) return;
  2183. const arg = getSlice(start, end);
  2184. if (inVPre && !isVPre(currentProp)) {
  2185. currentProp.name += arg;
  2186. setLocEnd(currentProp.nameLoc, end);
  2187. } else {
  2188. const isStatic = arg[0] !== `[`;
  2189. currentProp.arg = createExp(
  2190. isStatic ? arg : arg.slice(1, -1),
  2191. isStatic,
  2192. getLoc(start, end),
  2193. isStatic ? 3 : 0
  2194. );
  2195. }
  2196. },
  2197. ondirmodifier(start, end) {
  2198. const mod = getSlice(start, end);
  2199. if (inVPre && !isVPre(currentProp)) {
  2200. currentProp.name += "." + mod;
  2201. setLocEnd(currentProp.nameLoc, end);
  2202. } else if (currentProp.name === "slot") {
  2203. const arg = currentProp.arg;
  2204. if (arg) {
  2205. arg.content += "." + mod;
  2206. setLocEnd(arg.loc, end);
  2207. }
  2208. } else {
  2209. const exp = createSimpleExpression(mod, true, getLoc(start, end));
  2210. currentProp.modifiers.push(exp);
  2211. }
  2212. },
  2213. onattribdata(start, end) {
  2214. currentAttrValue += getSlice(start, end);
  2215. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  2216. currentAttrEndIndex = end;
  2217. },
  2218. onattribentity(char, start, end) {
  2219. currentAttrValue += char;
  2220. if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
  2221. currentAttrEndIndex = end;
  2222. },
  2223. onattribnameend(end) {
  2224. const start = currentProp.loc.start.offset;
  2225. const name = getSlice(start, end);
  2226. if (currentProp.type === 7) {
  2227. currentProp.rawName = name;
  2228. }
  2229. if (currentOpenTag.props.some(
  2230. (p) => (p.type === 7 ? p.rawName : p.name) === name
  2231. )) {
  2232. emitError(2, start);
  2233. }
  2234. },
  2235. onattribend(quote, end) {
  2236. if (currentOpenTag && currentProp) {
  2237. setLocEnd(currentProp.loc, end);
  2238. if (quote !== 0) {
  2239. if (currentAttrValue.includes("&")) {
  2240. currentAttrValue = currentOptions.decodeEntities(
  2241. currentAttrValue,
  2242. true
  2243. );
  2244. }
  2245. if (currentProp.type === 6) {
  2246. if (currentProp.name === "class") {
  2247. currentAttrValue = condense(currentAttrValue).trim();
  2248. }
  2249. if (quote === 1 && !currentAttrValue) {
  2250. emitError(13, end);
  2251. }
  2252. currentProp.value = {
  2253. type: 2,
  2254. content: currentAttrValue,
  2255. loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
  2256. };
  2257. if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
  2258. tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
  2259. }
  2260. } else {
  2261. let expParseMode = 0 /* Normal */;
  2262. currentProp.exp = createExp(
  2263. currentAttrValue,
  2264. false,
  2265. getLoc(currentAttrStartIndex, currentAttrEndIndex),
  2266. 0,
  2267. expParseMode
  2268. );
  2269. if (currentProp.name === "for") {
  2270. currentProp.forParseResult = parseForExpression(currentProp.exp);
  2271. }
  2272. let syncIndex = -1;
  2273. if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.findIndex(
  2274. (mod) => mod.content === "sync"
  2275. )) > -1 && checkCompatEnabled(
  2276. "COMPILER_V_BIND_SYNC",
  2277. currentOptions,
  2278. currentProp.loc,
  2279. currentProp.arg.loc.source
  2280. )) {
  2281. currentProp.name = "model";
  2282. currentProp.modifiers.splice(syncIndex, 1);
  2283. }
  2284. }
  2285. }
  2286. if (currentProp.type !== 7 || currentProp.name !== "pre") {
  2287. currentOpenTag.props.push(currentProp);
  2288. }
  2289. }
  2290. currentAttrValue = "";
  2291. currentAttrStartIndex = currentAttrEndIndex = -1;
  2292. },
  2293. oncomment(start, end) {
  2294. if (currentOptions.comments) {
  2295. addNode({
  2296. type: 3,
  2297. content: getSlice(start, end),
  2298. loc: getLoc(start - 4, end + 3)
  2299. });
  2300. }
  2301. },
  2302. onend() {
  2303. const end = currentInput.length;
  2304. if (tokenizer.state !== 1) {
  2305. switch (tokenizer.state) {
  2306. case 5:
  2307. case 8:
  2308. emitError(5, end);
  2309. break;
  2310. case 3:
  2311. case 4:
  2312. emitError(
  2313. 25,
  2314. tokenizer.sectionStart
  2315. );
  2316. break;
  2317. case 28:
  2318. if (tokenizer.currentSequence === Sequences.CdataEnd) {
  2319. emitError(6, end);
  2320. } else {
  2321. emitError(7, end);
  2322. }
  2323. break;
  2324. case 6:
  2325. case 7:
  2326. case 9:
  2327. case 11:
  2328. case 12:
  2329. case 13:
  2330. case 14:
  2331. case 15:
  2332. case 16:
  2333. case 17:
  2334. case 18:
  2335. case 19:
  2336. // "
  2337. case 20:
  2338. // '
  2339. case 21:
  2340. emitError(9, end);
  2341. break;
  2342. }
  2343. }
  2344. for (let index = 0; index < stack.length; index++) {
  2345. onCloseTag(stack[index], end - 1);
  2346. emitError(24, stack[index].loc.start.offset);
  2347. }
  2348. },
  2349. oncdata(start, end) {
  2350. if (stack[0].ns !== 0) {
  2351. onText(getSlice(start, end), start, end);
  2352. } else {
  2353. emitError(1, start - 9);
  2354. }
  2355. },
  2356. onprocessinginstruction(start) {
  2357. if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  2358. emitError(
  2359. 21,
  2360. start - 1
  2361. );
  2362. }
  2363. }
  2364. });
  2365. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  2366. const stripParensRE = /^\(|\)$/g;
  2367. function parseForExpression(input) {
  2368. const loc = input.loc;
  2369. const exp = input.content;
  2370. const inMatch = exp.match(forAliasRE);
  2371. if (!inMatch) return;
  2372. const [, LHS, RHS] = inMatch;
  2373. const createAliasExpression = (content, offset, asParam = false) => {
  2374. const start = loc.start.offset + offset;
  2375. const end = start + content.length;
  2376. return createExp(
  2377. content,
  2378. false,
  2379. getLoc(start, end),
  2380. 0,
  2381. asParam ? 1 /* Params */ : 0 /* Normal */
  2382. );
  2383. };
  2384. const result = {
  2385. source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
  2386. value: void 0,
  2387. key: void 0,
  2388. index: void 0,
  2389. finalized: false
  2390. };
  2391. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  2392. const trimmedOffset = LHS.indexOf(valueContent);
  2393. const iteratorMatch = valueContent.match(forIteratorRE);
  2394. if (iteratorMatch) {
  2395. valueContent = valueContent.replace(forIteratorRE, "").trim();
  2396. const keyContent = iteratorMatch[1].trim();
  2397. let keyOffset;
  2398. if (keyContent) {
  2399. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  2400. result.key = createAliasExpression(keyContent, keyOffset, true);
  2401. }
  2402. if (iteratorMatch[2]) {
  2403. const indexContent = iteratorMatch[2].trim();
  2404. if (indexContent) {
  2405. result.index = createAliasExpression(
  2406. indexContent,
  2407. exp.indexOf(
  2408. indexContent,
  2409. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  2410. ),
  2411. true
  2412. );
  2413. }
  2414. }
  2415. }
  2416. if (valueContent) {
  2417. result.value = createAliasExpression(valueContent, trimmedOffset, true);
  2418. }
  2419. return result;
  2420. }
  2421. function getSlice(start, end) {
  2422. return currentInput.slice(start, end);
  2423. }
  2424. function endOpenTag(end) {
  2425. if (tokenizer.inSFCRoot) {
  2426. currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
  2427. }
  2428. addNode(currentOpenTag);
  2429. const { tag, ns } = currentOpenTag;
  2430. if (ns === 0 && currentOptions.isPreTag(tag)) {
  2431. inPre++;
  2432. }
  2433. if (currentOptions.isVoidTag(tag)) {
  2434. onCloseTag(currentOpenTag, end);
  2435. } else {
  2436. stack.unshift(currentOpenTag);
  2437. if (ns === 1 || ns === 2) {
  2438. tokenizer.inXML = true;
  2439. }
  2440. }
  2441. currentOpenTag = null;
  2442. }
  2443. function onText(content, start, end) {
  2444. {
  2445. const tag = stack[0] && stack[0].tag;
  2446. if (tag !== "script" && tag !== "style" && content.includes("&")) {
  2447. content = currentOptions.decodeEntities(content, false);
  2448. }
  2449. }
  2450. const parent = stack[0] || currentRoot;
  2451. const lastNode = parent.children[parent.children.length - 1];
  2452. if (lastNode && lastNode.type === 2) {
  2453. lastNode.content += content;
  2454. setLocEnd(lastNode.loc, end);
  2455. } else {
  2456. parent.children.push({
  2457. type: 2,
  2458. content,
  2459. loc: getLoc(start, end)
  2460. });
  2461. }
  2462. }
  2463. function onCloseTag(el, end, isImplied = false) {
  2464. if (isImplied) {
  2465. setLocEnd(el.loc, backTrack(end, 60));
  2466. } else {
  2467. setLocEnd(el.loc, lookAhead(end, 62) + 1);
  2468. }
  2469. if (tokenizer.inSFCRoot) {
  2470. if (el.children.length) {
  2471. el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
  2472. } else {
  2473. el.innerLoc.end = extend({}, el.innerLoc.start);
  2474. }
  2475. el.innerLoc.source = getSlice(
  2476. el.innerLoc.start.offset,
  2477. el.innerLoc.end.offset
  2478. );
  2479. }
  2480. const { tag, ns, children } = el;
  2481. if (!inVPre) {
  2482. if (tag === "slot") {
  2483. el.tagType = 2;
  2484. } else if (isFragmentTemplate(el)) {
  2485. el.tagType = 3;
  2486. } else if (isComponent(el)) {
  2487. el.tagType = 1;
  2488. }
  2489. }
  2490. if (!tokenizer.inRCDATA) {
  2491. el.children = condenseWhitespace(children);
  2492. }
  2493. if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
  2494. const first = children[0];
  2495. if (first && first.type === 2) {
  2496. first.content = first.content.replace(/^\r?\n/, "");
  2497. }
  2498. }
  2499. if (ns === 0 && currentOptions.isPreTag(tag)) {
  2500. inPre--;
  2501. }
  2502. if (currentVPreBoundary === el) {
  2503. inVPre = tokenizer.inVPre = false;
  2504. currentVPreBoundary = null;
  2505. }
  2506. if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  2507. tokenizer.inXML = false;
  2508. }
  2509. {
  2510. const props = el.props;
  2511. if (isCompatEnabled(
  2512. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  2513. currentOptions
  2514. )) {
  2515. let hasIf = false;
  2516. let hasFor = false;
  2517. for (let i = 0; i < props.length; i++) {
  2518. const p = props[i];
  2519. if (p.type === 7) {
  2520. if (p.name === "if") {
  2521. hasIf = true;
  2522. } else if (p.name === "for") {
  2523. hasFor = true;
  2524. }
  2525. }
  2526. if (hasIf && hasFor) {
  2527. warnDeprecation(
  2528. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  2529. currentOptions,
  2530. el.loc
  2531. );
  2532. break;
  2533. }
  2534. }
  2535. }
  2536. if (!tokenizer.inSFCRoot && isCompatEnabled(
  2537. "COMPILER_NATIVE_TEMPLATE",
  2538. currentOptions
  2539. ) && el.tag === "template" && !isFragmentTemplate(el)) {
  2540. warnDeprecation(
  2541. "COMPILER_NATIVE_TEMPLATE",
  2542. currentOptions,
  2543. el.loc
  2544. );
  2545. const parent = stack[0] || currentRoot;
  2546. const index = parent.children.indexOf(el);
  2547. parent.children.splice(index, 1, ...el.children);
  2548. }
  2549. const inlineTemplateProp = props.find(
  2550. (p) => p.type === 6 && p.name === "inline-template"
  2551. );
  2552. if (inlineTemplateProp && checkCompatEnabled(
  2553. "COMPILER_INLINE_TEMPLATE",
  2554. currentOptions,
  2555. inlineTemplateProp.loc
  2556. ) && el.children.length) {
  2557. inlineTemplateProp.value = {
  2558. type: 2,
  2559. content: getSlice(
  2560. el.children[0].loc.start.offset,
  2561. el.children[el.children.length - 1].loc.end.offset
  2562. ),
  2563. loc: inlineTemplateProp.loc
  2564. };
  2565. }
  2566. }
  2567. }
  2568. function lookAhead(index, c) {
  2569. let i = index;
  2570. while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
  2571. return i;
  2572. }
  2573. function backTrack(index, c) {
  2574. let i = index;
  2575. while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
  2576. return i;
  2577. }
  2578. const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
  2579. function isFragmentTemplate({ tag, props }) {
  2580. if (tag === "template") {
  2581. for (let i = 0; i < props.length; i++) {
  2582. if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
  2583. return true;
  2584. }
  2585. }
  2586. }
  2587. return false;
  2588. }
  2589. function isComponent({ tag, props }) {
  2590. if (currentOptions.isCustomElement(tag)) {
  2591. return false;
  2592. }
  2593. if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
  2594. return true;
  2595. }
  2596. for (let i = 0; i < props.length; i++) {
  2597. const p = props[i];
  2598. if (p.type === 6) {
  2599. if (p.name === "is" && p.value) {
  2600. if (p.value.content.startsWith("vue:")) {
  2601. return true;
  2602. } else if (checkCompatEnabled(
  2603. "COMPILER_IS_ON_ELEMENT",
  2604. currentOptions,
  2605. p.loc
  2606. )) {
  2607. return true;
  2608. }
  2609. }
  2610. } else if (// :is on plain element - only treat as component in compat mode
  2611. p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
  2612. "COMPILER_IS_ON_ELEMENT",
  2613. currentOptions,
  2614. p.loc
  2615. )) {
  2616. return true;
  2617. }
  2618. }
  2619. return false;
  2620. }
  2621. function isUpperCase(c) {
  2622. return c > 64 && c < 91;
  2623. }
  2624. const windowsNewlineRE = /\r\n/g;
  2625. function condenseWhitespace(nodes) {
  2626. const shouldCondense = currentOptions.whitespace !== "preserve";
  2627. let removedWhitespace = false;
  2628. for (let i = 0; i < nodes.length; i++) {
  2629. const node = nodes[i];
  2630. if (node.type === 2) {
  2631. if (!inPre) {
  2632. if (isAllWhitespace(node.content)) {
  2633. const prev = nodes[i - 1] && nodes[i - 1].type;
  2634. const next = nodes[i + 1] && nodes[i + 1].type;
  2635. if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
  2636. removedWhitespace = true;
  2637. nodes[i] = null;
  2638. } else {
  2639. node.content = " ";
  2640. }
  2641. } else if (shouldCondense) {
  2642. node.content = condense(node.content);
  2643. }
  2644. } else {
  2645. node.content = node.content.replace(windowsNewlineRE, "\n");
  2646. }
  2647. }
  2648. }
  2649. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  2650. }
  2651. function isAllWhitespace(str) {
  2652. for (let i = 0; i < str.length; i++) {
  2653. if (!isWhitespace(str.charCodeAt(i))) {
  2654. return false;
  2655. }
  2656. }
  2657. return true;
  2658. }
  2659. function hasNewlineChar(str) {
  2660. for (let i = 0; i < str.length; i++) {
  2661. const c = str.charCodeAt(i);
  2662. if (c === 10 || c === 13) {
  2663. return true;
  2664. }
  2665. }
  2666. return false;
  2667. }
  2668. function condense(str) {
  2669. let ret = "";
  2670. let prevCharIsWhitespace = false;
  2671. for (let i = 0; i < str.length; i++) {
  2672. if (isWhitespace(str.charCodeAt(i))) {
  2673. if (!prevCharIsWhitespace) {
  2674. ret += " ";
  2675. prevCharIsWhitespace = true;
  2676. }
  2677. } else {
  2678. ret += str[i];
  2679. prevCharIsWhitespace = false;
  2680. }
  2681. }
  2682. return ret;
  2683. }
  2684. function addNode(node) {
  2685. (stack[0] || currentRoot).children.push(node);
  2686. }
  2687. function getLoc(start, end) {
  2688. return {
  2689. start: tokenizer.getPos(start),
  2690. // @ts-expect-error allow late attachment
  2691. end: end == null ? end : tokenizer.getPos(end),
  2692. // @ts-expect-error allow late attachment
  2693. source: end == null ? end : getSlice(start, end)
  2694. };
  2695. }
  2696. function cloneLoc(loc) {
  2697. return getLoc(loc.start.offset, loc.end.offset);
  2698. }
  2699. function setLocEnd(loc, end) {
  2700. loc.end = tokenizer.getPos(end);
  2701. loc.source = getSlice(loc.start.offset, end);
  2702. }
  2703. function dirToAttr(dir) {
  2704. const attr = {
  2705. type: 6,
  2706. name: dir.rawName,
  2707. nameLoc: getLoc(
  2708. dir.loc.start.offset,
  2709. dir.loc.start.offset + dir.rawName.length
  2710. ),
  2711. value: void 0,
  2712. loc: dir.loc
  2713. };
  2714. if (dir.exp) {
  2715. const loc = dir.exp.loc;
  2716. if (loc.end.offset < dir.loc.end.offset) {
  2717. loc.start.offset--;
  2718. loc.start.column--;
  2719. loc.end.offset++;
  2720. loc.end.column++;
  2721. }
  2722. attr.value = {
  2723. type: 2,
  2724. content: dir.exp.content,
  2725. loc
  2726. };
  2727. }
  2728. return attr;
  2729. }
  2730. function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
  2731. const exp = createSimpleExpression(content, isStatic, loc, constType);
  2732. return exp;
  2733. }
  2734. function emitError(code, index, message) {
  2735. currentOptions.onError(
  2736. createCompilerError(code, getLoc(index, index), void 0, message)
  2737. );
  2738. }
  2739. function reset() {
  2740. tokenizer.reset();
  2741. currentOpenTag = null;
  2742. currentProp = null;
  2743. currentAttrValue = "";
  2744. currentAttrStartIndex = -1;
  2745. currentAttrEndIndex = -1;
  2746. stack.length = 0;
  2747. }
  2748. function baseParse(input, options) {
  2749. reset();
  2750. currentInput = input;
  2751. currentOptions = extend({}, defaultParserOptions);
  2752. if (options) {
  2753. let key;
  2754. for (key in options) {
  2755. if (options[key] != null) {
  2756. currentOptions[key] = options[key];
  2757. }
  2758. }
  2759. }
  2760. {
  2761. if (!currentOptions.decodeEntities) {
  2762. throw new Error(
  2763. `[@vue/compiler-core] decodeEntities option is required in browser builds.`
  2764. );
  2765. }
  2766. }
  2767. tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
  2768. tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
  2769. const delimiters = options && options.delimiters;
  2770. if (delimiters) {
  2771. tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
  2772. tokenizer.delimiterClose = toCharCodes(delimiters[1]);
  2773. }
  2774. const root = currentRoot = createRoot([], input);
  2775. tokenizer.parse(currentInput);
  2776. root.loc = getLoc(0, input.length);
  2777. root.children = condenseWhitespace(root.children);
  2778. currentRoot = null;
  2779. return root;
  2780. }
  2781. function cacheStatic(root, context) {
  2782. walk(
  2783. root,
  2784. void 0,
  2785. context,
  2786. // Root node is unfortunately non-hoistable due to potential parent
  2787. // fallthrough attributes.
  2788. !!getSingleElementRoot(root)
  2789. );
  2790. }
  2791. function getSingleElementRoot(root) {
  2792. const children = root.children.filter((x) => x.type !== 3);
  2793. return children.length === 1 && children[0].type === 1 && !isSlotOutlet(children[0]) ? children[0] : null;
  2794. }
  2795. function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
  2796. const { children } = node;
  2797. const toCache = [];
  2798. for (let i = 0; i < children.length; i++) {
  2799. const child = children[i];
  2800. if (child.type === 1 && child.tagType === 0) {
  2801. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  2802. if (constantType > 0) {
  2803. if (constantType >= 2) {
  2804. child.codegenNode.patchFlag = -1;
  2805. toCache.push(child);
  2806. continue;
  2807. }
  2808. } else {
  2809. const codegenNode = child.codegenNode;
  2810. if (codegenNode.type === 13) {
  2811. const flag = codegenNode.patchFlag;
  2812. if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  2813. const props = getNodeProps(child);
  2814. if (props) {
  2815. codegenNode.props = context.hoist(props);
  2816. }
  2817. }
  2818. if (codegenNode.dynamicProps) {
  2819. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  2820. }
  2821. }
  2822. }
  2823. } else if (child.type === 12) {
  2824. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  2825. if (constantType >= 2) {
  2826. if (child.codegenNode.type === 14 && child.codegenNode.arguments.length > 0) {
  2827. child.codegenNode.arguments.push(
  2828. -1 + (` /* ${PatchFlagNames[-1]} */` )
  2829. );
  2830. }
  2831. toCache.push(child);
  2832. continue;
  2833. }
  2834. }
  2835. if (child.type === 1) {
  2836. const isComponent = child.tagType === 1;
  2837. if (isComponent) {
  2838. context.scopes.vSlot++;
  2839. }
  2840. walk(child, node, context, false, inFor);
  2841. if (isComponent) {
  2842. context.scopes.vSlot--;
  2843. }
  2844. } else if (child.type === 11) {
  2845. walk(child, node, context, child.children.length === 1, true);
  2846. } else if (child.type === 9) {
  2847. for (let i2 = 0; i2 < child.branches.length; i2++) {
  2848. walk(
  2849. child.branches[i2],
  2850. node,
  2851. context,
  2852. child.branches[i2].children.length === 1,
  2853. inFor
  2854. );
  2855. }
  2856. }
  2857. }
  2858. let cachedAsArray = false;
  2859. if (toCache.length === children.length && node.type === 1) {
  2860. if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
  2861. node.codegenNode.children = getCacheExpression(
  2862. createArrayExpression(node.codegenNode.children)
  2863. );
  2864. cachedAsArray = true;
  2865. } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
  2866. const slot = getSlotNode(node.codegenNode, "default");
  2867. if (slot) {
  2868. slot.returns = getCacheExpression(
  2869. createArrayExpression(slot.returns)
  2870. );
  2871. cachedAsArray = true;
  2872. }
  2873. } else if (node.tagType === 3 && parent && parent.type === 1 && parent.tagType === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 15) {
  2874. const slotName = findDir(node, "slot", true);
  2875. const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
  2876. if (slot) {
  2877. slot.returns = getCacheExpression(
  2878. createArrayExpression(slot.returns)
  2879. );
  2880. cachedAsArray = true;
  2881. }
  2882. }
  2883. }
  2884. if (!cachedAsArray) {
  2885. for (const child of toCache) {
  2886. child.codegenNode = context.cache(child.codegenNode);
  2887. }
  2888. }
  2889. function getCacheExpression(value) {
  2890. const exp = context.cache(value);
  2891. exp.needArraySpread = true;
  2892. return exp;
  2893. }
  2894. function getSlotNode(node2, name) {
  2895. if (node2.children && !isArray(node2.children) && node2.children.type === 15) {
  2896. const slot = node2.children.properties.find(
  2897. (p) => p.key === name || p.key.content === name
  2898. );
  2899. return slot && slot.value;
  2900. }
  2901. }
  2902. if (toCache.length && context.transformHoist) {
  2903. context.transformHoist(children, context, node);
  2904. }
  2905. }
  2906. function getConstantType(node, context) {
  2907. const { constantCache } = context;
  2908. switch (node.type) {
  2909. case 1:
  2910. if (node.tagType !== 0) {
  2911. return 0;
  2912. }
  2913. const cached = constantCache.get(node);
  2914. if (cached !== void 0) {
  2915. return cached;
  2916. }
  2917. const codegenNode = node.codegenNode;
  2918. if (codegenNode.type !== 13) {
  2919. return 0;
  2920. }
  2921. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
  2922. return 0;
  2923. }
  2924. if (codegenNode.patchFlag === void 0) {
  2925. let returnType2 = 3;
  2926. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  2927. if (generatedPropsType === 0) {
  2928. constantCache.set(node, 0);
  2929. return 0;
  2930. }
  2931. if (generatedPropsType < returnType2) {
  2932. returnType2 = generatedPropsType;
  2933. }
  2934. for (let i = 0; i < node.children.length; i++) {
  2935. const childType = getConstantType(node.children[i], context);
  2936. if (childType === 0) {
  2937. constantCache.set(node, 0);
  2938. return 0;
  2939. }
  2940. if (childType < returnType2) {
  2941. returnType2 = childType;
  2942. }
  2943. }
  2944. if (returnType2 > 1) {
  2945. for (let i = 0; i < node.props.length; i++) {
  2946. const p = node.props[i];
  2947. if (p.type === 7 && p.name === "bind" && p.exp) {
  2948. const expType = getConstantType(p.exp, context);
  2949. if (expType === 0) {
  2950. constantCache.set(node, 0);
  2951. return 0;
  2952. }
  2953. if (expType < returnType2) {
  2954. returnType2 = expType;
  2955. }
  2956. }
  2957. }
  2958. }
  2959. if (codegenNode.isBlock) {
  2960. for (let i = 0; i < node.props.length; i++) {
  2961. const p = node.props[i];
  2962. if (p.type === 7) {
  2963. constantCache.set(node, 0);
  2964. return 0;
  2965. }
  2966. }
  2967. context.removeHelper(OPEN_BLOCK);
  2968. context.removeHelper(
  2969. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  2970. );
  2971. codegenNode.isBlock = false;
  2972. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  2973. }
  2974. constantCache.set(node, returnType2);
  2975. return returnType2;
  2976. } else {
  2977. constantCache.set(node, 0);
  2978. return 0;
  2979. }
  2980. case 2:
  2981. case 3:
  2982. return 3;
  2983. case 9:
  2984. case 11:
  2985. case 10:
  2986. return 0;
  2987. case 5:
  2988. case 12:
  2989. return getConstantType(node.content, context);
  2990. case 4:
  2991. return node.constType;
  2992. case 8:
  2993. let returnType = 3;
  2994. for (let i = 0; i < node.children.length; i++) {
  2995. const child = node.children[i];
  2996. if (isString(child) || isSymbol(child)) {
  2997. continue;
  2998. }
  2999. const childType = getConstantType(child, context);
  3000. if (childType === 0) {
  3001. return 0;
  3002. } else if (childType < returnType) {
  3003. returnType = childType;
  3004. }
  3005. }
  3006. return returnType;
  3007. case 20:
  3008. return 2;
  3009. default:
  3010. return 0;
  3011. }
  3012. }
  3013. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  3014. NORMALIZE_CLASS,
  3015. NORMALIZE_STYLE,
  3016. NORMALIZE_PROPS,
  3017. GUARD_REACTIVE_PROPS
  3018. ]);
  3019. function getConstantTypeOfHelperCall(value, context) {
  3020. if (value.type === 14 && !isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  3021. const arg = value.arguments[0];
  3022. if (arg.type === 4) {
  3023. return getConstantType(arg, context);
  3024. } else if (arg.type === 14) {
  3025. return getConstantTypeOfHelperCall(arg, context);
  3026. }
  3027. }
  3028. return 0;
  3029. }
  3030. function getGeneratedPropsConstantType(node, context) {
  3031. let returnType = 3;
  3032. const props = getNodeProps(node);
  3033. if (props && props.type === 15) {
  3034. const { properties } = props;
  3035. for (let i = 0; i < properties.length; i++) {
  3036. const { key, value } = properties[i];
  3037. const keyType = getConstantType(key, context);
  3038. if (keyType === 0) {
  3039. return keyType;
  3040. }
  3041. if (keyType < returnType) {
  3042. returnType = keyType;
  3043. }
  3044. let valueType;
  3045. if (value.type === 4) {
  3046. valueType = getConstantType(value, context);
  3047. } else if (value.type === 14) {
  3048. valueType = getConstantTypeOfHelperCall(value, context);
  3049. } else {
  3050. valueType = 0;
  3051. }
  3052. if (valueType === 0) {
  3053. return valueType;
  3054. }
  3055. if (valueType < returnType) {
  3056. returnType = valueType;
  3057. }
  3058. }
  3059. }
  3060. return returnType;
  3061. }
  3062. function getNodeProps(node) {
  3063. const codegenNode = node.codegenNode;
  3064. if (codegenNode.type === 13) {
  3065. return codegenNode.props;
  3066. }
  3067. }
  3068. function createTransformContext(root, {
  3069. filename = "",
  3070. prefixIdentifiers = false,
  3071. hoistStatic = false,
  3072. hmr = false,
  3073. cacheHandlers = false,
  3074. nodeTransforms = [],
  3075. directiveTransforms = {},
  3076. transformHoist = null,
  3077. isBuiltInComponent = NOOP,
  3078. isCustomElement = NOOP,
  3079. expressionPlugins = [],
  3080. scopeId = null,
  3081. slotted = true,
  3082. ssr = false,
  3083. inSSR = false,
  3084. ssrCssVars = ``,
  3085. bindingMetadata = EMPTY_OBJ,
  3086. inline = false,
  3087. isTS = false,
  3088. onError = defaultOnError,
  3089. onWarn = defaultOnWarn,
  3090. compatConfig
  3091. }) {
  3092. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  3093. const context = {
  3094. // options
  3095. filename,
  3096. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  3097. prefixIdentifiers,
  3098. hoistStatic,
  3099. hmr,
  3100. cacheHandlers,
  3101. nodeTransforms,
  3102. directiveTransforms,
  3103. transformHoist,
  3104. isBuiltInComponent,
  3105. isCustomElement,
  3106. expressionPlugins,
  3107. scopeId,
  3108. slotted,
  3109. ssr,
  3110. inSSR,
  3111. ssrCssVars,
  3112. bindingMetadata,
  3113. inline,
  3114. isTS,
  3115. onError,
  3116. onWarn,
  3117. compatConfig,
  3118. // state
  3119. root,
  3120. helpers: /* @__PURE__ */ new Map(),
  3121. components: /* @__PURE__ */ new Set(),
  3122. directives: /* @__PURE__ */ new Set(),
  3123. hoists: [],
  3124. imports: [],
  3125. cached: [],
  3126. constantCache: /* @__PURE__ */ new WeakMap(),
  3127. temps: 0,
  3128. identifiers: /* @__PURE__ */ Object.create(null),
  3129. scopes: {
  3130. vFor: 0,
  3131. vSlot: 0,
  3132. vPre: 0,
  3133. vOnce: 0
  3134. },
  3135. parent: null,
  3136. grandParent: null,
  3137. currentNode: root,
  3138. childIndex: 0,
  3139. inVOnce: false,
  3140. // methods
  3141. helper(name) {
  3142. const count = context.helpers.get(name) || 0;
  3143. context.helpers.set(name, count + 1);
  3144. return name;
  3145. },
  3146. removeHelper(name) {
  3147. const count = context.helpers.get(name);
  3148. if (count) {
  3149. const currentCount = count - 1;
  3150. if (!currentCount) {
  3151. context.helpers.delete(name);
  3152. } else {
  3153. context.helpers.set(name, currentCount);
  3154. }
  3155. }
  3156. },
  3157. helperString(name) {
  3158. return `_${helperNameMap[context.helper(name)]}`;
  3159. },
  3160. replaceNode(node) {
  3161. {
  3162. if (!context.currentNode) {
  3163. throw new Error(`Node being replaced is already removed.`);
  3164. }
  3165. if (!context.parent) {
  3166. throw new Error(`Cannot replace root node.`);
  3167. }
  3168. }
  3169. context.parent.children[context.childIndex] = context.currentNode = node;
  3170. },
  3171. removeNode(node) {
  3172. if (!context.parent) {
  3173. throw new Error(`Cannot remove root node.`);
  3174. }
  3175. const list = context.parent.children;
  3176. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  3177. if (removalIndex < 0) {
  3178. throw new Error(`node being removed is not a child of current parent`);
  3179. }
  3180. if (!node || node === context.currentNode) {
  3181. context.currentNode = null;
  3182. context.onNodeRemoved();
  3183. } else {
  3184. if (context.childIndex > removalIndex) {
  3185. context.childIndex--;
  3186. context.onNodeRemoved();
  3187. }
  3188. }
  3189. context.parent.children.splice(removalIndex, 1);
  3190. },
  3191. onNodeRemoved: NOOP,
  3192. addIdentifiers(exp) {
  3193. },
  3194. removeIdentifiers(exp) {
  3195. },
  3196. hoist(exp) {
  3197. if (isString(exp)) exp = createSimpleExpression(exp);
  3198. context.hoists.push(exp);
  3199. const identifier = createSimpleExpression(
  3200. `_hoisted_${context.hoists.length}`,
  3201. false,
  3202. exp.loc,
  3203. 2
  3204. );
  3205. identifier.hoisted = exp;
  3206. return identifier;
  3207. },
  3208. cache(exp, isVNode = false, inVOnce = false) {
  3209. const cacheExp = createCacheExpression(
  3210. context.cached.length,
  3211. exp,
  3212. isVNode,
  3213. inVOnce
  3214. );
  3215. context.cached.push(cacheExp);
  3216. return cacheExp;
  3217. }
  3218. };
  3219. {
  3220. context.filters = /* @__PURE__ */ new Set();
  3221. }
  3222. return context;
  3223. }
  3224. function transform(root, options) {
  3225. const context = createTransformContext(root, options);
  3226. traverseNode(root, context);
  3227. if (options.hoistStatic) {
  3228. cacheStatic(root, context);
  3229. }
  3230. if (!options.ssr) {
  3231. createRootCodegen(root, context);
  3232. }
  3233. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  3234. root.components = [...context.components];
  3235. root.directives = [...context.directives];
  3236. root.imports = context.imports;
  3237. root.hoists = context.hoists;
  3238. root.temps = context.temps;
  3239. root.cached = context.cached;
  3240. root.transformed = true;
  3241. {
  3242. root.filters = [...context.filters];
  3243. }
  3244. }
  3245. function createRootCodegen(root, context) {
  3246. const { helper } = context;
  3247. const { children } = root;
  3248. if (children.length === 1) {
  3249. const singleElementRootChild = getSingleElementRoot(root);
  3250. if (singleElementRootChild && singleElementRootChild.codegenNode) {
  3251. const codegenNode = singleElementRootChild.codegenNode;
  3252. if (codegenNode.type === 13) {
  3253. convertToBlock(codegenNode, context);
  3254. }
  3255. root.codegenNode = codegenNode;
  3256. } else {
  3257. root.codegenNode = children[0];
  3258. }
  3259. } else if (children.length > 1) {
  3260. let patchFlag = 64;
  3261. if (children.filter((c) => c.type !== 3).length === 1) {
  3262. patchFlag |= 2048;
  3263. }
  3264. root.codegenNode = createVNodeCall(
  3265. context,
  3266. helper(FRAGMENT),
  3267. void 0,
  3268. root.children,
  3269. patchFlag,
  3270. void 0,
  3271. void 0,
  3272. true,
  3273. void 0,
  3274. false
  3275. );
  3276. } else ;
  3277. }
  3278. function traverseChildren(parent, context) {
  3279. let i = 0;
  3280. const nodeRemoved = () => {
  3281. i--;
  3282. };
  3283. for (; i < parent.children.length; i++) {
  3284. const child = parent.children[i];
  3285. if (isString(child)) continue;
  3286. context.grandParent = context.parent;
  3287. context.parent = parent;
  3288. context.childIndex = i;
  3289. context.onNodeRemoved = nodeRemoved;
  3290. traverseNode(child, context);
  3291. }
  3292. }
  3293. function traverseNode(node, context) {
  3294. context.currentNode = node;
  3295. const { nodeTransforms } = context;
  3296. const exitFns = [];
  3297. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  3298. const onExit = nodeTransforms[i2](node, context);
  3299. if (onExit) {
  3300. if (isArray(onExit)) {
  3301. exitFns.push(...onExit);
  3302. } else {
  3303. exitFns.push(onExit);
  3304. }
  3305. }
  3306. if (!context.currentNode) {
  3307. return;
  3308. } else {
  3309. node = context.currentNode;
  3310. }
  3311. }
  3312. switch (node.type) {
  3313. case 3:
  3314. if (!context.ssr) {
  3315. context.helper(CREATE_COMMENT);
  3316. }
  3317. break;
  3318. case 5:
  3319. if (!context.ssr) {
  3320. context.helper(TO_DISPLAY_STRING);
  3321. }
  3322. break;
  3323. // for container types, further traverse downwards
  3324. case 9:
  3325. for (let i2 = 0; i2 < node.branches.length; i2++) {
  3326. traverseNode(node.branches[i2], context);
  3327. }
  3328. break;
  3329. case 10:
  3330. case 11:
  3331. case 1:
  3332. case 0:
  3333. traverseChildren(node, context);
  3334. break;
  3335. }
  3336. context.currentNode = node;
  3337. let i = exitFns.length;
  3338. while (i--) {
  3339. exitFns[i]();
  3340. }
  3341. }
  3342. function createStructuralDirectiveTransform(name, fn) {
  3343. const matches = isString(name) ? (n) => n === name : (n) => name.test(n);
  3344. return (node, context) => {
  3345. if (node.type === 1) {
  3346. const { props } = node;
  3347. if (node.tagType === 3 && props.some(isVSlot)) {
  3348. return;
  3349. }
  3350. const exitFns = [];
  3351. for (let i = 0; i < props.length; i++) {
  3352. const prop = props[i];
  3353. if (prop.type === 7 && matches(prop.name)) {
  3354. props.splice(i, 1);
  3355. i--;
  3356. const onExit = fn(node, prop, context);
  3357. if (onExit) exitFns.push(onExit);
  3358. }
  3359. }
  3360. return exitFns;
  3361. }
  3362. };
  3363. }
  3364. const PURE_ANNOTATION = `/*@__PURE__*/`;
  3365. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  3366. function createCodegenContext(ast, {
  3367. mode = "function",
  3368. prefixIdentifiers = mode === "module",
  3369. sourceMap = false,
  3370. filename = `template.vue.html`,
  3371. scopeId = null,
  3372. optimizeImports = false,
  3373. runtimeGlobalName = `Vue`,
  3374. runtimeModuleName = `vue`,
  3375. ssrRuntimeModuleName = "vue/server-renderer",
  3376. ssr = false,
  3377. isTS = false,
  3378. inSSR = false
  3379. }) {
  3380. const context = {
  3381. mode,
  3382. prefixIdentifiers,
  3383. sourceMap,
  3384. filename,
  3385. scopeId,
  3386. optimizeImports,
  3387. runtimeGlobalName,
  3388. runtimeModuleName,
  3389. ssrRuntimeModuleName,
  3390. ssr,
  3391. isTS,
  3392. inSSR,
  3393. source: ast.source,
  3394. code: ``,
  3395. column: 1,
  3396. line: 1,
  3397. offset: 0,
  3398. indentLevel: 0,
  3399. pure: false,
  3400. map: void 0,
  3401. helper(key) {
  3402. return `_${helperNameMap[key]}`;
  3403. },
  3404. push(code, newlineIndex = -2 /* None */, node) {
  3405. context.code += code;
  3406. },
  3407. indent() {
  3408. newline(++context.indentLevel);
  3409. },
  3410. deindent(withoutNewLine = false) {
  3411. if (withoutNewLine) {
  3412. --context.indentLevel;
  3413. } else {
  3414. newline(--context.indentLevel);
  3415. }
  3416. },
  3417. newline() {
  3418. newline(context.indentLevel);
  3419. }
  3420. };
  3421. function newline(n) {
  3422. context.push("\n" + ` `.repeat(n), 0 /* Start */);
  3423. }
  3424. return context;
  3425. }
  3426. function generate(ast, options = {}) {
  3427. const context = createCodegenContext(ast, options);
  3428. if (options.onContextCreated) options.onContextCreated(context);
  3429. const {
  3430. mode,
  3431. push,
  3432. prefixIdentifiers,
  3433. indent,
  3434. deindent,
  3435. newline,
  3436. scopeId,
  3437. ssr
  3438. } = context;
  3439. const helpers = Array.from(ast.helpers);
  3440. const hasHelpers = helpers.length > 0;
  3441. const useWithBlock = !prefixIdentifiers && mode !== "module";
  3442. const preambleContext = context;
  3443. {
  3444. genFunctionPreamble(ast, preambleContext);
  3445. }
  3446. const functionName = ssr ? `ssrRender` : `render`;
  3447. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  3448. const signature = args.join(", ");
  3449. {
  3450. push(`function ${functionName}(${signature}) {`);
  3451. }
  3452. indent();
  3453. if (useWithBlock) {
  3454. push(`with (_ctx) {`);
  3455. indent();
  3456. if (hasHelpers) {
  3457. push(
  3458. `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
  3459. `,
  3460. -1 /* End */
  3461. );
  3462. newline();
  3463. }
  3464. }
  3465. if (ast.components.length) {
  3466. genAssets(ast.components, "component", context);
  3467. if (ast.directives.length || ast.temps > 0) {
  3468. newline();
  3469. }
  3470. }
  3471. if (ast.directives.length) {
  3472. genAssets(ast.directives, "directive", context);
  3473. if (ast.temps > 0) {
  3474. newline();
  3475. }
  3476. }
  3477. if (ast.filters && ast.filters.length) {
  3478. newline();
  3479. genAssets(ast.filters, "filter", context);
  3480. newline();
  3481. }
  3482. if (ast.temps > 0) {
  3483. push(`let `);
  3484. for (let i = 0; i < ast.temps; i++) {
  3485. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  3486. }
  3487. }
  3488. if (ast.components.length || ast.directives.length || ast.temps) {
  3489. push(`
  3490. `, 0 /* Start */);
  3491. newline();
  3492. }
  3493. if (!ssr) {
  3494. push(`return `);
  3495. }
  3496. if (ast.codegenNode) {
  3497. genNode(ast.codegenNode, context);
  3498. } else {
  3499. push(`null`);
  3500. }
  3501. if (useWithBlock) {
  3502. deindent();
  3503. push(`}`);
  3504. }
  3505. deindent();
  3506. push(`}`);
  3507. return {
  3508. ast,
  3509. code: context.code,
  3510. preamble: ``,
  3511. map: context.map ? context.map.toJSON() : void 0
  3512. };
  3513. }
  3514. function genFunctionPreamble(ast, context) {
  3515. const {
  3516. ssr,
  3517. prefixIdentifiers,
  3518. push,
  3519. newline,
  3520. runtimeModuleName,
  3521. runtimeGlobalName,
  3522. ssrRuntimeModuleName
  3523. } = context;
  3524. const VueBinding = runtimeGlobalName;
  3525. const helpers = Array.from(ast.helpers);
  3526. if (helpers.length > 0) {
  3527. {
  3528. push(`const _Vue = ${VueBinding}
  3529. `, -1 /* End */);
  3530. if (ast.hoists.length) {
  3531. const staticHelpers = [
  3532. CREATE_VNODE,
  3533. CREATE_ELEMENT_VNODE,
  3534. CREATE_COMMENT,
  3535. CREATE_TEXT,
  3536. CREATE_STATIC
  3537. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  3538. push(`const { ${staticHelpers} } = _Vue
  3539. `, -1 /* End */);
  3540. }
  3541. }
  3542. }
  3543. genHoists(ast.hoists, context);
  3544. newline();
  3545. push(`return `);
  3546. }
  3547. function genAssets(assets, type, { helper, push, newline, isTS }) {
  3548. const resolver = helper(
  3549. type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  3550. );
  3551. for (let i = 0; i < assets.length; i++) {
  3552. let id = assets[i];
  3553. const maybeSelfReference = id.endsWith("__self");
  3554. if (maybeSelfReference) {
  3555. id = id.slice(0, -6);
  3556. }
  3557. push(
  3558. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  3559. );
  3560. if (i < assets.length - 1) {
  3561. newline();
  3562. }
  3563. }
  3564. }
  3565. function genHoists(hoists, context) {
  3566. if (!hoists.length) {
  3567. return;
  3568. }
  3569. context.pure = true;
  3570. const { push, newline } = context;
  3571. newline();
  3572. for (let i = 0; i < hoists.length; i++) {
  3573. const exp = hoists[i];
  3574. if (exp) {
  3575. push(`const _hoisted_${i + 1} = `);
  3576. genNode(exp, context);
  3577. newline();
  3578. }
  3579. }
  3580. context.pure = false;
  3581. }
  3582. function isText(n) {
  3583. return isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  3584. }
  3585. function genNodeListAsArray(nodes, context) {
  3586. const multilines = nodes.length > 3 || nodes.some((n) => isArray(n) || !isText(n));
  3587. context.push(`[`);
  3588. multilines && context.indent();
  3589. genNodeList(nodes, context, multilines);
  3590. multilines && context.deindent();
  3591. context.push(`]`);
  3592. }
  3593. function genNodeList(nodes, context, multilines = false, comma = true) {
  3594. const { push, newline } = context;
  3595. for (let i = 0; i < nodes.length; i++) {
  3596. const node = nodes[i];
  3597. if (isString(node)) {
  3598. push(node, -3 /* Unknown */);
  3599. } else if (isArray(node)) {
  3600. genNodeListAsArray(node, context);
  3601. } else {
  3602. genNode(node, context);
  3603. }
  3604. if (i < nodes.length - 1) {
  3605. if (multilines) {
  3606. comma && push(",");
  3607. newline();
  3608. } else {
  3609. comma && push(", ");
  3610. }
  3611. }
  3612. }
  3613. }
  3614. function genNode(node, context) {
  3615. if (isString(node)) {
  3616. context.push(node, -3 /* Unknown */);
  3617. return;
  3618. }
  3619. if (isSymbol(node)) {
  3620. context.push(context.helper(node));
  3621. return;
  3622. }
  3623. switch (node.type) {
  3624. case 1:
  3625. case 9:
  3626. case 11:
  3627. assert(
  3628. node.codegenNode != null,
  3629. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  3630. );
  3631. genNode(node.codegenNode, context);
  3632. break;
  3633. case 2:
  3634. genText(node, context);
  3635. break;
  3636. case 4:
  3637. genExpression(node, context);
  3638. break;
  3639. case 5:
  3640. genInterpolation(node, context);
  3641. break;
  3642. case 12:
  3643. genNode(node.codegenNode, context);
  3644. break;
  3645. case 8:
  3646. genCompoundExpression(node, context);
  3647. break;
  3648. case 3:
  3649. genComment(node, context);
  3650. break;
  3651. case 13:
  3652. genVNodeCall(node, context);
  3653. break;
  3654. case 14:
  3655. genCallExpression(node, context);
  3656. break;
  3657. case 15:
  3658. genObjectExpression(node, context);
  3659. break;
  3660. case 17:
  3661. genArrayExpression(node, context);
  3662. break;
  3663. case 18:
  3664. genFunctionExpression(node, context);
  3665. break;
  3666. case 19:
  3667. genConditionalExpression(node, context);
  3668. break;
  3669. case 20:
  3670. genCacheExpression(node, context);
  3671. break;
  3672. case 21:
  3673. genNodeList(node.body, context, true, false);
  3674. break;
  3675. // SSR only types
  3676. case 22:
  3677. break;
  3678. case 23:
  3679. break;
  3680. case 24:
  3681. break;
  3682. case 25:
  3683. break;
  3684. case 26:
  3685. break;
  3686. /* v8 ignore start */
  3687. case 10:
  3688. break;
  3689. default:
  3690. {
  3691. assert(false, `unhandled codegen node type: ${node.type}`);
  3692. const exhaustiveCheck = node;
  3693. return exhaustiveCheck;
  3694. }
  3695. }
  3696. }
  3697. function genText(node, context) {
  3698. context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
  3699. }
  3700. function genExpression(node, context) {
  3701. const { content, isStatic } = node;
  3702. context.push(
  3703. isStatic ? JSON.stringify(content) : content,
  3704. -3 /* Unknown */,
  3705. node
  3706. );
  3707. }
  3708. function genInterpolation(node, context) {
  3709. const { push, helper, pure } = context;
  3710. if (pure) push(PURE_ANNOTATION);
  3711. push(`${helper(TO_DISPLAY_STRING)}(`);
  3712. genNode(node.content, context);
  3713. push(`)`);
  3714. }
  3715. function genCompoundExpression(node, context) {
  3716. for (let i = 0; i < node.children.length; i++) {
  3717. const child = node.children[i];
  3718. if (isString(child)) {
  3719. context.push(child, -3 /* Unknown */);
  3720. } else {
  3721. genNode(child, context);
  3722. }
  3723. }
  3724. }
  3725. function genExpressionAsPropertyKey(node, context) {
  3726. const { push } = context;
  3727. if (node.type === 8) {
  3728. push(`[`);
  3729. genCompoundExpression(node, context);
  3730. push(`]`);
  3731. } else if (node.isStatic) {
  3732. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  3733. push(text, -2 /* None */, node);
  3734. } else {
  3735. push(`[${node.content}]`, -3 /* Unknown */, node);
  3736. }
  3737. }
  3738. function genComment(node, context) {
  3739. const { push, helper, pure } = context;
  3740. if (pure) {
  3741. push(PURE_ANNOTATION);
  3742. }
  3743. push(
  3744. `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
  3745. -3 /* Unknown */,
  3746. node
  3747. );
  3748. }
  3749. function genVNodeCall(node, context) {
  3750. const { push, helper, pure } = context;
  3751. const {
  3752. tag,
  3753. props,
  3754. children,
  3755. patchFlag,
  3756. dynamicProps,
  3757. directives,
  3758. isBlock,
  3759. disableTracking,
  3760. isComponent
  3761. } = node;
  3762. let patchFlagString;
  3763. if (patchFlag) {
  3764. {
  3765. if (patchFlag < 0) {
  3766. patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  3767. } else {
  3768. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  3769. patchFlagString = patchFlag + ` /* ${flagNames} */`;
  3770. }
  3771. }
  3772. }
  3773. if (directives) {
  3774. push(helper(WITH_DIRECTIVES) + `(`);
  3775. }
  3776. if (isBlock) {
  3777. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  3778. }
  3779. if (pure) {
  3780. push(PURE_ANNOTATION);
  3781. }
  3782. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  3783. push(helper(callHelper) + `(`, -2 /* None */, node);
  3784. genNodeList(
  3785. genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
  3786. context
  3787. );
  3788. push(`)`);
  3789. if (isBlock) {
  3790. push(`)`);
  3791. }
  3792. if (directives) {
  3793. push(`, `);
  3794. genNode(directives, context);
  3795. push(`)`);
  3796. }
  3797. }
  3798. function genNullableArgs(args) {
  3799. let i = args.length;
  3800. while (i--) {
  3801. if (args[i] != null) break;
  3802. }
  3803. return args.slice(0, i + 1).map((arg) => arg || `null`);
  3804. }
  3805. function genCallExpression(node, context) {
  3806. const { push, helper, pure } = context;
  3807. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  3808. if (pure) {
  3809. push(PURE_ANNOTATION);
  3810. }
  3811. push(callee + `(`, -2 /* None */, node);
  3812. genNodeList(node.arguments, context);
  3813. push(`)`);
  3814. }
  3815. function genObjectExpression(node, context) {
  3816. const { push, indent, deindent, newline } = context;
  3817. const { properties } = node;
  3818. if (!properties.length) {
  3819. push(`{}`, -2 /* None */, node);
  3820. return;
  3821. }
  3822. const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
  3823. push(multilines ? `{` : `{ `);
  3824. multilines && indent();
  3825. for (let i = 0; i < properties.length; i++) {
  3826. const { key, value } = properties[i];
  3827. genExpressionAsPropertyKey(key, context);
  3828. push(`: `);
  3829. genNode(value, context);
  3830. if (i < properties.length - 1) {
  3831. push(`,`);
  3832. newline();
  3833. }
  3834. }
  3835. multilines && deindent();
  3836. push(multilines ? `}` : ` }`);
  3837. }
  3838. function genArrayExpression(node, context) {
  3839. genNodeListAsArray(node.elements, context);
  3840. }
  3841. function genFunctionExpression(node, context) {
  3842. const { push, indent, deindent } = context;
  3843. const { params, returns, body, newline, isSlot } = node;
  3844. if (isSlot) {
  3845. push(`_${helperNameMap[WITH_CTX]}(`);
  3846. }
  3847. push(`(`, -2 /* None */, node);
  3848. if (isArray(params)) {
  3849. genNodeList(params, context);
  3850. } else if (params) {
  3851. genNode(params, context);
  3852. }
  3853. push(`) => `);
  3854. if (newline || body) {
  3855. push(`{`);
  3856. indent();
  3857. }
  3858. if (returns) {
  3859. if (newline) {
  3860. push(`return `);
  3861. }
  3862. if (isArray(returns)) {
  3863. genNodeListAsArray(returns, context);
  3864. } else {
  3865. genNode(returns, context);
  3866. }
  3867. } else if (body) {
  3868. genNode(body, context);
  3869. }
  3870. if (newline || body) {
  3871. deindent();
  3872. push(`}`);
  3873. }
  3874. if (isSlot) {
  3875. if (node.isNonScopedSlot) {
  3876. push(`, undefined, true`);
  3877. }
  3878. push(`)`);
  3879. }
  3880. }
  3881. function genConditionalExpression(node, context) {
  3882. const { test, consequent, alternate, newline: needNewline } = node;
  3883. const { push, indent, deindent, newline } = context;
  3884. if (test.type === 4) {
  3885. const needsParens = !isSimpleIdentifier(test.content);
  3886. needsParens && push(`(`);
  3887. genExpression(test, context);
  3888. needsParens && push(`)`);
  3889. } else {
  3890. push(`(`);
  3891. genNode(test, context);
  3892. push(`)`);
  3893. }
  3894. needNewline && indent();
  3895. context.indentLevel++;
  3896. needNewline || push(` `);
  3897. push(`? `);
  3898. genNode(consequent, context);
  3899. context.indentLevel--;
  3900. needNewline && newline();
  3901. needNewline || push(` `);
  3902. push(`: `);
  3903. const isNested = alternate.type === 19;
  3904. if (!isNested) {
  3905. context.indentLevel++;
  3906. }
  3907. genNode(alternate, context);
  3908. if (!isNested) {
  3909. context.indentLevel--;
  3910. }
  3911. needNewline && deindent(
  3912. true
  3913. /* without newline */
  3914. );
  3915. }
  3916. function genCacheExpression(node, context) {
  3917. const { push, helper, indent, deindent, newline } = context;
  3918. const { needPauseTracking, needArraySpread } = node;
  3919. if (needArraySpread) {
  3920. push(`[...(`);
  3921. }
  3922. push(`_cache[${node.index}] || (`);
  3923. if (needPauseTracking) {
  3924. indent();
  3925. push(`${helper(SET_BLOCK_TRACKING)}(-1`);
  3926. if (node.inVOnce) push(`, true`);
  3927. push(`),`);
  3928. newline();
  3929. push(`(`);
  3930. }
  3931. push(`_cache[${node.index}] = `);
  3932. genNode(node.value, context);
  3933. if (needPauseTracking) {
  3934. push(`).cacheIndex = ${node.index},`);
  3935. newline();
  3936. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  3937. newline();
  3938. push(`_cache[${node.index}]`);
  3939. deindent();
  3940. }
  3941. push(`)`);
  3942. if (needArraySpread) {
  3943. push(`)]`);
  3944. }
  3945. }
  3946. const prohibitedKeywordRE = new RegExp(
  3947. "\\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"
  3948. );
  3949. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  3950. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  3951. const exp = node.content;
  3952. if (!exp.trim()) {
  3953. return;
  3954. }
  3955. try {
  3956. new Function(
  3957. asRawStatements ? ` ${exp} ` : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`
  3958. );
  3959. } catch (e) {
  3960. let message = e.message;
  3961. const keywordMatch = exp.replace(stripStringRE, "").match(prohibitedKeywordRE);
  3962. if (keywordMatch) {
  3963. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  3964. }
  3965. context.onError(
  3966. createCompilerError(
  3967. 45,
  3968. node.loc,
  3969. void 0,
  3970. message
  3971. )
  3972. );
  3973. }
  3974. }
  3975. const transformExpression = (node, context) => {
  3976. if (node.type === 5) {
  3977. node.content = processExpression(
  3978. node.content,
  3979. context
  3980. );
  3981. } else if (node.type === 1) {
  3982. const memo = findDir(node, "memo");
  3983. for (let i = 0; i < node.props.length; i++) {
  3984. const dir = node.props[i];
  3985. if (dir.type === 7 && dir.name !== "for") {
  3986. const exp = dir.exp;
  3987. const arg = dir.arg;
  3988. if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
  3989. !(memo && arg && arg.type === 4 && arg.content === "key")) {
  3990. dir.exp = processExpression(
  3991. exp,
  3992. context,
  3993. // slot args must be processed as function params
  3994. dir.name === "slot"
  3995. );
  3996. }
  3997. if (arg && arg.type === 4 && !arg.isStatic) {
  3998. dir.arg = processExpression(arg, context);
  3999. }
  4000. }
  4001. }
  4002. }
  4003. };
  4004. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  4005. {
  4006. {
  4007. validateBrowserExpression(node, context, asParams, asRawStatements);
  4008. }
  4009. return node;
  4010. }
  4011. }
  4012. function stringifyExpression(exp) {
  4013. if (isString(exp)) {
  4014. return exp;
  4015. } else if (exp.type === 4) {
  4016. return exp.content;
  4017. } else {
  4018. return exp.children.map(stringifyExpression).join("");
  4019. }
  4020. }
  4021. const transformIf = createStructuralDirectiveTransform(
  4022. /^(?:if|else|else-if)$/,
  4023. (node, dir, context) => {
  4024. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  4025. const siblings = context.parent.children;
  4026. let i = siblings.indexOf(ifNode);
  4027. let key = 0;
  4028. while (i-- >= 0) {
  4029. const sibling = siblings[i];
  4030. if (sibling && sibling.type === 9) {
  4031. key += sibling.branches.length;
  4032. }
  4033. }
  4034. return () => {
  4035. if (isRoot) {
  4036. ifNode.codegenNode = createCodegenNodeForBranch(
  4037. branch,
  4038. key,
  4039. context
  4040. );
  4041. } else {
  4042. const parentCondition = getParentCondition(ifNode.codegenNode);
  4043. parentCondition.alternate = createCodegenNodeForBranch(
  4044. branch,
  4045. key + ifNode.branches.length - 1,
  4046. context
  4047. );
  4048. }
  4049. };
  4050. });
  4051. }
  4052. );
  4053. function processIf(node, dir, context, processCodegen) {
  4054. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  4055. const loc = dir.exp ? dir.exp.loc : node.loc;
  4056. context.onError(
  4057. createCompilerError(28, dir.loc)
  4058. );
  4059. dir.exp = createSimpleExpression(`true`, false, loc);
  4060. }
  4061. if (dir.exp) {
  4062. validateBrowserExpression(dir.exp, context);
  4063. }
  4064. if (dir.name === "if") {
  4065. const branch = createIfBranch(node, dir);
  4066. const ifNode = {
  4067. type: 9,
  4068. loc: cloneLoc(node.loc),
  4069. branches: [branch]
  4070. };
  4071. context.replaceNode(ifNode);
  4072. if (processCodegen) {
  4073. return processCodegen(ifNode, branch, true);
  4074. }
  4075. } else {
  4076. const siblings = context.parent.children;
  4077. const comments = [];
  4078. let i = siblings.indexOf(node);
  4079. while (i-- >= -1) {
  4080. const sibling = siblings[i];
  4081. if (sibling && sibling.type === 3) {
  4082. context.removeNode(sibling);
  4083. comments.unshift(sibling);
  4084. continue;
  4085. }
  4086. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  4087. context.removeNode(sibling);
  4088. continue;
  4089. }
  4090. if (sibling && sibling.type === 9) {
  4091. if ((dir.name === "else-if" || dir.name === "else") && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  4092. context.onError(
  4093. createCompilerError(30, node.loc)
  4094. );
  4095. }
  4096. context.removeNode();
  4097. const branch = createIfBranch(node, dir);
  4098. if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  4099. !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
  4100. branch.children = [...comments, ...branch.children];
  4101. }
  4102. {
  4103. const key = branch.userKey;
  4104. if (key) {
  4105. sibling.branches.forEach(({ userKey }) => {
  4106. if (isSameKey(userKey, key)) {
  4107. context.onError(
  4108. createCompilerError(
  4109. 29,
  4110. branch.userKey.loc
  4111. )
  4112. );
  4113. }
  4114. });
  4115. }
  4116. }
  4117. sibling.branches.push(branch);
  4118. const onExit = processCodegen && processCodegen(sibling, branch, false);
  4119. traverseNode(branch, context);
  4120. if (onExit) onExit();
  4121. context.currentNode = null;
  4122. } else {
  4123. context.onError(
  4124. createCompilerError(30, node.loc)
  4125. );
  4126. }
  4127. break;
  4128. }
  4129. }
  4130. }
  4131. function createIfBranch(node, dir) {
  4132. const isTemplateIf = node.tagType === 3;
  4133. return {
  4134. type: 10,
  4135. loc: node.loc,
  4136. condition: dir.name === "else" ? void 0 : dir.exp,
  4137. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  4138. userKey: findProp(node, `key`),
  4139. isTemplateIf
  4140. };
  4141. }
  4142. function createCodegenNodeForBranch(branch, keyIndex, context) {
  4143. if (branch.condition) {
  4144. return createConditionalExpression(
  4145. branch.condition,
  4146. createChildrenCodegenNode(branch, keyIndex, context),
  4147. // make sure to pass in asBlock: true so that the comment node call
  4148. // closes the current block.
  4149. createCallExpression(context.helper(CREATE_COMMENT), [
  4150. '"v-if"' ,
  4151. "true"
  4152. ])
  4153. );
  4154. } else {
  4155. return createChildrenCodegenNode(branch, keyIndex, context);
  4156. }
  4157. }
  4158. function createChildrenCodegenNode(branch, keyIndex, context) {
  4159. const { helper } = context;
  4160. const keyProperty = createObjectProperty(
  4161. `key`,
  4162. createSimpleExpression(
  4163. `${keyIndex}`,
  4164. false,
  4165. locStub,
  4166. 2
  4167. )
  4168. );
  4169. const { children } = branch;
  4170. const firstChild = children[0];
  4171. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  4172. if (needFragmentWrapper) {
  4173. if (children.length === 1 && firstChild.type === 11) {
  4174. const vnodeCall = firstChild.codegenNode;
  4175. injectProp(vnodeCall, keyProperty, context);
  4176. return vnodeCall;
  4177. } else {
  4178. let patchFlag = 64;
  4179. if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  4180. patchFlag |= 2048;
  4181. }
  4182. return createVNodeCall(
  4183. context,
  4184. helper(FRAGMENT),
  4185. createObjectExpression([keyProperty]),
  4186. children,
  4187. patchFlag,
  4188. void 0,
  4189. void 0,
  4190. true,
  4191. false,
  4192. false,
  4193. branch.loc
  4194. );
  4195. }
  4196. } else {
  4197. const ret = firstChild.codegenNode;
  4198. const vnodeCall = getMemoedVNodeCall(ret);
  4199. if (vnodeCall.type === 13) {
  4200. convertToBlock(vnodeCall, context);
  4201. }
  4202. injectProp(vnodeCall, keyProperty, context);
  4203. return ret;
  4204. }
  4205. }
  4206. function isSameKey(a, b) {
  4207. if (!a || a.type !== b.type) {
  4208. return false;
  4209. }
  4210. if (a.type === 6) {
  4211. if (a.value.content !== b.value.content) {
  4212. return false;
  4213. }
  4214. } else {
  4215. const exp = a.exp;
  4216. const branchExp = b.exp;
  4217. if (exp.type !== branchExp.type) {
  4218. return false;
  4219. }
  4220. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  4221. return false;
  4222. }
  4223. }
  4224. return true;
  4225. }
  4226. function getParentCondition(node) {
  4227. while (true) {
  4228. if (node.type === 19) {
  4229. if (node.alternate.type === 19) {
  4230. node = node.alternate;
  4231. } else {
  4232. return node;
  4233. }
  4234. } else if (node.type === 20) {
  4235. node = node.value;
  4236. }
  4237. }
  4238. }
  4239. const transformBind = (dir, _node, context) => {
  4240. const { modifiers, loc } = dir;
  4241. const arg = dir.arg;
  4242. let { exp } = dir;
  4243. if (exp && exp.type === 4 && !exp.content.trim()) {
  4244. {
  4245. exp = void 0;
  4246. }
  4247. }
  4248. if (!exp) {
  4249. if (arg.type !== 4 || !arg.isStatic) {
  4250. context.onError(
  4251. createCompilerError(
  4252. 52,
  4253. arg.loc
  4254. )
  4255. );
  4256. return {
  4257. props: [
  4258. createObjectProperty(arg, createSimpleExpression("", true, loc))
  4259. ]
  4260. };
  4261. }
  4262. transformBindShorthand(dir);
  4263. exp = dir.exp;
  4264. }
  4265. if (arg.type !== 4) {
  4266. arg.children.unshift(`(`);
  4267. arg.children.push(`) || ""`);
  4268. } else if (!arg.isStatic) {
  4269. arg.content = arg.content ? `${arg.content} || ""` : `""`;
  4270. }
  4271. if (modifiers.some((mod) => mod.content === "camel")) {
  4272. if (arg.type === 4) {
  4273. if (arg.isStatic) {
  4274. arg.content = camelize(arg.content);
  4275. } else {
  4276. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  4277. }
  4278. } else {
  4279. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  4280. arg.children.push(`)`);
  4281. }
  4282. }
  4283. if (!context.inSSR) {
  4284. if (modifiers.some((mod) => mod.content === "prop")) {
  4285. injectPrefix(arg, ".");
  4286. }
  4287. if (modifiers.some((mod) => mod.content === "attr")) {
  4288. injectPrefix(arg, "^");
  4289. }
  4290. }
  4291. return {
  4292. props: [createObjectProperty(arg, exp)]
  4293. };
  4294. };
  4295. const transformBindShorthand = (dir, context) => {
  4296. const arg = dir.arg;
  4297. const propName = camelize(arg.content);
  4298. dir.exp = createSimpleExpression(propName, false, arg.loc);
  4299. };
  4300. const injectPrefix = (arg, prefix) => {
  4301. if (arg.type === 4) {
  4302. if (arg.isStatic) {
  4303. arg.content = prefix + arg.content;
  4304. } else {
  4305. arg.content = `\`${prefix}\${${arg.content}}\``;
  4306. }
  4307. } else {
  4308. arg.children.unshift(`'${prefix}' + (`);
  4309. arg.children.push(`)`);
  4310. }
  4311. };
  4312. const transformFor = createStructuralDirectiveTransform(
  4313. "for",
  4314. (node, dir, context) => {
  4315. const { helper, removeHelper } = context;
  4316. return processFor(node, dir, context, (forNode) => {
  4317. const renderExp = createCallExpression(helper(RENDER_LIST), [
  4318. forNode.source
  4319. ]);
  4320. const isTemplate = isTemplateNode(node);
  4321. const memo = findDir(node, "memo");
  4322. const keyProp = findProp(node, `key`, false, true);
  4323. const isDirKey = keyProp && keyProp.type === 7;
  4324. if (isDirKey && !keyProp.exp) {
  4325. transformBindShorthand(keyProp);
  4326. }
  4327. let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
  4328. const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
  4329. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  4330. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  4331. forNode.codegenNode = createVNodeCall(
  4332. context,
  4333. helper(FRAGMENT),
  4334. void 0,
  4335. renderExp,
  4336. fragmentFlag,
  4337. void 0,
  4338. void 0,
  4339. true,
  4340. !isStableFragment,
  4341. false,
  4342. node.loc
  4343. );
  4344. return () => {
  4345. let childBlock;
  4346. const { children } = forNode;
  4347. if (isTemplate) {
  4348. node.children.some((c) => {
  4349. if (c.type === 1) {
  4350. const key = findProp(c, "key");
  4351. if (key) {
  4352. context.onError(
  4353. createCompilerError(
  4354. 33,
  4355. key.loc
  4356. )
  4357. );
  4358. return true;
  4359. }
  4360. }
  4361. });
  4362. }
  4363. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  4364. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  4365. if (slotOutlet) {
  4366. childBlock = slotOutlet.codegenNode;
  4367. if (isTemplate && keyProperty) {
  4368. injectProp(childBlock, keyProperty, context);
  4369. }
  4370. } else if (needFragmentWrapper) {
  4371. childBlock = createVNodeCall(
  4372. context,
  4373. helper(FRAGMENT),
  4374. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  4375. node.children,
  4376. 64,
  4377. void 0,
  4378. void 0,
  4379. true,
  4380. void 0,
  4381. false
  4382. );
  4383. } else {
  4384. childBlock = children[0].codegenNode;
  4385. if (isTemplate && keyProperty) {
  4386. injectProp(childBlock, keyProperty, context);
  4387. }
  4388. if (childBlock.isBlock !== !isStableFragment) {
  4389. if (childBlock.isBlock) {
  4390. removeHelper(OPEN_BLOCK);
  4391. removeHelper(
  4392. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  4393. );
  4394. } else {
  4395. removeHelper(
  4396. getVNodeHelper(context.inSSR, childBlock.isComponent)
  4397. );
  4398. }
  4399. }
  4400. childBlock.isBlock = !isStableFragment;
  4401. if (childBlock.isBlock) {
  4402. helper(OPEN_BLOCK);
  4403. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  4404. } else {
  4405. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  4406. }
  4407. }
  4408. if (memo) {
  4409. const loop = createFunctionExpression(
  4410. createForLoopParams(forNode.parseResult, [
  4411. createSimpleExpression(`_cached`)
  4412. ])
  4413. );
  4414. loop.body = createBlockStatement([
  4415. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  4416. createCompoundExpression([
  4417. `if (_cached`,
  4418. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  4419. ` && ${context.helperString(
  4420. IS_MEMO_SAME
  4421. )}(_cached, _memo)) return _cached`
  4422. ]),
  4423. createCompoundExpression([`const _item = `, childBlock]),
  4424. createSimpleExpression(`_item.memo = _memo`),
  4425. createSimpleExpression(`return _item`)
  4426. ]);
  4427. renderExp.arguments.push(
  4428. loop,
  4429. createSimpleExpression(`_cache`),
  4430. createSimpleExpression(String(context.cached.length))
  4431. );
  4432. context.cached.push(null);
  4433. } else {
  4434. renderExp.arguments.push(
  4435. createFunctionExpression(
  4436. createForLoopParams(forNode.parseResult),
  4437. childBlock,
  4438. true
  4439. )
  4440. );
  4441. }
  4442. };
  4443. });
  4444. }
  4445. );
  4446. function processFor(node, dir, context, processCodegen) {
  4447. if (!dir.exp) {
  4448. context.onError(
  4449. createCompilerError(31, dir.loc)
  4450. );
  4451. return;
  4452. }
  4453. const parseResult = dir.forParseResult;
  4454. if (!parseResult) {
  4455. context.onError(
  4456. createCompilerError(32, dir.loc)
  4457. );
  4458. return;
  4459. }
  4460. finalizeForParseResult(parseResult, context);
  4461. const { addIdentifiers, removeIdentifiers, scopes } = context;
  4462. const { source, value, key, index } = parseResult;
  4463. const forNode = {
  4464. type: 11,
  4465. loc: dir.loc,
  4466. source,
  4467. valueAlias: value,
  4468. keyAlias: key,
  4469. objectIndexAlias: index,
  4470. parseResult,
  4471. children: isTemplateNode(node) ? node.children : [node]
  4472. };
  4473. context.replaceNode(forNode);
  4474. scopes.vFor++;
  4475. const onExit = processCodegen && processCodegen(forNode);
  4476. return () => {
  4477. scopes.vFor--;
  4478. if (onExit) onExit();
  4479. };
  4480. }
  4481. function finalizeForParseResult(result, context) {
  4482. if (result.finalized) return;
  4483. {
  4484. validateBrowserExpression(result.source, context);
  4485. if (result.key) {
  4486. validateBrowserExpression(
  4487. result.key,
  4488. context,
  4489. true
  4490. );
  4491. }
  4492. if (result.index) {
  4493. validateBrowserExpression(
  4494. result.index,
  4495. context,
  4496. true
  4497. );
  4498. }
  4499. if (result.value) {
  4500. validateBrowserExpression(
  4501. result.value,
  4502. context,
  4503. true
  4504. );
  4505. }
  4506. }
  4507. result.finalized = true;
  4508. }
  4509. function createForLoopParams({ value, key, index }, memoArgs = []) {
  4510. return createParamsList([value, key, index, ...memoArgs]);
  4511. }
  4512. function createParamsList(args) {
  4513. let i = args.length;
  4514. while (i--) {
  4515. if (args[i]) break;
  4516. }
  4517. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  4518. }
  4519. const defaultFallback = createSimpleExpression(`undefined`, false);
  4520. const trackSlotScopes = (node, context) => {
  4521. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  4522. const vSlot = findDir(node, "slot");
  4523. if (vSlot) {
  4524. vSlot.exp;
  4525. context.scopes.vSlot++;
  4526. return () => {
  4527. context.scopes.vSlot--;
  4528. };
  4529. }
  4530. }
  4531. };
  4532. const trackVForSlotScopes = (node, context) => {
  4533. let vFor;
  4534. if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
  4535. const result = vFor.forParseResult;
  4536. if (result) {
  4537. finalizeForParseResult(result, context);
  4538. const { value, key, index } = result;
  4539. const { addIdentifiers, removeIdentifiers } = context;
  4540. value && addIdentifiers(value);
  4541. key && addIdentifiers(key);
  4542. index && addIdentifiers(index);
  4543. return () => {
  4544. value && removeIdentifiers(value);
  4545. key && removeIdentifiers(key);
  4546. index && removeIdentifiers(index);
  4547. };
  4548. }
  4549. }
  4550. };
  4551. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  4552. props,
  4553. children,
  4554. false,
  4555. true,
  4556. children.length ? children[0].loc : loc
  4557. );
  4558. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  4559. context.helper(WITH_CTX);
  4560. const { children, loc } = node;
  4561. const slotsProperties = [];
  4562. const dynamicSlots = [];
  4563. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  4564. const onComponentSlot = findDir(node, "slot", true);
  4565. if (onComponentSlot) {
  4566. const { arg, exp } = onComponentSlot;
  4567. if (arg && !isStaticExp(arg)) {
  4568. hasDynamicSlots = true;
  4569. }
  4570. slotsProperties.push(
  4571. createObjectProperty(
  4572. arg || createSimpleExpression("default", true),
  4573. buildSlotFn(exp, void 0, children, loc)
  4574. )
  4575. );
  4576. }
  4577. let hasTemplateSlots = false;
  4578. let hasNamedDefaultSlot = false;
  4579. const implicitDefaultChildren = [];
  4580. const seenSlotNames = /* @__PURE__ */ new Set();
  4581. let conditionalBranchIndex = 0;
  4582. for (let i = 0; i < children.length; i++) {
  4583. const slotElement = children[i];
  4584. let slotDir;
  4585. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  4586. if (slotElement.type !== 3) {
  4587. implicitDefaultChildren.push(slotElement);
  4588. }
  4589. continue;
  4590. }
  4591. if (onComponentSlot) {
  4592. context.onError(
  4593. createCompilerError(37, slotDir.loc)
  4594. );
  4595. break;
  4596. }
  4597. hasTemplateSlots = true;
  4598. const { children: slotChildren, loc: slotLoc } = slotElement;
  4599. const {
  4600. arg: slotName = createSimpleExpression(`default`, true),
  4601. exp: slotProps,
  4602. loc: dirLoc
  4603. } = slotDir;
  4604. let staticSlotName;
  4605. if (isStaticExp(slotName)) {
  4606. staticSlotName = slotName ? slotName.content : `default`;
  4607. } else {
  4608. hasDynamicSlots = true;
  4609. }
  4610. const vFor = findDir(slotElement, "for");
  4611. const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
  4612. let vIf;
  4613. let vElse;
  4614. if (vIf = findDir(slotElement, "if")) {
  4615. hasDynamicSlots = true;
  4616. dynamicSlots.push(
  4617. createConditionalExpression(
  4618. vIf.exp,
  4619. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  4620. defaultFallback
  4621. )
  4622. );
  4623. } else if (vElse = findDir(
  4624. slotElement,
  4625. /^else(?:-if)?$/,
  4626. true
  4627. /* allowEmpty */
  4628. )) {
  4629. let j = i;
  4630. let prev;
  4631. while (j--) {
  4632. prev = children[j];
  4633. if (prev.type !== 3 && isNonWhitespaceContent(prev)) {
  4634. break;
  4635. }
  4636. }
  4637. if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
  4638. let conditional = dynamicSlots[dynamicSlots.length - 1];
  4639. while (conditional.alternate.type === 19) {
  4640. conditional = conditional.alternate;
  4641. }
  4642. conditional.alternate = vElse.exp ? createConditionalExpression(
  4643. vElse.exp,
  4644. buildDynamicSlot(
  4645. slotName,
  4646. slotFunction,
  4647. conditionalBranchIndex++
  4648. ),
  4649. defaultFallback
  4650. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  4651. } else {
  4652. context.onError(
  4653. createCompilerError(30, vElse.loc)
  4654. );
  4655. }
  4656. } else if (vFor) {
  4657. hasDynamicSlots = true;
  4658. const parseResult = vFor.forParseResult;
  4659. if (parseResult) {
  4660. finalizeForParseResult(parseResult, context);
  4661. dynamicSlots.push(
  4662. createCallExpression(context.helper(RENDER_LIST), [
  4663. parseResult.source,
  4664. createFunctionExpression(
  4665. createForLoopParams(parseResult),
  4666. buildDynamicSlot(slotName, slotFunction),
  4667. true
  4668. )
  4669. ])
  4670. );
  4671. } else {
  4672. context.onError(
  4673. createCompilerError(
  4674. 32,
  4675. vFor.loc
  4676. )
  4677. );
  4678. }
  4679. } else {
  4680. if (staticSlotName) {
  4681. if (seenSlotNames.has(staticSlotName)) {
  4682. context.onError(
  4683. createCompilerError(
  4684. 38,
  4685. dirLoc
  4686. )
  4687. );
  4688. continue;
  4689. }
  4690. seenSlotNames.add(staticSlotName);
  4691. if (staticSlotName === "default") {
  4692. hasNamedDefaultSlot = true;
  4693. }
  4694. }
  4695. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  4696. }
  4697. }
  4698. if (!onComponentSlot) {
  4699. const buildDefaultSlotProperty = (props, children2) => {
  4700. const fn = buildSlotFn(props, void 0, children2, loc);
  4701. if (context.compatConfig) {
  4702. fn.isNonScopedSlot = true;
  4703. }
  4704. return createObjectProperty(`default`, fn);
  4705. };
  4706. if (!hasTemplateSlots) {
  4707. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  4708. } else if (implicitDefaultChildren.length && // #3766
  4709. // with whitespace: 'preserve', whitespaces between slots will end up in
  4710. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  4711. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  4712. if (hasNamedDefaultSlot) {
  4713. context.onError(
  4714. createCompilerError(
  4715. 39,
  4716. implicitDefaultChildren[0].loc
  4717. )
  4718. );
  4719. } else {
  4720. slotsProperties.push(
  4721. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  4722. );
  4723. }
  4724. }
  4725. }
  4726. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  4727. let slots = createObjectExpression(
  4728. slotsProperties.concat(
  4729. createObjectProperty(
  4730. `_`,
  4731. // 2 = compiled but dynamic = can skip normalization, but must run diff
  4732. // 1 = compiled and static = can skip normalization AND diff as optimized
  4733. createSimpleExpression(
  4734. slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
  4735. false
  4736. )
  4737. )
  4738. ),
  4739. loc
  4740. );
  4741. if (dynamicSlots.length) {
  4742. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  4743. slots,
  4744. createArrayExpression(dynamicSlots)
  4745. ]);
  4746. }
  4747. return {
  4748. slots,
  4749. hasDynamicSlots
  4750. };
  4751. }
  4752. function buildDynamicSlot(name, fn, index) {
  4753. const props = [
  4754. createObjectProperty(`name`, name),
  4755. createObjectProperty(`fn`, fn)
  4756. ];
  4757. if (index != null) {
  4758. props.push(
  4759. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  4760. );
  4761. }
  4762. return createObjectExpression(props);
  4763. }
  4764. function hasForwardedSlots(children) {
  4765. for (let i = 0; i < children.length; i++) {
  4766. const child = children[i];
  4767. switch (child.type) {
  4768. case 1:
  4769. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  4770. return true;
  4771. }
  4772. break;
  4773. case 9:
  4774. if (hasForwardedSlots(child.branches)) return true;
  4775. break;
  4776. case 10:
  4777. case 11:
  4778. if (hasForwardedSlots(child.children)) return true;
  4779. break;
  4780. }
  4781. }
  4782. return false;
  4783. }
  4784. function isNonWhitespaceContent(node) {
  4785. if (node.type !== 2 && node.type !== 12)
  4786. return true;
  4787. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  4788. }
  4789. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  4790. const transformElement = (node, context) => {
  4791. return function postTransformElement() {
  4792. node = context.currentNode;
  4793. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  4794. return;
  4795. }
  4796. const { tag, props } = node;
  4797. const isComponent = node.tagType === 1;
  4798. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  4799. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  4800. let vnodeProps;
  4801. let vnodeChildren;
  4802. let patchFlag = 0;
  4803. let vnodeDynamicProps;
  4804. let dynamicPropNames;
  4805. let vnodeDirectives;
  4806. let shouldUseBlock = (
  4807. // dynamic component may resolve to plain elements
  4808. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  4809. // updates inside get proper isSVG flag at runtime. (#639, #643)
  4810. // This is technically web-specific, but splitting the logic out of core
  4811. // leads to too much unnecessary complexity.
  4812. (tag === "svg" || tag === "foreignObject" || tag === "math")
  4813. );
  4814. if (props.length > 0) {
  4815. const propsBuildResult = buildProps(
  4816. node,
  4817. context,
  4818. void 0,
  4819. isComponent,
  4820. isDynamicComponent
  4821. );
  4822. vnodeProps = propsBuildResult.props;
  4823. patchFlag = propsBuildResult.patchFlag;
  4824. dynamicPropNames = propsBuildResult.dynamicPropNames;
  4825. const directives = propsBuildResult.directives;
  4826. vnodeDirectives = directives && directives.length ? createArrayExpression(
  4827. directives.map((dir) => buildDirectiveArgs(dir, context))
  4828. ) : void 0;
  4829. if (propsBuildResult.shouldUseBlock) {
  4830. shouldUseBlock = true;
  4831. }
  4832. }
  4833. if (node.children.length > 0) {
  4834. if (vnodeTag === KEEP_ALIVE) {
  4835. shouldUseBlock = true;
  4836. patchFlag |= 1024;
  4837. if (node.children.length > 1) {
  4838. context.onError(
  4839. createCompilerError(46, {
  4840. start: node.children[0].loc.start,
  4841. end: node.children[node.children.length - 1].loc.end,
  4842. source: ""
  4843. })
  4844. );
  4845. }
  4846. }
  4847. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  4848. vnodeTag !== TELEPORT && // explained above.
  4849. vnodeTag !== KEEP_ALIVE;
  4850. if (shouldBuildAsSlots) {
  4851. const { slots, hasDynamicSlots } = buildSlots(node, context);
  4852. vnodeChildren = slots;
  4853. if (hasDynamicSlots) {
  4854. patchFlag |= 1024;
  4855. }
  4856. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  4857. const child = node.children[0];
  4858. const type = child.type;
  4859. const hasDynamicTextChild = type === 5 || type === 8;
  4860. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  4861. patchFlag |= 1;
  4862. }
  4863. if (hasDynamicTextChild || type === 2) {
  4864. vnodeChildren = child;
  4865. } else {
  4866. vnodeChildren = node.children;
  4867. }
  4868. } else {
  4869. vnodeChildren = node.children;
  4870. }
  4871. }
  4872. if (dynamicPropNames && dynamicPropNames.length) {
  4873. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  4874. }
  4875. node.codegenNode = createVNodeCall(
  4876. context,
  4877. vnodeTag,
  4878. vnodeProps,
  4879. vnodeChildren,
  4880. patchFlag === 0 ? void 0 : patchFlag,
  4881. vnodeDynamicProps,
  4882. vnodeDirectives,
  4883. !!shouldUseBlock,
  4884. false,
  4885. isComponent,
  4886. node.loc
  4887. );
  4888. };
  4889. };
  4890. function resolveComponentType(node, context, ssr = false) {
  4891. let { tag } = node;
  4892. const isExplicitDynamic = isComponentTag(tag);
  4893. const isProp = findProp(
  4894. node,
  4895. "is",
  4896. false,
  4897. true
  4898. /* allow empty */
  4899. );
  4900. if (isProp) {
  4901. if (isExplicitDynamic || isCompatEnabled(
  4902. "COMPILER_IS_ON_ELEMENT",
  4903. context
  4904. )) {
  4905. let exp;
  4906. if (isProp.type === 6) {
  4907. exp = isProp.value && createSimpleExpression(isProp.value.content, true);
  4908. } else {
  4909. exp = isProp.exp;
  4910. if (!exp) {
  4911. exp = createSimpleExpression(`is`, false, isProp.arg.loc);
  4912. }
  4913. }
  4914. if (exp) {
  4915. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  4916. exp
  4917. ]);
  4918. }
  4919. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  4920. tag = isProp.value.content.slice(4);
  4921. }
  4922. }
  4923. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  4924. if (builtIn) {
  4925. if (!ssr) context.helper(builtIn);
  4926. return builtIn;
  4927. }
  4928. context.helper(RESOLVE_COMPONENT);
  4929. context.components.add(tag);
  4930. return toValidAssetId(tag, `component`);
  4931. }
  4932. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  4933. const { tag, loc: elementLoc, children } = node;
  4934. let properties = [];
  4935. const mergeArgs = [];
  4936. const runtimeDirectives = [];
  4937. const hasChildren = children.length > 0;
  4938. let shouldUseBlock = false;
  4939. let patchFlag = 0;
  4940. let hasRef = false;
  4941. let hasClassBinding = false;
  4942. let hasStyleBinding = false;
  4943. let hasHydrationEventBinding = false;
  4944. let hasDynamicKeys = false;
  4945. let hasVnodeHook = false;
  4946. const dynamicPropNames = [];
  4947. const pushMergeArg = (arg) => {
  4948. if (properties.length) {
  4949. mergeArgs.push(
  4950. createObjectExpression(dedupeProperties(properties), elementLoc)
  4951. );
  4952. properties = [];
  4953. }
  4954. if (arg) mergeArgs.push(arg);
  4955. };
  4956. const pushRefVForMarker = () => {
  4957. if (context.scopes.vFor > 0) {
  4958. properties.push(
  4959. createObjectProperty(
  4960. createSimpleExpression("ref_for", true),
  4961. createSimpleExpression("true")
  4962. )
  4963. );
  4964. }
  4965. };
  4966. const analyzePatchFlag = ({ key, value }) => {
  4967. if (isStaticExp(key)) {
  4968. const name = key.content;
  4969. const isEventHandler = isOn(name);
  4970. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  4971. // dedicated fast path.
  4972. name.toLowerCase() !== "onclick" && // omit v-model handlers
  4973. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  4974. !isReservedProp(name)) {
  4975. hasHydrationEventBinding = true;
  4976. }
  4977. if (isEventHandler && isReservedProp(name)) {
  4978. hasVnodeHook = true;
  4979. }
  4980. if (isEventHandler && value.type === 14) {
  4981. value = value.arguments[0];
  4982. }
  4983. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  4984. return;
  4985. }
  4986. if (name === "ref") {
  4987. hasRef = true;
  4988. } else if (name === "class") {
  4989. hasClassBinding = true;
  4990. } else if (name === "style") {
  4991. hasStyleBinding = true;
  4992. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  4993. dynamicPropNames.push(name);
  4994. }
  4995. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  4996. dynamicPropNames.push(name);
  4997. }
  4998. } else {
  4999. hasDynamicKeys = true;
  5000. }
  5001. };
  5002. for (let i = 0; i < props.length; i++) {
  5003. const prop = props[i];
  5004. if (prop.type === 6) {
  5005. const { loc, name, nameLoc, value } = prop;
  5006. let isStatic = true;
  5007. if (name === "ref") {
  5008. hasRef = true;
  5009. pushRefVForMarker();
  5010. }
  5011. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
  5012. "COMPILER_IS_ON_ELEMENT",
  5013. context
  5014. ))) {
  5015. continue;
  5016. }
  5017. properties.push(
  5018. createObjectProperty(
  5019. createSimpleExpression(name, true, nameLoc),
  5020. createSimpleExpression(
  5021. value ? value.content : "",
  5022. isStatic,
  5023. value ? value.loc : loc
  5024. )
  5025. )
  5026. );
  5027. } else {
  5028. const { name, arg, exp, loc, modifiers } = prop;
  5029. const isVBind = name === "bind";
  5030. const isVOn = name === "on";
  5031. if (name === "slot") {
  5032. if (!isComponent) {
  5033. context.onError(
  5034. createCompilerError(40, loc)
  5035. );
  5036. }
  5037. continue;
  5038. }
  5039. if (name === "once" || name === "memo") {
  5040. continue;
  5041. }
  5042. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
  5043. "COMPILER_IS_ON_ELEMENT",
  5044. context
  5045. ))) {
  5046. continue;
  5047. }
  5048. if (isVOn && ssr) {
  5049. continue;
  5050. }
  5051. if (
  5052. // #938: elements with dynamic keys should be forced into blocks
  5053. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  5054. // before children
  5055. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  5056. ) {
  5057. shouldUseBlock = true;
  5058. }
  5059. if (isVBind && isStaticArgOf(arg, "ref")) {
  5060. pushRefVForMarker();
  5061. }
  5062. if (!arg && (isVBind || isVOn)) {
  5063. hasDynamicKeys = true;
  5064. if (exp) {
  5065. if (isVBind) {
  5066. {
  5067. pushMergeArg();
  5068. {
  5069. const hasOverridableKeys = mergeArgs.some((arg2) => {
  5070. if (arg2.type === 15) {
  5071. return arg2.properties.some(({ key }) => {
  5072. if (key.type !== 4 || !key.isStatic) {
  5073. return true;
  5074. }
  5075. return key.content !== "class" && key.content !== "style" && !isOn(key.content);
  5076. });
  5077. } else {
  5078. return true;
  5079. }
  5080. });
  5081. if (hasOverridableKeys) {
  5082. checkCompatEnabled(
  5083. "COMPILER_V_BIND_OBJECT_ORDER",
  5084. context,
  5085. loc
  5086. );
  5087. }
  5088. }
  5089. if (isCompatEnabled(
  5090. "COMPILER_V_BIND_OBJECT_ORDER",
  5091. context
  5092. )) {
  5093. mergeArgs.unshift(exp);
  5094. continue;
  5095. }
  5096. }
  5097. pushRefVForMarker();
  5098. pushMergeArg();
  5099. mergeArgs.push(exp);
  5100. } else {
  5101. pushMergeArg({
  5102. type: 14,
  5103. loc,
  5104. callee: context.helper(TO_HANDLERS),
  5105. arguments: isComponent ? [exp] : [exp, `true`]
  5106. });
  5107. }
  5108. } else {
  5109. context.onError(
  5110. createCompilerError(
  5111. isVBind ? 34 : 35,
  5112. loc
  5113. )
  5114. );
  5115. }
  5116. continue;
  5117. }
  5118. if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
  5119. patchFlag |= 32;
  5120. }
  5121. const directiveTransform = context.directiveTransforms[name];
  5122. if (directiveTransform) {
  5123. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  5124. !ssr && props2.forEach(analyzePatchFlag);
  5125. if (isVOn && arg && !isStaticExp(arg)) {
  5126. pushMergeArg(createObjectExpression(props2, elementLoc));
  5127. } else {
  5128. properties.push(...props2);
  5129. }
  5130. if (needRuntime) {
  5131. runtimeDirectives.push(prop);
  5132. if (isSymbol(needRuntime)) {
  5133. directiveImportMap.set(prop, needRuntime);
  5134. }
  5135. }
  5136. } else if (!isBuiltInDirective(name)) {
  5137. runtimeDirectives.push(prop);
  5138. if (hasChildren) {
  5139. shouldUseBlock = true;
  5140. }
  5141. }
  5142. }
  5143. }
  5144. let propsExpression = void 0;
  5145. if (mergeArgs.length) {
  5146. pushMergeArg();
  5147. if (mergeArgs.length > 1) {
  5148. propsExpression = createCallExpression(
  5149. context.helper(MERGE_PROPS),
  5150. mergeArgs,
  5151. elementLoc
  5152. );
  5153. } else {
  5154. propsExpression = mergeArgs[0];
  5155. }
  5156. } else if (properties.length) {
  5157. propsExpression = createObjectExpression(
  5158. dedupeProperties(properties),
  5159. elementLoc
  5160. );
  5161. }
  5162. if (hasDynamicKeys) {
  5163. patchFlag |= 16;
  5164. } else {
  5165. if (hasClassBinding && !isComponent) {
  5166. patchFlag |= 2;
  5167. }
  5168. if (hasStyleBinding && !isComponent) {
  5169. patchFlag |= 4;
  5170. }
  5171. if (dynamicPropNames.length) {
  5172. patchFlag |= 8;
  5173. }
  5174. if (hasHydrationEventBinding) {
  5175. patchFlag |= 32;
  5176. }
  5177. }
  5178. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  5179. patchFlag |= 512;
  5180. }
  5181. if (!context.inSSR && propsExpression) {
  5182. switch (propsExpression.type) {
  5183. case 15:
  5184. let classKeyIndex = -1;
  5185. let styleKeyIndex = -1;
  5186. let hasDynamicKey = false;
  5187. for (let i = 0; i < propsExpression.properties.length; i++) {
  5188. const key = propsExpression.properties[i].key;
  5189. if (isStaticExp(key)) {
  5190. if (key.content === "class") {
  5191. classKeyIndex = i;
  5192. } else if (key.content === "style") {
  5193. styleKeyIndex = i;
  5194. }
  5195. } else if (!key.isHandlerKey) {
  5196. hasDynamicKey = true;
  5197. }
  5198. }
  5199. const classProp = propsExpression.properties[classKeyIndex];
  5200. const styleProp = propsExpression.properties[styleKeyIndex];
  5201. if (!hasDynamicKey) {
  5202. if (classProp && !isStaticExp(classProp.value)) {
  5203. classProp.value = createCallExpression(
  5204. context.helper(NORMALIZE_CLASS),
  5205. [classProp.value]
  5206. );
  5207. }
  5208. if (styleProp && // the static style is compiled into an object,
  5209. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  5210. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  5211. // v-bind:style with static literal object
  5212. styleProp.value.type === 17)) {
  5213. styleProp.value = createCallExpression(
  5214. context.helper(NORMALIZE_STYLE),
  5215. [styleProp.value]
  5216. );
  5217. }
  5218. } else {
  5219. propsExpression = createCallExpression(
  5220. context.helper(NORMALIZE_PROPS),
  5221. [propsExpression]
  5222. );
  5223. }
  5224. break;
  5225. case 14:
  5226. break;
  5227. default:
  5228. propsExpression = createCallExpression(
  5229. context.helper(NORMALIZE_PROPS),
  5230. [
  5231. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  5232. propsExpression
  5233. ])
  5234. ]
  5235. );
  5236. break;
  5237. }
  5238. }
  5239. return {
  5240. props: propsExpression,
  5241. directives: runtimeDirectives,
  5242. patchFlag,
  5243. dynamicPropNames,
  5244. shouldUseBlock
  5245. };
  5246. }
  5247. function dedupeProperties(properties) {
  5248. const knownProps = /* @__PURE__ */ new Map();
  5249. const deduped = [];
  5250. for (let i = 0; i < properties.length; i++) {
  5251. const prop = properties[i];
  5252. if (prop.key.type === 8 || !prop.key.isStatic) {
  5253. deduped.push(prop);
  5254. continue;
  5255. }
  5256. const name = prop.key.content;
  5257. const existing = knownProps.get(name);
  5258. if (existing) {
  5259. if (name === "style" || name === "class" || isOn(name)) {
  5260. mergeAsArray(existing, prop);
  5261. }
  5262. } else {
  5263. knownProps.set(name, prop);
  5264. deduped.push(prop);
  5265. }
  5266. }
  5267. return deduped;
  5268. }
  5269. function mergeAsArray(existing, incoming) {
  5270. if (existing.value.type === 17) {
  5271. existing.value.elements.push(incoming.value);
  5272. } else {
  5273. existing.value = createArrayExpression(
  5274. [existing.value, incoming.value],
  5275. existing.loc
  5276. );
  5277. }
  5278. }
  5279. function buildDirectiveArgs(dir, context) {
  5280. const dirArgs = [];
  5281. const runtime = directiveImportMap.get(dir);
  5282. if (runtime) {
  5283. dirArgs.push(context.helperString(runtime));
  5284. } else {
  5285. {
  5286. context.helper(RESOLVE_DIRECTIVE);
  5287. context.directives.add(dir.name);
  5288. dirArgs.push(toValidAssetId(dir.name, `directive`));
  5289. }
  5290. }
  5291. const { loc } = dir;
  5292. if (dir.exp) dirArgs.push(dir.exp);
  5293. if (dir.arg) {
  5294. if (!dir.exp) {
  5295. dirArgs.push(`void 0`);
  5296. }
  5297. dirArgs.push(dir.arg);
  5298. }
  5299. if (Object.keys(dir.modifiers).length) {
  5300. if (!dir.arg) {
  5301. if (!dir.exp) {
  5302. dirArgs.push(`void 0`);
  5303. }
  5304. dirArgs.push(`void 0`);
  5305. }
  5306. const trueExpression = createSimpleExpression(`true`, false, loc);
  5307. dirArgs.push(
  5308. createObjectExpression(
  5309. dir.modifiers.map(
  5310. (modifier) => createObjectProperty(modifier, trueExpression)
  5311. ),
  5312. loc
  5313. )
  5314. );
  5315. }
  5316. return createArrayExpression(dirArgs, dir.loc);
  5317. }
  5318. function stringifyDynamicPropNames(props) {
  5319. let propsNamesString = `[`;
  5320. for (let i = 0, l = props.length; i < l; i++) {
  5321. propsNamesString += JSON.stringify(props[i]);
  5322. if (i < l - 1) propsNamesString += ", ";
  5323. }
  5324. return propsNamesString + `]`;
  5325. }
  5326. function isComponentTag(tag) {
  5327. return tag === "component" || tag === "Component";
  5328. }
  5329. const transformSlotOutlet = (node, context) => {
  5330. if (isSlotOutlet(node)) {
  5331. const { children, loc } = node;
  5332. const { slotName, slotProps } = processSlotOutlet(node, context);
  5333. const slotArgs = [
  5334. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  5335. slotName,
  5336. "{}",
  5337. "undefined",
  5338. "true"
  5339. ];
  5340. let expectedLen = 2;
  5341. if (slotProps) {
  5342. slotArgs[2] = slotProps;
  5343. expectedLen = 3;
  5344. }
  5345. if (children.length) {
  5346. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  5347. expectedLen = 4;
  5348. }
  5349. if (context.scopeId && !context.slotted) {
  5350. expectedLen = 5;
  5351. }
  5352. slotArgs.splice(expectedLen);
  5353. node.codegenNode = createCallExpression(
  5354. context.helper(RENDER_SLOT),
  5355. slotArgs,
  5356. loc
  5357. );
  5358. }
  5359. };
  5360. function processSlotOutlet(node, context) {
  5361. let slotName = `"default"`;
  5362. let slotProps = void 0;
  5363. const nonNameProps = [];
  5364. for (let i = 0; i < node.props.length; i++) {
  5365. const p = node.props[i];
  5366. if (p.type === 6) {
  5367. if (p.value) {
  5368. if (p.name === "name") {
  5369. slotName = JSON.stringify(p.value.content);
  5370. } else {
  5371. p.name = camelize(p.name);
  5372. nonNameProps.push(p);
  5373. }
  5374. }
  5375. } else {
  5376. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  5377. if (p.exp) {
  5378. slotName = p.exp;
  5379. } else if (p.arg && p.arg.type === 4) {
  5380. const name = camelize(p.arg.content);
  5381. slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
  5382. }
  5383. } else {
  5384. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  5385. p.arg.content = camelize(p.arg.content);
  5386. }
  5387. nonNameProps.push(p);
  5388. }
  5389. }
  5390. }
  5391. if (nonNameProps.length > 0) {
  5392. const { props, directives } = buildProps(
  5393. node,
  5394. context,
  5395. nonNameProps,
  5396. false,
  5397. false
  5398. );
  5399. slotProps = props;
  5400. if (directives.length) {
  5401. context.onError(
  5402. createCompilerError(
  5403. 36,
  5404. directives[0].loc
  5405. )
  5406. );
  5407. }
  5408. }
  5409. return {
  5410. slotName,
  5411. slotProps
  5412. };
  5413. }
  5414. const transformOn$1 = (dir, node, context, augmentor) => {
  5415. const { loc, modifiers, arg } = dir;
  5416. if (!dir.exp && !modifiers.length) {
  5417. context.onError(createCompilerError(35, loc));
  5418. }
  5419. let eventName;
  5420. if (arg.type === 4) {
  5421. if (arg.isStatic) {
  5422. let rawName = arg.content;
  5423. if (rawName.startsWith("vnode")) {
  5424. context.onError(createCompilerError(51, arg.loc));
  5425. }
  5426. if (rawName.startsWith("vue:")) {
  5427. rawName = `vnode-${rawName.slice(4)}`;
  5428. }
  5429. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  5430. // for non-element and vnode lifecycle event listeners, auto convert
  5431. // it to camelCase. See issue #2249
  5432. toHandlerKey(camelize(rawName))
  5433. ) : (
  5434. // preserve case for plain element listeners that have uppercase
  5435. // letters, as these may be custom elements' custom events
  5436. `on:${rawName}`
  5437. );
  5438. eventName = createSimpleExpression(eventString, true, arg.loc);
  5439. } else {
  5440. eventName = createCompoundExpression([
  5441. `${context.helperString(TO_HANDLER_KEY)}(`,
  5442. arg,
  5443. `)`
  5444. ]);
  5445. }
  5446. } else {
  5447. eventName = arg;
  5448. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  5449. eventName.children.push(`)`);
  5450. }
  5451. let exp = dir.exp;
  5452. if (exp && !exp.content.trim()) {
  5453. exp = void 0;
  5454. }
  5455. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  5456. if (exp) {
  5457. const isMemberExp = isMemberExpression(exp);
  5458. const isInlineStatement = !(isMemberExp || isFnExpression(exp));
  5459. const hasMultipleStatements = exp.content.includes(`;`);
  5460. {
  5461. validateBrowserExpression(
  5462. exp,
  5463. context,
  5464. false,
  5465. hasMultipleStatements
  5466. );
  5467. }
  5468. if (isInlineStatement || shouldCache && isMemberExp) {
  5469. exp = createCompoundExpression([
  5470. `${isInlineStatement ? `$event` : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  5471. exp,
  5472. hasMultipleStatements ? `}` : `)`
  5473. ]);
  5474. }
  5475. }
  5476. let ret = {
  5477. props: [
  5478. createObjectProperty(
  5479. eventName,
  5480. exp || createSimpleExpression(`() => {}`, false, loc)
  5481. )
  5482. ]
  5483. };
  5484. if (augmentor) {
  5485. ret = augmentor(ret);
  5486. }
  5487. if (shouldCache) {
  5488. ret.props[0].value = context.cache(ret.props[0].value);
  5489. }
  5490. ret.props.forEach((p) => p.key.isHandlerKey = true);
  5491. return ret;
  5492. };
  5493. const transformText = (node, context) => {
  5494. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  5495. return () => {
  5496. const children = node.children;
  5497. let currentContainer = void 0;
  5498. let hasText = false;
  5499. for (let i = 0; i < children.length; i++) {
  5500. const child = children[i];
  5501. if (isText$1(child)) {
  5502. hasText = true;
  5503. for (let j = i + 1; j < children.length; j++) {
  5504. const next = children[j];
  5505. if (isText$1(next)) {
  5506. if (!currentContainer) {
  5507. currentContainer = children[i] = createCompoundExpression(
  5508. [child],
  5509. child.loc
  5510. );
  5511. }
  5512. currentContainer.children.push(` + `, next);
  5513. children.splice(j, 1);
  5514. j--;
  5515. } else {
  5516. currentContainer = void 0;
  5517. break;
  5518. }
  5519. }
  5520. }
  5521. }
  5522. if (!hasText || // if this is a plain element with a single text child, leave it
  5523. // as-is since the runtime has dedicated fast path for this by directly
  5524. // setting textContent of the element.
  5525. // for component root it's always normalized anyway.
  5526. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  5527. // custom directives can potentially add DOM elements arbitrarily,
  5528. // we need to avoid setting textContent of the element at runtime
  5529. // to avoid accidentally overwriting the DOM elements added
  5530. // by the user through custom directives.
  5531. !node.props.find(
  5532. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  5533. ) && // in compat mode, <template> tags with no special directives
  5534. // will be rendered as a fragment so its children must be
  5535. // converted into vnodes.
  5536. !(node.tag === "template"))) {
  5537. return;
  5538. }
  5539. for (let i = 0; i < children.length; i++) {
  5540. const child = children[i];
  5541. if (isText$1(child) || child.type === 8) {
  5542. const callArgs = [];
  5543. if (child.type !== 2 || child.content !== " ") {
  5544. callArgs.push(child);
  5545. }
  5546. if (!context.ssr && getConstantType(child, context) === 0) {
  5547. callArgs.push(
  5548. 1 + (` /* ${PatchFlagNames[1]} */` )
  5549. );
  5550. }
  5551. children[i] = {
  5552. type: 12,
  5553. content: child,
  5554. loc: child.loc,
  5555. codegenNode: createCallExpression(
  5556. context.helper(CREATE_TEXT),
  5557. callArgs
  5558. )
  5559. };
  5560. }
  5561. }
  5562. };
  5563. }
  5564. };
  5565. const seen$1 = /* @__PURE__ */ new WeakSet();
  5566. const transformOnce = (node, context) => {
  5567. if (node.type === 1 && findDir(node, "once", true)) {
  5568. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  5569. return;
  5570. }
  5571. seen$1.add(node);
  5572. context.inVOnce = true;
  5573. context.helper(SET_BLOCK_TRACKING);
  5574. return () => {
  5575. context.inVOnce = false;
  5576. const cur = context.currentNode;
  5577. if (cur.codegenNode) {
  5578. cur.codegenNode = context.cache(
  5579. cur.codegenNode,
  5580. true,
  5581. true
  5582. );
  5583. }
  5584. };
  5585. }
  5586. };
  5587. const transformModel$1 = (dir, node, context) => {
  5588. const { exp, arg } = dir;
  5589. if (!exp) {
  5590. context.onError(
  5591. createCompilerError(41, dir.loc)
  5592. );
  5593. return createTransformProps();
  5594. }
  5595. const rawExp = exp.loc.source.trim();
  5596. const expString = exp.type === 4 ? exp.content : rawExp;
  5597. const bindingType = context.bindingMetadata[rawExp];
  5598. if (bindingType === "props" || bindingType === "props-aliased") {
  5599. context.onError(createCompilerError(44, exp.loc));
  5600. return createTransformProps();
  5601. }
  5602. if (!expString.trim() || !isMemberExpression(exp) && true) {
  5603. context.onError(
  5604. createCompilerError(42, exp.loc)
  5605. );
  5606. return createTransformProps();
  5607. }
  5608. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  5609. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  5610. let assignmentExp;
  5611. const eventArg = context.isTS ? `($event: any)` : `$event`;
  5612. {
  5613. assignmentExp = createCompoundExpression([
  5614. `${eventArg} => ((`,
  5615. exp,
  5616. `) = $event)`
  5617. ]);
  5618. }
  5619. const props = [
  5620. // modelValue: foo
  5621. createObjectProperty(propName, dir.exp),
  5622. // "onUpdate:modelValue": $event => (foo = $event)
  5623. createObjectProperty(eventName, assignmentExp)
  5624. ];
  5625. if (dir.modifiers.length && node.tagType === 1) {
  5626. const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  5627. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  5628. props.push(
  5629. createObjectProperty(
  5630. modifiersKey,
  5631. createSimpleExpression(
  5632. `{ ${modifiers} }`,
  5633. false,
  5634. dir.loc,
  5635. 2
  5636. )
  5637. )
  5638. );
  5639. }
  5640. return createTransformProps(props);
  5641. };
  5642. function createTransformProps(props = []) {
  5643. return { props };
  5644. }
  5645. const validDivisionCharRE = /[\w).+\-_$\]]/;
  5646. const transformFilter = (node, context) => {
  5647. if (!isCompatEnabled("COMPILER_FILTERS", context)) {
  5648. return;
  5649. }
  5650. if (node.type === 5) {
  5651. rewriteFilter(node.content, context);
  5652. } else if (node.type === 1) {
  5653. node.props.forEach((prop) => {
  5654. if (prop.type === 7 && prop.name !== "for" && prop.exp) {
  5655. rewriteFilter(prop.exp, context);
  5656. }
  5657. });
  5658. }
  5659. };
  5660. function rewriteFilter(node, context) {
  5661. if (node.type === 4) {
  5662. parseFilter(node, context);
  5663. } else {
  5664. for (let i = 0; i < node.children.length; i++) {
  5665. const child = node.children[i];
  5666. if (typeof child !== "object") continue;
  5667. if (child.type === 4) {
  5668. parseFilter(child, context);
  5669. } else if (child.type === 8) {
  5670. rewriteFilter(node, context);
  5671. } else if (child.type === 5) {
  5672. rewriteFilter(child.content, context);
  5673. }
  5674. }
  5675. }
  5676. }
  5677. function parseFilter(node, context) {
  5678. const exp = node.content;
  5679. let inSingle = false;
  5680. let inDouble = false;
  5681. let inTemplateString = false;
  5682. let inRegex = false;
  5683. let curly = 0;
  5684. let square = 0;
  5685. let paren = 0;
  5686. let lastFilterIndex = 0;
  5687. let c, prev, i, expression, filters = [];
  5688. for (i = 0; i < exp.length; i++) {
  5689. prev = c;
  5690. c = exp.charCodeAt(i);
  5691. if (inSingle) {
  5692. if (c === 39 && prev !== 92) inSingle = false;
  5693. } else if (inDouble) {
  5694. if (c === 34 && prev !== 92) inDouble = false;
  5695. } else if (inTemplateString) {
  5696. if (c === 96 && prev !== 92) inTemplateString = false;
  5697. } else if (inRegex) {
  5698. if (c === 47 && prev !== 92) inRegex = false;
  5699. } else if (c === 124 && // pipe
  5700. exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
  5701. if (expression === void 0) {
  5702. lastFilterIndex = i + 1;
  5703. expression = exp.slice(0, i).trim();
  5704. } else {
  5705. pushFilter();
  5706. }
  5707. } else {
  5708. switch (c) {
  5709. case 34:
  5710. inDouble = true;
  5711. break;
  5712. // "
  5713. case 39:
  5714. inSingle = true;
  5715. break;
  5716. // '
  5717. case 96:
  5718. inTemplateString = true;
  5719. break;
  5720. // `
  5721. case 40:
  5722. paren++;
  5723. break;
  5724. // (
  5725. case 41:
  5726. paren--;
  5727. break;
  5728. // )
  5729. case 91:
  5730. square++;
  5731. break;
  5732. // [
  5733. case 93:
  5734. square--;
  5735. break;
  5736. // ]
  5737. case 123:
  5738. curly++;
  5739. break;
  5740. // {
  5741. case 125:
  5742. curly--;
  5743. break;
  5744. }
  5745. if (c === 47) {
  5746. let j = i - 1;
  5747. let p;
  5748. for (; j >= 0; j--) {
  5749. p = exp.charAt(j);
  5750. if (p !== " ") break;
  5751. }
  5752. if (!p || !validDivisionCharRE.test(p)) {
  5753. inRegex = true;
  5754. }
  5755. }
  5756. }
  5757. }
  5758. if (expression === void 0) {
  5759. expression = exp.slice(0, i).trim();
  5760. } else if (lastFilterIndex !== 0) {
  5761. pushFilter();
  5762. }
  5763. function pushFilter() {
  5764. filters.push(exp.slice(lastFilterIndex, i).trim());
  5765. lastFilterIndex = i + 1;
  5766. }
  5767. if (filters.length) {
  5768. warnDeprecation(
  5769. "COMPILER_FILTERS",
  5770. context,
  5771. node.loc
  5772. );
  5773. for (i = 0; i < filters.length; i++) {
  5774. expression = wrapFilter(expression, filters[i], context);
  5775. }
  5776. node.content = expression;
  5777. node.ast = void 0;
  5778. }
  5779. }
  5780. function wrapFilter(exp, filter, context) {
  5781. context.helper(RESOLVE_FILTER);
  5782. const i = filter.indexOf("(");
  5783. if (i < 0) {
  5784. context.filters.add(filter);
  5785. return `${toValidAssetId(filter, "filter")}(${exp})`;
  5786. } else {
  5787. const name = filter.slice(0, i);
  5788. const args = filter.slice(i + 1);
  5789. context.filters.add(name);
  5790. return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
  5791. }
  5792. }
  5793. const seen = /* @__PURE__ */ new WeakSet();
  5794. const transformMemo = (node, context) => {
  5795. if (node.type === 1) {
  5796. const dir = findDir(node, "memo");
  5797. if (!dir || seen.has(node) || context.inSSR) {
  5798. return;
  5799. }
  5800. seen.add(node);
  5801. return () => {
  5802. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  5803. if (codegenNode && codegenNode.type === 13) {
  5804. if (node.tagType !== 1) {
  5805. convertToBlock(codegenNode, context);
  5806. }
  5807. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  5808. dir.exp,
  5809. createFunctionExpression(void 0, codegenNode),
  5810. `_cache`,
  5811. String(context.cached.length)
  5812. ]);
  5813. context.cached.push(null);
  5814. }
  5815. };
  5816. }
  5817. };
  5818. function getBaseTransformPreset(prefixIdentifiers) {
  5819. return [
  5820. [
  5821. transformOnce,
  5822. transformIf,
  5823. transformMemo,
  5824. transformFor,
  5825. ...[transformFilter] ,
  5826. ...[transformExpression] ,
  5827. transformSlotOutlet,
  5828. transformElement,
  5829. trackSlotScopes,
  5830. transformText
  5831. ],
  5832. {
  5833. on: transformOn$1,
  5834. bind: transformBind,
  5835. model: transformModel$1
  5836. }
  5837. ];
  5838. }
  5839. function baseCompile(source, options = {}) {
  5840. const onError = options.onError || defaultOnError;
  5841. const isModuleMode = options.mode === "module";
  5842. {
  5843. if (options.prefixIdentifiers === true) {
  5844. onError(createCompilerError(47));
  5845. } else if (isModuleMode) {
  5846. onError(createCompilerError(48));
  5847. }
  5848. }
  5849. const prefixIdentifiers = false;
  5850. if (options.cacheHandlers) {
  5851. onError(createCompilerError(49));
  5852. }
  5853. if (options.scopeId && !isModuleMode) {
  5854. onError(createCompilerError(50));
  5855. }
  5856. const resolvedOptions = extend({}, options, {
  5857. prefixIdentifiers
  5858. });
  5859. const ast = isString(source) ? baseParse(source, resolvedOptions) : source;
  5860. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  5861. transform(
  5862. ast,
  5863. extend({}, resolvedOptions, {
  5864. nodeTransforms: [
  5865. ...nodeTransforms,
  5866. ...options.nodeTransforms || []
  5867. // user transforms
  5868. ],
  5869. directiveTransforms: extend(
  5870. {},
  5871. directiveTransforms,
  5872. options.directiveTransforms || {}
  5873. // user transforms
  5874. )
  5875. })
  5876. );
  5877. return generate(ast, resolvedOptions);
  5878. }
  5879. const BindingTypes = {
  5880. "DATA": "data",
  5881. "PROPS": "props",
  5882. "PROPS_ALIASED": "props-aliased",
  5883. "SETUP_LET": "setup-let",
  5884. "SETUP_CONST": "setup-const",
  5885. "SETUP_REACTIVE_CONST": "setup-reactive-const",
  5886. "SETUP_MAYBE_REF": "setup-maybe-ref",
  5887. "SETUP_REF": "setup-ref",
  5888. "OPTIONS": "options",
  5889. "LITERAL_CONST": "literal-const"
  5890. };
  5891. const noopDirectiveTransform = () => ({ props: [] });
  5892. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  5893. const V_MODEL_CHECKBOX = Symbol(
  5894. `vModelCheckbox`
  5895. );
  5896. const V_MODEL_TEXT = Symbol(`vModelText` );
  5897. const V_MODEL_SELECT = Symbol(
  5898. `vModelSelect`
  5899. );
  5900. const V_MODEL_DYNAMIC = Symbol(
  5901. `vModelDynamic`
  5902. );
  5903. const V_ON_WITH_MODIFIERS = Symbol(
  5904. `vOnModifiersGuard`
  5905. );
  5906. const V_ON_WITH_KEYS = Symbol(
  5907. `vOnKeysGuard`
  5908. );
  5909. const V_SHOW = Symbol(`vShow` );
  5910. const TRANSITION = Symbol(`Transition` );
  5911. const TRANSITION_GROUP = Symbol(
  5912. `TransitionGroup`
  5913. );
  5914. registerRuntimeHelpers({
  5915. [V_MODEL_RADIO]: `vModelRadio`,
  5916. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  5917. [V_MODEL_TEXT]: `vModelText`,
  5918. [V_MODEL_SELECT]: `vModelSelect`,
  5919. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  5920. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  5921. [V_ON_WITH_KEYS]: `withKeys`,
  5922. [V_SHOW]: `vShow`,
  5923. [TRANSITION]: `Transition`,
  5924. [TRANSITION_GROUP]: `TransitionGroup`
  5925. });
  5926. let decoder;
  5927. function decodeHtmlBrowser(raw, asAttr = false) {
  5928. if (!decoder) {
  5929. decoder = document.createElement("div");
  5930. }
  5931. if (asAttr) {
  5932. decoder.innerHTML = `<div foo="${raw.replace(/"/g, "&quot;")}">`;
  5933. return decoder.children[0].getAttribute("foo");
  5934. } else {
  5935. decoder.innerHTML = raw;
  5936. return decoder.textContent;
  5937. }
  5938. }
  5939. const parserOptions = {
  5940. parseMode: "html",
  5941. isVoidTag,
  5942. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
  5943. isPreTag: (tag) => tag === "pre",
  5944. isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
  5945. decodeEntities: decodeHtmlBrowser ,
  5946. isBuiltInComponent: (tag) => {
  5947. if (tag === "Transition" || tag === "transition") {
  5948. return TRANSITION;
  5949. } else if (tag === "TransitionGroup" || tag === "transition-group") {
  5950. return TRANSITION_GROUP;
  5951. }
  5952. },
  5953. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  5954. getNamespace(tag, parent, rootNamespace) {
  5955. let ns = parent ? parent.ns : rootNamespace;
  5956. if (parent && ns === 2) {
  5957. if (parent.tag === "annotation-xml") {
  5958. if (tag === "svg") {
  5959. return 1;
  5960. }
  5961. if (parent.props.some(
  5962. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  5963. )) {
  5964. ns = 0;
  5965. }
  5966. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  5967. ns = 0;
  5968. }
  5969. } else if (parent && ns === 1) {
  5970. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  5971. ns = 0;
  5972. }
  5973. }
  5974. if (ns === 0) {
  5975. if (tag === "svg") {
  5976. return 1;
  5977. }
  5978. if (tag === "math") {
  5979. return 2;
  5980. }
  5981. }
  5982. return ns;
  5983. }
  5984. };
  5985. const transformStyle = (node) => {
  5986. if (node.type === 1) {
  5987. node.props.forEach((p, i) => {
  5988. if (p.type === 6 && p.name === "style" && p.value) {
  5989. node.props[i] = {
  5990. type: 7,
  5991. name: `bind`,
  5992. arg: createSimpleExpression(`style`, true, p.loc),
  5993. exp: parseInlineCSS(p.value.content, p.loc),
  5994. modifiers: [],
  5995. loc: p.loc
  5996. };
  5997. }
  5998. });
  5999. }
  6000. };
  6001. const parseInlineCSS = (cssText, loc) => {
  6002. const normalized = parseStringStyle(cssText);
  6003. return createSimpleExpression(
  6004. JSON.stringify(normalized),
  6005. false,
  6006. loc,
  6007. 3
  6008. );
  6009. };
  6010. function createDOMCompilerError(code, loc) {
  6011. return createCompilerError(
  6012. code,
  6013. loc,
  6014. DOMErrorMessages
  6015. );
  6016. }
  6017. const DOMErrorCodes = {
  6018. "X_V_HTML_NO_EXPRESSION": 53,
  6019. "53": "X_V_HTML_NO_EXPRESSION",
  6020. "X_V_HTML_WITH_CHILDREN": 54,
  6021. "54": "X_V_HTML_WITH_CHILDREN",
  6022. "X_V_TEXT_NO_EXPRESSION": 55,
  6023. "55": "X_V_TEXT_NO_EXPRESSION",
  6024. "X_V_TEXT_WITH_CHILDREN": 56,
  6025. "56": "X_V_TEXT_WITH_CHILDREN",
  6026. "X_V_MODEL_ON_INVALID_ELEMENT": 57,
  6027. "57": "X_V_MODEL_ON_INVALID_ELEMENT",
  6028. "X_V_MODEL_ARG_ON_ELEMENT": 58,
  6029. "58": "X_V_MODEL_ARG_ON_ELEMENT",
  6030. "X_V_MODEL_ON_FILE_INPUT_ELEMENT": 59,
  6031. "59": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
  6032. "X_V_MODEL_UNNECESSARY_VALUE": 60,
  6033. "60": "X_V_MODEL_UNNECESSARY_VALUE",
  6034. "X_V_SHOW_NO_EXPRESSION": 61,
  6035. "61": "X_V_SHOW_NO_EXPRESSION",
  6036. "X_TRANSITION_INVALID_CHILDREN": 62,
  6037. "62": "X_TRANSITION_INVALID_CHILDREN",
  6038. "X_IGNORED_SIDE_EFFECT_TAG": 63,
  6039. "63": "X_IGNORED_SIDE_EFFECT_TAG",
  6040. "__EXTEND_POINT__": 64,
  6041. "64": "__EXTEND_POINT__"
  6042. };
  6043. const DOMErrorMessages = {
  6044. [53]: `v-html is missing expression.`,
  6045. [54]: `v-html will override element children.`,
  6046. [55]: `v-text is missing expression.`,
  6047. [56]: `v-text will override element children.`,
  6048. [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  6049. [58]: `v-model argument is not supported on plain elements.`,
  6050. [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  6051. [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  6052. [61]: `v-show is missing expression.`,
  6053. [62]: `<Transition> expects exactly one child element or component.`,
  6054. [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  6055. };
  6056. const transformVHtml = (dir, node, context) => {
  6057. const { exp, loc } = dir;
  6058. if (!exp) {
  6059. context.onError(
  6060. createDOMCompilerError(53, loc)
  6061. );
  6062. }
  6063. if (node.children.length) {
  6064. context.onError(
  6065. createDOMCompilerError(54, loc)
  6066. );
  6067. node.children.length = 0;
  6068. }
  6069. return {
  6070. props: [
  6071. createObjectProperty(
  6072. createSimpleExpression(`innerHTML`, true, loc),
  6073. exp || createSimpleExpression("", true)
  6074. )
  6075. ]
  6076. };
  6077. };
  6078. const transformVText = (dir, node, context) => {
  6079. const { exp, loc } = dir;
  6080. if (!exp) {
  6081. context.onError(
  6082. createDOMCompilerError(55, loc)
  6083. );
  6084. }
  6085. if (node.children.length) {
  6086. context.onError(
  6087. createDOMCompilerError(56, loc)
  6088. );
  6089. node.children.length = 0;
  6090. }
  6091. return {
  6092. props: [
  6093. createObjectProperty(
  6094. createSimpleExpression(`textContent`, true),
  6095. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  6096. context.helperString(TO_DISPLAY_STRING),
  6097. [exp],
  6098. loc
  6099. ) : createSimpleExpression("", true)
  6100. )
  6101. ]
  6102. };
  6103. };
  6104. const transformModel = (dir, node, context) => {
  6105. const baseResult = transformModel$1(dir, node, context);
  6106. if (!baseResult.props.length || node.tagType === 1) {
  6107. return baseResult;
  6108. }
  6109. if (dir.arg) {
  6110. context.onError(
  6111. createDOMCompilerError(
  6112. 58,
  6113. dir.arg.loc
  6114. )
  6115. );
  6116. }
  6117. function checkDuplicatedValue() {
  6118. const value = findDir(node, "bind");
  6119. if (value && isStaticArgOf(value.arg, "value")) {
  6120. context.onError(
  6121. createDOMCompilerError(
  6122. 60,
  6123. value.loc
  6124. )
  6125. );
  6126. }
  6127. }
  6128. const { tag } = node;
  6129. const isCustomElement = context.isCustomElement(tag);
  6130. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  6131. let directiveToUse = V_MODEL_TEXT;
  6132. let isInvalidType = false;
  6133. if (tag === "input" || isCustomElement) {
  6134. const type = findProp(node, `type`);
  6135. if (type) {
  6136. if (type.type === 7) {
  6137. directiveToUse = V_MODEL_DYNAMIC;
  6138. } else if (type.value) {
  6139. switch (type.value.content) {
  6140. case "radio":
  6141. directiveToUse = V_MODEL_RADIO;
  6142. break;
  6143. case "checkbox":
  6144. directiveToUse = V_MODEL_CHECKBOX;
  6145. break;
  6146. case "file":
  6147. isInvalidType = true;
  6148. context.onError(
  6149. createDOMCompilerError(
  6150. 59,
  6151. dir.loc
  6152. )
  6153. );
  6154. break;
  6155. default:
  6156. checkDuplicatedValue();
  6157. break;
  6158. }
  6159. }
  6160. } else if (hasDynamicKeyVBind(node)) {
  6161. directiveToUse = V_MODEL_DYNAMIC;
  6162. } else {
  6163. checkDuplicatedValue();
  6164. }
  6165. } else if (tag === "select") {
  6166. directiveToUse = V_MODEL_SELECT;
  6167. } else {
  6168. checkDuplicatedValue();
  6169. }
  6170. if (!isInvalidType) {
  6171. baseResult.needRuntime = context.helper(directiveToUse);
  6172. }
  6173. } else {
  6174. context.onError(
  6175. createDOMCompilerError(
  6176. 57,
  6177. dir.loc
  6178. )
  6179. );
  6180. }
  6181. baseResult.props = baseResult.props.filter(
  6182. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  6183. );
  6184. return baseResult;
  6185. };
  6186. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  6187. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  6188. // event propagation management
  6189. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  6190. );
  6191. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  6192. const isKeyboardEvent = /* @__PURE__ */ makeMap(`onkeyup,onkeydown,onkeypress`);
  6193. const resolveModifiers = (key, modifiers, context, loc) => {
  6194. const keyModifiers = [];
  6195. const nonKeyModifiers = [];
  6196. const eventOptionModifiers = [];
  6197. for (let i = 0; i < modifiers.length; i++) {
  6198. const modifier = modifiers[i].content;
  6199. if (modifier === "native" && checkCompatEnabled(
  6200. "COMPILER_V_ON_NATIVE",
  6201. context,
  6202. loc
  6203. )) {
  6204. eventOptionModifiers.push(modifier);
  6205. } else if (isEventOptionModifier(modifier)) {
  6206. eventOptionModifiers.push(modifier);
  6207. } else {
  6208. if (maybeKeyModifier(modifier)) {
  6209. if (isStaticExp(key)) {
  6210. if (isKeyboardEvent(key.content.toLowerCase())) {
  6211. keyModifiers.push(modifier);
  6212. } else {
  6213. nonKeyModifiers.push(modifier);
  6214. }
  6215. } else {
  6216. keyModifiers.push(modifier);
  6217. nonKeyModifiers.push(modifier);
  6218. }
  6219. } else {
  6220. if (isNonKeyModifier(modifier)) {
  6221. nonKeyModifiers.push(modifier);
  6222. } else {
  6223. keyModifiers.push(modifier);
  6224. }
  6225. }
  6226. }
  6227. }
  6228. return {
  6229. keyModifiers,
  6230. nonKeyModifiers,
  6231. eventOptionModifiers
  6232. };
  6233. };
  6234. const transformClick = (key, event) => {
  6235. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  6236. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  6237. `(`,
  6238. key,
  6239. `) === "onClick" ? "${event}" : (`,
  6240. key,
  6241. `)`
  6242. ]) : key;
  6243. };
  6244. const transformOn = (dir, node, context) => {
  6245. return transformOn$1(dir, node, context, (baseResult) => {
  6246. const { modifiers } = dir;
  6247. if (!modifiers.length) return baseResult;
  6248. let { key, value: handlerExp } = baseResult.props[0];
  6249. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  6250. if (nonKeyModifiers.includes("right")) {
  6251. key = transformClick(key, `onContextmenu`);
  6252. }
  6253. if (nonKeyModifiers.includes("middle")) {
  6254. key = transformClick(key, `onMouseup`);
  6255. }
  6256. if (nonKeyModifiers.length) {
  6257. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  6258. handlerExp,
  6259. JSON.stringify(nonKeyModifiers)
  6260. ]);
  6261. }
  6262. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  6263. (!isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
  6264. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  6265. handlerExp,
  6266. JSON.stringify(keyModifiers)
  6267. ]);
  6268. }
  6269. if (eventOptionModifiers.length) {
  6270. const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
  6271. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  6272. }
  6273. return {
  6274. props: [createObjectProperty(key, handlerExp)]
  6275. };
  6276. });
  6277. };
  6278. const transformShow = (dir, node, context) => {
  6279. const { exp, loc } = dir;
  6280. if (!exp) {
  6281. context.onError(
  6282. createDOMCompilerError(61, loc)
  6283. );
  6284. }
  6285. return {
  6286. props: [],
  6287. needRuntime: context.helper(V_SHOW)
  6288. };
  6289. };
  6290. const transformTransition = (node, context) => {
  6291. if (node.type === 1 && node.tagType === 1) {
  6292. const component = context.isBuiltInComponent(node.tag);
  6293. if (component === TRANSITION) {
  6294. return () => {
  6295. if (!node.children.length) {
  6296. return;
  6297. }
  6298. if (hasMultipleChildren(node)) {
  6299. context.onError(
  6300. createDOMCompilerError(
  6301. 62,
  6302. {
  6303. start: node.children[0].loc.start,
  6304. end: node.children[node.children.length - 1].loc.end,
  6305. source: ""
  6306. }
  6307. )
  6308. );
  6309. }
  6310. const child = node.children[0];
  6311. if (child.type === 1) {
  6312. for (const p of child.props) {
  6313. if (p.type === 7 && p.name === "show") {
  6314. node.props.push({
  6315. type: 6,
  6316. name: "persisted",
  6317. nameLoc: node.loc,
  6318. value: void 0,
  6319. loc: node.loc
  6320. });
  6321. }
  6322. }
  6323. }
  6324. };
  6325. }
  6326. }
  6327. };
  6328. function hasMultipleChildren(node) {
  6329. const children = node.children = node.children.filter(
  6330. (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
  6331. );
  6332. const child = children[0];
  6333. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  6334. }
  6335. const ignoreSideEffectTags = (node, context) => {
  6336. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  6337. context.onError(
  6338. createDOMCompilerError(
  6339. 63,
  6340. node.loc
  6341. )
  6342. );
  6343. context.removeNode();
  6344. }
  6345. };
  6346. function isValidHTMLNesting(parent, child) {
  6347. if (parent === "template") {
  6348. return true;
  6349. }
  6350. if (parent in onlyValidChildren) {
  6351. return onlyValidChildren[parent].has(child);
  6352. }
  6353. if (child in onlyValidParents) {
  6354. return onlyValidParents[child].has(parent);
  6355. }
  6356. if (parent in knownInvalidChildren) {
  6357. if (knownInvalidChildren[parent].has(child)) return false;
  6358. }
  6359. if (child in knownInvalidParents) {
  6360. if (knownInvalidParents[child].has(parent)) return false;
  6361. }
  6362. return true;
  6363. }
  6364. const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
  6365. const emptySet = /* @__PURE__ */ new Set([]);
  6366. const onlyValidChildren = {
  6367. head: /* @__PURE__ */ new Set([
  6368. "base",
  6369. "basefront",
  6370. "bgsound",
  6371. "link",
  6372. "meta",
  6373. "title",
  6374. "noscript",
  6375. "noframes",
  6376. "style",
  6377. "script",
  6378. "template"
  6379. ]),
  6380. optgroup: /* @__PURE__ */ new Set(["option"]),
  6381. select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
  6382. // table
  6383. table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
  6384. tr: /* @__PURE__ */ new Set(["td", "th"]),
  6385. colgroup: /* @__PURE__ */ new Set(["col"]),
  6386. tbody: /* @__PURE__ */ new Set(["tr"]),
  6387. thead: /* @__PURE__ */ new Set(["tr"]),
  6388. tfoot: /* @__PURE__ */ new Set(["tr"]),
  6389. // these elements can not have any children elements
  6390. script: emptySet,
  6391. iframe: emptySet,
  6392. option: emptySet,
  6393. textarea: emptySet,
  6394. style: emptySet,
  6395. title: emptySet
  6396. };
  6397. const onlyValidParents = {
  6398. // sections
  6399. html: emptySet,
  6400. body: /* @__PURE__ */ new Set(["html"]),
  6401. head: /* @__PURE__ */ new Set(["html"]),
  6402. // table
  6403. td: /* @__PURE__ */ new Set(["tr"]),
  6404. colgroup: /* @__PURE__ */ new Set(["table"]),
  6405. caption: /* @__PURE__ */ new Set(["table"]),
  6406. tbody: /* @__PURE__ */ new Set(["table"]),
  6407. tfoot: /* @__PURE__ */ new Set(["table"]),
  6408. col: /* @__PURE__ */ new Set(["colgroup"]),
  6409. th: /* @__PURE__ */ new Set(["tr"]),
  6410. thead: /* @__PURE__ */ new Set(["table"]),
  6411. tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
  6412. // data list
  6413. dd: /* @__PURE__ */ new Set(["dl", "div"]),
  6414. dt: /* @__PURE__ */ new Set(["dl", "div"]),
  6415. // other
  6416. figcaption: /* @__PURE__ */ new Set(["figure"]),
  6417. // li: new Set(["ul", "ol"]),
  6418. summary: /* @__PURE__ */ new Set(["details"]),
  6419. area: /* @__PURE__ */ new Set(["map"])
  6420. };
  6421. const knownInvalidChildren = {
  6422. p: /* @__PURE__ */ new Set([
  6423. "address",
  6424. "article",
  6425. "aside",
  6426. "blockquote",
  6427. "center",
  6428. "details",
  6429. "dialog",
  6430. "dir",
  6431. "div",
  6432. "dl",
  6433. "fieldset",
  6434. "figure",
  6435. "footer",
  6436. "form",
  6437. "h1",
  6438. "h2",
  6439. "h3",
  6440. "h4",
  6441. "h5",
  6442. "h6",
  6443. "header",
  6444. "hgroup",
  6445. "hr",
  6446. "li",
  6447. "main",
  6448. "nav",
  6449. "menu",
  6450. "ol",
  6451. "p",
  6452. "pre",
  6453. "section",
  6454. "table",
  6455. "ul"
  6456. ]),
  6457. svg: /* @__PURE__ */ new Set([
  6458. "b",
  6459. "blockquote",
  6460. "br",
  6461. "code",
  6462. "dd",
  6463. "div",
  6464. "dl",
  6465. "dt",
  6466. "em",
  6467. "embed",
  6468. "h1",
  6469. "h2",
  6470. "h3",
  6471. "h4",
  6472. "h5",
  6473. "h6",
  6474. "hr",
  6475. "i",
  6476. "img",
  6477. "li",
  6478. "menu",
  6479. "meta",
  6480. "ol",
  6481. "p",
  6482. "pre",
  6483. "ruby",
  6484. "s",
  6485. "small",
  6486. "span",
  6487. "strong",
  6488. "sub",
  6489. "sup",
  6490. "table",
  6491. "u",
  6492. "ul",
  6493. "var"
  6494. ])
  6495. };
  6496. const knownInvalidParents = {
  6497. a: /* @__PURE__ */ new Set(["a"]),
  6498. button: /* @__PURE__ */ new Set(["button"]),
  6499. dd: /* @__PURE__ */ new Set(["dd", "dt"]),
  6500. dt: /* @__PURE__ */ new Set(["dd", "dt"]),
  6501. form: /* @__PURE__ */ new Set(["form"]),
  6502. li: /* @__PURE__ */ new Set(["li"]),
  6503. h1: headings,
  6504. h2: headings,
  6505. h3: headings,
  6506. h4: headings,
  6507. h5: headings,
  6508. h6: headings
  6509. };
  6510. const validateHtmlNesting = (node, context) => {
  6511. if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
  6512. const error = new SyntaxError(
  6513. `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
  6514. );
  6515. error.loc = node.loc;
  6516. context.onWarn(error);
  6517. }
  6518. };
  6519. const DOMNodeTransforms = [
  6520. transformStyle,
  6521. ...[transformTransition, validateHtmlNesting]
  6522. ];
  6523. const DOMDirectiveTransforms = {
  6524. cloak: noopDirectiveTransform,
  6525. html: transformVHtml,
  6526. text: transformVText,
  6527. model: transformModel,
  6528. // override compiler-core
  6529. on: transformOn,
  6530. // override compiler-core
  6531. show: transformShow
  6532. };
  6533. function compile(src, options = {}) {
  6534. return baseCompile(
  6535. src,
  6536. extend({}, parserOptions, options, {
  6537. nodeTransforms: [
  6538. // ignore <script> and <tag>
  6539. // this is not put inside DOMNodeTransforms because that list is used
  6540. // by compiler-ssr to generate vnode fallback branches
  6541. ignoreSideEffectTags,
  6542. ...DOMNodeTransforms,
  6543. ...options.nodeTransforms || []
  6544. ],
  6545. directiveTransforms: extend(
  6546. {},
  6547. DOMDirectiveTransforms,
  6548. options.directiveTransforms || {}
  6549. ),
  6550. transformHoist: null
  6551. })
  6552. );
  6553. }
  6554. function parse(template, options = {}) {
  6555. return baseParse(template, extend({}, parserOptions, options));
  6556. }
  6557. exports.BASE_TRANSITION = BASE_TRANSITION;
  6558. exports.BindingTypes = BindingTypes;
  6559. exports.CAMELIZE = CAMELIZE;
  6560. exports.CAPITALIZE = CAPITALIZE;
  6561. exports.CREATE_BLOCK = CREATE_BLOCK;
  6562. exports.CREATE_COMMENT = CREATE_COMMENT;
  6563. exports.CREATE_ELEMENT_BLOCK = CREATE_ELEMENT_BLOCK;
  6564. exports.CREATE_ELEMENT_VNODE = CREATE_ELEMENT_VNODE;
  6565. exports.CREATE_SLOTS = CREATE_SLOTS;
  6566. exports.CREATE_STATIC = CREATE_STATIC;
  6567. exports.CREATE_TEXT = CREATE_TEXT;
  6568. exports.CREATE_VNODE = CREATE_VNODE;
  6569. exports.CompilerDeprecationTypes = CompilerDeprecationTypes;
  6570. exports.ConstantTypes = ConstantTypes;
  6571. exports.DOMDirectiveTransforms = DOMDirectiveTransforms;
  6572. exports.DOMErrorCodes = DOMErrorCodes;
  6573. exports.DOMErrorMessages = DOMErrorMessages;
  6574. exports.DOMNodeTransforms = DOMNodeTransforms;
  6575. exports.ElementTypes = ElementTypes;
  6576. exports.ErrorCodes = ErrorCodes;
  6577. exports.FRAGMENT = FRAGMENT;
  6578. exports.GUARD_REACTIVE_PROPS = GUARD_REACTIVE_PROPS;
  6579. exports.IS_MEMO_SAME = IS_MEMO_SAME;
  6580. exports.IS_REF = IS_REF;
  6581. exports.KEEP_ALIVE = KEEP_ALIVE;
  6582. exports.MERGE_PROPS = MERGE_PROPS;
  6583. exports.NORMALIZE_CLASS = NORMALIZE_CLASS;
  6584. exports.NORMALIZE_PROPS = NORMALIZE_PROPS;
  6585. exports.NORMALIZE_STYLE = NORMALIZE_STYLE;
  6586. exports.Namespaces = Namespaces;
  6587. exports.NodeTypes = NodeTypes;
  6588. exports.OPEN_BLOCK = OPEN_BLOCK;
  6589. exports.POP_SCOPE_ID = POP_SCOPE_ID;
  6590. exports.PUSH_SCOPE_ID = PUSH_SCOPE_ID;
  6591. exports.RENDER_LIST = RENDER_LIST;
  6592. exports.RENDER_SLOT = RENDER_SLOT;
  6593. exports.RESOLVE_COMPONENT = RESOLVE_COMPONENT;
  6594. exports.RESOLVE_DIRECTIVE = RESOLVE_DIRECTIVE;
  6595. exports.RESOLVE_DYNAMIC_COMPONENT = RESOLVE_DYNAMIC_COMPONENT;
  6596. exports.RESOLVE_FILTER = RESOLVE_FILTER;
  6597. exports.SET_BLOCK_TRACKING = SET_BLOCK_TRACKING;
  6598. exports.SUSPENSE = SUSPENSE;
  6599. exports.TELEPORT = TELEPORT;
  6600. exports.TO_DISPLAY_STRING = TO_DISPLAY_STRING;
  6601. exports.TO_HANDLERS = TO_HANDLERS;
  6602. exports.TO_HANDLER_KEY = TO_HANDLER_KEY;
  6603. exports.TRANSITION = TRANSITION;
  6604. exports.TRANSITION_GROUP = TRANSITION_GROUP;
  6605. exports.TS_NODE_TYPES = TS_NODE_TYPES;
  6606. exports.UNREF = UNREF;
  6607. exports.V_MODEL_CHECKBOX = V_MODEL_CHECKBOX;
  6608. exports.V_MODEL_DYNAMIC = V_MODEL_DYNAMIC;
  6609. exports.V_MODEL_RADIO = V_MODEL_RADIO;
  6610. exports.V_MODEL_SELECT = V_MODEL_SELECT;
  6611. exports.V_MODEL_TEXT = V_MODEL_TEXT;
  6612. exports.V_ON_WITH_KEYS = V_ON_WITH_KEYS;
  6613. exports.V_ON_WITH_MODIFIERS = V_ON_WITH_MODIFIERS;
  6614. exports.V_SHOW = V_SHOW;
  6615. exports.WITH_CTX = WITH_CTX;
  6616. exports.WITH_DIRECTIVES = WITH_DIRECTIVES;
  6617. exports.WITH_MEMO = WITH_MEMO;
  6618. exports.advancePositionWithClone = advancePositionWithClone;
  6619. exports.advancePositionWithMutation = advancePositionWithMutation;
  6620. exports.assert = assert;
  6621. exports.baseCompile = baseCompile;
  6622. exports.baseParse = baseParse;
  6623. exports.buildDirectiveArgs = buildDirectiveArgs;
  6624. exports.buildProps = buildProps;
  6625. exports.buildSlots = buildSlots;
  6626. exports.checkCompatEnabled = checkCompatEnabled;
  6627. exports.compile = compile;
  6628. exports.convertToBlock = convertToBlock;
  6629. exports.createArrayExpression = createArrayExpression;
  6630. exports.createAssignmentExpression = createAssignmentExpression;
  6631. exports.createBlockStatement = createBlockStatement;
  6632. exports.createCacheExpression = createCacheExpression;
  6633. exports.createCallExpression = createCallExpression;
  6634. exports.createCompilerError = createCompilerError;
  6635. exports.createCompoundExpression = createCompoundExpression;
  6636. exports.createConditionalExpression = createConditionalExpression;
  6637. exports.createDOMCompilerError = createDOMCompilerError;
  6638. exports.createForLoopParams = createForLoopParams;
  6639. exports.createFunctionExpression = createFunctionExpression;
  6640. exports.createIfStatement = createIfStatement;
  6641. exports.createInterpolation = createInterpolation;
  6642. exports.createObjectExpression = createObjectExpression;
  6643. exports.createObjectProperty = createObjectProperty;
  6644. exports.createReturnStatement = createReturnStatement;
  6645. exports.createRoot = createRoot;
  6646. exports.createSequenceExpression = createSequenceExpression;
  6647. exports.createSimpleExpression = createSimpleExpression;
  6648. exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
  6649. exports.createTemplateLiteral = createTemplateLiteral;
  6650. exports.createTransformContext = createTransformContext;
  6651. exports.createVNodeCall = createVNodeCall;
  6652. exports.errorMessages = errorMessages;
  6653. exports.extractIdentifiers = extractIdentifiers;
  6654. exports.findDir = findDir;
  6655. exports.findProp = findProp;
  6656. exports.forAliasRE = forAliasRE;
  6657. exports.generate = generate;
  6658. exports.generateCodeFrame = generateCodeFrame;
  6659. exports.getBaseTransformPreset = getBaseTransformPreset;
  6660. exports.getConstantType = getConstantType;
  6661. exports.getMemoedVNodeCall = getMemoedVNodeCall;
  6662. exports.getVNodeBlockHelper = getVNodeBlockHelper;
  6663. exports.getVNodeHelper = getVNodeHelper;
  6664. exports.hasDynamicKeyVBind = hasDynamicKeyVBind;
  6665. exports.hasScopeRef = hasScopeRef;
  6666. exports.helperNameMap = helperNameMap;
  6667. exports.injectProp = injectProp;
  6668. exports.isCoreComponent = isCoreComponent;
  6669. exports.isFnExpression = isFnExpression;
  6670. exports.isFnExpressionBrowser = isFnExpressionBrowser;
  6671. exports.isFnExpressionNode = isFnExpressionNode;
  6672. exports.isFunctionType = isFunctionType;
  6673. exports.isInDestructureAssignment = isInDestructureAssignment;
  6674. exports.isInNewExpression = isInNewExpression;
  6675. exports.isMemberExpression = isMemberExpression;
  6676. exports.isMemberExpressionBrowser = isMemberExpressionBrowser;
  6677. exports.isMemberExpressionNode = isMemberExpressionNode;
  6678. exports.isReferencedIdentifier = isReferencedIdentifier;
  6679. exports.isSimpleIdentifier = isSimpleIdentifier;
  6680. exports.isSlotOutlet = isSlotOutlet;
  6681. exports.isStaticArgOf = isStaticArgOf;
  6682. exports.isStaticExp = isStaticExp;
  6683. exports.isStaticProperty = isStaticProperty;
  6684. exports.isStaticPropertyKey = isStaticPropertyKey;
  6685. exports.isTemplateNode = isTemplateNode;
  6686. exports.isText = isText$1;
  6687. exports.isVPre = isVPre;
  6688. exports.isVSlot = isVSlot;
  6689. exports.locStub = locStub;
  6690. exports.noopDirectiveTransform = noopDirectiveTransform;
  6691. exports.parse = parse;
  6692. exports.parserOptions = parserOptions;
  6693. exports.processExpression = processExpression;
  6694. exports.processFor = processFor;
  6695. exports.processIf = processIf;
  6696. exports.processSlotOutlet = processSlotOutlet;
  6697. exports.registerRuntimeHelpers = registerRuntimeHelpers;
  6698. exports.resolveComponentType = resolveComponentType;
  6699. exports.stringifyExpression = stringifyExpression;
  6700. exports.toValidAssetId = toValidAssetId;
  6701. exports.trackSlotScopes = trackSlotScopes;
  6702. exports.trackVForSlotScopes = trackVForSlotScopes;
  6703. exports.transform = transform;
  6704. exports.transformBind = transformBind;
  6705. exports.transformElement = transformElement;
  6706. exports.transformExpression = transformExpression;
  6707. exports.transformModel = transformModel$1;
  6708. exports.transformOn = transformOn$1;
  6709. exports.transformStyle = transformStyle;
  6710. exports.traverseNode = traverseNode;
  6711. exports.unwrapTSNode = unwrapTSNode;
  6712. exports.walkBlockDeclarations = walkBlockDeclarations;
  6713. exports.walkFunctionParams = walkFunctionParams;
  6714. exports.walkIdentifiers = walkIdentifiers;
  6715. exports.warnDeprecation = warnDeprecation;
  6716. return exports;
  6717. })({});