compiler-core.cjs.js 198 KB

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