compiler-core.esm-bundler.js 166 KB

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