compiler-dom.global.js 206 KB

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