compiler-dom.global.js 206 KB

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