compiler-dom.esm-browser.js 190 KB

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