compiler-core.cjs.js 201 KB

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