移动储能车V1版本
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

compiler-dom.global.js 198KB

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