compiler-dom.global.js 198 KB

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