compiler-dom.esm-browser.js 188 KB

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