compiler-core.cjs.prod.js 196 KB

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