compiler-core.cjs.prod.js 194 KB

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