compiler-core.esm-bundler.js 168 KB

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