compiler-core.cjs.js 191 KB

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