vue-test-utils.esm-browser.js 477 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783
  1. /**
  2. * @vue/test-utils v2.4.5
  3. * (c) 2024 Lachlan Miller
  4. * Released under the MIT License
  5. */
  6. import * as Vue from 'vue';
  7. import { isRef, nextTick, setDevtoolsHook, Transition, BaseTransition, TransitionGroup, defineComponent, h, shallowReactive, reactive, ref, createApp, transformVNodeArgs, initDirectivesForSSR, createVNode, ssrContextKey, warn, Fragment, Static, Comment, Text, mergeProps, ssrUtils, computed } from 'vue';
  8. /******************************************************************************
  9. Copyright (c) Microsoft Corporation.
  10. Permission to use, copy, modify, and/or distribute this software for any
  11. purpose with or without fee is hereby granted.
  12. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  13. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  14. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  15. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  16. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  17. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  18. PERFORMANCE OF THIS SOFTWARE.
  19. ***************************************************************************** */
  20. /* global Reflect, Promise, SuppressedError, Symbol */
  21. var extendStatics = function(d, b) {
  22. extendStatics = Object.setPrototypeOf ||
  23. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  24. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  25. return extendStatics(d, b);
  26. };
  27. function __extends(d, b) {
  28. if (typeof b !== "function" && b !== null)
  29. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  30. extendStatics(d, b);
  31. function __() { this.constructor = d; }
  32. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  33. }
  34. var __assign = function() {
  35. __assign = Object.assign || function __assign(t) {
  36. for (var s, i = 1, n = arguments.length; i < n; i++) {
  37. s = arguments[i];
  38. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  39. }
  40. return t;
  41. };
  42. return __assign.apply(this, arguments);
  43. };
  44. function __awaiter(thisArg, _arguments, P, generator) {
  45. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  46. return new (P || (P = Promise))(function (resolve, reject) {
  47. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  48. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  49. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  50. step((generator = generator.apply(thisArg, _arguments || [])).next());
  51. });
  52. }
  53. function __generator(thisArg, body) {
  54. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  55. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  56. function verb(n) { return function (v) { return step([n, v]); }; }
  57. function step(op) {
  58. if (f) throw new TypeError("Generator is already executing.");
  59. while (g && (g = 0, op[0] && (_ = 0)), _) try {
  60. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  61. if (y = 0, t) op = [op[0] & 2, t.value];
  62. switch (op[0]) {
  63. case 0: case 1: t = op; break;
  64. case 4: _.label++; return { value: op[1], done: false };
  65. case 5: _.label++; y = op[1]; op = [0]; continue;
  66. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  67. default:
  68. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  69. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  70. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  71. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  72. if (t[2]) _.ops.pop();
  73. _.trys.pop(); continue;
  74. }
  75. op = body.call(thisArg, _);
  76. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  77. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  78. }
  79. }
  80. function __spreadArray(to, from, pack) {
  81. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  82. if (ar || !(i in from)) {
  83. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  84. ar[i] = from[i];
  85. }
  86. }
  87. return to.concat(ar || Array.prototype.slice.call(from));
  88. }
  89. typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
  90. var e = new Error(message);
  91. return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
  92. };
  93. var Pluggable = /** @class */ (function () {
  94. function Pluggable() {
  95. this.installedPlugins = [];
  96. }
  97. Pluggable.prototype.install = function (handler, options) {
  98. if (typeof handler !== 'function') {
  99. console.error('plugin.install must receive a function');
  100. handler = function () { return ({}); };
  101. }
  102. this.installedPlugins.push({ handler: handler, options: options });
  103. };
  104. Pluggable.prototype.extend = function (instance) {
  105. var invokeSetup = function (_a) {
  106. var handler = _a.handler, options = _a.options;
  107. return handler(instance, options); // invoke the setup method passed to install
  108. };
  109. var bindProperty = function (_a) {
  110. var property = _a[0], value = _a[1];
  111. instance[property] =
  112. typeof value === 'function' ? value.bind(instance) : value;
  113. };
  114. var addAllPropertiesFromSetup = function (setupResult) {
  115. setupResult = typeof setupResult === 'object' ? setupResult : {};
  116. Object.entries(setupResult).forEach(bindProperty);
  117. };
  118. this.installedPlugins.map(invokeSetup).forEach(addAllPropertiesFromSetup);
  119. };
  120. /** For testing */
  121. Pluggable.prototype.reset = function () {
  122. this.installedPlugins = [];
  123. };
  124. return Pluggable;
  125. }());
  126. var config = {
  127. global: {
  128. stubs: {
  129. transition: true,
  130. 'transition-group': true
  131. },
  132. provide: {},
  133. components: {},
  134. config: {},
  135. directives: {},
  136. mixins: [],
  137. mocks: {},
  138. plugins: [],
  139. renderStubDefaultSlot: false
  140. },
  141. plugins: {
  142. VueWrapper: new Pluggable(),
  143. DOMWrapper: new Pluggable()
  144. }
  145. };
  146. function mergeStubs(target, source) {
  147. if (source.stubs) {
  148. if (Array.isArray(source.stubs)) {
  149. source.stubs.forEach(function (x) { return (target[x] = true); });
  150. }
  151. else {
  152. for (var _i = 0, _a = Object.entries(source.stubs); _i < _a.length; _i++) {
  153. var _b = _a[_i], k = _b[0], v = _b[1];
  154. target[k] = v;
  155. }
  156. }
  157. }
  158. }
  159. // perform 1-level-deep-pseudo-clone merge in order to prevent config leaks
  160. // example: vue-router overwrites globalProperties.$router
  161. function mergeAppConfig(configGlobalConfig, mountGlobalConfig) {
  162. return __assign(__assign(__assign({}, configGlobalConfig), mountGlobalConfig), { globalProperties: __assign(__assign({}, configGlobalConfig === null || configGlobalConfig === void 0 ? void 0 : configGlobalConfig.globalProperties), mountGlobalConfig === null || mountGlobalConfig === void 0 ? void 0 : mountGlobalConfig.globalProperties) });
  163. }
  164. function mergeGlobalProperties(mountGlobal) {
  165. var _a, _b, _c;
  166. if (mountGlobal === void 0) { mountGlobal = {}; }
  167. var stubs = {};
  168. var configGlobal = (_a = config === null || config === void 0 ? void 0 : config.global) !== null && _a !== void 0 ? _a : {};
  169. mergeStubs(stubs, configGlobal);
  170. mergeStubs(stubs, mountGlobal);
  171. var renderStubDefaultSlot = (_c = (_b = mountGlobal.renderStubDefaultSlot) !== null && _b !== void 0 ? _b : (configGlobal.renderStubDefaultSlot || (config === null || config === void 0 ? void 0 : config.renderStubDefaultSlot))) !== null && _c !== void 0 ? _c : false;
  172. if (config.renderStubDefaultSlot === true) {
  173. console.warn('config.renderStubDefaultSlot is deprecated, use config.global.renderStubDefaultSlot instead');
  174. }
  175. return {
  176. mixins: __spreadArray(__spreadArray([], (configGlobal.mixins || []), true), (mountGlobal.mixins || []), true),
  177. plugins: __spreadArray(__spreadArray([], (configGlobal.plugins || []), true), (mountGlobal.plugins || []), true),
  178. stubs: stubs,
  179. components: __assign(__assign({}, configGlobal.components), mountGlobal.components),
  180. provide: __assign(__assign({}, configGlobal.provide), mountGlobal.provide),
  181. mocks: __assign(__assign({}, configGlobal.mocks), mountGlobal.mocks),
  182. config: mergeAppConfig(configGlobal.config, mountGlobal.config),
  183. directives: __assign(__assign({}, configGlobal.directives), mountGlobal.directives),
  184. renderStubDefaultSlot: renderStubDefaultSlot
  185. };
  186. }
  187. var isObject$1 = function (obj) {
  188. return !!obj && typeof obj === 'object';
  189. };
  190. function isClass(obj) {
  191. if (!(obj instanceof Object))
  192. return;
  193. var isCtorClass = obj.constructor && obj.constructor.toString().substring(0, 5) === 'class';
  194. if (!('prototype' in obj)) {
  195. return isCtorClass;
  196. }
  197. var prototype = obj.prototype;
  198. var isPrototypeCtorClass = prototype.constructor &&
  199. prototype.constructor.toString &&
  200. prototype.constructor.toString().substring(0, 5) === 'class';
  201. return isCtorClass || isPrototypeCtorClass;
  202. }
  203. // https://stackoverflow.com/a/48218209
  204. var mergeDeep = function (target, source) {
  205. var _a;
  206. if (!isObject$1(target) || !isObject$1(source)) {
  207. return source;
  208. }
  209. Object.keys(source)
  210. .concat(isClass(source)
  211. ? Object.getOwnPropertyNames((_a = Object.getPrototypeOf(source)) !== null && _a !== void 0 ? _a : {})
  212. : Object.getOwnPropertyNames(source))
  213. .forEach(function (key) {
  214. var targetValue = target[key];
  215. var sourceValue = source[key];
  216. if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
  217. target[key] = sourceValue;
  218. }
  219. else if (sourceValue instanceof Date) {
  220. target[key] = sourceValue;
  221. }
  222. else if (isObject$1(targetValue) && isObject$1(sourceValue)) {
  223. target[key] = mergeDeep(Object.assign({}, targetValue), sourceValue);
  224. }
  225. else {
  226. target[key] = sourceValue;
  227. }
  228. });
  229. return target;
  230. };
  231. function isClassComponent(component) {
  232. return typeof component === 'function' && '__vccOpts' in component;
  233. }
  234. function isComponent$1(component) {
  235. return Boolean(component &&
  236. (typeof component === 'object' || typeof component === 'function'));
  237. }
  238. function isFunctionalComponent(component) {
  239. return typeof component === 'function' && !isClassComponent(component);
  240. }
  241. function isObjectComponent(component) {
  242. return Boolean(component && typeof component === 'object');
  243. }
  244. function textContent(element) {
  245. var _a, _b;
  246. // we check if the element is a comment first
  247. // to return an empty string in that case, instead of the comment content
  248. return element.nodeType !== Node.COMMENT_NODE
  249. ? (_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : ''
  250. : '';
  251. }
  252. function hasOwnProperty(obj, prop) {
  253. return obj.hasOwnProperty(prop);
  254. }
  255. function isNotNullOrUndefined(obj) {
  256. return Boolean(obj);
  257. }
  258. function isRefSelector(selector) {
  259. return typeof selector === 'object' && 'ref' in selector;
  260. }
  261. function convertStubsToRecord(stubs) {
  262. if (Array.isArray(stubs)) {
  263. // ['Foo', 'Bar'] => { Foo: true, Bar: true }
  264. return stubs.reduce(function (acc, current) {
  265. acc[current] = true;
  266. return acc;
  267. }, {});
  268. }
  269. return stubs;
  270. }
  271. var isDirectiveKey = function (key) { return key.match(/^v[A-Z].*/); };
  272. function getComponentsFromStubs(stubs) {
  273. var normalizedStubs = convertStubsToRecord(stubs);
  274. return Object.fromEntries(Object.entries(normalizedStubs).filter(function (_a) {
  275. var key = _a[0];
  276. return !isDirectiveKey(key);
  277. }));
  278. }
  279. function getDirectivesFromStubs(stubs) {
  280. var normalizedStubs = convertStubsToRecord(stubs);
  281. return Object.fromEntries(Object.entries(normalizedStubs)
  282. .filter(function (_a) {
  283. var key = _a[0], value = _a[1];
  284. return isDirectiveKey(key) && value !== false;
  285. })
  286. .map(function (_a) {
  287. var key = _a[0], value = _a[1];
  288. return [key.substring(1), value];
  289. }));
  290. }
  291. function hasSetupState(vm) {
  292. return (vm &&
  293. vm.$.devtoolsRawSetupState);
  294. }
  295. function isScriptSetup(vm) {
  296. return (vm && vm.$.setupState.__isScriptSetup);
  297. }
  298. var _globalThis$1;
  299. var getGlobalThis$1 = function () {
  300. return (_globalThis$1 ||
  301. (_globalThis$1 =
  302. typeof globalThis !== 'undefined'
  303. ? globalThis
  304. : typeof self !== 'undefined'
  305. ? self
  306. : typeof window !== 'undefined'
  307. ? window
  308. : typeof global !== 'undefined'
  309. ? global
  310. : {}));
  311. };
  312. /**
  313. * Checks if the given value is a DeepRef.
  314. *
  315. * For both arrays and objects, it will recursively check
  316. * if any of their values is a Ref.
  317. *
  318. * @param {DeepRef<T> | unknown} r - The value to check.
  319. * @returns {boolean} Returns true if the value is a DeepRef, false otherwise.
  320. */
  321. var isDeepRef = function (r) {
  322. return isRef(r) || (isObject$1(r) && Object.values(r).some(isDeepRef));
  323. };
  324. var ignorableKeyModifiers = [
  325. 'stop',
  326. 'prevent',
  327. 'self',
  328. 'exact',
  329. 'prevent',
  330. 'capture'
  331. ];
  332. var systemKeyModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  333. var mouseKeyModifiers = ['left', 'middle', 'right'];
  334. var keyCodesByKeyName = {
  335. backspace: 8,
  336. tab: 9,
  337. enter: 13,
  338. esc: 27,
  339. space: 32,
  340. pageup: 33,
  341. pagedown: 34,
  342. end: 35,
  343. home: 36,
  344. left: 37,
  345. up: 38,
  346. right: 39,
  347. down: 40,
  348. insert: 45,
  349. delete: 46
  350. };
  351. var domEvents = {
  352. abort: {
  353. eventInterface: 'Event',
  354. bubbles: false,
  355. cancelable: false
  356. },
  357. afterprint: {
  358. eventInterface: 'Event',
  359. bubbles: false,
  360. cancelable: false
  361. },
  362. animationend: {
  363. eventInterface: 'AnimationEvent',
  364. bubbles: true,
  365. cancelable: false
  366. },
  367. animationiteration: {
  368. eventInterface: 'AnimationEvent',
  369. bubbles: true,
  370. cancelable: false
  371. },
  372. animationstart: {
  373. eventInterface: 'AnimationEvent',
  374. bubbles: true,
  375. cancelable: false
  376. },
  377. appinstalled: {
  378. eventInterface: 'Event',
  379. bubbles: false,
  380. cancelable: false
  381. },
  382. /**
  383. * @deprecated
  384. */
  385. audioprocess: {
  386. eventInterface: 'AudioProcessingEvent',
  387. bubbles: false,
  388. cancelable: false
  389. },
  390. audioend: {
  391. eventInterface: 'Event',
  392. bubbles: false,
  393. cancelable: false
  394. },
  395. audiostart: {
  396. eventInterface: 'Event',
  397. bubbles: false,
  398. cancelable: false
  399. },
  400. beforeprint: {
  401. eventInterface: 'Event',
  402. bubbles: false,
  403. cancelable: false
  404. },
  405. beforeunload: {
  406. eventInterface: 'BeforeUnloadEvent',
  407. bubbles: false,
  408. cancelable: true
  409. },
  410. beginEvent: {
  411. eventInterface: 'TimeEvent',
  412. bubbles: false,
  413. cancelable: false
  414. },
  415. blur: {
  416. eventInterface: 'FocusEvent',
  417. bubbles: false,
  418. cancelable: false
  419. },
  420. boundary: {
  421. eventInterface: 'SpeechSynthesisEvent',
  422. bubbles: false,
  423. cancelable: false
  424. },
  425. cached: {
  426. eventInterface: 'Event',
  427. bubbles: false,
  428. cancelable: false
  429. },
  430. canplay: {
  431. eventInterface: 'Event',
  432. bubbles: false,
  433. cancelable: false
  434. },
  435. canplaythrough: {
  436. eventInterface: 'Event',
  437. bubbles: false,
  438. cancelable: false
  439. },
  440. change: {
  441. eventInterface: 'Event',
  442. bubbles: true,
  443. cancelable: false
  444. },
  445. chargingchange: {
  446. eventInterface: 'Event',
  447. bubbles: false,
  448. cancelable: false
  449. },
  450. chargingtimechange: {
  451. eventInterface: 'Event',
  452. bubbles: false,
  453. cancelable: false
  454. },
  455. checking: {
  456. eventInterface: 'Event',
  457. bubbles: false,
  458. cancelable: false
  459. },
  460. click: {
  461. eventInterface: 'MouseEvent',
  462. bubbles: true,
  463. cancelable: true
  464. },
  465. close: {
  466. eventInterface: 'Event',
  467. bubbles: false,
  468. cancelable: false
  469. },
  470. complete: {
  471. eventInterface: 'OfflineAudioCompletionEvent',
  472. bubbles: false,
  473. cancelable: false
  474. },
  475. compositionend: {
  476. eventInterface: 'CompositionEvent',
  477. bubbles: true,
  478. cancelable: true
  479. },
  480. compositionstart: {
  481. eventInterface: 'CompositionEvent',
  482. bubbles: true,
  483. cancelable: true
  484. },
  485. compositionupdate: {
  486. eventInterface: 'CompositionEvent',
  487. bubbles: true,
  488. cancelable: false
  489. },
  490. contextmenu: {
  491. eventInterface: 'MouseEvent',
  492. bubbles: true,
  493. cancelable: true
  494. },
  495. copy: {
  496. eventInterface: 'ClipboardEvent',
  497. bubbles: true,
  498. cancelable: true
  499. },
  500. cut: {
  501. eventInterface: 'ClipboardEvent',
  502. bubbles: true,
  503. cancelable: true
  504. },
  505. dblclick: {
  506. eventInterface: 'MouseEvent',
  507. bubbles: true,
  508. cancelable: true
  509. },
  510. devicechange: {
  511. eventInterface: 'Event',
  512. bubbles: false,
  513. cancelable: false
  514. },
  515. devicelight: {
  516. eventInterface: 'DeviceLightEvent',
  517. bubbles: false,
  518. cancelable: false
  519. },
  520. devicemotion: {
  521. eventInterface: 'DeviceMotionEvent',
  522. bubbles: false,
  523. cancelable: false
  524. },
  525. deviceorientation: {
  526. eventInterface: 'DeviceOrientationEvent',
  527. bubbles: false,
  528. cancelable: false
  529. },
  530. deviceproximity: {
  531. eventInterface: 'DeviceProximityEvent',
  532. bubbles: false,
  533. cancelable: false
  534. },
  535. dischargingtimechange: {
  536. eventInterface: 'Event',
  537. bubbles: false,
  538. cancelable: false
  539. },
  540. DOMActivate: {
  541. eventInterface: 'UIEvent',
  542. bubbles: true,
  543. cancelable: true
  544. },
  545. DOMAttributeNameChanged: {
  546. eventInterface: 'MutationNameEvent',
  547. bubbles: true,
  548. cancelable: true
  549. },
  550. DOMAttrModified: {
  551. eventInterface: 'MutationEvent',
  552. bubbles: true,
  553. cancelable: true
  554. },
  555. DOMCharacterDataModified: {
  556. eventInterface: 'MutationEvent',
  557. bubbles: true,
  558. cancelable: true
  559. },
  560. DOMContentLoaded: {
  561. eventInterface: 'Event',
  562. bubbles: true,
  563. cancelable: true
  564. },
  565. DOMElementNameChanged: {
  566. eventInterface: 'MutationNameEvent',
  567. bubbles: true,
  568. cancelable: true
  569. },
  570. DOMFocusIn: {
  571. eventInterface: 'FocusEvent',
  572. bubbles: true,
  573. cancelable: true
  574. },
  575. DOMFocusOut: {
  576. eventInterface: 'FocusEvent',
  577. bubbles: true,
  578. cancelable: true
  579. },
  580. DOMNodeInserted: {
  581. eventInterface: 'MutationEvent',
  582. bubbles: true,
  583. cancelable: true
  584. },
  585. DOMNodeInsertedIntoDocument: {
  586. eventInterface: 'MutationEvent',
  587. bubbles: true,
  588. cancelable: true
  589. },
  590. DOMNodeRemoved: {
  591. eventInterface: 'MutationEvent',
  592. bubbles: true,
  593. cancelable: true
  594. },
  595. DOMNodeRemovedFromDocument: {
  596. eventInterface: 'MutationEvent',
  597. bubbles: true,
  598. cancelable: true
  599. },
  600. /**
  601. * @deprecated
  602. */
  603. DOMSubtreeModified: {
  604. eventInterface: 'MutationEvent',
  605. bubbles: true,
  606. cancelable: false
  607. },
  608. downloading: {
  609. eventInterface: 'Event',
  610. bubbles: false,
  611. cancelable: false
  612. },
  613. drag: {
  614. eventInterface: 'DragEvent',
  615. bubbles: true,
  616. cancelable: true
  617. },
  618. dragend: {
  619. eventInterface: 'DragEvent',
  620. bubbles: true,
  621. cancelable: false
  622. },
  623. dragenter: {
  624. eventInterface: 'DragEvent',
  625. bubbles: true,
  626. cancelable: true
  627. },
  628. dragleave: {
  629. eventInterface: 'DragEvent',
  630. bubbles: true,
  631. cancelable: false
  632. },
  633. dragover: {
  634. eventInterface: 'DragEvent',
  635. bubbles: true,
  636. cancelable: true
  637. },
  638. dragstart: {
  639. eventInterface: 'DragEvent',
  640. bubbles: true,
  641. cancelable: true
  642. },
  643. drop: {
  644. eventInterface: 'DragEvent',
  645. bubbles: true,
  646. cancelable: true
  647. },
  648. durationchange: {
  649. eventInterface: 'Event',
  650. bubbles: false,
  651. cancelable: false
  652. },
  653. emptied: {
  654. eventInterface: 'Event',
  655. bubbles: false,
  656. cancelable: false
  657. },
  658. end: {
  659. eventInterface: 'Event',
  660. bubbles: false,
  661. cancelable: false
  662. },
  663. ended: {
  664. eventInterface: 'Event',
  665. bubbles: false,
  666. cancelable: false
  667. },
  668. endEvent: {
  669. eventInterface: 'TimeEvent',
  670. bubbles: false,
  671. cancelable: false
  672. },
  673. error: {
  674. eventInterface: 'Event',
  675. bubbles: false,
  676. cancelable: false
  677. },
  678. focus: {
  679. eventInterface: 'FocusEvent',
  680. bubbles: false,
  681. cancelable: false
  682. },
  683. focusin: {
  684. eventInterface: 'FocusEvent',
  685. bubbles: true,
  686. cancelable: false
  687. },
  688. focusout: {
  689. eventInterface: 'FocusEvent',
  690. bubbles: true,
  691. cancelable: false
  692. },
  693. fullscreenchange: {
  694. eventInterface: 'Event',
  695. bubbles: true,
  696. cancelable: false
  697. },
  698. fullscreenerror: {
  699. eventInterface: 'Event',
  700. bubbles: true,
  701. cancelable: false
  702. },
  703. gamepadconnected: {
  704. eventInterface: 'GamepadEvent',
  705. bubbles: false,
  706. cancelable: false
  707. },
  708. gamepaddisconnected: {
  709. eventInterface: 'GamepadEvent',
  710. bubbles: false,
  711. cancelable: false
  712. },
  713. gotpointercapture: {
  714. eventInterface: 'PointerEvent',
  715. bubbles: false,
  716. cancelable: false
  717. },
  718. hashchange: {
  719. eventInterface: 'HashChangeEvent',
  720. bubbles: true,
  721. cancelable: false
  722. },
  723. lostpointercapture: {
  724. eventInterface: 'PointerEvent',
  725. bubbles: false,
  726. cancelable: false
  727. },
  728. input: {
  729. eventInterface: 'Event',
  730. bubbles: true,
  731. cancelable: false
  732. },
  733. invalid: {
  734. eventInterface: 'Event',
  735. cancelable: true,
  736. bubbles: false
  737. },
  738. keydown: {
  739. eventInterface: 'KeyboardEvent',
  740. bubbles: true,
  741. cancelable: true
  742. },
  743. keypress: {
  744. eventInterface: 'KeyboardEvent',
  745. bubbles: true,
  746. cancelable: true
  747. },
  748. keyup: {
  749. eventInterface: 'KeyboardEvent',
  750. bubbles: true,
  751. cancelable: true
  752. },
  753. languagechange: {
  754. eventInterface: 'Event',
  755. bubbles: false,
  756. cancelable: false
  757. },
  758. levelchange: {
  759. eventInterface: 'Event',
  760. bubbles: false,
  761. cancelable: false
  762. },
  763. load: {
  764. eventInterface: 'UIEvent',
  765. bubbles: false,
  766. cancelable: false
  767. },
  768. loadeddata: {
  769. eventInterface: 'Event',
  770. bubbles: false,
  771. cancelable: false
  772. },
  773. loadedmetadata: {
  774. eventInterface: 'Event',
  775. bubbles: false,
  776. cancelable: false
  777. },
  778. loadend: {
  779. eventInterface: 'ProgressEvent',
  780. bubbles: false,
  781. cancelable: false
  782. },
  783. loadstart: {
  784. eventInterface: 'ProgressEvent',
  785. bubbles: false,
  786. cancelable: false
  787. },
  788. mark: {
  789. eventInterface: 'SpeechSynthesisEvent',
  790. bubbles: false,
  791. cancelable: false
  792. },
  793. message: {
  794. eventInterface: 'MessageEvent',
  795. bubbles: false,
  796. cancelable: false
  797. },
  798. messageerror: {
  799. eventInterface: 'MessageEvent',
  800. bubbles: false,
  801. cancelable: false
  802. },
  803. mousedown: {
  804. eventInterface: 'MouseEvent',
  805. bubbles: true,
  806. cancelable: true
  807. },
  808. mouseenter: {
  809. eventInterface: 'MouseEvent',
  810. bubbles: false,
  811. cancelable: false
  812. },
  813. mouseleave: {
  814. eventInterface: 'MouseEvent',
  815. bubbles: false,
  816. cancelable: false
  817. },
  818. mousemove: {
  819. eventInterface: 'MouseEvent',
  820. bubbles: true,
  821. cancelable: true
  822. },
  823. mouseout: {
  824. eventInterface: 'MouseEvent',
  825. bubbles: true,
  826. cancelable: true
  827. },
  828. mouseover: {
  829. eventInterface: 'MouseEvent',
  830. bubbles: true,
  831. cancelable: true
  832. },
  833. mouseup: {
  834. eventInterface: 'MouseEvent',
  835. bubbles: true,
  836. cancelable: true
  837. },
  838. nomatch: {
  839. eventInterface: 'SpeechRecognitionEvent',
  840. bubbles: false,
  841. cancelable: false
  842. },
  843. notificationclick: {
  844. eventInterface: 'NotificationEvent',
  845. bubbles: false,
  846. cancelable: false
  847. },
  848. noupdate: {
  849. eventInterface: 'Event',
  850. bubbles: false,
  851. cancelable: false
  852. },
  853. obsolete: {
  854. eventInterface: 'Event',
  855. bubbles: false,
  856. cancelable: false
  857. },
  858. offline: {
  859. eventInterface: 'Event',
  860. bubbles: false,
  861. cancelable: false
  862. },
  863. online: {
  864. eventInterface: 'Event',
  865. bubbles: false,
  866. cancelable: false
  867. },
  868. open: {
  869. eventInterface: 'Event',
  870. bubbles: false,
  871. cancelable: false
  872. },
  873. orientationchange: {
  874. eventInterface: 'Event',
  875. bubbles: false,
  876. cancelable: false
  877. },
  878. pagehide: {
  879. eventInterface: 'PageTransitionEvent',
  880. bubbles: false,
  881. cancelable: false
  882. },
  883. pageshow: {
  884. eventInterface: 'PageTransitionEvent',
  885. bubbles: false,
  886. cancelable: false
  887. },
  888. paste: {
  889. eventInterface: 'ClipboardEvent',
  890. bubbles: true,
  891. cancelable: true
  892. },
  893. pause: {
  894. eventInterface: 'SpeechSynthesisEvent',
  895. bubbles: false,
  896. cancelable: false
  897. },
  898. pointercancel: {
  899. eventInterface: 'PointerEvent',
  900. bubbles: true,
  901. cancelable: false
  902. },
  903. pointerdown: {
  904. eventInterface: 'PointerEvent',
  905. bubbles: true,
  906. cancelable: true
  907. },
  908. pointerenter: {
  909. eventInterface: 'PointerEvent',
  910. bubbles: false,
  911. cancelable: false
  912. },
  913. pointerleave: {
  914. eventInterface: 'PointerEvent',
  915. bubbles: false,
  916. cancelable: false
  917. },
  918. pointerlockchange: {
  919. eventInterface: 'Event',
  920. bubbles: true,
  921. cancelable: false
  922. },
  923. pointerlockerror: {
  924. eventInterface: 'Event',
  925. bubbles: true,
  926. cancelable: false
  927. },
  928. pointermove: {
  929. eventInterface: 'PointerEvent',
  930. bubbles: true,
  931. cancelable: true
  932. },
  933. pointerout: {
  934. eventInterface: 'PointerEvent',
  935. bubbles: true,
  936. cancelable: true
  937. },
  938. pointerover: {
  939. eventInterface: 'PointerEvent',
  940. bubbles: true,
  941. cancelable: true
  942. },
  943. pointerup: {
  944. eventInterface: 'PointerEvent',
  945. bubbles: true,
  946. cancelable: true
  947. },
  948. play: {
  949. eventInterface: 'Event',
  950. bubbles: false,
  951. cancelable: false
  952. },
  953. playing: {
  954. eventInterface: 'Event',
  955. bubbles: false,
  956. cancelable: false
  957. },
  958. popstate: {
  959. eventInterface: 'PopStateEvent',
  960. bubbles: true,
  961. cancelable: false
  962. },
  963. progress: {
  964. eventInterface: 'ProgressEvent',
  965. bubbles: false,
  966. cancelable: false
  967. },
  968. push: {
  969. eventInterface: 'PushEvent',
  970. bubbles: false,
  971. cancelable: false
  972. },
  973. pushsubscriptionchange: {
  974. eventInterface: 'PushEvent',
  975. bubbles: false,
  976. cancelable: false
  977. },
  978. ratechange: {
  979. eventInterface: 'Event',
  980. bubbles: false,
  981. cancelable: false
  982. },
  983. readystatechange: {
  984. eventInterface: 'Event',
  985. bubbles: false,
  986. cancelable: false
  987. },
  988. repeatEvent: {
  989. eventInterface: 'TimeEvent',
  990. bubbles: false,
  991. cancelable: false
  992. },
  993. reset: {
  994. eventInterface: 'Event',
  995. bubbles: true,
  996. cancelable: true
  997. },
  998. resize: {
  999. eventInterface: 'UIEvent',
  1000. bubbles: false,
  1001. cancelable: false
  1002. },
  1003. resourcetimingbufferfull: {
  1004. eventInterface: 'Performance',
  1005. bubbles: true,
  1006. cancelable: true
  1007. },
  1008. result: {
  1009. eventInterface: 'SpeechRecognitionEvent',
  1010. bubbles: false,
  1011. cancelable: false
  1012. },
  1013. resume: {
  1014. eventInterface: 'SpeechSynthesisEvent',
  1015. bubbles: false,
  1016. cancelable: false
  1017. },
  1018. scroll: {
  1019. eventInterface: 'UIEvent',
  1020. bubbles: false,
  1021. cancelable: false
  1022. },
  1023. seeked: {
  1024. eventInterface: 'Event',
  1025. bubbles: false,
  1026. cancelable: false
  1027. },
  1028. seeking: {
  1029. eventInterface: 'Event',
  1030. bubbles: false,
  1031. cancelable: false
  1032. },
  1033. select: {
  1034. eventInterface: 'UIEvent',
  1035. bubbles: true,
  1036. cancelable: false
  1037. },
  1038. selectstart: {
  1039. eventInterface: 'Event',
  1040. bubbles: true,
  1041. cancelable: true
  1042. },
  1043. selectionchange: {
  1044. eventInterface: 'Event',
  1045. bubbles: false,
  1046. cancelable: false
  1047. },
  1048. show: {
  1049. eventInterface: 'MouseEvent',
  1050. bubbles: false,
  1051. cancelable: false
  1052. },
  1053. slotchange: {
  1054. eventInterface: 'Event',
  1055. bubbles: true,
  1056. cancelable: false
  1057. },
  1058. soundend: {
  1059. eventInterface: 'Event',
  1060. bubbles: false,
  1061. cancelable: false
  1062. },
  1063. soundstart: {
  1064. eventInterface: 'Event',
  1065. bubbles: false,
  1066. cancelable: false
  1067. },
  1068. speechend: {
  1069. eventInterface: 'Event',
  1070. bubbles: false,
  1071. cancelable: false
  1072. },
  1073. speechstart: {
  1074. eventInterface: 'Event',
  1075. bubbles: false,
  1076. cancelable: false
  1077. },
  1078. stalled: {
  1079. eventInterface: 'Event',
  1080. bubbles: false,
  1081. cancelable: false
  1082. },
  1083. start: {
  1084. eventInterface: 'SpeechSynthesisEvent',
  1085. bubbles: false,
  1086. cancelable: false
  1087. },
  1088. storage: {
  1089. eventInterface: 'StorageEvent',
  1090. bubbles: false,
  1091. cancelable: false
  1092. },
  1093. submit: {
  1094. eventInterface: 'Event',
  1095. bubbles: true,
  1096. cancelable: true
  1097. },
  1098. success: {
  1099. eventInterface: 'Event',
  1100. bubbles: false,
  1101. cancelable: false
  1102. },
  1103. suspend: {
  1104. eventInterface: 'Event',
  1105. bubbles: false,
  1106. cancelable: false
  1107. },
  1108. SVGAbort: {
  1109. eventInterface: 'SVGEvent',
  1110. bubbles: true,
  1111. cancelable: false
  1112. },
  1113. SVGError: {
  1114. eventInterface: 'SVGEvent',
  1115. bubbles: true,
  1116. cancelable: false
  1117. },
  1118. SVGLoad: {
  1119. eventInterface: 'SVGEvent',
  1120. bubbles: false,
  1121. cancelable: false
  1122. },
  1123. SVGResize: {
  1124. eventInterface: 'SVGEvent',
  1125. bubbles: true,
  1126. cancelable: false
  1127. },
  1128. SVGScroll: {
  1129. eventInterface: 'SVGEvent',
  1130. bubbles: true,
  1131. cancelable: false
  1132. },
  1133. SVGUnload: {
  1134. eventInterface: 'SVGEvent',
  1135. bubbles: false,
  1136. cancelable: false
  1137. },
  1138. SVGZoom: {
  1139. eventInterface: 'SVGZoomEvent',
  1140. bubbles: true,
  1141. cancelable: false
  1142. },
  1143. timeout: {
  1144. eventInterface: 'ProgressEvent',
  1145. bubbles: false,
  1146. cancelable: false
  1147. },
  1148. timeupdate: {
  1149. eventInterface: 'Event',
  1150. bubbles: false,
  1151. cancelable: false
  1152. },
  1153. touchcancel: {
  1154. eventInterface: 'TouchEvent',
  1155. bubbles: true,
  1156. cancelable: false
  1157. },
  1158. touchend: {
  1159. eventInterface: 'TouchEvent',
  1160. bubbles: true,
  1161. cancelable: true
  1162. },
  1163. touchmove: {
  1164. eventInterface: 'TouchEvent',
  1165. bubbles: true,
  1166. cancelable: true
  1167. },
  1168. touchstart: {
  1169. eventInterface: 'TouchEvent',
  1170. bubbles: true,
  1171. cancelable: true
  1172. },
  1173. transitionend: {
  1174. eventInterface: 'TransitionEvent',
  1175. bubbles: true,
  1176. cancelable: true
  1177. },
  1178. unload: {
  1179. eventInterface: 'UIEvent',
  1180. bubbles: false,
  1181. cancelable: false
  1182. },
  1183. updateready: {
  1184. eventInterface: 'Event',
  1185. bubbles: false,
  1186. cancelable: false
  1187. },
  1188. userproximity: {
  1189. eventInterface: 'UserProximityEvent',
  1190. bubbles: false,
  1191. cancelable: false
  1192. },
  1193. voiceschanged: {
  1194. eventInterface: 'Event',
  1195. bubbles: false,
  1196. cancelable: false
  1197. },
  1198. visibilitychange: {
  1199. eventInterface: 'Event',
  1200. bubbles: true,
  1201. cancelable: false
  1202. },
  1203. volumechange: {
  1204. eventInterface: 'Event',
  1205. bubbles: false,
  1206. cancelable: false
  1207. },
  1208. waiting: {
  1209. eventInterface: 'Event',
  1210. bubbles: false,
  1211. cancelable: false
  1212. },
  1213. wheel: {
  1214. eventInterface: 'WheelEvent',
  1215. bubbles: true,
  1216. cancelable: true
  1217. }
  1218. };
  1219. /**
  1220. * Groups modifiers into lists
  1221. */
  1222. function generateModifiers(modifiers, isOnClick) {
  1223. var keyModifiers = [];
  1224. var systemModifiers = [];
  1225. for (var i = 0; i < modifiers.length; i++) {
  1226. var modifier = modifiers[i];
  1227. // addEventListener() options, e.g. .passive & .capture, that we dont need to handle
  1228. if (ignorableKeyModifiers.includes(modifier)) {
  1229. continue;
  1230. }
  1231. // modifiers that require special conversion
  1232. // if passed a left/right key modifier with onClick, add it here as well.
  1233. if (systemKeyModifiers.includes(modifier) ||
  1234. (mouseKeyModifiers.includes(modifier) &&
  1235. isOnClick)) {
  1236. systemModifiers.push(modifier);
  1237. }
  1238. else {
  1239. keyModifiers.push(modifier);
  1240. }
  1241. }
  1242. return {
  1243. keyModifiers: keyModifiers,
  1244. systemModifiers: systemModifiers
  1245. };
  1246. }
  1247. function getEventProperties(eventParams) {
  1248. var modifiers = eventParams.modifiers, _a = eventParams.options, options = _a === void 0 ? {} : _a, eventType = eventParams.eventType;
  1249. var isOnClick = eventType === 'click';
  1250. var _b = generateModifiers(modifiers, isOnClick), keyModifiers = _b.keyModifiers, systemModifiers = _b.systemModifiers;
  1251. if (isOnClick) {
  1252. // if it's a right click, it should fire a `contextmenu` event
  1253. if (systemModifiers.includes('right')) {
  1254. eventType = 'contextmenu';
  1255. options.button = 2;
  1256. // if its a middle click, fire a `mouseup` event
  1257. }
  1258. else if (systemModifiers.includes('middle')) {
  1259. eventType = 'mouseup';
  1260. options.button = 1;
  1261. }
  1262. }
  1263. var meta = domEvents[eventType] || {
  1264. eventInterface: 'Event',
  1265. cancelable: true,
  1266. bubbles: true
  1267. };
  1268. // convert `shift, ctrl` to `shiftKey, ctrlKey`
  1269. // allows trigger('keydown.shift.ctrl.n') directly
  1270. var systemModifiersMeta = systemModifiers.reduce(function (all, key) {
  1271. all["".concat(key, "Key")] = true;
  1272. return all;
  1273. }, {});
  1274. // get the keyCode for backwards compat
  1275. var keyCode = keyCodesByKeyName[keyModifiers[0]] ||
  1276. (options && (options.keyCode || options.code));
  1277. var eventProperties = __assign(__assign(__assign(__assign({}, systemModifiersMeta), options), { bubbles: meta.bubbles, cancelable: meta.cancelable,
  1278. // Any derived options should go here
  1279. keyCode: keyCode, code: keyCode }), (keyModifiers[0] ? { key: keyModifiers[0] } : {}));
  1280. return {
  1281. eventProperties: eventProperties,
  1282. meta: meta,
  1283. eventType: eventType
  1284. };
  1285. }
  1286. function createEvent(eventParams) {
  1287. var _a = getEventProperties(eventParams), eventProperties = _a.eventProperties, meta = _a.meta, eventType = _a.eventType;
  1288. // user defined eventInterface
  1289. var eventInterface = meta.eventInterface;
  1290. var metaEventInterface = window[eventInterface];
  1291. var SupportedEventInterface = typeof metaEventInterface === 'function' ? metaEventInterface : window.Event;
  1292. return new SupportedEventInterface(eventType,
  1293. // event properties can only be added when the event is instantiated
  1294. // custom properties must be added after the event has been instantiated
  1295. eventProperties);
  1296. }
  1297. function createDOMEvent(eventString, options) {
  1298. // split eventString like `keydown.ctrl.shift` into `keydown` and array of modifiers
  1299. var _a = eventString.split('.'), eventType = _a[0], modifiers = _a.slice(1);
  1300. var eventParams = {
  1301. eventType: eventType,
  1302. modifiers: modifiers,
  1303. options: options
  1304. };
  1305. var event = createEvent(eventParams);
  1306. var eventPrototype = Object.getPrototypeOf(event);
  1307. // attach custom options to the event, like `relatedTarget` and so on.
  1308. options &&
  1309. Object.keys(options).forEach(function (key) {
  1310. var propertyDescriptor = Object.getOwnPropertyDescriptor(eventPrototype, key);
  1311. var canSetProperty = !(propertyDescriptor && propertyDescriptor.set === undefined);
  1312. if (canSetProperty) {
  1313. event[key] = options[key];
  1314. }
  1315. });
  1316. return event;
  1317. }
  1318. // Stubbing occurs when in vnode transformer we're swapping
  1319. // component vnode type due to stubbing either component
  1320. // or directive on component
  1321. // In order to be able to find components we need to track pairs
  1322. // stub --> original component
  1323. // Having this as global might feel unsafe at first point
  1324. // One can assume that sharing stub map across mounts might
  1325. // lead to false matches, however our vnode mappers always
  1326. // produce new nodeTypes for each mount even if you're reusing
  1327. // same stub, so we're safe and do not need to pass these stubs
  1328. // for each mount operation
  1329. var stubs = new WeakMap();
  1330. function registerStub(_a) {
  1331. var source = _a.source, stub = _a.stub;
  1332. stubs.set(stub, source);
  1333. }
  1334. function getOriginalComponentFromStub(stub) {
  1335. return stubs.get(stub);
  1336. }
  1337. var cacheStringFunction$1 = function (fn) {
  1338. var cache = Object.create(null);
  1339. return (function (str) {
  1340. var hit = cache[str];
  1341. return hit || (cache[str] = fn(str));
  1342. });
  1343. };
  1344. var camelizeRE$1 = /-(\w)/g;
  1345. var camelize$1 = cacheStringFunction$1(function (str) {
  1346. return str.replace(camelizeRE$1, function (_, c) { return (c ? c.toUpperCase() : ''); });
  1347. });
  1348. var capitalize$1 = cacheStringFunction$1(function (str) {
  1349. return str.charAt(0).toUpperCase() + str.slice(1);
  1350. });
  1351. var hyphenateRE$1 = /\B([A-Z])/g;
  1352. var hyphenate$1 = cacheStringFunction$1(function (str) {
  1353. return str.replace(hyphenateRE$1, '-$1').toLowerCase();
  1354. });
  1355. function matchName(target, sourceName) {
  1356. var camelized = camelize$1(target);
  1357. var capitalized = capitalize$1(camelized);
  1358. return (!!sourceName &&
  1359. (sourceName === target ||
  1360. sourceName === camelized ||
  1361. sourceName === capitalized ||
  1362. capitalize$1(camelize$1(sourceName)) === capitalized));
  1363. }
  1364. function isCompatEnabled$1(key) {
  1365. var _a, _b;
  1366. return (_b = (_a = Vue.compatUtils) === null || _a === void 0 ? void 0 : _a.isCompatEnabled(key)) !== null && _b !== void 0 ? _b : false;
  1367. }
  1368. function isLegacyExtendedComponent(component) {
  1369. if (!isCompatEnabled$1('GLOBAL_EXTEND') || typeof component !== 'function') {
  1370. return false;
  1371. }
  1372. return (hasOwnProperty(component, 'super') &&
  1373. component.super.extend({}).super === component.super);
  1374. }
  1375. function unwrapLegacyVueExtendComponent(selector) {
  1376. return isLegacyExtendedComponent(selector) ? selector.options : selector;
  1377. }
  1378. function isLegacyFunctionalComponent(component) {
  1379. return Boolean(component &&
  1380. typeof component === 'object' &&
  1381. hasOwnProperty(component, 'functional') &&
  1382. component.functional);
  1383. }
  1384. var getComponentNameInSetup = function (instance, type) {
  1385. return Object.keys((instance === null || instance === void 0 ? void 0 : instance.setupState) || {}).find(function (key) { var _a; return ((_a = Object.getOwnPropertyDescriptor(instance.setupState, key)) === null || _a === void 0 ? void 0 : _a.value) === type; });
  1386. };
  1387. var getComponentRegisteredName = function (instance, type) {
  1388. if (!instance || !instance.parent)
  1389. return null;
  1390. // try to infer the name based on local resolution
  1391. var registry = instance.type.components;
  1392. for (var key in registry) {
  1393. if (registry[key] === type) {
  1394. return key;
  1395. }
  1396. }
  1397. // try to retrieve name imported in script setup
  1398. return getComponentNameInSetup(instance.parent, type) || null;
  1399. };
  1400. var getComponentName = function (instance, type) {
  1401. if (isObjectComponent(type)) {
  1402. return (
  1403. // If the component we stub is a script setup component and is automatically
  1404. // imported by unplugin-vue-components we can only get its name through
  1405. // the `__name` property.
  1406. getComponentNameInSetup(instance, type) || type.name || type.__name || '');
  1407. }
  1408. if (isLegacyExtendedComponent(type)) {
  1409. return unwrapLegacyVueExtendComponent(type).name || '';
  1410. }
  1411. if (isFunctionalComponent(type)) {
  1412. return type.displayName || type.name;
  1413. }
  1414. return '';
  1415. };
  1416. /**
  1417. * Detect whether a selector matches a VNode
  1418. * @param node
  1419. * @param selector
  1420. * @return {boolean | ((value: any) => boolean)}
  1421. */
  1422. function matches(node, rawSelector) {
  1423. var _a, _b, _c;
  1424. var selector = unwrapLegacyVueExtendComponent(rawSelector);
  1425. // do not return none Vue components
  1426. if (!node.component)
  1427. return false;
  1428. var nodeType = node.type;
  1429. if (!isComponent$1(nodeType))
  1430. return false;
  1431. if (typeof selector === 'string') {
  1432. return (_b = (_a = node.el) === null || _a === void 0 ? void 0 : _a.matches) === null || _b === void 0 ? void 0 : _b.call(_a, selector);
  1433. }
  1434. // When we're using stubs we want user to be able to
  1435. // find stubbed components both by original component
  1436. // or stub definition. That's why we are trying to
  1437. // extract original component and also stub, which was
  1438. // used to create specialized stub for render
  1439. var nodeTypeCandidates = [
  1440. nodeType,
  1441. getOriginalComponentFromStub(nodeType)
  1442. ].filter(Boolean);
  1443. // our selector might be a stub itself
  1444. var target = (_c = getOriginalComponentFromStub(selector)) !== null && _c !== void 0 ? _c : selector;
  1445. if (nodeTypeCandidates.includes(target)) {
  1446. return true;
  1447. }
  1448. var componentName;
  1449. componentName = getComponentName(node.component, nodeType);
  1450. var selectorName = selector.name;
  1451. // the component and selector both have a name
  1452. if (componentName && selectorName) {
  1453. return matchName(selectorName, componentName);
  1454. }
  1455. componentName =
  1456. getComponentRegisteredName(node.component, nodeType) || undefined;
  1457. // if a name is missing, then check the locally registered components in the parent
  1458. if (node.component.parent) {
  1459. var registry = node.component.parent.type.components;
  1460. for (var key in registry) {
  1461. // is it the selector
  1462. if (!selectorName && registry[key] === selector) {
  1463. selectorName = key;
  1464. }
  1465. // is it the component
  1466. if (!componentName && registry[key] === nodeType) {
  1467. componentName = key;
  1468. }
  1469. }
  1470. }
  1471. if (selectorName && componentName) {
  1472. return matchName(selectorName, componentName);
  1473. }
  1474. return false;
  1475. }
  1476. /**
  1477. * Filters out the null, undefined and primitive values,
  1478. * to only keep VNode and VNodeArrayChildren values
  1479. * @param value
  1480. */
  1481. function nodesAsObject(value) {
  1482. return !!value && typeof value === 'object';
  1483. }
  1484. /**
  1485. * Collect all children
  1486. * @param nodes
  1487. * @param children
  1488. */
  1489. function aggregateChildren(nodes, children) {
  1490. if (children && Array.isArray(children)) {
  1491. var reversedNodes = __spreadArray([], children, true).reverse().filter(nodesAsObject);
  1492. reversedNodes.forEach(function (node) {
  1493. if (Array.isArray(node)) {
  1494. aggregateChildren(nodes, node);
  1495. }
  1496. else {
  1497. nodes.unshift(node);
  1498. }
  1499. });
  1500. }
  1501. }
  1502. function findAllVNodes(vnode, selector) {
  1503. var matchingNodes = [];
  1504. var nodes = [vnode];
  1505. while (nodes.length) {
  1506. var node = nodes.shift();
  1507. aggregateChildren(nodes, node.children);
  1508. if (node.component) {
  1509. aggregateChildren(nodes, [node.component.subTree]);
  1510. }
  1511. if (node.suspense) {
  1512. // match children if component is Suspense
  1513. var activeBranch = node.suspense.activeBranch;
  1514. aggregateChildren(nodes, [activeBranch]);
  1515. }
  1516. if (matches(node, selector) && !matchingNodes.includes(node)) {
  1517. matchingNodes.push(node);
  1518. }
  1519. }
  1520. return matchingNodes;
  1521. }
  1522. function find(root, selector) {
  1523. var matchingVNodes = findAllVNodes(root, selector);
  1524. if (typeof selector === 'string') {
  1525. // When searching by CSS selector we want only one (topmost) vnode for each el`
  1526. matchingVNodes = matchingVNodes.filter(function (vnode) { var _a; return ((_a = vnode.component.parent) === null || _a === void 0 ? void 0 : _a.vnode.el) !== vnode.el; });
  1527. }
  1528. return matchingVNodes.map(function (vnode) { return vnode.component; });
  1529. }
  1530. function createWrapperError(wrapperType) {
  1531. return new Proxy(Object.create(null), {
  1532. get: function (obj, prop) {
  1533. switch (prop) {
  1534. case 'then':
  1535. // allows for better errors when wrapping `find` in `await`
  1536. // https://github.com/vuejs/test-utils/issues/638
  1537. return;
  1538. case 'exists':
  1539. return function () { return false; };
  1540. default:
  1541. throw new Error("Cannot call ".concat(String(prop), " on an empty ").concat(wrapperType, "."));
  1542. }
  1543. }
  1544. });
  1545. }
  1546. /*!
  1547. * isElementVisible
  1548. * Adapted from https://github.com/testing-library/jest-dom
  1549. * Licensed under the MIT License.
  1550. */
  1551. function isStyleVisible(element) {
  1552. if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) {
  1553. return false;
  1554. }
  1555. var _a = getComputedStyle(element), display = _a.display, visibility = _a.visibility, opacity = _a.opacity;
  1556. return (display !== 'none' &&
  1557. visibility !== 'hidden' &&
  1558. visibility !== 'collapse' &&
  1559. opacity !== '0');
  1560. }
  1561. function isAttributeVisible(element) {
  1562. return (!element.hasAttribute('hidden') &&
  1563. (element.nodeName === 'DETAILS' ? element.hasAttribute('open') : true));
  1564. }
  1565. function isElementVisible(element) {
  1566. return (element.nodeName !== '#comment' &&
  1567. isStyleVisible(element) &&
  1568. isAttributeVisible(element) &&
  1569. (!element.parentElement || isElementVisible(element.parentElement)));
  1570. }
  1571. function isElement(element) {
  1572. return element instanceof Element;
  1573. }
  1574. var WrapperType;
  1575. (function (WrapperType) {
  1576. WrapperType[WrapperType["DOMWrapper"] = 0] = "DOMWrapper";
  1577. WrapperType[WrapperType["VueWrapper"] = 1] = "VueWrapper";
  1578. })(WrapperType || (WrapperType = {}));
  1579. var factories = {};
  1580. function registerFactory(type, fn) {
  1581. factories[type] = fn;
  1582. }
  1583. var createDOMWrapper = function (element) {
  1584. return factories[WrapperType.DOMWrapper](element);
  1585. };
  1586. var createVueWrapper = function (app, vm, setProps) {
  1587. return factories[WrapperType.VueWrapper](app, vm, setProps);
  1588. };
  1589. function stringifyNode(node) {
  1590. return node instanceof Element
  1591. ? node.outerHTML
  1592. : new XMLSerializer().serializeToString(node);
  1593. }
  1594. function getDefaultExportFromCjs (x) {
  1595. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  1596. }
  1597. var js = {exports: {}};
  1598. var src = {};
  1599. var javascript = {exports: {}};
  1600. var beautifier$2 = {};
  1601. var output = {};
  1602. /*jshint node:true */
  1603. var hasRequiredOutput;
  1604. function requireOutput () {
  1605. if (hasRequiredOutput) return output;
  1606. hasRequiredOutput = 1;
  1607. function OutputLine(parent) {
  1608. this.__parent = parent;
  1609. this.__character_count = 0;
  1610. // use indent_count as a marker for this.__lines that have preserved indentation
  1611. this.__indent_count = -1;
  1612. this.__alignment_count = 0;
  1613. this.__wrap_point_index = 0;
  1614. this.__wrap_point_character_count = 0;
  1615. this.__wrap_point_indent_count = -1;
  1616. this.__wrap_point_alignment_count = 0;
  1617. this.__items = [];
  1618. }
  1619. OutputLine.prototype.clone_empty = function() {
  1620. var line = new OutputLine(this.__parent);
  1621. line.set_indent(this.__indent_count, this.__alignment_count);
  1622. return line;
  1623. };
  1624. OutputLine.prototype.item = function(index) {
  1625. if (index < 0) {
  1626. return this.__items[this.__items.length + index];
  1627. } else {
  1628. return this.__items[index];
  1629. }
  1630. };
  1631. OutputLine.prototype.has_match = function(pattern) {
  1632. for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
  1633. if (this.__items[lastCheckedOutput].match(pattern)) {
  1634. return true;
  1635. }
  1636. }
  1637. return false;
  1638. };
  1639. OutputLine.prototype.set_indent = function(indent, alignment) {
  1640. if (this.is_empty()) {
  1641. this.__indent_count = indent || 0;
  1642. this.__alignment_count = alignment || 0;
  1643. this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
  1644. }
  1645. };
  1646. OutputLine.prototype._set_wrap_point = function() {
  1647. if (this.__parent.wrap_line_length) {
  1648. this.__wrap_point_index = this.__items.length;
  1649. this.__wrap_point_character_count = this.__character_count;
  1650. this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
  1651. this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
  1652. }
  1653. };
  1654. OutputLine.prototype._should_wrap = function() {
  1655. return this.__wrap_point_index &&
  1656. this.__character_count > this.__parent.wrap_line_length &&
  1657. this.__wrap_point_character_count > this.__parent.next_line.__character_count;
  1658. };
  1659. OutputLine.prototype._allow_wrap = function() {
  1660. if (this._should_wrap()) {
  1661. this.__parent.add_new_line();
  1662. var next = this.__parent.current_line;
  1663. next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
  1664. next.__items = this.__items.slice(this.__wrap_point_index);
  1665. this.__items = this.__items.slice(0, this.__wrap_point_index);
  1666. next.__character_count += this.__character_count - this.__wrap_point_character_count;
  1667. this.__character_count = this.__wrap_point_character_count;
  1668. if (next.__items[0] === " ") {
  1669. next.__items.splice(0, 1);
  1670. next.__character_count -= 1;
  1671. }
  1672. return true;
  1673. }
  1674. return false;
  1675. };
  1676. OutputLine.prototype.is_empty = function() {
  1677. return this.__items.length === 0;
  1678. };
  1679. OutputLine.prototype.last = function() {
  1680. if (!this.is_empty()) {
  1681. return this.__items[this.__items.length - 1];
  1682. } else {
  1683. return null;
  1684. }
  1685. };
  1686. OutputLine.prototype.push = function(item) {
  1687. this.__items.push(item);
  1688. var last_newline_index = item.lastIndexOf('\n');
  1689. if (last_newline_index !== -1) {
  1690. this.__character_count = item.length - last_newline_index;
  1691. } else {
  1692. this.__character_count += item.length;
  1693. }
  1694. };
  1695. OutputLine.prototype.pop = function() {
  1696. var item = null;
  1697. if (!this.is_empty()) {
  1698. item = this.__items.pop();
  1699. this.__character_count -= item.length;
  1700. }
  1701. return item;
  1702. };
  1703. OutputLine.prototype._remove_indent = function() {
  1704. if (this.__indent_count > 0) {
  1705. this.__indent_count -= 1;
  1706. this.__character_count -= this.__parent.indent_size;
  1707. }
  1708. };
  1709. OutputLine.prototype._remove_wrap_indent = function() {
  1710. if (this.__wrap_point_indent_count > 0) {
  1711. this.__wrap_point_indent_count -= 1;
  1712. }
  1713. };
  1714. OutputLine.prototype.trim = function() {
  1715. while (this.last() === ' ') {
  1716. this.__items.pop();
  1717. this.__character_count -= 1;
  1718. }
  1719. };
  1720. OutputLine.prototype.toString = function() {
  1721. var result = '';
  1722. if (this.is_empty()) {
  1723. if (this.__parent.indent_empty_lines) {
  1724. result = this.__parent.get_indent_string(this.__indent_count);
  1725. }
  1726. } else {
  1727. result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
  1728. result += this.__items.join('');
  1729. }
  1730. return result;
  1731. };
  1732. function IndentStringCache(options, baseIndentString) {
  1733. this.__cache = [''];
  1734. this.__indent_size = options.indent_size;
  1735. this.__indent_string = options.indent_char;
  1736. if (!options.indent_with_tabs) {
  1737. this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
  1738. }
  1739. // Set to null to continue support for auto detection of base indent
  1740. baseIndentString = baseIndentString || '';
  1741. if (options.indent_level > 0) {
  1742. baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
  1743. }
  1744. this.__base_string = baseIndentString;
  1745. this.__base_string_length = baseIndentString.length;
  1746. }
  1747. IndentStringCache.prototype.get_indent_size = function(indent, column) {
  1748. var result = this.__base_string_length;
  1749. column = column || 0;
  1750. if (indent < 0) {
  1751. result = 0;
  1752. }
  1753. result += indent * this.__indent_size;
  1754. result += column;
  1755. return result;
  1756. };
  1757. IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
  1758. var result = this.__base_string;
  1759. column = column || 0;
  1760. if (indent_level < 0) {
  1761. indent_level = 0;
  1762. result = '';
  1763. }
  1764. column += indent_level * this.__indent_size;
  1765. this.__ensure_cache(column);
  1766. result += this.__cache[column];
  1767. return result;
  1768. };
  1769. IndentStringCache.prototype.__ensure_cache = function(column) {
  1770. while (column >= this.__cache.length) {
  1771. this.__add_column();
  1772. }
  1773. };
  1774. IndentStringCache.prototype.__add_column = function() {
  1775. var column = this.__cache.length;
  1776. var indent = 0;
  1777. var result = '';
  1778. if (this.__indent_size && column >= this.__indent_size) {
  1779. indent = Math.floor(column / this.__indent_size);
  1780. column -= indent * this.__indent_size;
  1781. result = new Array(indent + 1).join(this.__indent_string);
  1782. }
  1783. if (column) {
  1784. result += new Array(column + 1).join(' ');
  1785. }
  1786. this.__cache.push(result);
  1787. };
  1788. function Output(options, baseIndentString) {
  1789. this.__indent_cache = new IndentStringCache(options, baseIndentString);
  1790. this.raw = false;
  1791. this._end_with_newline = options.end_with_newline;
  1792. this.indent_size = options.indent_size;
  1793. this.wrap_line_length = options.wrap_line_length;
  1794. this.indent_empty_lines = options.indent_empty_lines;
  1795. this.__lines = [];
  1796. this.previous_line = null;
  1797. this.current_line = null;
  1798. this.next_line = new OutputLine(this);
  1799. this.space_before_token = false;
  1800. this.non_breaking_space = false;
  1801. this.previous_token_wrapped = false;
  1802. // initialize
  1803. this.__add_outputline();
  1804. }
  1805. Output.prototype.__add_outputline = function() {
  1806. this.previous_line = this.current_line;
  1807. this.current_line = this.next_line.clone_empty();
  1808. this.__lines.push(this.current_line);
  1809. };
  1810. Output.prototype.get_line_number = function() {
  1811. return this.__lines.length;
  1812. };
  1813. Output.prototype.get_indent_string = function(indent, column) {
  1814. return this.__indent_cache.get_indent_string(indent, column);
  1815. };
  1816. Output.prototype.get_indent_size = function(indent, column) {
  1817. return this.__indent_cache.get_indent_size(indent, column);
  1818. };
  1819. Output.prototype.is_empty = function() {
  1820. return !this.previous_line && this.current_line.is_empty();
  1821. };
  1822. Output.prototype.add_new_line = function(force_newline) {
  1823. // never newline at the start of file
  1824. // otherwise, newline only if we didn't just add one or we're forced
  1825. if (this.is_empty() ||
  1826. (!force_newline && this.just_added_newline())) {
  1827. return false;
  1828. }
  1829. // if raw output is enabled, don't print additional newlines,
  1830. // but still return True as though you had
  1831. if (!this.raw) {
  1832. this.__add_outputline();
  1833. }
  1834. return true;
  1835. };
  1836. Output.prototype.get_code = function(eol) {
  1837. this.trim(true);
  1838. // handle some edge cases where the last tokens
  1839. // has text that ends with newline(s)
  1840. var last_item = this.current_line.pop();
  1841. if (last_item) {
  1842. if (last_item[last_item.length - 1] === '\n') {
  1843. last_item = last_item.replace(/\n+$/g, '');
  1844. }
  1845. this.current_line.push(last_item);
  1846. }
  1847. if (this._end_with_newline) {
  1848. this.__add_outputline();
  1849. }
  1850. var sweet_code = this.__lines.join('\n');
  1851. if (eol !== '\n') {
  1852. sweet_code = sweet_code.replace(/[\n]/g, eol);
  1853. }
  1854. return sweet_code;
  1855. };
  1856. Output.prototype.set_wrap_point = function() {
  1857. this.current_line._set_wrap_point();
  1858. };
  1859. Output.prototype.set_indent = function(indent, alignment) {
  1860. indent = indent || 0;
  1861. alignment = alignment || 0;
  1862. // Next line stores alignment values
  1863. this.next_line.set_indent(indent, alignment);
  1864. // Never indent your first output indent at the start of the file
  1865. if (this.__lines.length > 1) {
  1866. this.current_line.set_indent(indent, alignment);
  1867. return true;
  1868. }
  1869. this.current_line.set_indent();
  1870. return false;
  1871. };
  1872. Output.prototype.add_raw_token = function(token) {
  1873. for (var x = 0; x < token.newlines; x++) {
  1874. this.__add_outputline();
  1875. }
  1876. this.current_line.set_indent(-1);
  1877. this.current_line.push(token.whitespace_before);
  1878. this.current_line.push(token.text);
  1879. this.space_before_token = false;
  1880. this.non_breaking_space = false;
  1881. this.previous_token_wrapped = false;
  1882. };
  1883. Output.prototype.add_token = function(printable_token) {
  1884. this.__add_space_before_token();
  1885. this.current_line.push(printable_token);
  1886. this.space_before_token = false;
  1887. this.non_breaking_space = false;
  1888. this.previous_token_wrapped = this.current_line._allow_wrap();
  1889. };
  1890. Output.prototype.__add_space_before_token = function() {
  1891. if (this.space_before_token && !this.just_added_newline()) {
  1892. if (!this.non_breaking_space) {
  1893. this.set_wrap_point();
  1894. }
  1895. this.current_line.push(' ');
  1896. }
  1897. };
  1898. Output.prototype.remove_indent = function(index) {
  1899. var output_length = this.__lines.length;
  1900. while (index < output_length) {
  1901. this.__lines[index]._remove_indent();
  1902. index++;
  1903. }
  1904. this.current_line._remove_wrap_indent();
  1905. };
  1906. Output.prototype.trim = function(eat_newlines) {
  1907. eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
  1908. this.current_line.trim();
  1909. while (eat_newlines && this.__lines.length > 1 &&
  1910. this.current_line.is_empty()) {
  1911. this.__lines.pop();
  1912. this.current_line = this.__lines[this.__lines.length - 1];
  1913. this.current_line.trim();
  1914. }
  1915. this.previous_line = this.__lines.length > 1 ?
  1916. this.__lines[this.__lines.length - 2] : null;
  1917. };
  1918. Output.prototype.just_added_newline = function() {
  1919. return this.current_line.is_empty();
  1920. };
  1921. Output.prototype.just_added_blankline = function() {
  1922. return this.is_empty() ||
  1923. (this.current_line.is_empty() && this.previous_line.is_empty());
  1924. };
  1925. Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
  1926. var index = this.__lines.length - 2;
  1927. while (index >= 0) {
  1928. var potentialEmptyLine = this.__lines[index];
  1929. if (potentialEmptyLine.is_empty()) {
  1930. break;
  1931. } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
  1932. potentialEmptyLine.item(-1) !== ends_with) {
  1933. this.__lines.splice(index + 1, 0, new OutputLine(this));
  1934. this.previous_line = this.__lines[this.__lines.length - 2];
  1935. break;
  1936. }
  1937. index--;
  1938. }
  1939. };
  1940. output.Output = Output;
  1941. return output;
  1942. }
  1943. var token = {};
  1944. /*jshint node:true */
  1945. var hasRequiredToken;
  1946. function requireToken () {
  1947. if (hasRequiredToken) return token;
  1948. hasRequiredToken = 1;
  1949. function Token(type, text, newlines, whitespace_before) {
  1950. this.type = type;
  1951. this.text = text;
  1952. // comments_before are
  1953. // comments that have a new line before them
  1954. // and may or may not have a newline after
  1955. // this is a set of comments before
  1956. this.comments_before = null; /* inline comment*/
  1957. // this.comments_after = new TokenStream(); // no new line before and newline after
  1958. this.newlines = newlines || 0;
  1959. this.whitespace_before = whitespace_before || '';
  1960. this.parent = null;
  1961. this.next = null;
  1962. this.previous = null;
  1963. this.opened = null;
  1964. this.closed = null;
  1965. this.directives = null;
  1966. }
  1967. token.Token = Token;
  1968. return token;
  1969. }
  1970. var acorn = {};
  1971. /* jshint node: true, curly: false */
  1972. var hasRequiredAcorn;
  1973. function requireAcorn () {
  1974. if (hasRequiredAcorn) return acorn;
  1975. hasRequiredAcorn = 1;
  1976. (function (exports) {
  1977. // acorn used char codes to squeeze the last bit of performance out
  1978. // Beautifier is okay without that, so we're using regex
  1979. // permit # (23), $ (36), and @ (64). @ is used in ES7 decorators.
  1980. // 65 through 91 are uppercase letters.
  1981. // permit _ (95).
  1982. // 97 through 123 are lowercase letters.
  1983. var baseASCIIidentifierStartChars = "\\x23\\x24\\x40\\x41-\\x5a\\x5f\\x61-\\x7a";
  1984. // inside an identifier @ is not allowed but 0-9 are.
  1985. var baseASCIIidentifierChars = "\\x24\\x30-\\x39\\x41-\\x5a\\x5f\\x61-\\x7a";
  1986. // Big ugly regular expressions that match characters in the
  1987. // whitespace, identifier, and identifier-start categories. These
  1988. // are only applied when a character is found to actually have a
  1989. // code point above 128.
  1990. var nonASCIIidentifierStartChars = "\\xaa\\xb5\\xba\\xc0-\\xd6\\xd8-\\xf6\\xf8-\\u02c1\\u02c6-\\u02d1\\u02e0-\\u02e4\\u02ec\\u02ee\\u0370-\\u0374\\u0376\\u0377\\u037a-\\u037d\\u0386\\u0388-\\u038a\\u038c\\u038e-\\u03a1\\u03a3-\\u03f5\\u03f7-\\u0481\\u048a-\\u0527\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05d0-\\u05ea\\u05f0-\\u05f2\\u0620-\\u064a\\u066e\\u066f\\u0671-\\u06d3\\u06d5\\u06e5\\u06e6\\u06ee\\u06ef\\u06fa-\\u06fc\\u06ff\\u0710\\u0712-\\u072f\\u074d-\\u07a5\\u07b1\\u07ca-\\u07ea\\u07f4\\u07f5\\u07fa\\u0800-\\u0815\\u081a\\u0824\\u0828\\u0840-\\u0858\\u08a0\\u08a2-\\u08ac\\u0904-\\u0939\\u093d\\u0950\\u0958-\\u0961\\u0971-\\u0977\\u0979-\\u097f\\u0985-\\u098c\\u098f\\u0990\\u0993-\\u09a8\\u09aa-\\u09b0\\u09b2\\u09b6-\\u09b9\\u09bd\\u09ce\\u09dc\\u09dd\\u09df-\\u09e1\\u09f0\\u09f1\\u0a05-\\u0a0a\\u0a0f\\u0a10\\u0a13-\\u0a28\\u0a2a-\\u0a30\\u0a32\\u0a33\\u0a35\\u0a36\\u0a38\\u0a39\\u0a59-\\u0a5c\\u0a5e\\u0a72-\\u0a74\\u0a85-\\u0a8d\\u0a8f-\\u0a91\\u0a93-\\u0aa8\\u0aaa-\\u0ab0\\u0ab2\\u0ab3\\u0ab5-\\u0ab9\\u0abd\\u0ad0\\u0ae0\\u0ae1\\u0b05-\\u0b0c\\u0b0f\\u0b10\\u0b13-\\u0b28\\u0b2a-\\u0b30\\u0b32\\u0b33\\u0b35-\\u0b39\\u0b3d\\u0b5c\\u0b5d\\u0b5f-\\u0b61\\u0b71\\u0b83\\u0b85-\\u0b8a\\u0b8e-\\u0b90\\u0b92-\\u0b95\\u0b99\\u0b9a\\u0b9c\\u0b9e\\u0b9f\\u0ba3\\u0ba4\\u0ba8-\\u0baa\\u0bae-\\u0bb9\\u0bd0\\u0c05-\\u0c0c\\u0c0e-\\u0c10\\u0c12-\\u0c28\\u0c2a-\\u0c33\\u0c35-\\u0c39\\u0c3d\\u0c58\\u0c59\\u0c60\\u0c61\\u0c85-\\u0c8c\\u0c8e-\\u0c90\\u0c92-\\u0ca8\\u0caa-\\u0cb3\\u0cb5-\\u0cb9\\u0cbd\\u0cde\\u0ce0\\u0ce1\\u0cf1\\u0cf2\\u0d05-\\u0d0c\\u0d0e-\\u0d10\\u0d12-\\u0d3a\\u0d3d\\u0d4e\\u0d60\\u0d61\\u0d7a-\\u0d7f\\u0d85-\\u0d96\\u0d9a-\\u0db1\\u0db3-\\u0dbb\\u0dbd\\u0dc0-\\u0dc6\\u0e01-\\u0e30\\u0e32\\u0e33\\u0e40-\\u0e46\\u0e81\\u0e82\\u0e84\\u0e87\\u0e88\\u0e8a\\u0e8d\\u0e94-\\u0e97\\u0e99-\\u0e9f\\u0ea1-\\u0ea3\\u0ea5\\u0ea7\\u0eaa\\u0eab\\u0ead-\\u0eb0\\u0eb2\\u0eb3\\u0ebd\\u0ec0-\\u0ec4\\u0ec6\\u0edc-\\u0edf\\u0f00\\u0f40-\\u0f47\\u0f49-\\u0f6c\\u0f88-\\u0f8c\\u1000-\\u102a\\u103f\\u1050-\\u1055\\u105a-\\u105d\\u1061\\u1065\\u1066\\u106e-\\u1070\\u1075-\\u1081\\u108e\\u10a0-\\u10c5\\u10c7\\u10cd\\u10d0-\\u10fa\\u10fc-\\u1248\\u124a-\\u124d\\u1250-\\u1256\\u1258\\u125a-\\u125d\\u1260-\\u1288\\u128a-\\u128d\\u1290-\\u12b0\\u12b2-\\u12b5\\u12b8-\\u12be\\u12c0\\u12c2-\\u12c5\\u12c8-\\u12d6\\u12d8-\\u1310\\u1312-\\u1315\\u1318-\\u135a\\u1380-\\u138f\\u13a0-\\u13f4\\u1401-\\u166c\\u166f-\\u167f\\u1681-\\u169a\\u16a0-\\u16ea\\u16ee-\\u16f0\\u1700-\\u170c\\u170e-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176c\\u176e-\\u1770\\u1780-\\u17b3\\u17d7\\u17dc\\u1820-\\u1877\\u1880-\\u18a8\\u18aa\\u18b0-\\u18f5\\u1900-\\u191c\\u1950-\\u196d\\u1970-\\u1974\\u1980-\\u19ab\\u19c1-\\u19c7\\u1a00-\\u1a16\\u1a20-\\u1a54\\u1aa7\\u1b05-\\u1b33\\u1b45-\\u1b4b\\u1b83-\\u1ba0\\u1bae\\u1baf\\u1bba-\\u1be5\\u1c00-\\u1c23\\u1c4d-\\u1c4f\\u1c5a-\\u1c7d\\u1ce9-\\u1cec\\u1cee-\\u1cf1\\u1cf5\\u1cf6\\u1d00-\\u1dbf\\u1e00-\\u1f15\\u1f18-\\u1f1d\\u1f20-\\u1f45\\u1f48-\\u1f4d\\u1f50-\\u1f57\\u1f59\\u1f5b\\u1f5d\\u1f5f-\\u1f7d\\u1f80-\\u1fb4\\u1fb6-\\u1fbc\\u1fbe\\u1fc2-\\u1fc4\\u1fc6-\\u1fcc\\u1fd0-\\u1fd3\\u1fd6-\\u1fdb\\u1fe0-\\u1fec\\u1ff2-\\u1ff4\\u1ff6-\\u1ffc\\u2071\\u207f\\u2090-\\u209c\\u2102\\u2107\\u210a-\\u2113\\u2115\\u2119-\\u211d\\u2124\\u2126\\u2128\\u212a-\\u212d\\u212f-\\u2139\\u213c-\\u213f\\u2145-\\u2149\\u214e\\u2160-\\u2188\\u2c00-\\u2c2e\\u2c30-\\u2c5e\\u2c60-\\u2ce4\\u2ceb-\\u2cee\\u2cf2\\u2cf3\\u2d00-\\u2d25\\u2d27\\u2d2d\\u2d30-\\u2d67\\u2d6f\\u2d80-\\u2d96\\u2da0-\\u2da6\\u2da8-\\u2dae\\u2db0-\\u2db6\\u2db8-\\u2dbe\\u2dc0-\\u2dc6\\u2dc8-\\u2dce\\u2dd0-\\u2dd6\\u2dd8-\\u2dde\\u2e2f\\u3005-\\u3007\\u3021-\\u3029\\u3031-\\u3035\\u3038-\\u303c\\u3041-\\u3096\\u309d-\\u309f\\u30a1-\\u30fa\\u30fc-\\u30ff\\u3105-\\u312d\\u3131-\\u318e\\u31a0-\\u31ba\\u31f0-\\u31ff\\u3400-\\u4db5\\u4e00-\\u9fcc\\ua000-\\ua48c\\ua4d0-\\ua4fd\\ua500-\\ua60c\\ua610-\\ua61f\\ua62a\\ua62b\\ua640-\\ua66e\\ua67f-\\ua697\\ua6a0-\\ua6ef\\ua717-\\ua71f\\ua722-\\ua788\\ua78b-\\ua78e\\ua790-\\ua793\\ua7a0-\\ua7aa\\ua7f8-\\ua801\\ua803-\\ua805\\ua807-\\ua80a\\ua80c-\\ua822\\ua840-\\ua873\\ua882-\\ua8b3\\ua8f2-\\ua8f7\\ua8fb\\ua90a-\\ua925\\ua930-\\ua946\\ua960-\\ua97c\\ua984-\\ua9b2\\ua9cf\\uaa00-\\uaa28\\uaa40-\\uaa42\\uaa44-\\uaa4b\\uaa60-\\uaa76\\uaa7a\\uaa80-\\uaaaf\\uaab1\\uaab5\\uaab6\\uaab9-\\uaabd\\uaac0\\uaac2\\uaadb-\\uaadd\\uaae0-\\uaaea\\uaaf2-\\uaaf4\\uab01-\\uab06\\uab09-\\uab0e\\uab11-\\uab16\\uab20-\\uab26\\uab28-\\uab2e\\uabc0-\\uabe2\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\uf900-\\ufa6d\\ufa70-\\ufad9\\ufb00-\\ufb06\\ufb13-\\ufb17\\ufb1d\\ufb1f-\\ufb28\\ufb2a-\\ufb36\\ufb38-\\ufb3c\\ufb3e\\ufb40\\ufb41\\ufb43\\ufb44\\ufb46-\\ufbb1\\ufbd3-\\ufd3d\\ufd50-\\ufd8f\\ufd92-\\ufdc7\\ufdf0-\\ufdfb\\ufe70-\\ufe74\\ufe76-\\ufefc\\uff21-\\uff3a\\uff41-\\uff5a\\uff66-\\uffbe\\uffc2-\\uffc7\\uffca-\\uffcf\\uffd2-\\uffd7\\uffda-\\uffdc";
  1991. var nonASCIIidentifierChars = "\\u0300-\\u036f\\u0483-\\u0487\\u0591-\\u05bd\\u05bf\\u05c1\\u05c2\\u05c4\\u05c5\\u05c7\\u0610-\\u061a\\u0620-\\u0649\\u0672-\\u06d3\\u06e7-\\u06e8\\u06fb-\\u06fc\\u0730-\\u074a\\u0800-\\u0814\\u081b-\\u0823\\u0825-\\u0827\\u0829-\\u082d\\u0840-\\u0857\\u08e4-\\u08fe\\u0900-\\u0903\\u093a-\\u093c\\u093e-\\u094f\\u0951-\\u0957\\u0962-\\u0963\\u0966-\\u096f\\u0981-\\u0983\\u09bc\\u09be-\\u09c4\\u09c7\\u09c8\\u09d7\\u09df-\\u09e0\\u0a01-\\u0a03\\u0a3c\\u0a3e-\\u0a42\\u0a47\\u0a48\\u0a4b-\\u0a4d\\u0a51\\u0a66-\\u0a71\\u0a75\\u0a81-\\u0a83\\u0abc\\u0abe-\\u0ac5\\u0ac7-\\u0ac9\\u0acb-\\u0acd\\u0ae2-\\u0ae3\\u0ae6-\\u0aef\\u0b01-\\u0b03\\u0b3c\\u0b3e-\\u0b44\\u0b47\\u0b48\\u0b4b-\\u0b4d\\u0b56\\u0b57\\u0b5f-\\u0b60\\u0b66-\\u0b6f\\u0b82\\u0bbe-\\u0bc2\\u0bc6-\\u0bc8\\u0bca-\\u0bcd\\u0bd7\\u0be6-\\u0bef\\u0c01-\\u0c03\\u0c46-\\u0c48\\u0c4a-\\u0c4d\\u0c55\\u0c56\\u0c62-\\u0c63\\u0c66-\\u0c6f\\u0c82\\u0c83\\u0cbc\\u0cbe-\\u0cc4\\u0cc6-\\u0cc8\\u0cca-\\u0ccd\\u0cd5\\u0cd6\\u0ce2-\\u0ce3\\u0ce6-\\u0cef\\u0d02\\u0d03\\u0d46-\\u0d48\\u0d57\\u0d62-\\u0d63\\u0d66-\\u0d6f\\u0d82\\u0d83\\u0dca\\u0dcf-\\u0dd4\\u0dd6\\u0dd8-\\u0ddf\\u0df2\\u0df3\\u0e34-\\u0e3a\\u0e40-\\u0e45\\u0e50-\\u0e59\\u0eb4-\\u0eb9\\u0ec8-\\u0ecd\\u0ed0-\\u0ed9\\u0f18\\u0f19\\u0f20-\\u0f29\\u0f35\\u0f37\\u0f39\\u0f41-\\u0f47\\u0f71-\\u0f84\\u0f86-\\u0f87\\u0f8d-\\u0f97\\u0f99-\\u0fbc\\u0fc6\\u1000-\\u1029\\u1040-\\u1049\\u1067-\\u106d\\u1071-\\u1074\\u1082-\\u108d\\u108f-\\u109d\\u135d-\\u135f\\u170e-\\u1710\\u1720-\\u1730\\u1740-\\u1750\\u1772\\u1773\\u1780-\\u17b2\\u17dd\\u17e0-\\u17e9\\u180b-\\u180d\\u1810-\\u1819\\u1920-\\u192b\\u1930-\\u193b\\u1951-\\u196d\\u19b0-\\u19c0\\u19c8-\\u19c9\\u19d0-\\u19d9\\u1a00-\\u1a15\\u1a20-\\u1a53\\u1a60-\\u1a7c\\u1a7f-\\u1a89\\u1a90-\\u1a99\\u1b46-\\u1b4b\\u1b50-\\u1b59\\u1b6b-\\u1b73\\u1bb0-\\u1bb9\\u1be6-\\u1bf3\\u1c00-\\u1c22\\u1c40-\\u1c49\\u1c5b-\\u1c7d\\u1cd0-\\u1cd2\\u1d00-\\u1dbe\\u1e01-\\u1f15\\u200c\\u200d\\u203f\\u2040\\u2054\\u20d0-\\u20dc\\u20e1\\u20e5-\\u20f0\\u2d81-\\u2d96\\u2de0-\\u2dff\\u3021-\\u3028\\u3099\\u309a\\ua640-\\ua66d\\ua674-\\ua67d\\ua69f\\ua6f0-\\ua6f1\\ua7f8-\\ua800\\ua806\\ua80b\\ua823-\\ua827\\ua880-\\ua881\\ua8b4-\\ua8c4\\ua8d0-\\ua8d9\\ua8f3-\\ua8f7\\ua900-\\ua909\\ua926-\\ua92d\\ua930-\\ua945\\ua980-\\ua983\\ua9b3-\\ua9c0\\uaa00-\\uaa27\\uaa40-\\uaa41\\uaa4c-\\uaa4d\\uaa50-\\uaa59\\uaa7b\\uaae0-\\uaae9\\uaaf2-\\uaaf3\\uabc0-\\uabe1\\uabec\\uabed\\uabf0-\\uabf9\\ufb20-\\ufb28\\ufe00-\\ufe0f\\ufe20-\\ufe26\\ufe33\\ufe34\\ufe4d-\\ufe4f\\uff10-\\uff19\\uff3f";
  1992. //var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  1993. //var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  1994. var identifierStart = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "])";
  1995. var identifierChars = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])*";
  1996. exports.identifier = new RegExp(identifierStart + identifierChars, 'g');
  1997. exports.identifierStart = new RegExp(identifierStart);
  1998. exports.identifierMatch = new RegExp("(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])+");
  1999. // Whether a single character denotes a newline.
  2000. exports.newline = /[\n\r\u2028\u2029]/;
  2001. // Matches a whole line break (where CRLF is considered a single
  2002. // line break). Used to count lines.
  2003. // in javascript, these two differ
  2004. // in python they are the same, different methods are called on them
  2005. exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
  2006. exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
  2007. } (acorn));
  2008. return acorn;
  2009. }
  2010. var options$3 = {};
  2011. var options$2 = {};
  2012. /*jshint node:true */
  2013. var hasRequiredOptions$3;
  2014. function requireOptions$3 () {
  2015. if (hasRequiredOptions$3) return options$2;
  2016. hasRequiredOptions$3 = 1;
  2017. function Options(options, merge_child_field) {
  2018. this.raw_options = _mergeOpts(options, merge_child_field);
  2019. // Support passing the source text back with no change
  2020. this.disabled = this._get_boolean('disabled');
  2021. this.eol = this._get_characters('eol', 'auto');
  2022. this.end_with_newline = this._get_boolean('end_with_newline');
  2023. this.indent_size = this._get_number('indent_size', 4);
  2024. this.indent_char = this._get_characters('indent_char', ' ');
  2025. this.indent_level = this._get_number('indent_level');
  2026. this.preserve_newlines = this._get_boolean('preserve_newlines', true);
  2027. this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
  2028. if (!this.preserve_newlines) {
  2029. this.max_preserve_newlines = 0;
  2030. }
  2031. this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
  2032. if (this.indent_with_tabs) {
  2033. this.indent_char = '\t';
  2034. // indent_size behavior changed after 1.8.6
  2035. // It used to be that indent_size would be
  2036. // set to 1 for indent_with_tabs. That is no longer needed and
  2037. // actually doesn't make sense - why not use spaces? Further,
  2038. // that might produce unexpected behavior - tabs being used
  2039. // for single-column alignment. So, when indent_with_tabs is true
  2040. // and indent_size is 1, reset indent_size to 4.
  2041. if (this.indent_size === 1) {
  2042. this.indent_size = 4;
  2043. }
  2044. }
  2045. // Backwards compat with 1.3.x
  2046. this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
  2047. this.indent_empty_lines = this._get_boolean('indent_empty_lines');
  2048. // valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty']
  2049. // For now, 'auto' = all off for javascript, all on for html (and inline javascript).
  2050. // other values ignored
  2051. this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
  2052. }
  2053. Options.prototype._get_array = function(name, default_value) {
  2054. var option_value = this.raw_options[name];
  2055. var result = default_value || [];
  2056. if (typeof option_value === 'object') {
  2057. if (option_value !== null && typeof option_value.concat === 'function') {
  2058. result = option_value.concat();
  2059. }
  2060. } else if (typeof option_value === 'string') {
  2061. result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
  2062. }
  2063. return result;
  2064. };
  2065. Options.prototype._get_boolean = function(name, default_value) {
  2066. var option_value = this.raw_options[name];
  2067. var result = option_value === undefined ? !!default_value : !!option_value;
  2068. return result;
  2069. };
  2070. Options.prototype._get_characters = function(name, default_value) {
  2071. var option_value = this.raw_options[name];
  2072. var result = default_value || '';
  2073. if (typeof option_value === 'string') {
  2074. result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
  2075. }
  2076. return result;
  2077. };
  2078. Options.prototype._get_number = function(name, default_value) {
  2079. var option_value = this.raw_options[name];
  2080. default_value = parseInt(default_value, 10);
  2081. if (isNaN(default_value)) {
  2082. default_value = 0;
  2083. }
  2084. var result = parseInt(option_value, 10);
  2085. if (isNaN(result)) {
  2086. result = default_value;
  2087. }
  2088. return result;
  2089. };
  2090. Options.prototype._get_selection = function(name, selection_list, default_value) {
  2091. var result = this._get_selection_list(name, selection_list, default_value);
  2092. if (result.length !== 1) {
  2093. throw new Error(
  2094. "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
  2095. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  2096. }
  2097. return result[0];
  2098. };
  2099. Options.prototype._get_selection_list = function(name, selection_list, default_value) {
  2100. if (!selection_list || selection_list.length === 0) {
  2101. throw new Error("Selection list cannot be empty.");
  2102. }
  2103. default_value = default_value || [selection_list[0]];
  2104. if (!this._is_valid_selection(default_value, selection_list)) {
  2105. throw new Error("Invalid Default Value!");
  2106. }
  2107. var result = this._get_array(name, default_value);
  2108. if (!this._is_valid_selection(result, selection_list)) {
  2109. throw new Error(
  2110. "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
  2111. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  2112. }
  2113. return result;
  2114. };
  2115. Options.prototype._is_valid_selection = function(result, selection_list) {
  2116. return result.length && selection_list.length &&
  2117. !result.some(function(item) { return selection_list.indexOf(item) === -1; });
  2118. };
  2119. // merges child options up with the parent options object
  2120. // Example: obj = {a: 1, b: {a: 2}}
  2121. // mergeOpts(obj, 'b')
  2122. //
  2123. // Returns: {a: 2}
  2124. function _mergeOpts(allOptions, childFieldName) {
  2125. var finalOpts = {};
  2126. allOptions = _normalizeOpts(allOptions);
  2127. var name;
  2128. for (name in allOptions) {
  2129. if (name !== childFieldName) {
  2130. finalOpts[name] = allOptions[name];
  2131. }
  2132. }
  2133. //merge in the per type settings for the childFieldName
  2134. if (childFieldName && allOptions[childFieldName]) {
  2135. for (name in allOptions[childFieldName]) {
  2136. finalOpts[name] = allOptions[childFieldName][name];
  2137. }
  2138. }
  2139. return finalOpts;
  2140. }
  2141. function _normalizeOpts(options) {
  2142. var convertedOpts = {};
  2143. var key;
  2144. for (key in options) {
  2145. var newKey = key.replace(/-/g, "_");
  2146. convertedOpts[newKey] = options[key];
  2147. }
  2148. return convertedOpts;
  2149. }
  2150. options$2.Options = Options;
  2151. options$2.normalizeOpts = _normalizeOpts;
  2152. options$2.mergeOpts = _mergeOpts;
  2153. return options$2;
  2154. }
  2155. /*jshint node:true */
  2156. var hasRequiredOptions$2;
  2157. function requireOptions$2 () {
  2158. if (hasRequiredOptions$2) return options$3;
  2159. hasRequiredOptions$2 = 1;
  2160. var BaseOptions = requireOptions$3().Options;
  2161. var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
  2162. function Options(options) {
  2163. BaseOptions.call(this, options, 'js');
  2164. // compatibility, re
  2165. var raw_brace_style = this.raw_options.brace_style || null;
  2166. if (raw_brace_style === "expand-strict") { //graceful handling of deprecated option
  2167. this.raw_options.brace_style = "expand";
  2168. } else if (raw_brace_style === "collapse-preserve-inline") { //graceful handling of deprecated option
  2169. this.raw_options.brace_style = "collapse,preserve-inline";
  2170. } else if (this.raw_options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
  2171. this.raw_options.brace_style = this.raw_options.braces_on_own_line ? "expand" : "collapse";
  2172. // } else if (!raw_brace_style) { //Nothing exists to set it
  2173. // raw_brace_style = "collapse";
  2174. }
  2175. //preserve-inline in delimited string will trigger brace_preserve_inline, everything
  2176. //else is considered a brace_style and the last one only will have an effect
  2177. var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
  2178. this.brace_preserve_inline = false; //Defaults in case one or other was not specified in meta-option
  2179. this.brace_style = "collapse";
  2180. for (var bs = 0; bs < brace_style_split.length; bs++) {
  2181. if (brace_style_split[bs] === "preserve-inline") {
  2182. this.brace_preserve_inline = true;
  2183. } else {
  2184. this.brace_style = brace_style_split[bs];
  2185. }
  2186. }
  2187. this.unindent_chained_methods = this._get_boolean('unindent_chained_methods');
  2188. this.break_chained_methods = this._get_boolean('break_chained_methods');
  2189. this.space_in_paren = this._get_boolean('space_in_paren');
  2190. this.space_in_empty_paren = this._get_boolean('space_in_empty_paren');
  2191. this.jslint_happy = this._get_boolean('jslint_happy');
  2192. this.space_after_anon_function = this._get_boolean('space_after_anon_function');
  2193. this.space_after_named_function = this._get_boolean('space_after_named_function');
  2194. this.keep_array_indentation = this._get_boolean('keep_array_indentation');
  2195. this.space_before_conditional = this._get_boolean('space_before_conditional', true);
  2196. this.unescape_strings = this._get_boolean('unescape_strings');
  2197. this.e4x = this._get_boolean('e4x');
  2198. this.comma_first = this._get_boolean('comma_first');
  2199. this.operator_position = this._get_selection('operator_position', validPositionValues);
  2200. // For testing of beautify preserve:start directive
  2201. this.test_output_raw = this._get_boolean('test_output_raw');
  2202. // force this._options.space_after_anon_function to true if this._options.jslint_happy
  2203. if (this.jslint_happy) {
  2204. this.space_after_anon_function = true;
  2205. }
  2206. }
  2207. Options.prototype = new BaseOptions();
  2208. options$3.Options = Options;
  2209. return options$3;
  2210. }
  2211. var tokenizer$3 = {};
  2212. var inputscanner = {};
  2213. /*jshint node:true */
  2214. var hasRequiredInputscanner;
  2215. function requireInputscanner () {
  2216. if (hasRequiredInputscanner) return inputscanner;
  2217. hasRequiredInputscanner = 1;
  2218. var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
  2219. function InputScanner(input_string) {
  2220. this.__input = input_string || '';
  2221. this.__input_length = this.__input.length;
  2222. this.__position = 0;
  2223. }
  2224. InputScanner.prototype.restart = function() {
  2225. this.__position = 0;
  2226. };
  2227. InputScanner.prototype.back = function() {
  2228. if (this.__position > 0) {
  2229. this.__position -= 1;
  2230. }
  2231. };
  2232. InputScanner.prototype.hasNext = function() {
  2233. return this.__position < this.__input_length;
  2234. };
  2235. InputScanner.prototype.next = function() {
  2236. var val = null;
  2237. if (this.hasNext()) {
  2238. val = this.__input.charAt(this.__position);
  2239. this.__position += 1;
  2240. }
  2241. return val;
  2242. };
  2243. InputScanner.prototype.peek = function(index) {
  2244. var val = null;
  2245. index = index || 0;
  2246. index += this.__position;
  2247. if (index >= 0 && index < this.__input_length) {
  2248. val = this.__input.charAt(index);
  2249. }
  2250. return val;
  2251. };
  2252. // This is a JavaScript only helper function (not in python)
  2253. // Javascript doesn't have a match method
  2254. // and not all implementation support "sticky" flag.
  2255. // If they do not support sticky then both this.match() and this.test() method
  2256. // must get the match and check the index of the match.
  2257. // If sticky is supported and set, this method will use it.
  2258. // Otherwise it will check that global is set, and fall back to the slower method.
  2259. InputScanner.prototype.__match = function(pattern, index) {
  2260. pattern.lastIndex = index;
  2261. var pattern_match = pattern.exec(this.__input);
  2262. if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
  2263. if (pattern_match.index !== index) {
  2264. pattern_match = null;
  2265. }
  2266. }
  2267. return pattern_match;
  2268. };
  2269. InputScanner.prototype.test = function(pattern, index) {
  2270. index = index || 0;
  2271. index += this.__position;
  2272. if (index >= 0 && index < this.__input_length) {
  2273. return !!this.__match(pattern, index);
  2274. } else {
  2275. return false;
  2276. }
  2277. };
  2278. InputScanner.prototype.testChar = function(pattern, index) {
  2279. // test one character regex match
  2280. var val = this.peek(index);
  2281. pattern.lastIndex = 0;
  2282. return val !== null && pattern.test(val);
  2283. };
  2284. InputScanner.prototype.match = function(pattern) {
  2285. var pattern_match = this.__match(pattern, this.__position);
  2286. if (pattern_match) {
  2287. this.__position += pattern_match[0].length;
  2288. } else {
  2289. pattern_match = null;
  2290. }
  2291. return pattern_match;
  2292. };
  2293. InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
  2294. var val = '';
  2295. var match;
  2296. if (starting_pattern) {
  2297. match = this.match(starting_pattern);
  2298. if (match) {
  2299. val += match[0];
  2300. }
  2301. }
  2302. if (until_pattern && (match || !starting_pattern)) {
  2303. val += this.readUntil(until_pattern, until_after);
  2304. }
  2305. return val;
  2306. };
  2307. InputScanner.prototype.readUntil = function(pattern, until_after) {
  2308. var val = '';
  2309. var match_index = this.__position;
  2310. pattern.lastIndex = this.__position;
  2311. var pattern_match = pattern.exec(this.__input);
  2312. if (pattern_match) {
  2313. match_index = pattern_match.index;
  2314. if (until_after) {
  2315. match_index += pattern_match[0].length;
  2316. }
  2317. } else {
  2318. match_index = this.__input_length;
  2319. }
  2320. val = this.__input.substring(this.__position, match_index);
  2321. this.__position = match_index;
  2322. return val;
  2323. };
  2324. InputScanner.prototype.readUntilAfter = function(pattern) {
  2325. return this.readUntil(pattern, true);
  2326. };
  2327. InputScanner.prototype.get_regexp = function(pattern, match_from) {
  2328. var result = null;
  2329. var flags = 'g';
  2330. if (match_from && regexp_has_sticky) {
  2331. flags = 'y';
  2332. }
  2333. // strings are converted to regexp
  2334. if (typeof pattern === "string" && pattern !== '') {
  2335. // result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags);
  2336. result = new RegExp(pattern, flags);
  2337. } else if (pattern) {
  2338. result = new RegExp(pattern.source, flags);
  2339. }
  2340. return result;
  2341. };
  2342. InputScanner.prototype.get_literal_regexp = function(literal_string) {
  2343. return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
  2344. };
  2345. /* css beautifier legacy helpers */
  2346. InputScanner.prototype.peekUntilAfter = function(pattern) {
  2347. var start = this.__position;
  2348. var val = this.readUntilAfter(pattern);
  2349. this.__position = start;
  2350. return val;
  2351. };
  2352. InputScanner.prototype.lookBack = function(testVal) {
  2353. var start = this.__position - 1;
  2354. return start >= testVal.length && this.__input.substring(start - testVal.length, start)
  2355. .toLowerCase() === testVal;
  2356. };
  2357. inputscanner.InputScanner = InputScanner;
  2358. return inputscanner;
  2359. }
  2360. var tokenizer$2 = {};
  2361. var tokenstream = {};
  2362. /*jshint node:true */
  2363. var hasRequiredTokenstream;
  2364. function requireTokenstream () {
  2365. if (hasRequiredTokenstream) return tokenstream;
  2366. hasRequiredTokenstream = 1;
  2367. function TokenStream(parent_token) {
  2368. // private
  2369. this.__tokens = [];
  2370. this.__tokens_length = this.__tokens.length;
  2371. this.__position = 0;
  2372. this.__parent_token = parent_token;
  2373. }
  2374. TokenStream.prototype.restart = function() {
  2375. this.__position = 0;
  2376. };
  2377. TokenStream.prototype.isEmpty = function() {
  2378. return this.__tokens_length === 0;
  2379. };
  2380. TokenStream.prototype.hasNext = function() {
  2381. return this.__position < this.__tokens_length;
  2382. };
  2383. TokenStream.prototype.next = function() {
  2384. var val = null;
  2385. if (this.hasNext()) {
  2386. val = this.__tokens[this.__position];
  2387. this.__position += 1;
  2388. }
  2389. return val;
  2390. };
  2391. TokenStream.prototype.peek = function(index) {
  2392. var val = null;
  2393. index = index || 0;
  2394. index += this.__position;
  2395. if (index >= 0 && index < this.__tokens_length) {
  2396. val = this.__tokens[index];
  2397. }
  2398. return val;
  2399. };
  2400. TokenStream.prototype.add = function(token) {
  2401. if (this.__parent_token) {
  2402. token.parent = this.__parent_token;
  2403. }
  2404. this.__tokens.push(token);
  2405. this.__tokens_length += 1;
  2406. };
  2407. tokenstream.TokenStream = TokenStream;
  2408. return tokenstream;
  2409. }
  2410. var whitespacepattern = {};
  2411. var pattern = {};
  2412. /*jshint node:true */
  2413. var hasRequiredPattern;
  2414. function requirePattern () {
  2415. if (hasRequiredPattern) return pattern;
  2416. hasRequiredPattern = 1;
  2417. function Pattern(input_scanner, parent) {
  2418. this._input = input_scanner;
  2419. this._starting_pattern = null;
  2420. this._match_pattern = null;
  2421. this._until_pattern = null;
  2422. this._until_after = false;
  2423. if (parent) {
  2424. this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true);
  2425. this._match_pattern = this._input.get_regexp(parent._match_pattern, true);
  2426. this._until_pattern = this._input.get_regexp(parent._until_pattern);
  2427. this._until_after = parent._until_after;
  2428. }
  2429. }
  2430. Pattern.prototype.read = function() {
  2431. var result = this._input.read(this._starting_pattern);
  2432. if (!this._starting_pattern || result) {
  2433. result += this._input.read(this._match_pattern, this._until_pattern, this._until_after);
  2434. }
  2435. return result;
  2436. };
  2437. Pattern.prototype.read_match = function() {
  2438. return this._input.match(this._match_pattern);
  2439. };
  2440. Pattern.prototype.until_after = function(pattern) {
  2441. var result = this._create();
  2442. result._until_after = true;
  2443. result._until_pattern = this._input.get_regexp(pattern);
  2444. result._update();
  2445. return result;
  2446. };
  2447. Pattern.prototype.until = function(pattern) {
  2448. var result = this._create();
  2449. result._until_after = false;
  2450. result._until_pattern = this._input.get_regexp(pattern);
  2451. result._update();
  2452. return result;
  2453. };
  2454. Pattern.prototype.starting_with = function(pattern) {
  2455. var result = this._create();
  2456. result._starting_pattern = this._input.get_regexp(pattern, true);
  2457. result._update();
  2458. return result;
  2459. };
  2460. Pattern.prototype.matching = function(pattern) {
  2461. var result = this._create();
  2462. result._match_pattern = this._input.get_regexp(pattern, true);
  2463. result._update();
  2464. return result;
  2465. };
  2466. Pattern.prototype._create = function() {
  2467. return new Pattern(this._input, this);
  2468. };
  2469. Pattern.prototype._update = function() {};
  2470. pattern.Pattern = Pattern;
  2471. return pattern;
  2472. }
  2473. /*jshint node:true */
  2474. var hasRequiredWhitespacepattern;
  2475. function requireWhitespacepattern () {
  2476. if (hasRequiredWhitespacepattern) return whitespacepattern;
  2477. hasRequiredWhitespacepattern = 1;
  2478. var Pattern = requirePattern().Pattern;
  2479. function WhitespacePattern(input_scanner, parent) {
  2480. Pattern.call(this, input_scanner, parent);
  2481. if (parent) {
  2482. this._line_regexp = this._input.get_regexp(parent._line_regexp);
  2483. } else {
  2484. this.__set_whitespace_patterns('', '');
  2485. }
  2486. this.newline_count = 0;
  2487. this.whitespace_before_token = '';
  2488. }
  2489. WhitespacePattern.prototype = new Pattern();
  2490. WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) {
  2491. whitespace_chars += '\\t ';
  2492. newline_chars += '\\n\\r';
  2493. this._match_pattern = this._input.get_regexp(
  2494. '[' + whitespace_chars + newline_chars + ']+', true);
  2495. this._newline_regexp = this._input.get_regexp(
  2496. '\\r\\n|[' + newline_chars + ']');
  2497. };
  2498. WhitespacePattern.prototype.read = function() {
  2499. this.newline_count = 0;
  2500. this.whitespace_before_token = '';
  2501. var resulting_string = this._input.read(this._match_pattern);
  2502. if (resulting_string === ' ') {
  2503. this.whitespace_before_token = ' ';
  2504. } else if (resulting_string) {
  2505. var matches = this.__split(this._newline_regexp, resulting_string);
  2506. this.newline_count = matches.length - 1;
  2507. this.whitespace_before_token = matches[this.newline_count];
  2508. }
  2509. return resulting_string;
  2510. };
  2511. WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) {
  2512. var result = this._create();
  2513. result.__set_whitespace_patterns(whitespace_chars, newline_chars);
  2514. result._update();
  2515. return result;
  2516. };
  2517. WhitespacePattern.prototype._create = function() {
  2518. return new WhitespacePattern(this._input, this);
  2519. };
  2520. WhitespacePattern.prototype.__split = function(regexp, input_string) {
  2521. regexp.lastIndex = 0;
  2522. var start_index = 0;
  2523. var result = [];
  2524. var next_match = regexp.exec(input_string);
  2525. while (next_match) {
  2526. result.push(input_string.substring(start_index, next_match.index));
  2527. start_index = next_match.index + next_match[0].length;
  2528. next_match = regexp.exec(input_string);
  2529. }
  2530. if (start_index < input_string.length) {
  2531. result.push(input_string.substring(start_index, input_string.length));
  2532. } else {
  2533. result.push('');
  2534. }
  2535. return result;
  2536. };
  2537. whitespacepattern.WhitespacePattern = WhitespacePattern;
  2538. return whitespacepattern;
  2539. }
  2540. /*jshint node:true */
  2541. var hasRequiredTokenizer$2;
  2542. function requireTokenizer$2 () {
  2543. if (hasRequiredTokenizer$2) return tokenizer$2;
  2544. hasRequiredTokenizer$2 = 1;
  2545. var InputScanner = requireInputscanner().InputScanner;
  2546. var Token = requireToken().Token;
  2547. var TokenStream = requireTokenstream().TokenStream;
  2548. var WhitespacePattern = requireWhitespacepattern().WhitespacePattern;
  2549. var TOKEN = {
  2550. START: 'TK_START',
  2551. RAW: 'TK_RAW',
  2552. EOF: 'TK_EOF'
  2553. };
  2554. var Tokenizer = function(input_string, options) {
  2555. this._input = new InputScanner(input_string);
  2556. this._options = options || {};
  2557. this.__tokens = null;
  2558. this._patterns = {};
  2559. this._patterns.whitespace = new WhitespacePattern(this._input);
  2560. };
  2561. Tokenizer.prototype.tokenize = function() {
  2562. this._input.restart();
  2563. this.__tokens = new TokenStream();
  2564. this._reset();
  2565. var current;
  2566. var previous = new Token(TOKEN.START, '');
  2567. var open_token = null;
  2568. var open_stack = [];
  2569. var comments = new TokenStream();
  2570. while (previous.type !== TOKEN.EOF) {
  2571. current = this._get_next_token(previous, open_token);
  2572. while (this._is_comment(current)) {
  2573. comments.add(current);
  2574. current = this._get_next_token(previous, open_token);
  2575. }
  2576. if (!comments.isEmpty()) {
  2577. current.comments_before = comments;
  2578. comments = new TokenStream();
  2579. }
  2580. current.parent = open_token;
  2581. if (this._is_opening(current)) {
  2582. open_stack.push(open_token);
  2583. open_token = current;
  2584. } else if (open_token && this._is_closing(current, open_token)) {
  2585. current.opened = open_token;
  2586. open_token.closed = current;
  2587. open_token = open_stack.pop();
  2588. current.parent = open_token;
  2589. }
  2590. current.previous = previous;
  2591. previous.next = current;
  2592. this.__tokens.add(current);
  2593. previous = current;
  2594. }
  2595. return this.__tokens;
  2596. };
  2597. Tokenizer.prototype._is_first_token = function() {
  2598. return this.__tokens.isEmpty();
  2599. };
  2600. Tokenizer.prototype._reset = function() {};
  2601. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  2602. this._readWhitespace();
  2603. var resulting_string = this._input.read(/.+/g);
  2604. if (resulting_string) {
  2605. return this._create_token(TOKEN.RAW, resulting_string);
  2606. } else {
  2607. return this._create_token(TOKEN.EOF, '');
  2608. }
  2609. };
  2610. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  2611. return false;
  2612. };
  2613. Tokenizer.prototype._is_opening = function(current_token) { // jshint unused:false
  2614. return false;
  2615. };
  2616. Tokenizer.prototype._is_closing = function(current_token, open_token) { // jshint unused:false
  2617. return false;
  2618. };
  2619. Tokenizer.prototype._create_token = function(type, text) {
  2620. var token = new Token(type, text,
  2621. this._patterns.whitespace.newline_count,
  2622. this._patterns.whitespace.whitespace_before_token);
  2623. return token;
  2624. };
  2625. Tokenizer.prototype._readWhitespace = function() {
  2626. return this._patterns.whitespace.read();
  2627. };
  2628. tokenizer$2.Tokenizer = Tokenizer;
  2629. tokenizer$2.TOKEN = TOKEN;
  2630. return tokenizer$2;
  2631. }
  2632. var directives = {};
  2633. /*jshint node:true */
  2634. var hasRequiredDirectives;
  2635. function requireDirectives () {
  2636. if (hasRequiredDirectives) return directives;
  2637. hasRequiredDirectives = 1;
  2638. function Directives(start_block_pattern, end_block_pattern) {
  2639. start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
  2640. end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
  2641. this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
  2642. this.__directive_pattern = / (\w+)[:](\w+)/g;
  2643. this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
  2644. }
  2645. Directives.prototype.get_directives = function(text) {
  2646. if (!text.match(this.__directives_block_pattern)) {
  2647. return null;
  2648. }
  2649. var directives = {};
  2650. this.__directive_pattern.lastIndex = 0;
  2651. var directive_match = this.__directive_pattern.exec(text);
  2652. while (directive_match) {
  2653. directives[directive_match[1]] = directive_match[2];
  2654. directive_match = this.__directive_pattern.exec(text);
  2655. }
  2656. return directives;
  2657. };
  2658. Directives.prototype.readIgnored = function(input) {
  2659. return input.readUntilAfter(this.__directives_end_ignore_pattern);
  2660. };
  2661. directives.Directives = Directives;
  2662. return directives;
  2663. }
  2664. var templatablepattern = {};
  2665. /*jshint node:true */
  2666. var hasRequiredTemplatablepattern;
  2667. function requireTemplatablepattern () {
  2668. if (hasRequiredTemplatablepattern) return templatablepattern;
  2669. hasRequiredTemplatablepattern = 1;
  2670. var Pattern = requirePattern().Pattern;
  2671. var template_names = {
  2672. django: false,
  2673. erb: false,
  2674. handlebars: false,
  2675. php: false,
  2676. smarty: false
  2677. };
  2678. // This lets templates appear anywhere we would do a readUntil
  2679. // The cost is higher but it is pay to play.
  2680. function TemplatablePattern(input_scanner, parent) {
  2681. Pattern.call(this, input_scanner, parent);
  2682. this.__template_pattern = null;
  2683. this._disabled = Object.assign({}, template_names);
  2684. this._excluded = Object.assign({}, template_names);
  2685. if (parent) {
  2686. this.__template_pattern = this._input.get_regexp(parent.__template_pattern);
  2687. this._excluded = Object.assign(this._excluded, parent._excluded);
  2688. this._disabled = Object.assign(this._disabled, parent._disabled);
  2689. }
  2690. var pattern = new Pattern(input_scanner);
  2691. this.__patterns = {
  2692. handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
  2693. handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
  2694. handlebars: pattern.starting_with(/{{/).until_after(/}}/),
  2695. php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/),
  2696. erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
  2697. // django coflicts with handlebars a bit.
  2698. django: pattern.starting_with(/{%/).until_after(/%}/),
  2699. django_value: pattern.starting_with(/{{/).until_after(/}}/),
  2700. django_comment: pattern.starting_with(/{#/).until_after(/#}/),
  2701. smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/),
  2702. smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/),
  2703. smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/)
  2704. };
  2705. }
  2706. TemplatablePattern.prototype = new Pattern();
  2707. TemplatablePattern.prototype._create = function() {
  2708. return new TemplatablePattern(this._input, this);
  2709. };
  2710. TemplatablePattern.prototype._update = function() {
  2711. this.__set_templated_pattern();
  2712. };
  2713. TemplatablePattern.prototype.disable = function(language) {
  2714. var result = this._create();
  2715. result._disabled[language] = true;
  2716. result._update();
  2717. return result;
  2718. };
  2719. TemplatablePattern.prototype.read_options = function(options) {
  2720. var result = this._create();
  2721. for (var language in template_names) {
  2722. result._disabled[language] = options.templating.indexOf(language) === -1;
  2723. }
  2724. result._update();
  2725. return result;
  2726. };
  2727. TemplatablePattern.prototype.exclude = function(language) {
  2728. var result = this._create();
  2729. result._excluded[language] = true;
  2730. result._update();
  2731. return result;
  2732. };
  2733. TemplatablePattern.prototype.read = function() {
  2734. var result = '';
  2735. if (this._match_pattern) {
  2736. result = this._input.read(this._starting_pattern);
  2737. } else {
  2738. result = this._input.read(this._starting_pattern, this.__template_pattern);
  2739. }
  2740. var next = this._read_template();
  2741. while (next) {
  2742. if (this._match_pattern) {
  2743. next += this._input.read(this._match_pattern);
  2744. } else {
  2745. next += this._input.readUntil(this.__template_pattern);
  2746. }
  2747. result += next;
  2748. next = this._read_template();
  2749. }
  2750. if (this._until_after) {
  2751. result += this._input.readUntilAfter(this._until_pattern);
  2752. }
  2753. return result;
  2754. };
  2755. TemplatablePattern.prototype.__set_templated_pattern = function() {
  2756. var items = [];
  2757. if (!this._disabled.php) {
  2758. items.push(this.__patterns.php._starting_pattern.source);
  2759. }
  2760. if (!this._disabled.handlebars) {
  2761. items.push(this.__patterns.handlebars._starting_pattern.source);
  2762. }
  2763. if (!this._disabled.erb) {
  2764. items.push(this.__patterns.erb._starting_pattern.source);
  2765. }
  2766. if (!this._disabled.django) {
  2767. items.push(this.__patterns.django._starting_pattern.source);
  2768. // The starting pattern for django is more complex because it has different
  2769. // patterns for value, comment, and other sections
  2770. items.push(this.__patterns.django_value._starting_pattern.source);
  2771. items.push(this.__patterns.django_comment._starting_pattern.source);
  2772. }
  2773. if (!this._disabled.smarty) {
  2774. items.push(this.__patterns.smarty._starting_pattern.source);
  2775. }
  2776. if (this._until_pattern) {
  2777. items.push(this._until_pattern.source);
  2778. }
  2779. this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')');
  2780. };
  2781. TemplatablePattern.prototype._read_template = function() {
  2782. var resulting_string = '';
  2783. var c = this._input.peek();
  2784. if (c === '<') {
  2785. var peek1 = this._input.peek(1);
  2786. //if we're in a comment, do something special
  2787. // We treat all comments as literals, even more than preformatted tags
  2788. // we just look for the appropriate close tag
  2789. if (!this._disabled.php && !this._excluded.php && peek1 === '?') {
  2790. resulting_string = resulting_string ||
  2791. this.__patterns.php.read();
  2792. }
  2793. if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') {
  2794. resulting_string = resulting_string ||
  2795. this.__patterns.erb.read();
  2796. }
  2797. } else if (c === '{') {
  2798. if (!this._disabled.handlebars && !this._excluded.handlebars) {
  2799. resulting_string = resulting_string ||
  2800. this.__patterns.handlebars_comment.read();
  2801. resulting_string = resulting_string ||
  2802. this.__patterns.handlebars_unescaped.read();
  2803. resulting_string = resulting_string ||
  2804. this.__patterns.handlebars.read();
  2805. }
  2806. if (!this._disabled.django) {
  2807. // django coflicts with handlebars a bit.
  2808. if (!this._excluded.django && !this._excluded.handlebars) {
  2809. resulting_string = resulting_string ||
  2810. this.__patterns.django_value.read();
  2811. }
  2812. if (!this._excluded.django) {
  2813. resulting_string = resulting_string ||
  2814. this.__patterns.django_comment.read();
  2815. resulting_string = resulting_string ||
  2816. this.__patterns.django.read();
  2817. }
  2818. }
  2819. if (!this._disabled.smarty) {
  2820. // smarty cannot be enabled with django or handlebars enabled
  2821. if (this._disabled.django && this._disabled.handlebars) {
  2822. resulting_string = resulting_string ||
  2823. this.__patterns.smarty_comment.read();
  2824. resulting_string = resulting_string ||
  2825. this.__patterns.smarty_literal.read();
  2826. resulting_string = resulting_string ||
  2827. this.__patterns.smarty.read();
  2828. }
  2829. }
  2830. }
  2831. return resulting_string;
  2832. };
  2833. templatablepattern.TemplatablePattern = TemplatablePattern;
  2834. return templatablepattern;
  2835. }
  2836. /*jshint node:true */
  2837. var hasRequiredTokenizer$1;
  2838. function requireTokenizer$1 () {
  2839. if (hasRequiredTokenizer$1) return tokenizer$3;
  2840. hasRequiredTokenizer$1 = 1;
  2841. var InputScanner = requireInputscanner().InputScanner;
  2842. var BaseTokenizer = requireTokenizer$2().Tokenizer;
  2843. var BASETOKEN = requireTokenizer$2().TOKEN;
  2844. var Directives = requireDirectives().Directives;
  2845. var acorn = requireAcorn();
  2846. var Pattern = requirePattern().Pattern;
  2847. var TemplatablePattern = requireTemplatablepattern().TemplatablePattern;
  2848. function in_array(what, arr) {
  2849. return arr.indexOf(what) !== -1;
  2850. }
  2851. var TOKEN = {
  2852. START_EXPR: 'TK_START_EXPR',
  2853. END_EXPR: 'TK_END_EXPR',
  2854. START_BLOCK: 'TK_START_BLOCK',
  2855. END_BLOCK: 'TK_END_BLOCK',
  2856. WORD: 'TK_WORD',
  2857. RESERVED: 'TK_RESERVED',
  2858. SEMICOLON: 'TK_SEMICOLON',
  2859. STRING: 'TK_STRING',
  2860. EQUALS: 'TK_EQUALS',
  2861. OPERATOR: 'TK_OPERATOR',
  2862. COMMA: 'TK_COMMA',
  2863. BLOCK_COMMENT: 'TK_BLOCK_COMMENT',
  2864. COMMENT: 'TK_COMMENT',
  2865. DOT: 'TK_DOT',
  2866. UNKNOWN: 'TK_UNKNOWN',
  2867. START: BASETOKEN.START,
  2868. RAW: BASETOKEN.RAW,
  2869. EOF: BASETOKEN.EOF
  2870. };
  2871. var directives_core = new Directives(/\/\*/, /\*\//);
  2872. var number_pattern = /0[xX][0123456789abcdefABCDEF_]*n?|0[oO][01234567_]*n?|0[bB][01_]*n?|\d[\d_]*n|(?:\.\d[\d_]*|\d[\d_]*\.?[\d_]*)(?:[eE][+-]?[\d_]+)?/;
  2873. var digit = /[0-9]/;
  2874. // Dot "." must be distinguished from "..." and decimal
  2875. var dot_pattern = /[^\d\.]/;
  2876. var positionable_operators = (
  2877. ">>> === !== &&= ??= ||= " +
  2878. "<< && >= ** != == <= >> || ?? |> " +
  2879. "< / - + > : & % ? ^ | *").split(' ');
  2880. // IMPORTANT: this must be sorted longest to shortest or tokenizing many not work.
  2881. // Also, you must update possitionable operators separately from punct
  2882. var punct =
  2883. ">>>= " +
  2884. "... >>= <<= === >>> !== **= &&= ??= ||= " +
  2885. "=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
  2886. "= ! ? > < : / ^ - + * & % ~ |";
  2887. punct = punct.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
  2888. // ?. but not if followed by a number
  2889. punct = '\\?\\.(?!\\d) ' + punct;
  2890. punct = punct.replace(/ /g, '|');
  2891. var punct_pattern = new RegExp(punct);
  2892. // words which should always start on new line.
  2893. var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
  2894. var reserved_words = line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as', 'class', 'extends']);
  2895. var reserved_word_pattern = new RegExp('^(?:' + reserved_words.join('|') + ')$');
  2896. // var template_pattern = /(?:(?:<\?php|<\?=)[\s\S]*?\?>)|(?:<%[\s\S]*?%>)/g;
  2897. var in_html_comment;
  2898. var Tokenizer = function(input_string, options) {
  2899. BaseTokenizer.call(this, input_string, options);
  2900. this._patterns.whitespace = this._patterns.whitespace.matching(
  2901. /\u00A0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff/.source,
  2902. /\u2028\u2029/.source);
  2903. var pattern_reader = new Pattern(this._input);
  2904. var templatable = new TemplatablePattern(this._input)
  2905. .read_options(this._options);
  2906. this.__patterns = {
  2907. template: templatable,
  2908. identifier: templatable.starting_with(acorn.identifier).matching(acorn.identifierMatch),
  2909. number: pattern_reader.matching(number_pattern),
  2910. punct: pattern_reader.matching(punct_pattern),
  2911. // comment ends just before nearest linefeed or end of file
  2912. comment: pattern_reader.starting_with(/\/\//).until(/[\n\r\u2028\u2029]/),
  2913. // /* ... */ comment ends with nearest */ or end of file
  2914. block_comment: pattern_reader.starting_with(/\/\*/).until_after(/\*\//),
  2915. html_comment_start: pattern_reader.matching(/<!--/),
  2916. html_comment_end: pattern_reader.matching(/-->/),
  2917. include: pattern_reader.starting_with(/#include/).until_after(acorn.lineBreak),
  2918. shebang: pattern_reader.starting_with(/#!/).until_after(acorn.lineBreak),
  2919. xml: pattern_reader.matching(/[\s\S]*?<(\/?)([-a-zA-Z:0-9_.]+|{[^}]+?}|!\[CDATA\[[^\]]*?\]\]|)(\s*{[^}]+?}|\s+[-a-zA-Z:0-9_.]+|\s+[-a-zA-Z:0-9_.]+\s*=\s*('[^']*'|"[^"]*"|{([^{}]|{[^}]+?})+?}))*\s*(\/?)\s*>/),
  2920. single_quote: templatable.until(/['\\\n\r\u2028\u2029]/),
  2921. double_quote: templatable.until(/["\\\n\r\u2028\u2029]/),
  2922. template_text: templatable.until(/[`\\$]/),
  2923. template_expression: templatable.until(/[`}\\]/)
  2924. };
  2925. };
  2926. Tokenizer.prototype = new BaseTokenizer();
  2927. Tokenizer.prototype._is_comment = function(current_token) {
  2928. return current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.BLOCK_COMMENT || current_token.type === TOKEN.UNKNOWN;
  2929. };
  2930. Tokenizer.prototype._is_opening = function(current_token) {
  2931. return current_token.type === TOKEN.START_BLOCK || current_token.type === TOKEN.START_EXPR;
  2932. };
  2933. Tokenizer.prototype._is_closing = function(current_token, open_token) {
  2934. return (current_token.type === TOKEN.END_BLOCK || current_token.type === TOKEN.END_EXPR) &&
  2935. (open_token && (
  2936. (current_token.text === ']' && open_token.text === '[') ||
  2937. (current_token.text === ')' && open_token.text === '(') ||
  2938. (current_token.text === '}' && open_token.text === '{')));
  2939. };
  2940. Tokenizer.prototype._reset = function() {
  2941. in_html_comment = false;
  2942. };
  2943. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  2944. var token = null;
  2945. this._readWhitespace();
  2946. var c = this._input.peek();
  2947. if (c === null) {
  2948. return this._create_token(TOKEN.EOF, '');
  2949. }
  2950. token = token || this._read_non_javascript(c);
  2951. token = token || this._read_string(c);
  2952. token = token || this._read_pair(c, this._input.peek(1)); // Issue #2062 hack for record type '#{'
  2953. token = token || this._read_word(previous_token);
  2954. token = token || this._read_singles(c);
  2955. token = token || this._read_comment(c);
  2956. token = token || this._read_regexp(c, previous_token);
  2957. token = token || this._read_xml(c, previous_token);
  2958. token = token || this._read_punctuation();
  2959. token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
  2960. return token;
  2961. };
  2962. Tokenizer.prototype._read_word = function(previous_token) {
  2963. var resulting_string;
  2964. resulting_string = this.__patterns.identifier.read();
  2965. if (resulting_string !== '') {
  2966. resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
  2967. if (!(previous_token.type === TOKEN.DOT ||
  2968. (previous_token.type === TOKEN.RESERVED && (previous_token.text === 'set' || previous_token.text === 'get'))) &&
  2969. reserved_word_pattern.test(resulting_string)) {
  2970. if ((resulting_string === 'in' || resulting_string === 'of') &&
  2971. (previous_token.type === TOKEN.WORD || previous_token.type === TOKEN.STRING)) { // hack for 'in' and 'of' operators
  2972. return this._create_token(TOKEN.OPERATOR, resulting_string);
  2973. }
  2974. return this._create_token(TOKEN.RESERVED, resulting_string);
  2975. }
  2976. return this._create_token(TOKEN.WORD, resulting_string);
  2977. }
  2978. resulting_string = this.__patterns.number.read();
  2979. if (resulting_string !== '') {
  2980. return this._create_token(TOKEN.WORD, resulting_string);
  2981. }
  2982. };
  2983. Tokenizer.prototype._read_singles = function(c) {
  2984. var token = null;
  2985. if (c === '(' || c === '[') {
  2986. token = this._create_token(TOKEN.START_EXPR, c);
  2987. } else if (c === ')' || c === ']') {
  2988. token = this._create_token(TOKEN.END_EXPR, c);
  2989. } else if (c === '{') {
  2990. token = this._create_token(TOKEN.START_BLOCK, c);
  2991. } else if (c === '}') {
  2992. token = this._create_token(TOKEN.END_BLOCK, c);
  2993. } else if (c === ';') {
  2994. token = this._create_token(TOKEN.SEMICOLON, c);
  2995. } else if (c === '.' && dot_pattern.test(this._input.peek(1))) {
  2996. token = this._create_token(TOKEN.DOT, c);
  2997. } else if (c === ',') {
  2998. token = this._create_token(TOKEN.COMMA, c);
  2999. }
  3000. if (token) {
  3001. this._input.next();
  3002. }
  3003. return token;
  3004. };
  3005. Tokenizer.prototype._read_pair = function(c, d) {
  3006. var token = null;
  3007. if (c === '#' && d === '{') {
  3008. token = this._create_token(TOKEN.START_BLOCK, c + d);
  3009. }
  3010. if (token) {
  3011. this._input.next();
  3012. this._input.next();
  3013. }
  3014. return token;
  3015. };
  3016. Tokenizer.prototype._read_punctuation = function() {
  3017. var resulting_string = this.__patterns.punct.read();
  3018. if (resulting_string !== '') {
  3019. if (resulting_string === '=') {
  3020. return this._create_token(TOKEN.EQUALS, resulting_string);
  3021. } else if (resulting_string === '?.') {
  3022. return this._create_token(TOKEN.DOT, resulting_string);
  3023. } else {
  3024. return this._create_token(TOKEN.OPERATOR, resulting_string);
  3025. }
  3026. }
  3027. };
  3028. Tokenizer.prototype._read_non_javascript = function(c) {
  3029. var resulting_string = '';
  3030. if (c === '#') {
  3031. if (this._is_first_token()) {
  3032. resulting_string = this.__patterns.shebang.read();
  3033. if (resulting_string) {
  3034. return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
  3035. }
  3036. }
  3037. // handles extendscript #includes
  3038. resulting_string = this.__patterns.include.read();
  3039. if (resulting_string) {
  3040. return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
  3041. }
  3042. c = this._input.next();
  3043. // Spidermonkey-specific sharp variables for circular references. Considered obsolete.
  3044. var sharp = '#';
  3045. if (this._input.hasNext() && this._input.testChar(digit)) {
  3046. do {
  3047. c = this._input.next();
  3048. sharp += c;
  3049. } while (this._input.hasNext() && c !== '#' && c !== '=');
  3050. if (c === '#') ; else if (this._input.peek() === '[' && this._input.peek(1) === ']') {
  3051. sharp += '[]';
  3052. this._input.next();
  3053. this._input.next();
  3054. } else if (this._input.peek() === '{' && this._input.peek(1) === '}') {
  3055. sharp += '{}';
  3056. this._input.next();
  3057. this._input.next();
  3058. }
  3059. return this._create_token(TOKEN.WORD, sharp);
  3060. }
  3061. this._input.back();
  3062. } else if (c === '<' && this._is_first_token()) {
  3063. resulting_string = this.__patterns.html_comment_start.read();
  3064. if (resulting_string) {
  3065. while (this._input.hasNext() && !this._input.testChar(acorn.newline)) {
  3066. resulting_string += this._input.next();
  3067. }
  3068. in_html_comment = true;
  3069. return this._create_token(TOKEN.COMMENT, resulting_string);
  3070. }
  3071. } else if (in_html_comment && c === '-') {
  3072. resulting_string = this.__patterns.html_comment_end.read();
  3073. if (resulting_string) {
  3074. in_html_comment = false;
  3075. return this._create_token(TOKEN.COMMENT, resulting_string);
  3076. }
  3077. }
  3078. return null;
  3079. };
  3080. Tokenizer.prototype._read_comment = function(c) {
  3081. var token = null;
  3082. if (c === '/') {
  3083. var comment = '';
  3084. if (this._input.peek(1) === '*') {
  3085. // peek for comment /* ... */
  3086. comment = this.__patterns.block_comment.read();
  3087. var directives = directives_core.get_directives(comment);
  3088. if (directives && directives.ignore === 'start') {
  3089. comment += directives_core.readIgnored(this._input);
  3090. }
  3091. comment = comment.replace(acorn.allLineBreaks, '\n');
  3092. token = this._create_token(TOKEN.BLOCK_COMMENT, comment);
  3093. token.directives = directives;
  3094. } else if (this._input.peek(1) === '/') {
  3095. // peek for comment // ...
  3096. comment = this.__patterns.comment.read();
  3097. token = this._create_token(TOKEN.COMMENT, comment);
  3098. }
  3099. }
  3100. return token;
  3101. };
  3102. Tokenizer.prototype._read_string = function(c) {
  3103. if (c === '`' || c === "'" || c === '"') {
  3104. var resulting_string = this._input.next();
  3105. this.has_char_escapes = false;
  3106. if (c === '`') {
  3107. resulting_string += this._read_string_recursive('`', true, '${');
  3108. } else {
  3109. resulting_string += this._read_string_recursive(c);
  3110. }
  3111. if (this.has_char_escapes && this._options.unescape_strings) {
  3112. resulting_string = unescape_string(resulting_string);
  3113. }
  3114. if (this._input.peek() === c) {
  3115. resulting_string += this._input.next();
  3116. }
  3117. resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
  3118. return this._create_token(TOKEN.STRING, resulting_string);
  3119. }
  3120. return null;
  3121. };
  3122. Tokenizer.prototype._allow_regexp_or_xml = function(previous_token) {
  3123. // regex and xml can only appear in specific locations during parsing
  3124. return (previous_token.type === TOKEN.RESERVED && in_array(previous_token.text, ['return', 'case', 'throw', 'else', 'do', 'typeof', 'yield'])) ||
  3125. (previous_token.type === TOKEN.END_EXPR && previous_token.text === ')' &&
  3126. previous_token.opened.previous.type === TOKEN.RESERVED && in_array(previous_token.opened.previous.text, ['if', 'while', 'for'])) ||
  3127. (in_array(previous_token.type, [TOKEN.COMMENT, TOKEN.START_EXPR, TOKEN.START_BLOCK, TOKEN.START,
  3128. TOKEN.END_BLOCK, TOKEN.OPERATOR, TOKEN.EQUALS, TOKEN.EOF, TOKEN.SEMICOLON, TOKEN.COMMA
  3129. ]));
  3130. };
  3131. Tokenizer.prototype._read_regexp = function(c, previous_token) {
  3132. if (c === '/' && this._allow_regexp_or_xml(previous_token)) {
  3133. // handle regexp
  3134. //
  3135. var resulting_string = this._input.next();
  3136. var esc = false;
  3137. var in_char_class = false;
  3138. while (this._input.hasNext() &&
  3139. ((esc || in_char_class || this._input.peek() !== c) &&
  3140. !this._input.testChar(acorn.newline))) {
  3141. resulting_string += this._input.peek();
  3142. if (!esc) {
  3143. esc = this._input.peek() === '\\';
  3144. if (this._input.peek() === '[') {
  3145. in_char_class = true;
  3146. } else if (this._input.peek() === ']') {
  3147. in_char_class = false;
  3148. }
  3149. } else {
  3150. esc = false;
  3151. }
  3152. this._input.next();
  3153. }
  3154. if (this._input.peek() === c) {
  3155. resulting_string += this._input.next();
  3156. // regexps may have modifiers /regexp/MOD , so fetch those, too
  3157. // Only [gim] are valid, but if the user puts in garbage, do what we can to take it.
  3158. resulting_string += this._input.read(acorn.identifier);
  3159. }
  3160. return this._create_token(TOKEN.STRING, resulting_string);
  3161. }
  3162. return null;
  3163. };
  3164. Tokenizer.prototype._read_xml = function(c, previous_token) {
  3165. if (this._options.e4x && c === "<" && this._allow_regexp_or_xml(previous_token)) {
  3166. var xmlStr = '';
  3167. var match = this.__patterns.xml.read_match();
  3168. // handle e4x xml literals
  3169. //
  3170. if (match) {
  3171. // Trim root tag to attempt to
  3172. var rootTag = match[2].replace(/^{\s+/, '{').replace(/\s+}$/, '}');
  3173. var isCurlyRoot = rootTag.indexOf('{') === 0;
  3174. var depth = 0;
  3175. while (match) {
  3176. var isEndTag = !!match[1];
  3177. var tagName = match[2];
  3178. var isSingletonTag = (!!match[match.length - 1]) || (tagName.slice(0, 8) === "![CDATA[");
  3179. if (!isSingletonTag &&
  3180. (tagName === rootTag || (isCurlyRoot && tagName.replace(/^{\s+/, '{').replace(/\s+}$/, '}')))) {
  3181. if (isEndTag) {
  3182. --depth;
  3183. } else {
  3184. ++depth;
  3185. }
  3186. }
  3187. xmlStr += match[0];
  3188. if (depth <= 0) {
  3189. break;
  3190. }
  3191. match = this.__patterns.xml.read_match();
  3192. }
  3193. // if we didn't close correctly, keep unformatted.
  3194. if (!match) {
  3195. xmlStr += this._input.match(/[\s\S]*/g)[0];
  3196. }
  3197. xmlStr = xmlStr.replace(acorn.allLineBreaks, '\n');
  3198. return this._create_token(TOKEN.STRING, xmlStr);
  3199. }
  3200. }
  3201. return null;
  3202. };
  3203. function unescape_string(s) {
  3204. // You think that a regex would work for this
  3205. // return s.replace(/\\x([0-9a-f]{2})/gi, function(match, val) {
  3206. // return String.fromCharCode(parseInt(val, 16));
  3207. // })
  3208. // However, dealing with '\xff', '\\xff', '\\\xff' makes this more fun.
  3209. var out = '',
  3210. escaped = 0;
  3211. var input_scan = new InputScanner(s);
  3212. var matched = null;
  3213. while (input_scan.hasNext()) {
  3214. // Keep any whitespace, non-slash characters
  3215. // also keep slash pairs.
  3216. matched = input_scan.match(/([\s]|[^\\]|\\\\)+/g);
  3217. if (matched) {
  3218. out += matched[0];
  3219. }
  3220. if (input_scan.peek() === '\\') {
  3221. input_scan.next();
  3222. if (input_scan.peek() === 'x') {
  3223. matched = input_scan.match(/x([0-9A-Fa-f]{2})/g);
  3224. } else if (input_scan.peek() === 'u') {
  3225. matched = input_scan.match(/u([0-9A-Fa-f]{4})/g);
  3226. } else {
  3227. out += '\\';
  3228. if (input_scan.hasNext()) {
  3229. out += input_scan.next();
  3230. }
  3231. continue;
  3232. }
  3233. // If there's some error decoding, return the original string
  3234. if (!matched) {
  3235. return s;
  3236. }
  3237. escaped = parseInt(matched[1], 16);
  3238. if (escaped > 0x7e && escaped <= 0xff && matched[0].indexOf('x') === 0) {
  3239. // we bail out on \x7f..\xff,
  3240. // leaving whole string escaped,
  3241. // as it's probably completely binary
  3242. return s;
  3243. } else if (escaped >= 0x00 && escaped < 0x20) {
  3244. // leave 0x00...0x1f escaped
  3245. out += '\\' + matched[0];
  3246. continue;
  3247. } else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
  3248. // single-quote, apostrophe, backslash - escape these
  3249. out += '\\' + String.fromCharCode(escaped);
  3250. } else {
  3251. out += String.fromCharCode(escaped);
  3252. }
  3253. }
  3254. }
  3255. return out;
  3256. }
  3257. // handle string
  3258. //
  3259. Tokenizer.prototype._read_string_recursive = function(delimiter, allow_unescaped_newlines, start_sub) {
  3260. var current_char;
  3261. var pattern;
  3262. if (delimiter === '\'') {
  3263. pattern = this.__patterns.single_quote;
  3264. } else if (delimiter === '"') {
  3265. pattern = this.__patterns.double_quote;
  3266. } else if (delimiter === '`') {
  3267. pattern = this.__patterns.template_text;
  3268. } else if (delimiter === '}') {
  3269. pattern = this.__patterns.template_expression;
  3270. }
  3271. var resulting_string = pattern.read();
  3272. var next = '';
  3273. while (this._input.hasNext()) {
  3274. next = this._input.next();
  3275. if (next === delimiter ||
  3276. (!allow_unescaped_newlines && acorn.newline.test(next))) {
  3277. this._input.back();
  3278. break;
  3279. } else if (next === '\\' && this._input.hasNext()) {
  3280. current_char = this._input.peek();
  3281. if (current_char === 'x' || current_char === 'u') {
  3282. this.has_char_escapes = true;
  3283. } else if (current_char === '\r' && this._input.peek(1) === '\n') {
  3284. this._input.next();
  3285. }
  3286. next += this._input.next();
  3287. } else if (start_sub) {
  3288. if (start_sub === '${' && next === '$' && this._input.peek() === '{') {
  3289. next += this._input.next();
  3290. }
  3291. if (start_sub === next) {
  3292. if (delimiter === '`') {
  3293. next += this._read_string_recursive('}', allow_unescaped_newlines, '`');
  3294. } else {
  3295. next += this._read_string_recursive('`', allow_unescaped_newlines, '${');
  3296. }
  3297. if (this._input.hasNext()) {
  3298. next += this._input.next();
  3299. }
  3300. }
  3301. }
  3302. next += pattern.read();
  3303. resulting_string += next;
  3304. }
  3305. return resulting_string;
  3306. };
  3307. tokenizer$3.Tokenizer = Tokenizer;
  3308. tokenizer$3.TOKEN = TOKEN;
  3309. tokenizer$3.positionable_operators = positionable_operators.slice();
  3310. tokenizer$3.line_starters = line_starters.slice();
  3311. return tokenizer$3;
  3312. }
  3313. /*jshint node:true */
  3314. var hasRequiredBeautifier$2;
  3315. function requireBeautifier$2 () {
  3316. if (hasRequiredBeautifier$2) return beautifier$2;
  3317. hasRequiredBeautifier$2 = 1;
  3318. var Output = requireOutput().Output;
  3319. var Token = requireToken().Token;
  3320. var acorn = requireAcorn();
  3321. var Options = requireOptions$2().Options;
  3322. var Tokenizer = requireTokenizer$1().Tokenizer;
  3323. var line_starters = requireTokenizer$1().line_starters;
  3324. var positionable_operators = requireTokenizer$1().positionable_operators;
  3325. var TOKEN = requireTokenizer$1().TOKEN;
  3326. function in_array(what, arr) {
  3327. return arr.indexOf(what) !== -1;
  3328. }
  3329. function ltrim(s) {
  3330. return s.replace(/^\s+/g, '');
  3331. }
  3332. function generateMapFromStrings(list) {
  3333. var result = {};
  3334. for (var x = 0; x < list.length; x++) {
  3335. // make the mapped names underscored instead of dash
  3336. result[list[x].replace(/-/g, '_')] = list[x];
  3337. }
  3338. return result;
  3339. }
  3340. function reserved_word(token, word) {
  3341. return token && token.type === TOKEN.RESERVED && token.text === word;
  3342. }
  3343. function reserved_array(token, words) {
  3344. return token && token.type === TOKEN.RESERVED && in_array(token.text, words);
  3345. }
  3346. // Unsure of what they mean, but they work. Worth cleaning up in future.
  3347. var special_words = ['case', 'return', 'do', 'if', 'throw', 'else', 'await', 'break', 'continue', 'async'];
  3348. var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
  3349. // Generate map from array
  3350. var OPERATOR_POSITION = generateMapFromStrings(validPositionValues);
  3351. var OPERATOR_POSITION_BEFORE_OR_PRESERVE = [OPERATOR_POSITION.before_newline, OPERATOR_POSITION.preserve_newline];
  3352. var MODE = {
  3353. BlockStatement: 'BlockStatement', // 'BLOCK'
  3354. Statement: 'Statement', // 'STATEMENT'
  3355. ObjectLiteral: 'ObjectLiteral', // 'OBJECT',
  3356. ArrayLiteral: 'ArrayLiteral', //'[EXPRESSION]',
  3357. ForInitializer: 'ForInitializer', //'(FOR-EXPRESSION)',
  3358. Conditional: 'Conditional', //'(COND-EXPRESSION)',
  3359. Expression: 'Expression' //'(EXPRESSION)'
  3360. };
  3361. function remove_redundant_indentation(output, frame) {
  3362. // This implementation is effective but has some issues:
  3363. // - can cause line wrap to happen too soon due to indent removal
  3364. // after wrap points are calculated
  3365. // These issues are minor compared to ugly indentation.
  3366. if (frame.multiline_frame ||
  3367. frame.mode === MODE.ForInitializer ||
  3368. frame.mode === MODE.Conditional) {
  3369. return;
  3370. }
  3371. // remove one indent from each line inside this section
  3372. output.remove_indent(frame.start_line_index);
  3373. }
  3374. // we could use just string.split, but
  3375. // IE doesn't like returning empty strings
  3376. function split_linebreaks(s) {
  3377. //return s.split(/\x0d\x0a|\x0a/);
  3378. s = s.replace(acorn.allLineBreaks, '\n');
  3379. var out = [],
  3380. idx = s.indexOf("\n");
  3381. while (idx !== -1) {
  3382. out.push(s.substring(0, idx));
  3383. s = s.substring(idx + 1);
  3384. idx = s.indexOf("\n");
  3385. }
  3386. if (s.length) {
  3387. out.push(s);
  3388. }
  3389. return out;
  3390. }
  3391. function is_array(mode) {
  3392. return mode === MODE.ArrayLiteral;
  3393. }
  3394. function is_expression(mode) {
  3395. return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
  3396. }
  3397. function all_lines_start_with(lines, c) {
  3398. for (var i = 0; i < lines.length; i++) {
  3399. var line = lines[i].trim();
  3400. if (line.charAt(0) !== c) {
  3401. return false;
  3402. }
  3403. }
  3404. return true;
  3405. }
  3406. function each_line_matches_indent(lines, indent) {
  3407. var i = 0,
  3408. len = lines.length,
  3409. line;
  3410. for (; i < len; i++) {
  3411. line = lines[i];
  3412. // allow empty lines to pass through
  3413. if (line && line.indexOf(indent) !== 0) {
  3414. return false;
  3415. }
  3416. }
  3417. return true;
  3418. }
  3419. function Beautifier(source_text, options) {
  3420. options = options || {};
  3421. this._source_text = source_text || '';
  3422. this._output = null;
  3423. this._tokens = null;
  3424. this._last_last_text = null;
  3425. this._flags = null;
  3426. this._previous_flags = null;
  3427. this._flag_store = null;
  3428. this._options = new Options(options);
  3429. }
  3430. Beautifier.prototype.create_flags = function(flags_base, mode) {
  3431. var next_indent_level = 0;
  3432. if (flags_base) {
  3433. next_indent_level = flags_base.indentation_level;
  3434. if (!this._output.just_added_newline() &&
  3435. flags_base.line_indent_level > next_indent_level) {
  3436. next_indent_level = flags_base.line_indent_level;
  3437. }
  3438. }
  3439. var next_flags = {
  3440. mode: mode,
  3441. parent: flags_base,
  3442. last_token: flags_base ? flags_base.last_token : new Token(TOKEN.START_BLOCK, ''), // last token text
  3443. last_word: flags_base ? flags_base.last_word : '', // last TOKEN.WORD passed
  3444. declaration_statement: false,
  3445. declaration_assignment: false,
  3446. multiline_frame: false,
  3447. inline_frame: false,
  3448. if_block: false,
  3449. else_block: false,
  3450. class_start_block: false, // class A { INSIDE HERE } or class B extends C { INSIDE HERE }
  3451. do_block: false,
  3452. do_while: false,
  3453. import_block: false,
  3454. in_case_statement: false, // switch(..){ INSIDE HERE }
  3455. in_case: false, // we're on the exact line with "case 0:"
  3456. case_body: false, // the indented case-action block
  3457. case_block: false, // the indented case-action block is wrapped with {}
  3458. indentation_level: next_indent_level,
  3459. alignment: 0,
  3460. line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
  3461. start_line_index: this._output.get_line_number(),
  3462. ternary_depth: 0
  3463. };
  3464. return next_flags;
  3465. };
  3466. Beautifier.prototype._reset = function(source_text) {
  3467. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  3468. this._last_last_text = ''; // pre-last token text
  3469. this._output = new Output(this._options, baseIndentString);
  3470. // If testing the ignore directive, start with output disable set to true
  3471. this._output.raw = this._options.test_output_raw;
  3472. // Stack of parsing/formatting states, including MODE.
  3473. // We tokenize, parse, and output in an almost purely a forward-only stream of token input
  3474. // and formatted output. This makes the beautifier less accurate than full parsers
  3475. // but also far more tolerant of syntax errors.
  3476. //
  3477. // For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type
  3478. // MODE.BlockStatement on the the stack, even though it could be object literal. If we later
  3479. // encounter a ":", we'll switch to to MODE.ObjectLiteral. If we then see a ";",
  3480. // most full parsers would die, but the beautifier gracefully falls back to
  3481. // MODE.BlockStatement and continues on.
  3482. this._flag_store = [];
  3483. this.set_mode(MODE.BlockStatement);
  3484. var tokenizer = new Tokenizer(source_text, this._options);
  3485. this._tokens = tokenizer.tokenize();
  3486. return source_text;
  3487. };
  3488. Beautifier.prototype.beautify = function() {
  3489. // if disabled, return the input unchanged.
  3490. if (this._options.disabled) {
  3491. return this._source_text;
  3492. }
  3493. var sweet_code;
  3494. var source_text = this._reset(this._source_text);
  3495. var eol = this._options.eol;
  3496. if (this._options.eol === 'auto') {
  3497. eol = '\n';
  3498. if (source_text && acorn.lineBreak.test(source_text || '')) {
  3499. eol = source_text.match(acorn.lineBreak)[0];
  3500. }
  3501. }
  3502. var current_token = this._tokens.next();
  3503. while (current_token) {
  3504. this.handle_token(current_token);
  3505. this._last_last_text = this._flags.last_token.text;
  3506. this._flags.last_token = current_token;
  3507. current_token = this._tokens.next();
  3508. }
  3509. sweet_code = this._output.get_code(eol);
  3510. return sweet_code;
  3511. };
  3512. Beautifier.prototype.handle_token = function(current_token, preserve_statement_flags) {
  3513. if (current_token.type === TOKEN.START_EXPR) {
  3514. this.handle_start_expr(current_token);
  3515. } else if (current_token.type === TOKEN.END_EXPR) {
  3516. this.handle_end_expr(current_token);
  3517. } else if (current_token.type === TOKEN.START_BLOCK) {
  3518. this.handle_start_block(current_token);
  3519. } else if (current_token.type === TOKEN.END_BLOCK) {
  3520. this.handle_end_block(current_token);
  3521. } else if (current_token.type === TOKEN.WORD) {
  3522. this.handle_word(current_token);
  3523. } else if (current_token.type === TOKEN.RESERVED) {
  3524. this.handle_word(current_token);
  3525. } else if (current_token.type === TOKEN.SEMICOLON) {
  3526. this.handle_semicolon(current_token);
  3527. } else if (current_token.type === TOKEN.STRING) {
  3528. this.handle_string(current_token);
  3529. } else if (current_token.type === TOKEN.EQUALS) {
  3530. this.handle_equals(current_token);
  3531. } else if (current_token.type === TOKEN.OPERATOR) {
  3532. this.handle_operator(current_token);
  3533. } else if (current_token.type === TOKEN.COMMA) {
  3534. this.handle_comma(current_token);
  3535. } else if (current_token.type === TOKEN.BLOCK_COMMENT) {
  3536. this.handle_block_comment(current_token, preserve_statement_flags);
  3537. } else if (current_token.type === TOKEN.COMMENT) {
  3538. this.handle_comment(current_token, preserve_statement_flags);
  3539. } else if (current_token.type === TOKEN.DOT) {
  3540. this.handle_dot(current_token);
  3541. } else if (current_token.type === TOKEN.EOF) {
  3542. this.handle_eof(current_token);
  3543. } else if (current_token.type === TOKEN.UNKNOWN) {
  3544. this.handle_unknown(current_token, preserve_statement_flags);
  3545. } else {
  3546. this.handle_unknown(current_token, preserve_statement_flags);
  3547. }
  3548. };
  3549. Beautifier.prototype.handle_whitespace_and_comments = function(current_token, preserve_statement_flags) {
  3550. var newlines = current_token.newlines;
  3551. var keep_whitespace = this._options.keep_array_indentation && is_array(this._flags.mode);
  3552. if (current_token.comments_before) {
  3553. var comment_token = current_token.comments_before.next();
  3554. while (comment_token) {
  3555. // The cleanest handling of inline comments is to treat them as though they aren't there.
  3556. // Just continue formatting and the behavior should be logical.
  3557. // Also ignore unknown tokens. Again, this should result in better behavior.
  3558. this.handle_whitespace_and_comments(comment_token, preserve_statement_flags);
  3559. this.handle_token(comment_token, preserve_statement_flags);
  3560. comment_token = current_token.comments_before.next();
  3561. }
  3562. }
  3563. if (keep_whitespace) {
  3564. for (var i = 0; i < newlines; i += 1) {
  3565. this.print_newline(i > 0, preserve_statement_flags);
  3566. }
  3567. } else {
  3568. if (this._options.max_preserve_newlines && newlines > this._options.max_preserve_newlines) {
  3569. newlines = this._options.max_preserve_newlines;
  3570. }
  3571. if (this._options.preserve_newlines) {
  3572. if (newlines > 1) {
  3573. this.print_newline(false, preserve_statement_flags);
  3574. for (var j = 1; j < newlines; j += 1) {
  3575. this.print_newline(true, preserve_statement_flags);
  3576. }
  3577. }
  3578. }
  3579. }
  3580. };
  3581. var newline_restricted_tokens = ['async', 'break', 'continue', 'return', 'throw', 'yield'];
  3582. Beautifier.prototype.allow_wrap_or_preserved_newline = function(current_token, force_linewrap) {
  3583. force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
  3584. // Never wrap the first token on a line
  3585. if (this._output.just_added_newline()) {
  3586. return;
  3587. }
  3588. var shouldPreserveOrForce = (this._options.preserve_newlines && current_token.newlines) || force_linewrap;
  3589. var operatorLogicApplies = in_array(this._flags.last_token.text, positionable_operators) ||
  3590. in_array(current_token.text, positionable_operators);
  3591. if (operatorLogicApplies) {
  3592. var shouldPrintOperatorNewline = (
  3593. in_array(this._flags.last_token.text, positionable_operators) &&
  3594. in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)
  3595. ) ||
  3596. in_array(current_token.text, positionable_operators);
  3597. shouldPreserveOrForce = shouldPreserveOrForce && shouldPrintOperatorNewline;
  3598. }
  3599. if (shouldPreserveOrForce) {
  3600. this.print_newline(false, true);
  3601. } else if (this._options.wrap_line_length) {
  3602. if (reserved_array(this._flags.last_token, newline_restricted_tokens)) {
  3603. // These tokens should never have a newline inserted
  3604. // between them and the following expression.
  3605. return;
  3606. }
  3607. this._output.set_wrap_point();
  3608. }
  3609. };
  3610. Beautifier.prototype.print_newline = function(force_newline, preserve_statement_flags) {
  3611. if (!preserve_statement_flags) {
  3612. if (this._flags.last_token.text !== ';' && this._flags.last_token.text !== ',' && this._flags.last_token.text !== '=' && (this._flags.last_token.type !== TOKEN.OPERATOR || this._flags.last_token.text === '--' || this._flags.last_token.text === '++')) {
  3613. var next_token = this._tokens.peek();
  3614. while (this._flags.mode === MODE.Statement &&
  3615. !(this._flags.if_block && reserved_word(next_token, 'else')) &&
  3616. !this._flags.do_block) {
  3617. this.restore_mode();
  3618. }
  3619. }
  3620. }
  3621. if (this._output.add_new_line(force_newline)) {
  3622. this._flags.multiline_frame = true;
  3623. }
  3624. };
  3625. Beautifier.prototype.print_token_line_indentation = function(current_token) {
  3626. if (this._output.just_added_newline()) {
  3627. if (this._options.keep_array_indentation &&
  3628. current_token.newlines &&
  3629. (current_token.text === '[' || is_array(this._flags.mode))) {
  3630. this._output.current_line.set_indent(-1);
  3631. this._output.current_line.push(current_token.whitespace_before);
  3632. this._output.space_before_token = false;
  3633. } else if (this._output.set_indent(this._flags.indentation_level, this._flags.alignment)) {
  3634. this._flags.line_indent_level = this._flags.indentation_level;
  3635. }
  3636. }
  3637. };
  3638. Beautifier.prototype.print_token = function(current_token) {
  3639. if (this._output.raw) {
  3640. this._output.add_raw_token(current_token);
  3641. return;
  3642. }
  3643. if (this._options.comma_first && current_token.previous && current_token.previous.type === TOKEN.COMMA &&
  3644. this._output.just_added_newline()) {
  3645. if (this._output.previous_line.last() === ',') {
  3646. var popped = this._output.previous_line.pop();
  3647. // if the comma was already at the start of the line,
  3648. // pull back onto that line and reprint the indentation
  3649. if (this._output.previous_line.is_empty()) {
  3650. this._output.previous_line.push(popped);
  3651. this._output.trim(true);
  3652. this._output.current_line.pop();
  3653. this._output.trim();
  3654. }
  3655. // add the comma in front of the next token
  3656. this.print_token_line_indentation(current_token);
  3657. this._output.add_token(',');
  3658. this._output.space_before_token = true;
  3659. }
  3660. }
  3661. this.print_token_line_indentation(current_token);
  3662. this._output.non_breaking_space = true;
  3663. this._output.add_token(current_token.text);
  3664. if (this._output.previous_token_wrapped) {
  3665. this._flags.multiline_frame = true;
  3666. }
  3667. };
  3668. Beautifier.prototype.indent = function() {
  3669. this._flags.indentation_level += 1;
  3670. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  3671. };
  3672. Beautifier.prototype.deindent = function() {
  3673. if (this._flags.indentation_level > 0 &&
  3674. ((!this._flags.parent) || this._flags.indentation_level > this._flags.parent.indentation_level)) {
  3675. this._flags.indentation_level -= 1;
  3676. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  3677. }
  3678. };
  3679. Beautifier.prototype.set_mode = function(mode) {
  3680. if (this._flags) {
  3681. this._flag_store.push(this._flags);
  3682. this._previous_flags = this._flags;
  3683. } else {
  3684. this._previous_flags = this.create_flags(null, mode);
  3685. }
  3686. this._flags = this.create_flags(this._previous_flags, mode);
  3687. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  3688. };
  3689. Beautifier.prototype.restore_mode = function() {
  3690. if (this._flag_store.length > 0) {
  3691. this._previous_flags = this._flags;
  3692. this._flags = this._flag_store.pop();
  3693. if (this._previous_flags.mode === MODE.Statement) {
  3694. remove_redundant_indentation(this._output, this._previous_flags);
  3695. }
  3696. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  3697. }
  3698. };
  3699. Beautifier.prototype.start_of_object_property = function() {
  3700. return this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement && (
  3701. (this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || (reserved_array(this._flags.last_token, ['get', 'set'])));
  3702. };
  3703. Beautifier.prototype.start_of_statement = function(current_token) {
  3704. var start = false;
  3705. start = start || reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD;
  3706. start = start || reserved_word(this._flags.last_token, 'do');
  3707. start = start || (!(this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement)) && reserved_array(this._flags.last_token, newline_restricted_tokens) && !current_token.newlines;
  3708. start = start || reserved_word(this._flags.last_token, 'else') &&
  3709. !(reserved_word(current_token, 'if') && !current_token.comments_before);
  3710. start = start || (this._flags.last_token.type === TOKEN.END_EXPR && (this._previous_flags.mode === MODE.ForInitializer || this._previous_flags.mode === MODE.Conditional));
  3711. start = start || (this._flags.last_token.type === TOKEN.WORD && this._flags.mode === MODE.BlockStatement &&
  3712. !this._flags.in_case &&
  3713. !(current_token.text === '--' || current_token.text === '++') &&
  3714. this._last_last_text !== 'function' &&
  3715. current_token.type !== TOKEN.WORD && current_token.type !== TOKEN.RESERVED);
  3716. start = start || (this._flags.mode === MODE.ObjectLiteral && (
  3717. (this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || reserved_array(this._flags.last_token, ['get', 'set'])));
  3718. if (start) {
  3719. this.set_mode(MODE.Statement);
  3720. this.indent();
  3721. this.handle_whitespace_and_comments(current_token, true);
  3722. // Issue #276:
  3723. // If starting a new statement with [if, for, while, do], push to a new line.
  3724. // if (a) if (b) if(c) d(); else e(); else f();
  3725. if (!this.start_of_object_property()) {
  3726. this.allow_wrap_or_preserved_newline(current_token,
  3727. reserved_array(current_token, ['do', 'for', 'if', 'while']));
  3728. }
  3729. return true;
  3730. }
  3731. return false;
  3732. };
  3733. Beautifier.prototype.handle_start_expr = function(current_token) {
  3734. // The conditional starts the statement if appropriate.
  3735. if (!this.start_of_statement(current_token)) {
  3736. this.handle_whitespace_and_comments(current_token);
  3737. }
  3738. var next_mode = MODE.Expression;
  3739. if (current_token.text === '[') {
  3740. if (this._flags.last_token.type === TOKEN.WORD || this._flags.last_token.text === ')') {
  3741. // this is array index specifier, break immediately
  3742. // a[x], fn()[x]
  3743. if (reserved_array(this._flags.last_token, line_starters)) {
  3744. this._output.space_before_token = true;
  3745. }
  3746. this.print_token(current_token);
  3747. this.set_mode(next_mode);
  3748. this.indent();
  3749. if (this._options.space_in_paren) {
  3750. this._output.space_before_token = true;
  3751. }
  3752. return;
  3753. }
  3754. next_mode = MODE.ArrayLiteral;
  3755. if (is_array(this._flags.mode)) {
  3756. if (this._flags.last_token.text === '[' ||
  3757. (this._flags.last_token.text === ',' && (this._last_last_text === ']' || this._last_last_text === '}'))) {
  3758. // ], [ goes to new line
  3759. // }, [ goes to new line
  3760. if (!this._options.keep_array_indentation) {
  3761. this.print_newline();
  3762. }
  3763. }
  3764. }
  3765. if (!in_array(this._flags.last_token.type, [TOKEN.START_EXPR, TOKEN.END_EXPR, TOKEN.WORD, TOKEN.OPERATOR, TOKEN.DOT])) {
  3766. this._output.space_before_token = true;
  3767. }
  3768. } else {
  3769. if (this._flags.last_token.type === TOKEN.RESERVED) {
  3770. if (this._flags.last_token.text === 'for') {
  3771. this._output.space_before_token = this._options.space_before_conditional;
  3772. next_mode = MODE.ForInitializer;
  3773. } else if (in_array(this._flags.last_token.text, ['if', 'while', 'switch'])) {
  3774. this._output.space_before_token = this._options.space_before_conditional;
  3775. next_mode = MODE.Conditional;
  3776. } else if (in_array(this._flags.last_word, ['await', 'async'])) {
  3777. // Should be a space between await and an IIFE, or async and an arrow function
  3778. this._output.space_before_token = true;
  3779. } else if (this._flags.last_token.text === 'import' && current_token.whitespace_before === '') {
  3780. this._output.space_before_token = false;
  3781. } else if (in_array(this._flags.last_token.text, line_starters) || this._flags.last_token.text === 'catch') {
  3782. this._output.space_before_token = true;
  3783. }
  3784. } else if (this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
  3785. // Support of this kind of newline preservation.
  3786. // a = (b &&
  3787. // (c || d));
  3788. if (!this.start_of_object_property()) {
  3789. this.allow_wrap_or_preserved_newline(current_token);
  3790. }
  3791. } else if (this._flags.last_token.type === TOKEN.WORD) {
  3792. this._output.space_before_token = false;
  3793. // function name() vs function name ()
  3794. // function* name() vs function* name ()
  3795. // async name() vs async name ()
  3796. // In ES6, you can also define the method properties of an object
  3797. // var obj = {a: function() {}}
  3798. // It can be abbreviated
  3799. // var obj = {a() {}}
  3800. // var obj = { a() {}} vs var obj = { a () {}}
  3801. // var obj = { * a() {}} vs var obj = { * a () {}}
  3802. var peek_back_two = this._tokens.peek(-3);
  3803. if (this._options.space_after_named_function && peek_back_two) {
  3804. // peek starts at next character so -1 is current token
  3805. var peek_back_three = this._tokens.peek(-4);
  3806. if (reserved_array(peek_back_two, ['async', 'function']) ||
  3807. (peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) {
  3808. this._output.space_before_token = true;
  3809. } else if (this._flags.mode === MODE.ObjectLiteral) {
  3810. if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
  3811. (peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
  3812. this._output.space_before_token = true;
  3813. }
  3814. } else if (this._flags.parent && this._flags.parent.class_start_block) {
  3815. this._output.space_before_token = true;
  3816. }
  3817. }
  3818. } else {
  3819. // Support preserving wrapped arrow function expressions
  3820. // a.b('c',
  3821. // () => d.e
  3822. // )
  3823. this.allow_wrap_or_preserved_newline(current_token);
  3824. }
  3825. // function() vs function ()
  3826. // yield*() vs yield* ()
  3827. // function*() vs function* ()
  3828. if ((this._flags.last_token.type === TOKEN.RESERVED && (this._flags.last_word === 'function' || this._flags.last_word === 'typeof')) ||
  3829. (this._flags.last_token.text === '*' &&
  3830. (in_array(this._last_last_text, ['function', 'yield']) ||
  3831. (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
  3832. this._output.space_before_token = this._options.space_after_anon_function;
  3833. }
  3834. }
  3835. if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) {
  3836. this.print_newline();
  3837. } else if (this._flags.last_token.type === TOKEN.END_EXPR || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.END_BLOCK || this._flags.last_token.text === '.' || this._flags.last_token.type === TOKEN.COMMA) {
  3838. // do nothing on (( and )( and ][ and ]( and .(
  3839. // TODO: Consider whether forcing this is required. Review failing tests when removed.
  3840. this.allow_wrap_or_preserved_newline(current_token, current_token.newlines);
  3841. }
  3842. this.print_token(current_token);
  3843. this.set_mode(next_mode);
  3844. if (this._options.space_in_paren) {
  3845. this._output.space_before_token = true;
  3846. }
  3847. // In all cases, if we newline while inside an expression it should be indented.
  3848. this.indent();
  3849. };
  3850. Beautifier.prototype.handle_end_expr = function(current_token) {
  3851. // statements inside expressions are not valid syntax, but...
  3852. // statements must all be closed when their container closes
  3853. while (this._flags.mode === MODE.Statement) {
  3854. this.restore_mode();
  3855. }
  3856. this.handle_whitespace_and_comments(current_token);
  3857. if (this._flags.multiline_frame) {
  3858. this.allow_wrap_or_preserved_newline(current_token,
  3859. current_token.text === ']' && is_array(this._flags.mode) && !this._options.keep_array_indentation);
  3860. }
  3861. if (this._options.space_in_paren) {
  3862. if (this._flags.last_token.type === TOKEN.START_EXPR && !this._options.space_in_empty_paren) {
  3863. // () [] no inner space in empty parens like these, ever, ref #320
  3864. this._output.trim();
  3865. this._output.space_before_token = false;
  3866. } else {
  3867. this._output.space_before_token = true;
  3868. }
  3869. }
  3870. this.deindent();
  3871. this.print_token(current_token);
  3872. this.restore_mode();
  3873. remove_redundant_indentation(this._output, this._previous_flags);
  3874. // do {} while () // no statement required after
  3875. if (this._flags.do_while && this._previous_flags.mode === MODE.Conditional) {
  3876. this._previous_flags.mode = MODE.Expression;
  3877. this._flags.do_block = false;
  3878. this._flags.do_while = false;
  3879. }
  3880. };
  3881. Beautifier.prototype.handle_start_block = function(current_token) {
  3882. this.handle_whitespace_and_comments(current_token);
  3883. // Check if this is should be treated as a ObjectLiteral
  3884. var next_token = this._tokens.peek();
  3885. var second_token = this._tokens.peek(1);
  3886. if (this._flags.last_word === 'switch' && this._flags.last_token.type === TOKEN.END_EXPR) {
  3887. this.set_mode(MODE.BlockStatement);
  3888. this._flags.in_case_statement = true;
  3889. } else if (this._flags.case_body) {
  3890. this.set_mode(MODE.BlockStatement);
  3891. } else if (second_token && (
  3892. (in_array(second_token.text, [':', ',']) && in_array(next_token.type, [TOKEN.STRING, TOKEN.WORD, TOKEN.RESERVED])) ||
  3893. (in_array(next_token.text, ['get', 'set', '...']) && in_array(second_token.type, [TOKEN.WORD, TOKEN.RESERVED]))
  3894. )) {
  3895. // We don't support TypeScript,but we didn't break it for a very long time.
  3896. // We'll try to keep not breaking it.
  3897. if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) {
  3898. this.set_mode(MODE.BlockStatement);
  3899. } else {
  3900. this.set_mode(MODE.ObjectLiteral);
  3901. }
  3902. } else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
  3903. // arrow function: (param1, paramN) => { statements }
  3904. this.set_mode(MODE.BlockStatement);
  3905. } else if (in_array(this._flags.last_token.type, [TOKEN.EQUALS, TOKEN.START_EXPR, TOKEN.COMMA, TOKEN.OPERATOR]) ||
  3906. reserved_array(this._flags.last_token, ['return', 'throw', 'import', 'default'])
  3907. ) {
  3908. // Detecting shorthand function syntax is difficult by scanning forward,
  3909. // so check the surrounding context.
  3910. // If the block is being returned, imported, export default, passed as arg,
  3911. // assigned with = or assigned in a nested object, treat as an ObjectLiteral.
  3912. this.set_mode(MODE.ObjectLiteral);
  3913. } else {
  3914. this.set_mode(MODE.BlockStatement);
  3915. }
  3916. if (this._flags.last_token) {
  3917. if (reserved_array(this._flags.last_token.previous, ['class', 'extends'])) {
  3918. this._flags.class_start_block = true;
  3919. }
  3920. }
  3921. var empty_braces = !next_token.comments_before && next_token.text === '}';
  3922. var empty_anonymous_function = empty_braces && this._flags.last_word === 'function' &&
  3923. this._flags.last_token.type === TOKEN.END_EXPR;
  3924. if (this._options.brace_preserve_inline) // check for inline, set inline_frame if so
  3925. {
  3926. // search forward for a newline wanted inside this block
  3927. var index = 0;
  3928. var check_token = null;
  3929. this._flags.inline_frame = true;
  3930. do {
  3931. index += 1;
  3932. check_token = this._tokens.peek(index - 1);
  3933. if (check_token.newlines) {
  3934. this._flags.inline_frame = false;
  3935. break;
  3936. }
  3937. } while (check_token.type !== TOKEN.EOF &&
  3938. !(check_token.type === TOKEN.END_BLOCK && check_token.opened === current_token));
  3939. }
  3940. if ((this._options.brace_style === "expand" ||
  3941. (this._options.brace_style === "none" && current_token.newlines)) &&
  3942. !this._flags.inline_frame) {
  3943. if (this._flags.last_token.type !== TOKEN.OPERATOR &&
  3944. (empty_anonymous_function ||
  3945. this._flags.last_token.type === TOKEN.EQUALS ||
  3946. (reserved_array(this._flags.last_token, special_words) && this._flags.last_token.text !== 'else'))) {
  3947. this._output.space_before_token = true;
  3948. } else {
  3949. this.print_newline(false, true);
  3950. }
  3951. } else { // collapse || inline_frame
  3952. if (is_array(this._previous_flags.mode) && (this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.COMMA)) {
  3953. if (this._flags.last_token.type === TOKEN.COMMA || this._options.space_in_paren) {
  3954. this._output.space_before_token = true;
  3955. }
  3956. if (this._flags.last_token.type === TOKEN.COMMA || (this._flags.last_token.type === TOKEN.START_EXPR && this._flags.inline_frame)) {
  3957. this.allow_wrap_or_preserved_newline(current_token);
  3958. this._previous_flags.multiline_frame = this._previous_flags.multiline_frame || this._flags.multiline_frame;
  3959. this._flags.multiline_frame = false;
  3960. }
  3961. }
  3962. if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
  3963. if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
  3964. this.print_newline();
  3965. } else {
  3966. this._output.space_before_token = true;
  3967. }
  3968. }
  3969. }
  3970. this.print_token(current_token);
  3971. this.indent();
  3972. // Except for specific cases, open braces are followed by a new line.
  3973. if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) {
  3974. this.print_newline();
  3975. }
  3976. };
  3977. Beautifier.prototype.handle_end_block = function(current_token) {
  3978. // statements must all be closed when their container closes
  3979. this.handle_whitespace_and_comments(current_token);
  3980. while (this._flags.mode === MODE.Statement) {
  3981. this.restore_mode();
  3982. }
  3983. var empty_braces = this._flags.last_token.type === TOKEN.START_BLOCK;
  3984. if (this._flags.inline_frame && !empty_braces) { // try inline_frame (only set if this._options.braces-preserve-inline) first
  3985. this._output.space_before_token = true;
  3986. } else if (this._options.brace_style === "expand") {
  3987. if (!empty_braces) {
  3988. this.print_newline();
  3989. }
  3990. } else {
  3991. // skip {}
  3992. if (!empty_braces) {
  3993. if (is_array(this._flags.mode) && this._options.keep_array_indentation) {
  3994. // we REALLY need a newline here, but newliner would skip that
  3995. this._options.keep_array_indentation = false;
  3996. this.print_newline();
  3997. this._options.keep_array_indentation = true;
  3998. } else {
  3999. this.print_newline();
  4000. }
  4001. }
  4002. }
  4003. this.restore_mode();
  4004. this.print_token(current_token);
  4005. };
  4006. Beautifier.prototype.handle_word = function(current_token) {
  4007. if (current_token.type === TOKEN.RESERVED) {
  4008. if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
  4009. current_token.type = TOKEN.WORD;
  4010. } else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) {
  4011. current_token.type = TOKEN.WORD;
  4012. } else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
  4013. current_token.type = TOKEN.WORD;
  4014. } else if (this._flags.mode === MODE.ObjectLiteral) {
  4015. var next_token = this._tokens.peek();
  4016. if (next_token.text === ':') {
  4017. current_token.type = TOKEN.WORD;
  4018. }
  4019. }
  4020. }
  4021. if (this.start_of_statement(current_token)) {
  4022. // The conditional starts the statement if appropriate.
  4023. if (reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD) {
  4024. this._flags.declaration_statement = true;
  4025. }
  4026. } else if (current_token.newlines && !is_expression(this._flags.mode) &&
  4027. (this._flags.last_token.type !== TOKEN.OPERATOR || (this._flags.last_token.text === '--' || this._flags.last_token.text === '++')) &&
  4028. this._flags.last_token.type !== TOKEN.EQUALS &&
  4029. (this._options.preserve_newlines || !reserved_array(this._flags.last_token, ['var', 'let', 'const', 'set', 'get']))) {
  4030. this.handle_whitespace_and_comments(current_token);
  4031. this.print_newline();
  4032. } else {
  4033. this.handle_whitespace_and_comments(current_token);
  4034. }
  4035. if (this._flags.do_block && !this._flags.do_while) {
  4036. if (reserved_word(current_token, 'while')) {
  4037. // do {} ## while ()
  4038. this._output.space_before_token = true;
  4039. this.print_token(current_token);
  4040. this._output.space_before_token = true;
  4041. this._flags.do_while = true;
  4042. return;
  4043. } else {
  4044. // do {} should always have while as the next word.
  4045. // if we don't see the expected while, recover
  4046. this.print_newline();
  4047. this._flags.do_block = false;
  4048. }
  4049. }
  4050. // if may be followed by else, or not
  4051. // Bare/inline ifs are tricky
  4052. // Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();
  4053. if (this._flags.if_block) {
  4054. if (!this._flags.else_block && reserved_word(current_token, 'else')) {
  4055. this._flags.else_block = true;
  4056. } else {
  4057. while (this._flags.mode === MODE.Statement) {
  4058. this.restore_mode();
  4059. }
  4060. this._flags.if_block = false;
  4061. this._flags.else_block = false;
  4062. }
  4063. }
  4064. if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) {
  4065. this.print_newline();
  4066. if (!this._flags.case_block && (this._flags.case_body || this._options.jslint_happy)) {
  4067. // switch cases following one another
  4068. this.deindent();
  4069. }
  4070. this._flags.case_body = false;
  4071. this.print_token(current_token);
  4072. this._flags.in_case = true;
  4073. return;
  4074. }
  4075. if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
  4076. if (!this.start_of_object_property()) {
  4077. this.allow_wrap_or_preserved_newline(current_token);
  4078. }
  4079. }
  4080. if (reserved_word(current_token, 'function')) {
  4081. if (in_array(this._flags.last_token.text, ['}', ';']) ||
  4082. (this._output.just_added_newline() && !(in_array(this._flags.last_token.text, ['(', '[', '{', ':', '=', ',']) || this._flags.last_token.type === TOKEN.OPERATOR))) {
  4083. // make sure there is a nice clean space of at least one blank line
  4084. // before a new function definition
  4085. if (!this._output.just_added_blankline() && !current_token.comments_before) {
  4086. this.print_newline();
  4087. this.print_newline(true);
  4088. }
  4089. }
  4090. if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD) {
  4091. if (reserved_array(this._flags.last_token, ['get', 'set', 'new', 'export']) ||
  4092. reserved_array(this._flags.last_token, newline_restricted_tokens)) {
  4093. this._output.space_before_token = true;
  4094. } else if (reserved_word(this._flags.last_token, 'default') && this._last_last_text === 'export') {
  4095. this._output.space_before_token = true;
  4096. } else if (this._flags.last_token.text === 'declare') {
  4097. // accomodates Typescript declare function formatting
  4098. this._output.space_before_token = true;
  4099. } else {
  4100. this.print_newline();
  4101. }
  4102. } else if (this._flags.last_token.type === TOKEN.OPERATOR || this._flags.last_token.text === '=') {
  4103. // foo = function
  4104. this._output.space_before_token = true;
  4105. } else if (!this._flags.multiline_frame && (is_expression(this._flags.mode) || is_array(this._flags.mode))) ; else {
  4106. this.print_newline();
  4107. }
  4108. this.print_token(current_token);
  4109. this._flags.last_word = current_token.text;
  4110. return;
  4111. }
  4112. var prefix = 'NONE';
  4113. if (this._flags.last_token.type === TOKEN.END_BLOCK) {
  4114. if (this._previous_flags.inline_frame) {
  4115. prefix = 'SPACE';
  4116. } else if (!reserved_array(current_token, ['else', 'catch', 'finally', 'from'])) {
  4117. prefix = 'NEWLINE';
  4118. } else {
  4119. if (this._options.brace_style === "expand" ||
  4120. this._options.brace_style === "end-expand" ||
  4121. (this._options.brace_style === "none" && current_token.newlines)) {
  4122. prefix = 'NEWLINE';
  4123. } else {
  4124. prefix = 'SPACE';
  4125. this._output.space_before_token = true;
  4126. }
  4127. }
  4128. } else if (this._flags.last_token.type === TOKEN.SEMICOLON && this._flags.mode === MODE.BlockStatement) {
  4129. // TODO: Should this be for STATEMENT as well?
  4130. prefix = 'NEWLINE';
  4131. } else if (this._flags.last_token.type === TOKEN.SEMICOLON && is_expression(this._flags.mode)) {
  4132. prefix = 'SPACE';
  4133. } else if (this._flags.last_token.type === TOKEN.STRING) {
  4134. prefix = 'NEWLINE';
  4135. } else if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD ||
  4136. (this._flags.last_token.text === '*' &&
  4137. (in_array(this._last_last_text, ['function', 'yield']) ||
  4138. (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
  4139. prefix = 'SPACE';
  4140. } else if (this._flags.last_token.type === TOKEN.START_BLOCK) {
  4141. if (this._flags.inline_frame) {
  4142. prefix = 'SPACE';
  4143. } else {
  4144. prefix = 'NEWLINE';
  4145. }
  4146. } else if (this._flags.last_token.type === TOKEN.END_EXPR) {
  4147. this._output.space_before_token = true;
  4148. prefix = 'NEWLINE';
  4149. }
  4150. if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
  4151. if (this._flags.inline_frame || this._flags.last_token.text === 'else' || this._flags.last_token.text === 'export') {
  4152. prefix = 'SPACE';
  4153. } else {
  4154. prefix = 'NEWLINE';
  4155. }
  4156. }
  4157. if (reserved_array(current_token, ['else', 'catch', 'finally'])) {
  4158. if ((!(this._flags.last_token.type === TOKEN.END_BLOCK && this._previous_flags.mode === MODE.BlockStatement) ||
  4159. this._options.brace_style === "expand" ||
  4160. this._options.brace_style === "end-expand" ||
  4161. (this._options.brace_style === "none" && current_token.newlines)) &&
  4162. !this._flags.inline_frame) {
  4163. this.print_newline();
  4164. } else {
  4165. this._output.trim(true);
  4166. var line = this._output.current_line;
  4167. // If we trimmed and there's something other than a close block before us
  4168. // put a newline back in. Handles '} // comment' scenario.
  4169. if (line.last() !== '}') {
  4170. this.print_newline();
  4171. }
  4172. this._output.space_before_token = true;
  4173. }
  4174. } else if (prefix === 'NEWLINE') {
  4175. if (reserved_array(this._flags.last_token, special_words)) {
  4176. // no newline between 'return nnn'
  4177. this._output.space_before_token = true;
  4178. } else if (this._flags.last_token.text === 'declare' && reserved_array(current_token, ['var', 'let', 'const'])) {
  4179. // accomodates Typescript declare formatting
  4180. this._output.space_before_token = true;
  4181. } else if (this._flags.last_token.type !== TOKEN.END_EXPR) {
  4182. if ((this._flags.last_token.type !== TOKEN.START_EXPR || !reserved_array(current_token, ['var', 'let', 'const'])) && this._flags.last_token.text !== ':') {
  4183. // no need to force newline on 'var': for (var x = 0...)
  4184. if (reserved_word(current_token, 'if') && reserved_word(current_token.previous, 'else')) {
  4185. // no newline for } else if {
  4186. this._output.space_before_token = true;
  4187. } else {
  4188. this.print_newline();
  4189. }
  4190. }
  4191. } else if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
  4192. this.print_newline();
  4193. }
  4194. } else if (this._flags.multiline_frame && is_array(this._flags.mode) && this._flags.last_token.text === ',' && this._last_last_text === '}') {
  4195. this.print_newline(); // }, in lists get a newline treatment
  4196. } else if (prefix === 'SPACE') {
  4197. this._output.space_before_token = true;
  4198. }
  4199. if (current_token.previous && (current_token.previous.type === TOKEN.WORD || current_token.previous.type === TOKEN.RESERVED)) {
  4200. this._output.space_before_token = true;
  4201. }
  4202. this.print_token(current_token);
  4203. this._flags.last_word = current_token.text;
  4204. if (current_token.type === TOKEN.RESERVED) {
  4205. if (current_token.text === 'do') {
  4206. this._flags.do_block = true;
  4207. } else if (current_token.text === 'if') {
  4208. this._flags.if_block = true;
  4209. } else if (current_token.text === 'import') {
  4210. this._flags.import_block = true;
  4211. } else if (this._flags.import_block && reserved_word(current_token, 'from')) {
  4212. this._flags.import_block = false;
  4213. }
  4214. }
  4215. };
  4216. Beautifier.prototype.handle_semicolon = function(current_token) {
  4217. if (this.start_of_statement(current_token)) {
  4218. // The conditional starts the statement if appropriate.
  4219. // Semicolon can be the start (and end) of a statement
  4220. this._output.space_before_token = false;
  4221. } else {
  4222. this.handle_whitespace_and_comments(current_token);
  4223. }
  4224. var next_token = this._tokens.peek();
  4225. while (this._flags.mode === MODE.Statement &&
  4226. !(this._flags.if_block && reserved_word(next_token, 'else')) &&
  4227. !this._flags.do_block) {
  4228. this.restore_mode();
  4229. }
  4230. // hacky but effective for the moment
  4231. if (this._flags.import_block) {
  4232. this._flags.import_block = false;
  4233. }
  4234. this.print_token(current_token);
  4235. };
  4236. Beautifier.prototype.handle_string = function(current_token) {
  4237. if (current_token.text.startsWith("`") && current_token.newlines === 0 && current_token.whitespace_before === '' && (current_token.previous.text === ')' || this._flags.last_token.type === TOKEN.WORD)) ; else if (this.start_of_statement(current_token)) {
  4238. // The conditional starts the statement if appropriate.
  4239. // One difference - strings want at least a space before
  4240. this._output.space_before_token = true;
  4241. } else {
  4242. this.handle_whitespace_and_comments(current_token);
  4243. if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD || this._flags.inline_frame) {
  4244. this._output.space_before_token = true;
  4245. } else if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
  4246. if (!this.start_of_object_property()) {
  4247. this.allow_wrap_or_preserved_newline(current_token);
  4248. }
  4249. } else if ((current_token.text.startsWith("`") && this._flags.last_token.type === TOKEN.END_EXPR && (current_token.previous.text === ']' || current_token.previous.text === ')') && current_token.newlines === 0)) {
  4250. this._output.space_before_token = true;
  4251. } else {
  4252. this.print_newline();
  4253. }
  4254. }
  4255. this.print_token(current_token);
  4256. };
  4257. Beautifier.prototype.handle_equals = function(current_token) {
  4258. if (this.start_of_statement(current_token)) ; else {
  4259. this.handle_whitespace_and_comments(current_token);
  4260. }
  4261. if (this._flags.declaration_statement) {
  4262. // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
  4263. this._flags.declaration_assignment = true;
  4264. }
  4265. this._output.space_before_token = true;
  4266. this.print_token(current_token);
  4267. this._output.space_before_token = true;
  4268. };
  4269. Beautifier.prototype.handle_comma = function(current_token) {
  4270. this.handle_whitespace_and_comments(current_token, true);
  4271. this.print_token(current_token);
  4272. this._output.space_before_token = true;
  4273. if (this._flags.declaration_statement) {
  4274. if (is_expression(this._flags.parent.mode)) {
  4275. // do not break on comma, for(var a = 1, b = 2)
  4276. this._flags.declaration_assignment = false;
  4277. }
  4278. if (this._flags.declaration_assignment) {
  4279. this._flags.declaration_assignment = false;
  4280. this.print_newline(false, true);
  4281. } else if (this._options.comma_first) {
  4282. // for comma-first, we want to allow a newline before the comma
  4283. // to turn into a newline after the comma, which we will fixup later
  4284. this.allow_wrap_or_preserved_newline(current_token);
  4285. }
  4286. } else if (this._flags.mode === MODE.ObjectLiteral ||
  4287. (this._flags.mode === MODE.Statement && this._flags.parent.mode === MODE.ObjectLiteral)) {
  4288. if (this._flags.mode === MODE.Statement) {
  4289. this.restore_mode();
  4290. }
  4291. if (!this._flags.inline_frame) {
  4292. this.print_newline();
  4293. }
  4294. } else if (this._options.comma_first) {
  4295. // EXPR or DO_BLOCK
  4296. // for comma-first, we want to allow a newline before the comma
  4297. // to turn into a newline after the comma, which we will fixup later
  4298. this.allow_wrap_or_preserved_newline(current_token);
  4299. }
  4300. };
  4301. Beautifier.prototype.handle_operator = function(current_token) {
  4302. var isGeneratorAsterisk = current_token.text === '*' &&
  4303. (reserved_array(this._flags.last_token, ['function', 'yield']) ||
  4304. (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.COMMA, TOKEN.END_BLOCK, TOKEN.SEMICOLON]))
  4305. );
  4306. var isUnary = in_array(current_token.text, ['-', '+']) && (
  4307. in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.START_EXPR, TOKEN.EQUALS, TOKEN.OPERATOR]) ||
  4308. in_array(this._flags.last_token.text, line_starters) ||
  4309. this._flags.last_token.text === ','
  4310. );
  4311. if (this.start_of_statement(current_token)) ; else {
  4312. var preserve_statement_flags = !isGeneratorAsterisk;
  4313. this.handle_whitespace_and_comments(current_token, preserve_statement_flags);
  4314. }
  4315. // hack for actionscript's import .*;
  4316. if (current_token.text === '*' && this._flags.last_token.type === TOKEN.DOT) {
  4317. this.print_token(current_token);
  4318. return;
  4319. }
  4320. if (current_token.text === '::') {
  4321. // no spaces around exotic namespacing syntax operator
  4322. this.print_token(current_token);
  4323. return;
  4324. }
  4325. // Allow line wrapping between operators when operator_position is
  4326. // set to before or preserve
  4327. if (this._flags.last_token.type === TOKEN.OPERATOR && in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) {
  4328. this.allow_wrap_or_preserved_newline(current_token);
  4329. }
  4330. if (current_token.text === ':' && this._flags.in_case) {
  4331. this.print_token(current_token);
  4332. this._flags.in_case = false;
  4333. this._flags.case_body = true;
  4334. if (this._tokens.peek().type !== TOKEN.START_BLOCK) {
  4335. this.indent();
  4336. this.print_newline();
  4337. this._flags.case_block = false;
  4338. } else {
  4339. this._flags.case_block = true;
  4340. this._output.space_before_token = true;
  4341. }
  4342. return;
  4343. }
  4344. var space_before = true;
  4345. var space_after = true;
  4346. var in_ternary = false;
  4347. if (current_token.text === ':') {
  4348. if (this._flags.ternary_depth === 0) {
  4349. // Colon is invalid javascript outside of ternary and object, but do our best to guess what was meant.
  4350. space_before = false;
  4351. } else {
  4352. this._flags.ternary_depth -= 1;
  4353. in_ternary = true;
  4354. }
  4355. } else if (current_token.text === '?') {
  4356. this._flags.ternary_depth += 1;
  4357. }
  4358. // let's handle the operator_position option prior to any conflicting logic
  4359. if (!isUnary && !isGeneratorAsterisk && this._options.preserve_newlines && in_array(current_token.text, positionable_operators)) {
  4360. var isColon = current_token.text === ':';
  4361. var isTernaryColon = (isColon && in_ternary);
  4362. var isOtherColon = (isColon && !in_ternary);
  4363. switch (this._options.operator_position) {
  4364. case OPERATOR_POSITION.before_newline:
  4365. // if the current token is : and it's not a ternary statement then we set space_before to false
  4366. this._output.space_before_token = !isOtherColon;
  4367. this.print_token(current_token);
  4368. if (!isColon || isTernaryColon) {
  4369. this.allow_wrap_or_preserved_newline(current_token);
  4370. }
  4371. this._output.space_before_token = true;
  4372. return;
  4373. case OPERATOR_POSITION.after_newline:
  4374. // if the current token is anything but colon, or (via deduction) it's a colon and in a ternary statement,
  4375. // then print a newline.
  4376. this._output.space_before_token = true;
  4377. if (!isColon || isTernaryColon) {
  4378. if (this._tokens.peek().newlines) {
  4379. this.print_newline(false, true);
  4380. } else {
  4381. this.allow_wrap_or_preserved_newline(current_token);
  4382. }
  4383. } else {
  4384. this._output.space_before_token = false;
  4385. }
  4386. this.print_token(current_token);
  4387. this._output.space_before_token = true;
  4388. return;
  4389. case OPERATOR_POSITION.preserve_newline:
  4390. if (!isOtherColon) {
  4391. this.allow_wrap_or_preserved_newline(current_token);
  4392. }
  4393. // if we just added a newline, or the current token is : and it's not a ternary statement,
  4394. // then we set space_before to false
  4395. space_before = !(this._output.just_added_newline() || isOtherColon);
  4396. this._output.space_before_token = space_before;
  4397. this.print_token(current_token);
  4398. this._output.space_before_token = true;
  4399. return;
  4400. }
  4401. }
  4402. if (isGeneratorAsterisk) {
  4403. this.allow_wrap_or_preserved_newline(current_token);
  4404. space_before = false;
  4405. var next_token = this._tokens.peek();
  4406. space_after = next_token && in_array(next_token.type, [TOKEN.WORD, TOKEN.RESERVED]);
  4407. } else if (current_token.text === '...') {
  4408. this.allow_wrap_or_preserved_newline(current_token);
  4409. space_before = this._flags.last_token.type === TOKEN.START_BLOCK;
  4410. space_after = false;
  4411. } else if (in_array(current_token.text, ['--', '++', '!', '~']) || isUnary) {
  4412. // unary operators (and binary +/- pretending to be unary) special cases
  4413. if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR) {
  4414. this.allow_wrap_or_preserved_newline(current_token);
  4415. }
  4416. space_before = false;
  4417. space_after = false;
  4418. // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
  4419. // if there is a newline between -- or ++ and anything else we should preserve it.
  4420. if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) {
  4421. var new_line_needed = reserved_array(this._flags.last_token, special_words) && current_token.newlines;
  4422. if (new_line_needed && (this._previous_flags.if_block || this._previous_flags.else_block)) {
  4423. this.restore_mode();
  4424. }
  4425. this.print_newline(new_line_needed, true);
  4426. }
  4427. if (this._flags.last_token.text === ';' && is_expression(this._flags.mode)) {
  4428. // for (;; ++i)
  4429. // ^^^
  4430. space_before = true;
  4431. }
  4432. if (this._flags.last_token.type === TOKEN.RESERVED) {
  4433. space_before = true;
  4434. } else if (this._flags.last_token.type === TOKEN.END_EXPR) {
  4435. space_before = !(this._flags.last_token.text === ']' && (current_token.text === '--' || current_token.text === '++'));
  4436. } else if (this._flags.last_token.type === TOKEN.OPERATOR) {
  4437. // a++ + ++b;
  4438. // a - -b
  4439. space_before = in_array(current_token.text, ['--', '-', '++', '+']) && in_array(this._flags.last_token.text, ['--', '-', '++', '+']);
  4440. // + and - are not unary when preceeded by -- or ++ operator
  4441. // a-- + b
  4442. // a * +b
  4443. // a - -b
  4444. if (in_array(current_token.text, ['+', '-']) && in_array(this._flags.last_token.text, ['--', '++'])) {
  4445. space_after = true;
  4446. }
  4447. }
  4448. if (((this._flags.mode === MODE.BlockStatement && !this._flags.inline_frame) || this._flags.mode === MODE.Statement) &&
  4449. (this._flags.last_token.text === '{' || this._flags.last_token.text === ';')) {
  4450. // { foo; --i }
  4451. // foo(); --bar;
  4452. this.print_newline();
  4453. }
  4454. }
  4455. this._output.space_before_token = this._output.space_before_token || space_before;
  4456. this.print_token(current_token);
  4457. this._output.space_before_token = space_after;
  4458. };
  4459. Beautifier.prototype.handle_block_comment = function(current_token, preserve_statement_flags) {
  4460. if (this._output.raw) {
  4461. this._output.add_raw_token(current_token);
  4462. if (current_token.directives && current_token.directives.preserve === 'end') {
  4463. // If we're testing the raw output behavior, do not allow a directive to turn it off.
  4464. this._output.raw = this._options.test_output_raw;
  4465. }
  4466. return;
  4467. }
  4468. if (current_token.directives) {
  4469. this.print_newline(false, preserve_statement_flags);
  4470. this.print_token(current_token);
  4471. if (current_token.directives.preserve === 'start') {
  4472. this._output.raw = true;
  4473. }
  4474. this.print_newline(false, true);
  4475. return;
  4476. }
  4477. // inline block
  4478. if (!acorn.newline.test(current_token.text) && !current_token.newlines) {
  4479. this._output.space_before_token = true;
  4480. this.print_token(current_token);
  4481. this._output.space_before_token = true;
  4482. return;
  4483. } else {
  4484. this.print_block_commment(current_token, preserve_statement_flags);
  4485. }
  4486. };
  4487. Beautifier.prototype.print_block_commment = function(current_token, preserve_statement_flags) {
  4488. var lines = split_linebreaks(current_token.text);
  4489. var j; // iterator for this case
  4490. var javadoc = false;
  4491. var starless = false;
  4492. var lastIndent = current_token.whitespace_before;
  4493. var lastIndentLength = lastIndent.length;
  4494. // block comment starts with a new line
  4495. this.print_newline(false, preserve_statement_flags);
  4496. // first line always indented
  4497. this.print_token_line_indentation(current_token);
  4498. this._output.add_token(lines[0]);
  4499. this.print_newline(false, preserve_statement_flags);
  4500. if (lines.length > 1) {
  4501. lines = lines.slice(1);
  4502. javadoc = all_lines_start_with(lines, '*');
  4503. starless = each_line_matches_indent(lines, lastIndent);
  4504. if (javadoc) {
  4505. this._flags.alignment = 1;
  4506. }
  4507. for (j = 0; j < lines.length; j++) {
  4508. if (javadoc) {
  4509. // javadoc: reformat and re-indent
  4510. this.print_token_line_indentation(current_token);
  4511. this._output.add_token(ltrim(lines[j]));
  4512. } else if (starless && lines[j]) {
  4513. // starless: re-indent non-empty content, avoiding trim
  4514. this.print_token_line_indentation(current_token);
  4515. this._output.add_token(lines[j].substring(lastIndentLength));
  4516. } else {
  4517. // normal comments output raw
  4518. this._output.current_line.set_indent(-1);
  4519. this._output.add_token(lines[j]);
  4520. }
  4521. // for comments on their own line or more than one line, make sure there's a new line after
  4522. this.print_newline(false, preserve_statement_flags);
  4523. }
  4524. this._flags.alignment = 0;
  4525. }
  4526. };
  4527. Beautifier.prototype.handle_comment = function(current_token, preserve_statement_flags) {
  4528. if (current_token.newlines) {
  4529. this.print_newline(false, preserve_statement_flags);
  4530. } else {
  4531. this._output.trim(true);
  4532. }
  4533. this._output.space_before_token = true;
  4534. this.print_token(current_token);
  4535. this.print_newline(false, preserve_statement_flags);
  4536. };
  4537. Beautifier.prototype.handle_dot = function(current_token) {
  4538. if (this.start_of_statement(current_token)) ; else {
  4539. this.handle_whitespace_and_comments(current_token, true);
  4540. }
  4541. if (this._flags.last_token.text.match('^[0-9]+$')) {
  4542. this._output.space_before_token = true;
  4543. }
  4544. if (reserved_array(this._flags.last_token, special_words)) {
  4545. this._output.space_before_token = false;
  4546. } else {
  4547. // allow preserved newlines before dots in general
  4548. // force newlines on dots after close paren when break_chained - for bar().baz()
  4549. this.allow_wrap_or_preserved_newline(current_token,
  4550. this._flags.last_token.text === ')' && this._options.break_chained_methods);
  4551. }
  4552. // Only unindent chained method dot if this dot starts a new line.
  4553. // Otherwise the automatic extra indentation removal will handle the over indent
  4554. if (this._options.unindent_chained_methods && this._output.just_added_newline()) {
  4555. this.deindent();
  4556. }
  4557. this.print_token(current_token);
  4558. };
  4559. Beautifier.prototype.handle_unknown = function(current_token, preserve_statement_flags) {
  4560. this.print_token(current_token);
  4561. if (current_token.text[current_token.text.length - 1] === '\n') {
  4562. this.print_newline(false, preserve_statement_flags);
  4563. }
  4564. };
  4565. Beautifier.prototype.handle_eof = function(current_token) {
  4566. // Unwind any open statements
  4567. while (this._flags.mode === MODE.Statement) {
  4568. this.restore_mode();
  4569. }
  4570. this.handle_whitespace_and_comments(current_token);
  4571. };
  4572. beautifier$2.Beautifier = Beautifier;
  4573. return beautifier$2;
  4574. }
  4575. /*jshint node:true */
  4576. var hasRequiredJavascript;
  4577. function requireJavascript () {
  4578. if (hasRequiredJavascript) return javascript.exports;
  4579. hasRequiredJavascript = 1;
  4580. var Beautifier = requireBeautifier$2().Beautifier,
  4581. Options = requireOptions$2().Options;
  4582. function js_beautify(js_source_text, options) {
  4583. var beautifier = new Beautifier(js_source_text, options);
  4584. return beautifier.beautify();
  4585. }
  4586. javascript.exports = js_beautify;
  4587. javascript.exports.defaultOptions = function() {
  4588. return new Options();
  4589. };
  4590. return javascript.exports;
  4591. }
  4592. var css = {exports: {}};
  4593. var beautifier$1 = {};
  4594. var options$1 = {};
  4595. /*jshint node:true */
  4596. var hasRequiredOptions$1;
  4597. function requireOptions$1 () {
  4598. if (hasRequiredOptions$1) return options$1;
  4599. hasRequiredOptions$1 = 1;
  4600. var BaseOptions = requireOptions$3().Options;
  4601. function Options(options) {
  4602. BaseOptions.call(this, options, 'css');
  4603. this.selector_separator_newline = this._get_boolean('selector_separator_newline', true);
  4604. this.newline_between_rules = this._get_boolean('newline_between_rules', true);
  4605. var space_around_selector_separator = this._get_boolean('space_around_selector_separator');
  4606. this.space_around_combinator = this._get_boolean('space_around_combinator') || space_around_selector_separator;
  4607. var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
  4608. this.brace_style = 'collapse';
  4609. for (var bs = 0; bs < brace_style_split.length; bs++) {
  4610. if (brace_style_split[bs] !== 'expand') {
  4611. // default to collapse, as only collapse|expand is implemented for now
  4612. this.brace_style = 'collapse';
  4613. } else {
  4614. this.brace_style = brace_style_split[bs];
  4615. }
  4616. }
  4617. }
  4618. Options.prototype = new BaseOptions();
  4619. options$1.Options = Options;
  4620. return options$1;
  4621. }
  4622. /*jshint node:true */
  4623. var hasRequiredBeautifier$1;
  4624. function requireBeautifier$1 () {
  4625. if (hasRequiredBeautifier$1) return beautifier$1;
  4626. hasRequiredBeautifier$1 = 1;
  4627. var Options = requireOptions$1().Options;
  4628. var Output = requireOutput().Output;
  4629. var InputScanner = requireInputscanner().InputScanner;
  4630. var Directives = requireDirectives().Directives;
  4631. var directives_core = new Directives(/\/\*/, /\*\//);
  4632. var lineBreak = /\r\n|[\r\n]/;
  4633. var allLineBreaks = /\r\n|[\r\n]/g;
  4634. // tokenizer
  4635. var whitespaceChar = /\s/;
  4636. var whitespacePattern = /(?:\s|\n)+/g;
  4637. var block_comment_pattern = /\/\*(?:[\s\S]*?)((?:\*\/)|$)/g;
  4638. var comment_pattern = /\/\/(?:[^\n\r\u2028\u2029]*)/g;
  4639. function Beautifier(source_text, options) {
  4640. this._source_text = source_text || '';
  4641. // Allow the setting of language/file-type specific options
  4642. // with inheritance of overall settings
  4643. this._options = new Options(options);
  4644. this._ch = null;
  4645. this._input = null;
  4646. // https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule
  4647. this.NESTED_AT_RULE = {
  4648. "page": true,
  4649. "font-face": true,
  4650. "keyframes": true,
  4651. // also in CONDITIONAL_GROUP_RULE below
  4652. "media": true,
  4653. "supports": true,
  4654. "document": true
  4655. };
  4656. this.CONDITIONAL_GROUP_RULE = {
  4657. "media": true,
  4658. "supports": true,
  4659. "document": true
  4660. };
  4661. this.NON_SEMICOLON_NEWLINE_PROPERTY = [
  4662. "grid-template-areas",
  4663. "grid-template"
  4664. ];
  4665. }
  4666. Beautifier.prototype.eatString = function(endChars) {
  4667. var result = '';
  4668. this._ch = this._input.next();
  4669. while (this._ch) {
  4670. result += this._ch;
  4671. if (this._ch === "\\") {
  4672. result += this._input.next();
  4673. } else if (endChars.indexOf(this._ch) !== -1 || this._ch === "\n") {
  4674. break;
  4675. }
  4676. this._ch = this._input.next();
  4677. }
  4678. return result;
  4679. };
  4680. // Skips any white space in the source text from the current position.
  4681. // When allowAtLeastOneNewLine is true, will output new lines for each
  4682. // newline character found; if the user has preserve_newlines off, only
  4683. // the first newline will be output
  4684. Beautifier.prototype.eatWhitespace = function(allowAtLeastOneNewLine) {
  4685. var result = whitespaceChar.test(this._input.peek());
  4686. var newline_count = 0;
  4687. while (whitespaceChar.test(this._input.peek())) {
  4688. this._ch = this._input.next();
  4689. if (allowAtLeastOneNewLine && this._ch === '\n') {
  4690. if (newline_count === 0 || newline_count < this._options.max_preserve_newlines) {
  4691. newline_count++;
  4692. this._output.add_new_line(true);
  4693. }
  4694. }
  4695. }
  4696. return result;
  4697. };
  4698. // Nested pseudo-class if we are insideRule
  4699. // and the next special character found opens
  4700. // a new block
  4701. Beautifier.prototype.foundNestedPseudoClass = function() {
  4702. var openParen = 0;
  4703. var i = 1;
  4704. var ch = this._input.peek(i);
  4705. while (ch) {
  4706. if (ch === "{") {
  4707. return true;
  4708. } else if (ch === '(') {
  4709. // pseudoclasses can contain ()
  4710. openParen += 1;
  4711. } else if (ch === ')') {
  4712. if (openParen === 0) {
  4713. return false;
  4714. }
  4715. openParen -= 1;
  4716. } else if (ch === ";" || ch === "}") {
  4717. return false;
  4718. }
  4719. i++;
  4720. ch = this._input.peek(i);
  4721. }
  4722. return false;
  4723. };
  4724. Beautifier.prototype.print_string = function(output_string) {
  4725. this._output.set_indent(this._indentLevel);
  4726. this._output.non_breaking_space = true;
  4727. this._output.add_token(output_string);
  4728. };
  4729. Beautifier.prototype.preserveSingleSpace = function(isAfterSpace) {
  4730. if (isAfterSpace) {
  4731. this._output.space_before_token = true;
  4732. }
  4733. };
  4734. Beautifier.prototype.indent = function() {
  4735. this._indentLevel++;
  4736. };
  4737. Beautifier.prototype.outdent = function() {
  4738. if (this._indentLevel > 0) {
  4739. this._indentLevel--;
  4740. }
  4741. };
  4742. /*_____________________--------------------_____________________*/
  4743. Beautifier.prototype.beautify = function() {
  4744. if (this._options.disabled) {
  4745. return this._source_text;
  4746. }
  4747. var source_text = this._source_text;
  4748. var eol = this._options.eol;
  4749. if (eol === 'auto') {
  4750. eol = '\n';
  4751. if (source_text && lineBreak.test(source_text || '')) {
  4752. eol = source_text.match(lineBreak)[0];
  4753. }
  4754. }
  4755. // HACK: newline parsing inconsistent. This brute force normalizes the this._input.
  4756. source_text = source_text.replace(allLineBreaks, '\n');
  4757. // reset
  4758. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  4759. this._output = new Output(this._options, baseIndentString);
  4760. this._input = new InputScanner(source_text);
  4761. this._indentLevel = 0;
  4762. this._nestedLevel = 0;
  4763. this._ch = null;
  4764. var parenLevel = 0;
  4765. var insideRule = false;
  4766. // This is the value side of a property value pair (blue in the following ex)
  4767. // label { content: blue }
  4768. var insidePropertyValue = false;
  4769. var enteringConditionalGroup = false;
  4770. var insideNonNestedAtRule = false;
  4771. var insideScssMap = false;
  4772. var topCharacter = this._ch;
  4773. var insideNonSemiColonValues = false;
  4774. var whitespace;
  4775. var isAfterSpace;
  4776. var previous_ch;
  4777. while (true) {
  4778. whitespace = this._input.read(whitespacePattern);
  4779. isAfterSpace = whitespace !== '';
  4780. previous_ch = topCharacter;
  4781. this._ch = this._input.next();
  4782. if (this._ch === '\\' && this._input.hasNext()) {
  4783. this._ch += this._input.next();
  4784. }
  4785. topCharacter = this._ch;
  4786. if (!this._ch) {
  4787. break;
  4788. } else if (this._ch === '/' && this._input.peek() === '*') {
  4789. // /* css comment */
  4790. // Always start block comments on a new line.
  4791. // This handles scenarios where a block comment immediately
  4792. // follows a property definition on the same line or where
  4793. // minified code is being beautified.
  4794. this._output.add_new_line();
  4795. this._input.back();
  4796. var comment = this._input.read(block_comment_pattern);
  4797. // Handle ignore directive
  4798. var directives = directives_core.get_directives(comment);
  4799. if (directives && directives.ignore === 'start') {
  4800. comment += directives_core.readIgnored(this._input);
  4801. }
  4802. this.print_string(comment);
  4803. // Ensures any new lines following the comment are preserved
  4804. this.eatWhitespace(true);
  4805. // Block comments are followed by a new line so they don't
  4806. // share a line with other properties
  4807. this._output.add_new_line();
  4808. } else if (this._ch === '/' && this._input.peek() === '/') {
  4809. // // single line comment
  4810. // Preserves the space before a comment
  4811. // on the same line as a rule
  4812. this._output.space_before_token = true;
  4813. this._input.back();
  4814. this.print_string(this._input.read(comment_pattern));
  4815. // Ensures any new lines following the comment are preserved
  4816. this.eatWhitespace(true);
  4817. } else if (this._ch === '$') {
  4818. this.preserveSingleSpace(isAfterSpace);
  4819. this.print_string(this._ch);
  4820. // strip trailing space, if present, for hash property checks
  4821. var variable = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
  4822. if (variable.match(/[ :]$/)) {
  4823. // we have a variable or pseudo-class, add it and insert one space before continuing
  4824. variable = this.eatString(": ").replace(/\s$/, '');
  4825. this.print_string(variable);
  4826. this._output.space_before_token = true;
  4827. }
  4828. variable = variable.replace(/\s$/, '');
  4829. // might be sass variable
  4830. if (parenLevel === 0 && variable.indexOf(':') !== -1) {
  4831. insidePropertyValue = true;
  4832. this.indent();
  4833. }
  4834. } else if (this._ch === '@') {
  4835. this.preserveSingleSpace(isAfterSpace);
  4836. // deal with less property mixins @{...}
  4837. if (this._input.peek() === '{') {
  4838. this.print_string(this._ch + this.eatString('}'));
  4839. } else {
  4840. this.print_string(this._ch);
  4841. // strip trailing space, if present, for hash property checks
  4842. var variableOrRule = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
  4843. if (variableOrRule.match(/[ :]$/)) {
  4844. // we have a variable or pseudo-class, add it and insert one space before continuing
  4845. variableOrRule = this.eatString(": ").replace(/\s$/, '');
  4846. this.print_string(variableOrRule);
  4847. this._output.space_before_token = true;
  4848. }
  4849. variableOrRule = variableOrRule.replace(/\s$/, '');
  4850. // might be less variable
  4851. if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
  4852. insidePropertyValue = true;
  4853. this.indent();
  4854. // might be a nesting at-rule
  4855. } else if (variableOrRule in this.NESTED_AT_RULE) {
  4856. this._nestedLevel += 1;
  4857. if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
  4858. enteringConditionalGroup = true;
  4859. }
  4860. // might be a non-nested at-rule
  4861. } else if (parenLevel === 0 && !insidePropertyValue) {
  4862. insideNonNestedAtRule = true;
  4863. }
  4864. }
  4865. } else if (this._ch === '#' && this._input.peek() === '{') {
  4866. this.preserveSingleSpace(isAfterSpace);
  4867. this.print_string(this._ch + this.eatString('}'));
  4868. } else if (this._ch === '{') {
  4869. if (insidePropertyValue) {
  4870. insidePropertyValue = false;
  4871. this.outdent();
  4872. }
  4873. // non nested at rule becomes nested
  4874. insideNonNestedAtRule = false;
  4875. // when entering conditional groups, only rulesets are allowed
  4876. if (enteringConditionalGroup) {
  4877. enteringConditionalGroup = false;
  4878. insideRule = (this._indentLevel >= this._nestedLevel);
  4879. } else {
  4880. // otherwise, declarations are also allowed
  4881. insideRule = (this._indentLevel >= this._nestedLevel - 1);
  4882. }
  4883. if (this._options.newline_between_rules && insideRule) {
  4884. if (this._output.previous_line && this._output.previous_line.item(-1) !== '{') {
  4885. this._output.ensure_empty_line_above('/', ',');
  4886. }
  4887. }
  4888. this._output.space_before_token = true;
  4889. // The difference in print_string and indent order is necessary to indent the '{' correctly
  4890. if (this._options.brace_style === 'expand') {
  4891. this._output.add_new_line();
  4892. this.print_string(this._ch);
  4893. this.indent();
  4894. this._output.set_indent(this._indentLevel);
  4895. } else {
  4896. // inside mixin and first param is object
  4897. if (previous_ch === '(') {
  4898. this._output.space_before_token = false;
  4899. } else if (previous_ch !== ',') {
  4900. this.indent();
  4901. }
  4902. this.print_string(this._ch);
  4903. }
  4904. this.eatWhitespace(true);
  4905. this._output.add_new_line();
  4906. } else if (this._ch === '}') {
  4907. this.outdent();
  4908. this._output.add_new_line();
  4909. if (previous_ch === '{') {
  4910. this._output.trim(true);
  4911. }
  4912. if (insidePropertyValue) {
  4913. this.outdent();
  4914. insidePropertyValue = false;
  4915. }
  4916. this.print_string(this._ch);
  4917. insideRule = false;
  4918. if (this._nestedLevel) {
  4919. this._nestedLevel--;
  4920. }
  4921. this.eatWhitespace(true);
  4922. this._output.add_new_line();
  4923. if (this._options.newline_between_rules && !this._output.just_added_blankline()) {
  4924. if (this._input.peek() !== '}') {
  4925. this._output.add_new_line(true);
  4926. }
  4927. }
  4928. if (this._input.peek() === ')') {
  4929. this._output.trim(true);
  4930. if (this._options.brace_style === "expand") {
  4931. this._output.add_new_line(true);
  4932. }
  4933. }
  4934. } else if (this._ch === ":") {
  4935. for (var i = 0; i < this.NON_SEMICOLON_NEWLINE_PROPERTY.length; i++) {
  4936. if (this._input.lookBack(this.NON_SEMICOLON_NEWLINE_PROPERTY[i])) {
  4937. insideNonSemiColonValues = true;
  4938. break;
  4939. }
  4940. }
  4941. if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideNonNestedAtRule && parenLevel === 0) {
  4942. // 'property: value' delimiter
  4943. // which could be in a conditional group query
  4944. this.print_string(':');
  4945. if (!insidePropertyValue) {
  4946. insidePropertyValue = true;
  4947. this._output.space_before_token = true;
  4948. this.eatWhitespace(true);
  4949. this.indent();
  4950. }
  4951. } else {
  4952. // sass/less parent reference don't use a space
  4953. // sass nested pseudo-class don't use a space
  4954. // preserve space before pseudoclasses/pseudoelements, as it means "in any child"
  4955. if (this._input.lookBack(" ")) {
  4956. this._output.space_before_token = true;
  4957. }
  4958. if (this._input.peek() === ":") {
  4959. // pseudo-element
  4960. this._ch = this._input.next();
  4961. this.print_string("::");
  4962. } else {
  4963. // pseudo-class
  4964. this.print_string(':');
  4965. }
  4966. }
  4967. } else if (this._ch === '"' || this._ch === '\'') {
  4968. var preserveQuoteSpace = previous_ch === '"' || previous_ch === '\'';
  4969. this.preserveSingleSpace(preserveQuoteSpace || isAfterSpace);
  4970. this.print_string(this._ch + this.eatString(this._ch));
  4971. this.eatWhitespace(true);
  4972. } else if (this._ch === ';') {
  4973. insideNonSemiColonValues = false;
  4974. if (parenLevel === 0) {
  4975. if (insidePropertyValue) {
  4976. this.outdent();
  4977. insidePropertyValue = false;
  4978. }
  4979. insideNonNestedAtRule = false;
  4980. this.print_string(this._ch);
  4981. this.eatWhitespace(true);
  4982. // This maintains single line comments on the same
  4983. // line. Block comments are also affected, but
  4984. // a new line is always output before one inside
  4985. // that section
  4986. if (this._input.peek() !== '/') {
  4987. this._output.add_new_line();
  4988. }
  4989. } else {
  4990. this.print_string(this._ch);
  4991. this.eatWhitespace(true);
  4992. this._output.space_before_token = true;
  4993. }
  4994. } else if (this._ch === '(') { // may be a url
  4995. if (this._input.lookBack("url")) {
  4996. this.print_string(this._ch);
  4997. this.eatWhitespace();
  4998. parenLevel++;
  4999. this.indent();
  5000. this._ch = this._input.next();
  5001. if (this._ch === ')' || this._ch === '"' || this._ch === '\'') {
  5002. this._input.back();
  5003. } else if (this._ch) {
  5004. this.print_string(this._ch + this.eatString(')'));
  5005. if (parenLevel) {
  5006. parenLevel--;
  5007. this.outdent();
  5008. }
  5009. }
  5010. } else {
  5011. var space_needed = false;
  5012. if (this._input.lookBack("with")) {
  5013. // look back is not an accurate solution, we need tokens to confirm without whitespaces
  5014. space_needed = true;
  5015. }
  5016. this.preserveSingleSpace(isAfterSpace || space_needed);
  5017. this.print_string(this._ch);
  5018. // handle scss/sass map
  5019. if (insidePropertyValue && previous_ch === "$" && this._options.selector_separator_newline) {
  5020. this._output.add_new_line();
  5021. insideScssMap = true;
  5022. } else {
  5023. this.eatWhitespace();
  5024. parenLevel++;
  5025. this.indent();
  5026. }
  5027. }
  5028. } else if (this._ch === ')') {
  5029. if (parenLevel) {
  5030. parenLevel--;
  5031. this.outdent();
  5032. }
  5033. if (insideScssMap && this._input.peek() === ";" && this._options.selector_separator_newline) {
  5034. insideScssMap = false;
  5035. this.outdent();
  5036. this._output.add_new_line();
  5037. }
  5038. this.print_string(this._ch);
  5039. } else if (this._ch === ',') {
  5040. this.print_string(this._ch);
  5041. this.eatWhitespace(true);
  5042. if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) {
  5043. this._output.add_new_line();
  5044. } else {
  5045. this._output.space_before_token = true;
  5046. }
  5047. } else if ((this._ch === '>' || this._ch === '+' || this._ch === '~') && !insidePropertyValue && parenLevel === 0) {
  5048. //handle combinator spacing
  5049. if (this._options.space_around_combinator) {
  5050. this._output.space_before_token = true;
  5051. this.print_string(this._ch);
  5052. this._output.space_before_token = true;
  5053. } else {
  5054. this.print_string(this._ch);
  5055. this.eatWhitespace();
  5056. // squash extra whitespace
  5057. if (this._ch && whitespaceChar.test(this._ch)) {
  5058. this._ch = '';
  5059. }
  5060. }
  5061. } else if (this._ch === ']') {
  5062. this.print_string(this._ch);
  5063. } else if (this._ch === '[') {
  5064. this.preserveSingleSpace(isAfterSpace);
  5065. this.print_string(this._ch);
  5066. } else if (this._ch === '=') { // no whitespace before or after
  5067. this.eatWhitespace();
  5068. this.print_string('=');
  5069. if (whitespaceChar.test(this._ch)) {
  5070. this._ch = '';
  5071. }
  5072. } else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
  5073. this._output.space_before_token = true;
  5074. this.print_string(this._ch);
  5075. } else {
  5076. var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
  5077. this.preserveSingleSpace(preserveAfterSpace || isAfterSpace);
  5078. this.print_string(this._ch);
  5079. if (!this._output.just_added_newline() && this._input.peek() === '\n' && insideNonSemiColonValues) {
  5080. this._output.add_new_line();
  5081. }
  5082. }
  5083. }
  5084. var sweetCode = this._output.get_code(eol);
  5085. return sweetCode;
  5086. };
  5087. beautifier$1.Beautifier = Beautifier;
  5088. return beautifier$1;
  5089. }
  5090. /*jshint node:true */
  5091. var hasRequiredCss;
  5092. function requireCss () {
  5093. if (hasRequiredCss) return css.exports;
  5094. hasRequiredCss = 1;
  5095. var Beautifier = requireBeautifier$1().Beautifier,
  5096. Options = requireOptions$1().Options;
  5097. function css_beautify(source_text, options) {
  5098. var beautifier = new Beautifier(source_text, options);
  5099. return beautifier.beautify();
  5100. }
  5101. css.exports = css_beautify;
  5102. css.exports.defaultOptions = function() {
  5103. return new Options();
  5104. };
  5105. return css.exports;
  5106. }
  5107. var html = {exports: {}};
  5108. var beautifier = {};
  5109. var options = {};
  5110. /*jshint node:true */
  5111. var hasRequiredOptions;
  5112. function requireOptions () {
  5113. if (hasRequiredOptions) return options;
  5114. hasRequiredOptions = 1;
  5115. var BaseOptions = requireOptions$3().Options;
  5116. function Options(options) {
  5117. BaseOptions.call(this, options, 'html');
  5118. if (this.templating.length === 1 && this.templating[0] === 'auto') {
  5119. this.templating = ['django', 'erb', 'handlebars', 'php'];
  5120. }
  5121. this.indent_inner_html = this._get_boolean('indent_inner_html');
  5122. this.indent_body_inner_html = this._get_boolean('indent_body_inner_html', true);
  5123. this.indent_head_inner_html = this._get_boolean('indent_head_inner_html', true);
  5124. this.indent_handlebars = this._get_boolean('indent_handlebars', true);
  5125. this.wrap_attributes = this._get_selection('wrap_attributes',
  5126. ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
  5127. this.wrap_attributes_min_attrs = this._get_number('wrap_attributes_min_attrs', 2);
  5128. this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
  5129. this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
  5130. // Block vs inline elements
  5131. // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
  5132. // https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
  5133. // https://www.w3.org/TR/html5/dom.html#phrasing-content
  5134. this.inline = this._get_array('inline', [
  5135. 'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite',
  5136. 'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img',
  5137. 'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'meter', 'noscript',
  5138. 'object', 'output', 'progress', 'q', 'ruby', 's', 'samp', /* 'script', */ 'select', 'small',
  5139. 'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
  5140. 'video', 'wbr', 'text',
  5141. // obsolete inline tags
  5142. 'acronym', 'big', 'strike', 'tt'
  5143. ]);
  5144. this.inline_custom_elements = this._get_boolean('inline_custom_elements', true);
  5145. this.void_elements = this._get_array('void_elements', [
  5146. // HTLM void elements - aka self-closing tags - aka singletons
  5147. // https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
  5148. 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
  5149. 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
  5150. // NOTE: Optional tags are too complex for a simple list
  5151. // they are hard coded in _do_optional_end_element
  5152. // Doctype and xml elements
  5153. '!doctype', '?xml',
  5154. // obsolete tags
  5155. // basefont: https://www.computerhope.com/jargon/h/html-basefont-tag.htm
  5156. // isndex: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/isindex
  5157. 'basefont', 'isindex'
  5158. ]);
  5159. this.unformatted = this._get_array('unformatted', []);
  5160. this.content_unformatted = this._get_array('content_unformatted', [
  5161. 'pre', 'textarea'
  5162. ]);
  5163. this.unformatted_content_delimiter = this._get_characters('unformatted_content_delimiter');
  5164. this.indent_scripts = this._get_selection('indent_scripts', ['normal', 'keep', 'separate']);
  5165. }
  5166. Options.prototype = new BaseOptions();
  5167. options.Options = Options;
  5168. return options;
  5169. }
  5170. var tokenizer$1 = {};
  5171. /*jshint node:true */
  5172. var hasRequiredTokenizer;
  5173. function requireTokenizer () {
  5174. if (hasRequiredTokenizer) return tokenizer$1;
  5175. hasRequiredTokenizer = 1;
  5176. var BaseTokenizer = requireTokenizer$2().Tokenizer;
  5177. var BASETOKEN = requireTokenizer$2().TOKEN;
  5178. var Directives = requireDirectives().Directives;
  5179. var TemplatablePattern = requireTemplatablepattern().TemplatablePattern;
  5180. var Pattern = requirePattern().Pattern;
  5181. var TOKEN = {
  5182. TAG_OPEN: 'TK_TAG_OPEN',
  5183. TAG_CLOSE: 'TK_TAG_CLOSE',
  5184. ATTRIBUTE: 'TK_ATTRIBUTE',
  5185. EQUALS: 'TK_EQUALS',
  5186. VALUE: 'TK_VALUE',
  5187. COMMENT: 'TK_COMMENT',
  5188. TEXT: 'TK_TEXT',
  5189. UNKNOWN: 'TK_UNKNOWN',
  5190. START: BASETOKEN.START,
  5191. RAW: BASETOKEN.RAW,
  5192. EOF: BASETOKEN.EOF
  5193. };
  5194. var directives_core = new Directives(/<\!--/, /-->/);
  5195. var Tokenizer = function(input_string, options) {
  5196. BaseTokenizer.call(this, input_string, options);
  5197. this._current_tag_name = '';
  5198. // Words end at whitespace or when a tag starts
  5199. // if we are indenting handlebars, they are considered tags
  5200. var templatable_reader = new TemplatablePattern(this._input).read_options(this._options);
  5201. var pattern_reader = new Pattern(this._input);
  5202. this.__patterns = {
  5203. word: templatable_reader.until(/[\n\r\t <]/),
  5204. single_quote: templatable_reader.until_after(/'/),
  5205. double_quote: templatable_reader.until_after(/"/),
  5206. attribute: templatable_reader.until(/[\n\r\t =>]|\/>/),
  5207. element_name: templatable_reader.until(/[\n\r\t >\/]/),
  5208. handlebars_comment: pattern_reader.starting_with(/{{!--/).until_after(/--}}/),
  5209. handlebars: pattern_reader.starting_with(/{{/).until_after(/}}/),
  5210. handlebars_open: pattern_reader.until(/[\n\r\t }]/),
  5211. handlebars_raw_close: pattern_reader.until(/}}/),
  5212. comment: pattern_reader.starting_with(/<!--/).until_after(/-->/),
  5213. cdata: pattern_reader.starting_with(/<!\[CDATA\[/).until_after(/]]>/),
  5214. // https://en.wikipedia.org/wiki/Conditional_comment
  5215. conditional_comment: pattern_reader.starting_with(/<!\[/).until_after(/]>/),
  5216. processing: pattern_reader.starting_with(/<\?/).until_after(/\?>/)
  5217. };
  5218. if (this._options.indent_handlebars) {
  5219. this.__patterns.word = this.__patterns.word.exclude('handlebars');
  5220. }
  5221. this._unformatted_content_delimiter = null;
  5222. if (this._options.unformatted_content_delimiter) {
  5223. var literal_regexp = this._input.get_literal_regexp(this._options.unformatted_content_delimiter);
  5224. this.__patterns.unformatted_content_delimiter =
  5225. pattern_reader.matching(literal_regexp)
  5226. .until_after(literal_regexp);
  5227. }
  5228. };
  5229. Tokenizer.prototype = new BaseTokenizer();
  5230. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  5231. return false; //current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.UNKNOWN;
  5232. };
  5233. Tokenizer.prototype._is_opening = function(current_token) {
  5234. return current_token.type === TOKEN.TAG_OPEN;
  5235. };
  5236. Tokenizer.prototype._is_closing = function(current_token, open_token) {
  5237. return current_token.type === TOKEN.TAG_CLOSE &&
  5238. (open_token && (
  5239. ((current_token.text === '>' || current_token.text === '/>') && open_token.text[0] === '<') ||
  5240. (current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{')));
  5241. };
  5242. Tokenizer.prototype._reset = function() {
  5243. this._current_tag_name = '';
  5244. };
  5245. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  5246. var token = null;
  5247. this._readWhitespace();
  5248. var c = this._input.peek();
  5249. if (c === null) {
  5250. return this._create_token(TOKEN.EOF, '');
  5251. }
  5252. token = token || this._read_open_handlebars(c, open_token);
  5253. token = token || this._read_attribute(c, previous_token, open_token);
  5254. token = token || this._read_close(c, open_token);
  5255. token = token || this._read_raw_content(c, previous_token, open_token);
  5256. token = token || this._read_content_word(c);
  5257. token = token || this._read_comment_or_cdata(c);
  5258. token = token || this._read_processing(c);
  5259. token = token || this._read_open(c, open_token);
  5260. token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
  5261. return token;
  5262. };
  5263. Tokenizer.prototype._read_comment_or_cdata = function(c) { // jshint unused:false
  5264. var token = null;
  5265. var resulting_string = null;
  5266. var directives = null;
  5267. if (c === '<') {
  5268. var peek1 = this._input.peek(1);
  5269. // We treat all comments as literals, even more than preformatted tags
  5270. // we only look for the appropriate closing marker
  5271. if (peek1 === '!') {
  5272. resulting_string = this.__patterns.comment.read();
  5273. // only process directive on html comments
  5274. if (resulting_string) {
  5275. directives = directives_core.get_directives(resulting_string);
  5276. if (directives && directives.ignore === 'start') {
  5277. resulting_string += directives_core.readIgnored(this._input);
  5278. }
  5279. } else {
  5280. resulting_string = this.__patterns.cdata.read();
  5281. }
  5282. }
  5283. if (resulting_string) {
  5284. token = this._create_token(TOKEN.COMMENT, resulting_string);
  5285. token.directives = directives;
  5286. }
  5287. }
  5288. return token;
  5289. };
  5290. Tokenizer.prototype._read_processing = function(c) { // jshint unused:false
  5291. var token = null;
  5292. var resulting_string = null;
  5293. var directives = null;
  5294. if (c === '<') {
  5295. var peek1 = this._input.peek(1);
  5296. if (peek1 === '!' || peek1 === '?') {
  5297. resulting_string = this.__patterns.conditional_comment.read();
  5298. resulting_string = resulting_string || this.__patterns.processing.read();
  5299. }
  5300. if (resulting_string) {
  5301. token = this._create_token(TOKEN.COMMENT, resulting_string);
  5302. token.directives = directives;
  5303. }
  5304. }
  5305. return token;
  5306. };
  5307. Tokenizer.prototype._read_open = function(c, open_token) {
  5308. var resulting_string = null;
  5309. var token = null;
  5310. if (!open_token) {
  5311. if (c === '<') {
  5312. resulting_string = this._input.next();
  5313. if (this._input.peek() === '/') {
  5314. resulting_string += this._input.next();
  5315. }
  5316. resulting_string += this.__patterns.element_name.read();
  5317. token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
  5318. }
  5319. }
  5320. return token;
  5321. };
  5322. Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
  5323. var resulting_string = null;
  5324. var token = null;
  5325. if (!open_token) {
  5326. if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
  5327. if (this._input.peek(2) === '!') {
  5328. resulting_string = this.__patterns.handlebars_comment.read();
  5329. resulting_string = resulting_string || this.__patterns.handlebars.read();
  5330. token = this._create_token(TOKEN.COMMENT, resulting_string);
  5331. } else {
  5332. resulting_string = this.__patterns.handlebars_open.read();
  5333. token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
  5334. }
  5335. }
  5336. }
  5337. return token;
  5338. };
  5339. Tokenizer.prototype._read_close = function(c, open_token) {
  5340. var resulting_string = null;
  5341. var token = null;
  5342. if (open_token) {
  5343. if (open_token.text[0] === '<' && (c === '>' || (c === '/' && this._input.peek(1) === '>'))) {
  5344. resulting_string = this._input.next();
  5345. if (c === '/') { // for close tag "/>"
  5346. resulting_string += this._input.next();
  5347. }
  5348. token = this._create_token(TOKEN.TAG_CLOSE, resulting_string);
  5349. } else if (open_token.text[0] === '{' && c === '}' && this._input.peek(1) === '}') {
  5350. this._input.next();
  5351. this._input.next();
  5352. token = this._create_token(TOKEN.TAG_CLOSE, '}}');
  5353. }
  5354. }
  5355. return token;
  5356. };
  5357. Tokenizer.prototype._read_attribute = function(c, previous_token, open_token) {
  5358. var token = null;
  5359. var resulting_string = '';
  5360. if (open_token && open_token.text[0] === '<') {
  5361. if (c === '=') {
  5362. token = this._create_token(TOKEN.EQUALS, this._input.next());
  5363. } else if (c === '"' || c === "'") {
  5364. var content = this._input.next();
  5365. if (c === '"') {
  5366. content += this.__patterns.double_quote.read();
  5367. } else {
  5368. content += this.__patterns.single_quote.read();
  5369. }
  5370. token = this._create_token(TOKEN.VALUE, content);
  5371. } else {
  5372. resulting_string = this.__patterns.attribute.read();
  5373. if (resulting_string) {
  5374. if (previous_token.type === TOKEN.EQUALS) {
  5375. token = this._create_token(TOKEN.VALUE, resulting_string);
  5376. } else {
  5377. token = this._create_token(TOKEN.ATTRIBUTE, resulting_string);
  5378. }
  5379. }
  5380. }
  5381. }
  5382. return token;
  5383. };
  5384. Tokenizer.prototype._is_content_unformatted = function(tag_name) {
  5385. // void_elements have no content and so cannot have unformatted content
  5386. // script and style tags should always be read as unformatted content
  5387. // finally content_unformatted and unformatted element contents are unformatted
  5388. return this._options.void_elements.indexOf(tag_name) === -1 &&
  5389. (this._options.content_unformatted.indexOf(tag_name) !== -1 ||
  5390. this._options.unformatted.indexOf(tag_name) !== -1);
  5391. };
  5392. Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
  5393. var resulting_string = '';
  5394. if (open_token && open_token.text[0] === '{') {
  5395. resulting_string = this.__patterns.handlebars_raw_close.read();
  5396. } else if (previous_token.type === TOKEN.TAG_CLOSE &&
  5397. previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
  5398. // ^^ empty tag has no content
  5399. var tag_name = previous_token.opened.text.substr(1).toLowerCase();
  5400. if (tag_name === 'script' || tag_name === 'style') {
  5401. // Script and style tags are allowed to have comments wrapping their content
  5402. // or just have regular content.
  5403. var token = this._read_comment_or_cdata(c);
  5404. if (token) {
  5405. token.type = TOKEN.TEXT;
  5406. return token;
  5407. }
  5408. resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
  5409. } else if (this._is_content_unformatted(tag_name)) {
  5410. resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
  5411. }
  5412. }
  5413. if (resulting_string) {
  5414. return this._create_token(TOKEN.TEXT, resulting_string);
  5415. }
  5416. return null;
  5417. };
  5418. Tokenizer.prototype._read_content_word = function(c) {
  5419. var resulting_string = '';
  5420. if (this._options.unformatted_content_delimiter) {
  5421. if (c === this._options.unformatted_content_delimiter[0]) {
  5422. resulting_string = this.__patterns.unformatted_content_delimiter.read();
  5423. }
  5424. }
  5425. if (!resulting_string) {
  5426. resulting_string = this.__patterns.word.read();
  5427. }
  5428. if (resulting_string) {
  5429. return this._create_token(TOKEN.TEXT, resulting_string);
  5430. }
  5431. };
  5432. tokenizer$1.Tokenizer = Tokenizer;
  5433. tokenizer$1.TOKEN = TOKEN;
  5434. return tokenizer$1;
  5435. }
  5436. /*jshint node:true */
  5437. var hasRequiredBeautifier;
  5438. function requireBeautifier () {
  5439. if (hasRequiredBeautifier) return beautifier;
  5440. hasRequiredBeautifier = 1;
  5441. var Options = requireOptions().Options;
  5442. var Output = requireOutput().Output;
  5443. var Tokenizer = requireTokenizer().Tokenizer;
  5444. var TOKEN = requireTokenizer().TOKEN;
  5445. var lineBreak = /\r\n|[\r\n]/;
  5446. var allLineBreaks = /\r\n|[\r\n]/g;
  5447. var Printer = function(options, base_indent_string) { //handles input/output and some other printing functions
  5448. this.indent_level = 0;
  5449. this.alignment_size = 0;
  5450. this.max_preserve_newlines = options.max_preserve_newlines;
  5451. this.preserve_newlines = options.preserve_newlines;
  5452. this._output = new Output(options, base_indent_string);
  5453. };
  5454. Printer.prototype.current_line_has_match = function(pattern) {
  5455. return this._output.current_line.has_match(pattern);
  5456. };
  5457. Printer.prototype.set_space_before_token = function(value, non_breaking) {
  5458. this._output.space_before_token = value;
  5459. this._output.non_breaking_space = non_breaking;
  5460. };
  5461. Printer.prototype.set_wrap_point = function() {
  5462. this._output.set_indent(this.indent_level, this.alignment_size);
  5463. this._output.set_wrap_point();
  5464. };
  5465. Printer.prototype.add_raw_token = function(token) {
  5466. this._output.add_raw_token(token);
  5467. };
  5468. Printer.prototype.print_preserved_newlines = function(raw_token) {
  5469. var newlines = 0;
  5470. if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) {
  5471. newlines = raw_token.newlines ? 1 : 0;
  5472. }
  5473. if (this.preserve_newlines) {
  5474. newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1;
  5475. }
  5476. for (var n = 0; n < newlines; n++) {
  5477. this.print_newline(n > 0);
  5478. }
  5479. return newlines !== 0;
  5480. };
  5481. Printer.prototype.traverse_whitespace = function(raw_token) {
  5482. if (raw_token.whitespace_before || raw_token.newlines) {
  5483. if (!this.print_preserved_newlines(raw_token)) {
  5484. this._output.space_before_token = true;
  5485. }
  5486. return true;
  5487. }
  5488. return false;
  5489. };
  5490. Printer.prototype.previous_token_wrapped = function() {
  5491. return this._output.previous_token_wrapped;
  5492. };
  5493. Printer.prototype.print_newline = function(force) {
  5494. this._output.add_new_line(force);
  5495. };
  5496. Printer.prototype.print_token = function(token) {
  5497. if (token.text) {
  5498. this._output.set_indent(this.indent_level, this.alignment_size);
  5499. this._output.add_token(token.text);
  5500. }
  5501. };
  5502. Printer.prototype.indent = function() {
  5503. this.indent_level++;
  5504. };
  5505. Printer.prototype.get_full_indent = function(level) {
  5506. level = this.indent_level + (level || 0);
  5507. if (level < 1) {
  5508. return '';
  5509. }
  5510. return this._output.get_indent_string(level);
  5511. };
  5512. var get_type_attribute = function(start_token) {
  5513. var result = null;
  5514. var raw_token = start_token.next;
  5515. // Search attributes for a type attribute
  5516. while (raw_token.type !== TOKEN.EOF && start_token.closed !== raw_token) {
  5517. if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') {
  5518. if (raw_token.next && raw_token.next.type === TOKEN.EQUALS &&
  5519. raw_token.next.next && raw_token.next.next.type === TOKEN.VALUE) {
  5520. result = raw_token.next.next.text;
  5521. }
  5522. break;
  5523. }
  5524. raw_token = raw_token.next;
  5525. }
  5526. return result;
  5527. };
  5528. var get_custom_beautifier_name = function(tag_check, raw_token) {
  5529. var typeAttribute = null;
  5530. var result = null;
  5531. if (!raw_token.closed) {
  5532. return null;
  5533. }
  5534. if (tag_check === 'script') {
  5535. typeAttribute = 'text/javascript';
  5536. } else if (tag_check === 'style') {
  5537. typeAttribute = 'text/css';
  5538. }
  5539. typeAttribute = get_type_attribute(raw_token) || typeAttribute;
  5540. // For script and style tags that have a type attribute, only enable custom beautifiers for matching values
  5541. // For those without a type attribute use default;
  5542. if (typeAttribute.search('text/css') > -1) {
  5543. result = 'css';
  5544. } else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
  5545. result = 'javascript';
  5546. } else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
  5547. result = 'html';
  5548. } else if (typeAttribute.search(/test\/null/) > -1) {
  5549. // Test only mime-type for testing the beautifier when null is passed as beautifing function
  5550. result = 'null';
  5551. }
  5552. return result;
  5553. };
  5554. function in_array(what, arr) {
  5555. return arr.indexOf(what) !== -1;
  5556. }
  5557. function TagFrame(parent, parser_token, indent_level) {
  5558. this.parent = parent || null;
  5559. this.tag = parser_token ? parser_token.tag_name : '';
  5560. this.indent_level = indent_level || 0;
  5561. this.parser_token = parser_token || null;
  5562. }
  5563. function TagStack(printer) {
  5564. this._printer = printer;
  5565. this._current_frame = null;
  5566. }
  5567. TagStack.prototype.get_parser_token = function() {
  5568. return this._current_frame ? this._current_frame.parser_token : null;
  5569. };
  5570. TagStack.prototype.record_tag = function(parser_token) { //function to record a tag and its parent in this.tags Object
  5571. var new_frame = new TagFrame(this._current_frame, parser_token, this._printer.indent_level);
  5572. this._current_frame = new_frame;
  5573. };
  5574. TagStack.prototype._try_pop_frame = function(frame) { //function to retrieve the opening tag to the corresponding closer
  5575. var parser_token = null;
  5576. if (frame) {
  5577. parser_token = frame.parser_token;
  5578. this._printer.indent_level = frame.indent_level;
  5579. this._current_frame = frame.parent;
  5580. }
  5581. return parser_token;
  5582. };
  5583. TagStack.prototype._get_frame = function(tag_list, stop_list) { //function to retrieve the opening tag to the corresponding closer
  5584. var frame = this._current_frame;
  5585. while (frame) { //till we reach '' (the initial value);
  5586. if (tag_list.indexOf(frame.tag) !== -1) { //if this is it use it
  5587. break;
  5588. } else if (stop_list && stop_list.indexOf(frame.tag) !== -1) {
  5589. frame = null;
  5590. break;
  5591. }
  5592. frame = frame.parent;
  5593. }
  5594. return frame;
  5595. };
  5596. TagStack.prototype.try_pop = function(tag, stop_list) { //function to retrieve the opening tag to the corresponding closer
  5597. var frame = this._get_frame([tag], stop_list);
  5598. return this._try_pop_frame(frame);
  5599. };
  5600. TagStack.prototype.indent_to_tag = function(tag_list) {
  5601. var frame = this._get_frame(tag_list);
  5602. if (frame) {
  5603. this._printer.indent_level = frame.indent_level;
  5604. }
  5605. };
  5606. function Beautifier(source_text, options, js_beautify, css_beautify) {
  5607. //Wrapper function to invoke all the necessary constructors and deal with the output.
  5608. this._source_text = source_text || '';
  5609. options = options || {};
  5610. this._js_beautify = js_beautify;
  5611. this._css_beautify = css_beautify;
  5612. this._tag_stack = null;
  5613. // Allow the setting of language/file-type specific options
  5614. // with inheritance of overall settings
  5615. var optionHtml = new Options(options, 'html');
  5616. this._options = optionHtml;
  5617. this._is_wrap_attributes_force = this._options.wrap_attributes.substr(0, 'force'.length) === 'force';
  5618. this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
  5619. this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
  5620. this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
  5621. this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
  5622. this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
  5623. }
  5624. Beautifier.prototype.beautify = function() {
  5625. // if disabled, return the input unchanged.
  5626. if (this._options.disabled) {
  5627. return this._source_text;
  5628. }
  5629. var source_text = this._source_text;
  5630. var eol = this._options.eol;
  5631. if (this._options.eol === 'auto') {
  5632. eol = '\n';
  5633. if (source_text && lineBreak.test(source_text)) {
  5634. eol = source_text.match(lineBreak)[0];
  5635. }
  5636. }
  5637. // HACK: newline parsing inconsistent. This brute force normalizes the input.
  5638. source_text = source_text.replace(allLineBreaks, '\n');
  5639. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  5640. var last_token = {
  5641. text: '',
  5642. type: ''
  5643. };
  5644. var last_tag_token = new TagOpenParserToken();
  5645. var printer = new Printer(this._options, baseIndentString);
  5646. var tokens = new Tokenizer(source_text, this._options).tokenize();
  5647. this._tag_stack = new TagStack(printer);
  5648. var parser_token = null;
  5649. var raw_token = tokens.next();
  5650. while (raw_token.type !== TOKEN.EOF) {
  5651. if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
  5652. parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token, tokens);
  5653. last_tag_token = parser_token;
  5654. } else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
  5655. (raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
  5656. parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, last_token);
  5657. } else if (raw_token.type === TOKEN.TAG_CLOSE) {
  5658. parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);
  5659. } else if (raw_token.type === TOKEN.TEXT) {
  5660. parser_token = this._handle_text(printer, raw_token, last_tag_token);
  5661. } else {
  5662. // This should never happen, but if it does. Print the raw token
  5663. printer.add_raw_token(raw_token);
  5664. }
  5665. last_token = parser_token;
  5666. raw_token = tokens.next();
  5667. }
  5668. var sweet_code = printer._output.get_code(eol);
  5669. return sweet_code;
  5670. };
  5671. Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
  5672. var parser_token = {
  5673. text: raw_token.text,
  5674. type: raw_token.type
  5675. };
  5676. printer.alignment_size = 0;
  5677. last_tag_token.tag_complete = true;
  5678. printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
  5679. if (last_tag_token.is_unformatted) {
  5680. printer.add_raw_token(raw_token);
  5681. } else {
  5682. if (last_tag_token.tag_start_char === '<') {
  5683. printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before >
  5684. if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
  5685. printer.print_newline(false);
  5686. }
  5687. }
  5688. printer.print_token(raw_token);
  5689. }
  5690. if (last_tag_token.indent_content &&
  5691. !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
  5692. printer.indent();
  5693. // only indent once per opened tag
  5694. last_tag_token.indent_content = false;
  5695. }
  5696. if (!last_tag_token.is_inline_element &&
  5697. !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
  5698. printer.set_wrap_point();
  5699. }
  5700. return parser_token;
  5701. };
  5702. Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, last_token) {
  5703. var wrapped = last_tag_token.has_wrapped_attrs;
  5704. var parser_token = {
  5705. text: raw_token.text,
  5706. type: raw_token.type
  5707. };
  5708. printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
  5709. if (last_tag_token.is_unformatted) {
  5710. printer.add_raw_token(raw_token);
  5711. } else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) {
  5712. // For the insides of handlebars allow newlines or a single space between open and contents
  5713. if (printer.print_preserved_newlines(raw_token)) {
  5714. raw_token.newlines = 0;
  5715. printer.add_raw_token(raw_token);
  5716. } else {
  5717. printer.print_token(raw_token);
  5718. }
  5719. } else {
  5720. if (raw_token.type === TOKEN.ATTRIBUTE) {
  5721. printer.set_space_before_token(true);
  5722. } else if (raw_token.type === TOKEN.EQUALS) { //no space before =
  5723. printer.set_space_before_token(false);
  5724. } else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) { //no space before value
  5725. printer.set_space_before_token(false);
  5726. }
  5727. if (raw_token.type === TOKEN.ATTRIBUTE && last_tag_token.tag_start_char === '<') {
  5728. if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
  5729. printer.traverse_whitespace(raw_token);
  5730. wrapped = wrapped || raw_token.newlines !== 0;
  5731. }
  5732. // Wrap for 'force' options, and if the number of attributes is at least that specified in 'wrap_attributes_min_attrs':
  5733. // 1. always wrap the second and beyond attributes
  5734. // 2. wrap the first attribute only if 'force-expand-multiline' is specified
  5735. if (this._is_wrap_attributes_force &&
  5736. last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
  5737. (last_token.type !== TOKEN.TAG_OPEN || // ie. second attribute and beyond
  5738. this._is_wrap_attributes_force_expand_multiline)) {
  5739. printer.print_newline(false);
  5740. wrapped = true;
  5741. }
  5742. }
  5743. printer.print_token(raw_token);
  5744. wrapped = wrapped || printer.previous_token_wrapped();
  5745. last_tag_token.has_wrapped_attrs = wrapped;
  5746. }
  5747. return parser_token;
  5748. };
  5749. Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
  5750. var parser_token = {
  5751. text: raw_token.text,
  5752. type: 'TK_CONTENT'
  5753. };
  5754. if (last_tag_token.custom_beautifier_name) { //check if we need to format javascript
  5755. this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
  5756. } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
  5757. printer.add_raw_token(raw_token);
  5758. } else {
  5759. printer.traverse_whitespace(raw_token);
  5760. printer.print_token(raw_token);
  5761. }
  5762. return parser_token;
  5763. };
  5764. Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) {
  5765. var local = this;
  5766. if (raw_token.text !== '') {
  5767. var text = raw_token.text,
  5768. _beautifier,
  5769. script_indent_level = 1,
  5770. pre = '',
  5771. post = '';
  5772. if (last_tag_token.custom_beautifier_name === 'javascript' && typeof this._js_beautify === 'function') {
  5773. _beautifier = this._js_beautify;
  5774. } else if (last_tag_token.custom_beautifier_name === 'css' && typeof this._css_beautify === 'function') {
  5775. _beautifier = this._css_beautify;
  5776. } else if (last_tag_token.custom_beautifier_name === 'html') {
  5777. _beautifier = function(html_source, options) {
  5778. var beautifier = new Beautifier(html_source, options, local._js_beautify, local._css_beautify);
  5779. return beautifier.beautify();
  5780. };
  5781. }
  5782. if (this._options.indent_scripts === "keep") {
  5783. script_indent_level = 0;
  5784. } else if (this._options.indent_scripts === "separate") {
  5785. script_indent_level = -printer.indent_level;
  5786. }
  5787. var indentation = printer.get_full_indent(script_indent_level);
  5788. // if there is at least one empty line at the end of this text, strip it
  5789. // we'll be adding one back after the text but before the containing tag.
  5790. text = text.replace(/\n[ \t]*$/, '');
  5791. // Handle the case where content is wrapped in a comment or cdata.
  5792. if (last_tag_token.custom_beautifier_name !== 'html' &&
  5793. text[0] === '<' && text.match(/^(<!--|<!\[CDATA\[)/)) {
  5794. var matched = /^(<!--[^\n]*|<!\[CDATA\[)(\n?)([ \t\n]*)([\s\S]*)(-->|]]>)$/.exec(text);
  5795. // if we start to wrap but don't finish, print raw
  5796. if (!matched) {
  5797. printer.add_raw_token(raw_token);
  5798. return;
  5799. }
  5800. pre = indentation + matched[1] + '\n';
  5801. text = matched[4];
  5802. if (matched[5]) {
  5803. post = indentation + matched[5];
  5804. }
  5805. // if there is at least one empty line at the end of this text, strip it
  5806. // we'll be adding one back after the text but before the containing tag.
  5807. text = text.replace(/\n[ \t]*$/, '');
  5808. if (matched[2] || matched[3].indexOf('\n') !== -1) {
  5809. // if the first line of the non-comment text has spaces
  5810. // use that as the basis for indenting in null case.
  5811. matched = matched[3].match(/[ \t]+$/);
  5812. if (matched) {
  5813. raw_token.whitespace_before = matched[0];
  5814. }
  5815. }
  5816. }
  5817. if (text) {
  5818. if (_beautifier) {
  5819. // call the Beautifier if avaliable
  5820. var Child_options = function() {
  5821. this.eol = '\n';
  5822. };
  5823. Child_options.prototype = this._options.raw_options;
  5824. var child_options = new Child_options();
  5825. text = _beautifier(indentation + text, child_options);
  5826. } else {
  5827. // simply indent the string otherwise
  5828. var white = raw_token.whitespace_before;
  5829. if (white) {
  5830. text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n');
  5831. }
  5832. text = indentation + text.replace(/\n/g, '\n' + indentation);
  5833. }
  5834. }
  5835. if (pre) {
  5836. if (!text) {
  5837. text = pre + post;
  5838. } else {
  5839. text = pre + text + '\n' + post;
  5840. }
  5841. }
  5842. printer.print_newline(false);
  5843. if (text) {
  5844. raw_token.text = text;
  5845. raw_token.whitespace_before = '';
  5846. raw_token.newlines = 0;
  5847. printer.add_raw_token(raw_token);
  5848. printer.print_newline(true);
  5849. }
  5850. }
  5851. };
  5852. Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token, tokens) {
  5853. var parser_token = this._get_tag_open_token(raw_token);
  5854. if ((last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) &&
  5855. !last_tag_token.is_empty_element &&
  5856. raw_token.type === TOKEN.TAG_OPEN && !parser_token.is_start_tag) {
  5857. // End element tags for unformatted or content_unformatted elements
  5858. // are printed raw to keep any newlines inside them exactly the same.
  5859. printer.add_raw_token(raw_token);
  5860. parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
  5861. } else {
  5862. printer.traverse_whitespace(raw_token);
  5863. this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
  5864. if (!parser_token.is_inline_element) {
  5865. printer.set_wrap_point();
  5866. }
  5867. printer.print_token(raw_token);
  5868. }
  5869. // count the number of attributes
  5870. if (parser_token.is_start_tag && this._is_wrap_attributes_force) {
  5871. var peek_index = 0;
  5872. var peek_token;
  5873. do {
  5874. peek_token = tokens.peek(peek_index);
  5875. if (peek_token.type === TOKEN.ATTRIBUTE) {
  5876. parser_token.attr_count += 1;
  5877. }
  5878. peek_index += 1;
  5879. } while (peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
  5880. }
  5881. //indent attributes an auto, forced, aligned or forced-align line-wrap
  5882. if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
  5883. parser_token.alignment_size = raw_token.text.length + 1;
  5884. }
  5885. if (!parser_token.tag_complete && !parser_token.is_unformatted) {
  5886. printer.alignment_size = parser_token.alignment_size;
  5887. }
  5888. return parser_token;
  5889. };
  5890. var TagOpenParserToken = function(parent, raw_token) {
  5891. this.parent = parent || null;
  5892. this.text = '';
  5893. this.type = 'TK_TAG_OPEN';
  5894. this.tag_name = '';
  5895. this.is_inline_element = false;
  5896. this.is_unformatted = false;
  5897. this.is_content_unformatted = false;
  5898. this.is_empty_element = false;
  5899. this.is_start_tag = false;
  5900. this.is_end_tag = false;
  5901. this.indent_content = false;
  5902. this.multiline_content = false;
  5903. this.custom_beautifier_name = null;
  5904. this.start_tag_token = null;
  5905. this.attr_count = 0;
  5906. this.has_wrapped_attrs = false;
  5907. this.alignment_size = 0;
  5908. this.tag_complete = false;
  5909. this.tag_start_char = '';
  5910. this.tag_check = '';
  5911. if (!raw_token) {
  5912. this.tag_complete = true;
  5913. } else {
  5914. var tag_check_match;
  5915. this.tag_start_char = raw_token.text[0];
  5916. this.text = raw_token.text;
  5917. if (this.tag_start_char === '<') {
  5918. tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
  5919. this.tag_check = tag_check_match ? tag_check_match[1] : '';
  5920. } else {
  5921. tag_check_match = raw_token.text.match(/^{{~?(?:[\^]|#\*?)?([^\s}]+)/);
  5922. this.tag_check = tag_check_match ? tag_check_match[1] : '';
  5923. // handle "{{#> myPartial}}" or "{{~#> myPartial}}"
  5924. if ((raw_token.text.startsWith('{{#>') || raw_token.text.startsWith('{{~#>')) && this.tag_check[0] === '>') {
  5925. if (this.tag_check === '>' && raw_token.next !== null) {
  5926. this.tag_check = raw_token.next.text.split(' ')[0];
  5927. } else {
  5928. this.tag_check = raw_token.text.split('>')[1];
  5929. }
  5930. }
  5931. }
  5932. this.tag_check = this.tag_check.toLowerCase();
  5933. if (raw_token.type === TOKEN.COMMENT) {
  5934. this.tag_complete = true;
  5935. }
  5936. this.is_start_tag = this.tag_check.charAt(0) !== '/';
  5937. this.tag_name = !this.is_start_tag ? this.tag_check.substr(1) : this.tag_check;
  5938. this.is_end_tag = !this.is_start_tag ||
  5939. (raw_token.closed && raw_token.closed.text === '/>');
  5940. // if whitespace handler ~ included (i.e. {{~#if true}}), handlebars tags start at pos 3 not pos 2
  5941. var handlebar_starts = 2;
  5942. if (this.tag_start_char === '{' && this.text.length >= 3) {
  5943. if (this.text.charAt(2) === '~') {
  5944. handlebar_starts = 3;
  5945. }
  5946. }
  5947. // handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
  5948. this.is_end_tag = this.is_end_tag ||
  5949. (this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
  5950. }
  5951. };
  5952. Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
  5953. var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
  5954. parser_token.alignment_size = this._options.wrap_attributes_indent_size;
  5955. parser_token.is_end_tag = parser_token.is_end_tag ||
  5956. in_array(parser_token.tag_check, this._options.void_elements);
  5957. parser_token.is_empty_element = parser_token.tag_complete ||
  5958. (parser_token.is_start_tag && parser_token.is_end_tag);
  5959. parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
  5960. parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
  5961. parser_token.is_inline_element = in_array(parser_token.tag_name, this._options.inline) || (this._options.inline_custom_elements && parser_token.tag_name.includes("-")) || parser_token.tag_start_char === '{';
  5962. return parser_token;
  5963. };
  5964. Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_token, last_tag_token, last_token) {
  5965. if (!parser_token.is_empty_element) {
  5966. if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
  5967. parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name); //remove it and all ancestors
  5968. } else { // it's a start-tag
  5969. // check if this tag is starting an element that has optional end element
  5970. // and do an ending needed
  5971. if (this._do_optional_end_element(parser_token)) {
  5972. if (!parser_token.is_inline_element) {
  5973. printer.print_newline(false);
  5974. }
  5975. }
  5976. this._tag_stack.record_tag(parser_token); //push it on the tag stack
  5977. if ((parser_token.tag_name === 'script' || parser_token.tag_name === 'style') &&
  5978. !(parser_token.is_unformatted || parser_token.is_content_unformatted)) {
  5979. parser_token.custom_beautifier_name = get_custom_beautifier_name(parser_token.tag_check, raw_token);
  5980. }
  5981. }
  5982. }
  5983. if (in_array(parser_token.tag_check, this._options.extra_liners)) { //check if this double needs an extra line
  5984. printer.print_newline(false);
  5985. if (!printer._output.just_added_blankline()) {
  5986. printer.print_newline(true);
  5987. }
  5988. }
  5989. if (parser_token.is_empty_element) { //if this tag name is a single tag type (either in the list or has a closing /)
  5990. // if you hit an else case, reset the indent level if you are inside an:
  5991. // 'if', 'unless', or 'each' block.
  5992. if (parser_token.tag_start_char === '{' && parser_token.tag_check === 'else') {
  5993. this._tag_stack.indent_to_tag(['if', 'unless', 'each']);
  5994. parser_token.indent_content = true;
  5995. // Don't add a newline if opening {{#if}} tag is on the current line
  5996. var foundIfOnCurrentLine = printer.current_line_has_match(/{{#if/);
  5997. if (!foundIfOnCurrentLine) {
  5998. printer.print_newline(false);
  5999. }
  6000. }
  6001. // Don't add a newline before elements that should remain where they are.
  6002. if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE &&
  6003. last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) ; else {
  6004. if (!(parser_token.is_inline_element || parser_token.is_unformatted)) {
  6005. printer.print_newline(false);
  6006. }
  6007. this._calcluate_parent_multiline(printer, parser_token);
  6008. }
  6009. } else if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
  6010. var do_end_expand = false;
  6011. // deciding whether a block is multiline should not be this hard
  6012. do_end_expand = parser_token.start_tag_token && parser_token.start_tag_token.multiline_content;
  6013. do_end_expand = do_end_expand || (!parser_token.is_inline_element &&
  6014. !(last_tag_token.is_inline_element || last_tag_token.is_unformatted) &&
  6015. !(last_token.type === TOKEN.TAG_CLOSE && parser_token.start_tag_token === last_tag_token) &&
  6016. last_token.type !== 'TK_CONTENT'
  6017. );
  6018. if (parser_token.is_content_unformatted || parser_token.is_unformatted) {
  6019. do_end_expand = false;
  6020. }
  6021. if (do_end_expand) {
  6022. printer.print_newline(false);
  6023. }
  6024. } else { // it's a start-tag
  6025. parser_token.indent_content = !parser_token.custom_beautifier_name;
  6026. if (parser_token.tag_start_char === '<') {
  6027. if (parser_token.tag_name === 'html') {
  6028. parser_token.indent_content = this._options.indent_inner_html;
  6029. } else if (parser_token.tag_name === 'head') {
  6030. parser_token.indent_content = this._options.indent_head_inner_html;
  6031. } else if (parser_token.tag_name === 'body') {
  6032. parser_token.indent_content = this._options.indent_body_inner_html;
  6033. }
  6034. }
  6035. if (!(parser_token.is_inline_element || parser_token.is_unformatted) &&
  6036. (last_token.type !== 'TK_CONTENT' || parser_token.is_content_unformatted)) {
  6037. printer.print_newline(false);
  6038. }
  6039. this._calcluate_parent_multiline(printer, parser_token);
  6040. }
  6041. };
  6042. Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_token) {
  6043. if (parser_token.parent && printer._output.just_added_newline() &&
  6044. !((parser_token.is_inline_element || parser_token.is_unformatted) && parser_token.parent.is_inline_element)) {
  6045. parser_token.parent.multiline_content = true;
  6046. }
  6047. };
  6048. //To be used for <p> tag special case:
  6049. var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
  6050. var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
  6051. Beautifier.prototype._do_optional_end_element = function(parser_token) {
  6052. var result = null;
  6053. // NOTE: cases of "if there is no more content in the parent element"
  6054. // are handled automatically by the beautifier.
  6055. // It assumes parent or ancestor close tag closes all children.
  6056. // https://www.w3.org/TR/html5/syntax.html#optional-tags
  6057. if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
  6058. return;
  6059. }
  6060. if (parser_token.tag_name === 'body') {
  6061. // A head element’s end tag may be omitted if the head element is not immediately followed by a space character or a comment.
  6062. result = result || this._tag_stack.try_pop('head');
  6063. //} else if (parser_token.tag_name === 'body') {
  6064. // DONE: A body element’s end tag may be omitted if the body element is not immediately followed by a comment.
  6065. } else if (parser_token.tag_name === 'li') {
  6066. // An li element’s end tag may be omitted if the li element is immediately followed by another li element or if there is no more content in the parent element.
  6067. result = result || this._tag_stack.try_pop('li', ['ol', 'ul', 'menu']);
  6068. } else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
  6069. // A dd element’s end tag may be omitted if the dd element is immediately followed by another dd element or a dt element, or if there is no more content in the parent element.
  6070. // A dt element’s end tag may be omitted if the dt element is immediately followed by another dt element or a dd element.
  6071. result = result || this._tag_stack.try_pop('dt', ['dl']);
  6072. result = result || this._tag_stack.try_pop('dd', ['dl']);
  6073. } else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) {
  6074. // IMPORTANT: this else-if works because p_closers has no overlap with any other element we look for in this method
  6075. // check for the parent element is an HTML element that is not an <a>, <audio>, <del>, <ins>, <map>, <noscript>, or <video> element, or an autonomous custom element.
  6076. // To do this right, this needs to be coded as an inclusion of the inverse of the exclusion above.
  6077. // But to start with (if we ignore "autonomous custom elements") the exclusion would be fine.
  6078. var p_parent = parser_token.parent.parent;
  6079. if (!p_parent || p_parent_excludes.indexOf(p_parent.tag_name) === -1) {
  6080. result = result || this._tag_stack.try_pop('p');
  6081. }
  6082. } else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
  6083. // An rt element’s end tag may be omitted if the rt element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
  6084. // An rp element’s end tag may be omitted if the rp element is immediately followed by an rt or rp element, or if there is no more content in the parent element.
  6085. result = result || this._tag_stack.try_pop('rt', ['ruby', 'rtc']);
  6086. result = result || this._tag_stack.try_pop('rp', ['ruby', 'rtc']);
  6087. } else if (parser_token.tag_name === 'optgroup') {
  6088. // An optgroup element’s end tag may be omitted if the optgroup element is immediately followed by another optgroup element, or if there is no more content in the parent element.
  6089. // An option element’s end tag may be omitted if the option element is immediately followed by another option element, or if it is immediately followed by an optgroup element, or if there is no more content in the parent element.
  6090. result = result || this._tag_stack.try_pop('optgroup', ['select']);
  6091. //result = result || this._tag_stack.try_pop('option', ['select']);
  6092. } else if (parser_token.tag_name === 'option') {
  6093. // An option element’s end tag may be omitted if the option element is immediately followed by another option element, or if it is immediately followed by an optgroup element, or if there is no more content in the parent element.
  6094. result = result || this._tag_stack.try_pop('option', ['select', 'datalist', 'optgroup']);
  6095. } else if (parser_token.tag_name === 'colgroup') {
  6096. // DONE: A colgroup element’s end tag may be omitted if the colgroup element is not immediately followed by a space character or a comment.
  6097. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  6098. result = result || this._tag_stack.try_pop('caption', ['table']);
  6099. } else if (parser_token.tag_name === 'thead') {
  6100. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  6101. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  6102. result = result || this._tag_stack.try_pop('caption', ['table']);
  6103. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  6104. //} else if (parser_token.tag_name === 'caption') {
  6105. // DONE: A caption element’s end tag may be omitted if the caption element is not immediately followed by a space character or a comment.
  6106. } else if (parser_token.tag_name === 'tbody' || parser_token.tag_name === 'tfoot') {
  6107. // A thead element’s end tag may be omitted if the thead element is immediately followed by a tbody or tfoot element.
  6108. // A tbody element’s end tag may be omitted if the tbody element is immediately followed by a tbody or tfoot element, or if there is no more content in the parent element.
  6109. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  6110. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  6111. result = result || this._tag_stack.try_pop('caption', ['table']);
  6112. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  6113. result = result || this._tag_stack.try_pop('thead', ['table']);
  6114. result = result || this._tag_stack.try_pop('tbody', ['table']);
  6115. //} else if (parser_token.tag_name === 'tfoot') {
  6116. // DONE: A tfoot element’s end tag may be omitted if there is no more content in the parent element.
  6117. } else if (parser_token.tag_name === 'tr') {
  6118. // A tr element’s end tag may be omitted if the tr element is immediately followed by another tr element, or if there is no more content in the parent element.
  6119. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  6120. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  6121. result = result || this._tag_stack.try_pop('caption', ['table']);
  6122. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  6123. result = result || this._tag_stack.try_pop('tr', ['table', 'thead', 'tbody', 'tfoot']);
  6124. } else if (parser_token.tag_name === 'th' || parser_token.tag_name === 'td') {
  6125. // A td element’s end tag may be omitted if the td element is immediately followed by a td or th element, or if there is no more content in the parent element.
  6126. // A th element’s end tag may be omitted if the th element is immediately followed by a td or th element, or if there is no more content in the parent element.
  6127. result = result || this._tag_stack.try_pop('td', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
  6128. result = result || this._tag_stack.try_pop('th', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
  6129. }
  6130. // Start element omission not handled currently
  6131. // A head element’s start tag may be omitted if the element is empty, or if the first thing inside the head element is an element.
  6132. // A tbody element’s start tag may be omitted if the first thing inside the tbody element is a tr element, and if the element is not immediately preceded by a tbody, thead, or tfoot element whose end tag has been omitted. (It can’t be omitted if the element is empty.)
  6133. // A colgroup element’s start tag may be omitted if the first thing inside the colgroup element is a col element, and if the element is not immediately preceded by another colgroup element whose end tag has been omitted. (It can’t be omitted if the element is empty.)
  6134. // Fix up the parent of the parser token
  6135. parser_token.parent = this._tag_stack.get_parser_token();
  6136. return result;
  6137. };
  6138. beautifier.Beautifier = Beautifier;
  6139. return beautifier;
  6140. }
  6141. /*jshint node:true */
  6142. var hasRequiredHtml;
  6143. function requireHtml () {
  6144. if (hasRequiredHtml) return html.exports;
  6145. hasRequiredHtml = 1;
  6146. var Beautifier = requireBeautifier().Beautifier,
  6147. Options = requireOptions().Options;
  6148. function style_html(html_source, options, js_beautify, css_beautify) {
  6149. var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
  6150. return beautifier.beautify();
  6151. }
  6152. html.exports = style_html;
  6153. html.exports.defaultOptions = function() {
  6154. return new Options();
  6155. };
  6156. return html.exports;
  6157. }
  6158. /*jshint node:true */
  6159. var hasRequiredSrc;
  6160. function requireSrc () {
  6161. if (hasRequiredSrc) return src;
  6162. hasRequiredSrc = 1;
  6163. var js_beautify = requireJavascript();
  6164. var css_beautify = requireCss();
  6165. var html_beautify = requireHtml();
  6166. function style_html(html_source, options, js, css) {
  6167. js = js || js_beautify;
  6168. css = css || css_beautify;
  6169. return html_beautify(html_source, options, js, css);
  6170. }
  6171. style_html.defaultOptions = html_beautify.defaultOptions;
  6172. src.js = js_beautify;
  6173. src.css = css_beautify;
  6174. src.html = style_html;
  6175. return src;
  6176. }
  6177. /*jshint node:true */
  6178. (function (module) {
  6179. /**
  6180. The following batches are equivalent:
  6181. var beautify_js = require('js-beautify');
  6182. var beautify_js = require('js-beautify').js;
  6183. var beautify_js = require('js-beautify').js_beautify;
  6184. var beautify_css = require('js-beautify').css;
  6185. var beautify_css = require('js-beautify').css_beautify;
  6186. var beautify_html = require('js-beautify').html;
  6187. var beautify_html = require('js-beautify').html_beautify;
  6188. All methods returned accept two arguments, the source string and an options object.
  6189. **/
  6190. function get_beautify(js_beautify, css_beautify, html_beautify) {
  6191. // the default is js
  6192. var beautify = function(src, config) {
  6193. return js_beautify.js_beautify(src, config);
  6194. };
  6195. // short aliases
  6196. beautify.js = js_beautify.js_beautify;
  6197. beautify.css = css_beautify.css_beautify;
  6198. beautify.html = html_beautify.html_beautify;
  6199. // legacy aliases
  6200. beautify.js_beautify = js_beautify.js_beautify;
  6201. beautify.css_beautify = css_beautify.css_beautify;
  6202. beautify.html_beautify = html_beautify.html_beautify;
  6203. return beautify;
  6204. }
  6205. {
  6206. (function(mod) {
  6207. var beautifier = requireSrc();
  6208. beautifier.js_beautify = beautifier.js;
  6209. beautifier.css_beautify = beautifier.css;
  6210. beautifier.html_beautify = beautifier.html;
  6211. mod.exports = get_beautify(beautifier, beautifier, beautifier);
  6212. })(module);
  6213. }
  6214. } (js));
  6215. var jsExports = js.exports;
  6216. var beautify = /*@__PURE__*/getDefaultExportFromCjs(jsExports);
  6217. var BaseWrapper = /** @class */ (function () {
  6218. function BaseWrapper(element) {
  6219. var _this = this;
  6220. this.isDisabled = function () {
  6221. var validTagsToBeDisabled = [
  6222. 'BUTTON',
  6223. 'COMMAND',
  6224. 'FIELDSET',
  6225. 'KEYGEN',
  6226. 'OPTGROUP',
  6227. 'OPTION',
  6228. 'SELECT',
  6229. 'TEXTAREA',
  6230. 'INPUT'
  6231. ];
  6232. var hasDisabledAttribute = _this.attributes().disabled !== undefined;
  6233. var elementCanBeDisabled = isElement(_this.element) &&
  6234. validTagsToBeDisabled.includes(_this.element.tagName);
  6235. return hasDisabledAttribute && elementCanBeDisabled;
  6236. };
  6237. this.wrapperElement = element;
  6238. }
  6239. Object.defineProperty(BaseWrapper.prototype, "element", {
  6240. get: function () {
  6241. return this.wrapperElement;
  6242. },
  6243. enumerable: false,
  6244. configurable: true
  6245. });
  6246. BaseWrapper.prototype.findAllDOMElements = function (selector) {
  6247. var elementRootNodes = this.getRootNodes().filter(isElement);
  6248. if (elementRootNodes.length === 0)
  6249. return [];
  6250. var result = __spreadArray([], elementRootNodes.filter(function (node) { return node.matches(selector); }), true);
  6251. elementRootNodes.forEach(function (rootNode) {
  6252. result.push.apply(result, Array.from(rootNode.querySelectorAll(selector)));
  6253. });
  6254. return result;
  6255. };
  6256. BaseWrapper.prototype.find = function (selector) {
  6257. if (typeof selector === 'object' && 'ref' in selector) {
  6258. var currentComponent = this.getCurrentComponent();
  6259. if (!currentComponent) {
  6260. return createWrapperError('DOMWrapper');
  6261. }
  6262. var result = currentComponent.refs[selector.ref];
  6263. // When using ref inside v-for, then refs contains array of component instances and nodes
  6264. if (Array.isArray(result)) {
  6265. result = result.length ? result[0] : undefined;
  6266. }
  6267. if (result instanceof Node) {
  6268. return createDOMWrapper(result);
  6269. }
  6270. else {
  6271. return createWrapperError('DOMWrapper');
  6272. }
  6273. }
  6274. var elements = this.findAll(selector);
  6275. if (elements.length > 0) {
  6276. return elements[0];
  6277. }
  6278. return createWrapperError('DOMWrapper');
  6279. };
  6280. BaseWrapper.prototype.findComponent = function (selector) {
  6281. var currentComponent = this.getCurrentComponent();
  6282. if (!currentComponent) {
  6283. return createWrapperError('VueWrapper');
  6284. }
  6285. if (typeof selector === 'object' && 'ref' in selector) {
  6286. var result_1 = currentComponent.refs[selector.ref];
  6287. // When using ref inside v-for, then refs contains array of component instances
  6288. if (Array.isArray(result_1)) {
  6289. result_1 = result_1.length ? result_1[0] : undefined;
  6290. }
  6291. if (result_1 && !(result_1 instanceof HTMLElement)) {
  6292. return createVueWrapper(null, result_1);
  6293. }
  6294. else {
  6295. return createWrapperError('VueWrapper');
  6296. }
  6297. }
  6298. if (matches(currentComponent.vnode, selector) &&
  6299. this.element.contains(currentComponent.vnode.el)) {
  6300. return createVueWrapper(null, currentComponent.subTree.component
  6301. ? currentComponent.subTree.component.proxy
  6302. : currentComponent.proxy);
  6303. }
  6304. var result = this.findAllComponents(selector)[0];
  6305. return result !== null && result !== void 0 ? result : createWrapperError('VueWrapper');
  6306. };
  6307. BaseWrapper.prototype.findAllComponents = function (selector) {
  6308. var currentComponent = this.getCurrentComponent();
  6309. if (!currentComponent) {
  6310. return [];
  6311. }
  6312. var results = find(currentComponent.subTree, selector);
  6313. return results.map(function (c) {
  6314. return c.proxy
  6315. ? createVueWrapper(null, c.proxy)
  6316. : createDOMWrapper(c.vnode.el);
  6317. });
  6318. };
  6319. BaseWrapper.prototype.html = function (options) {
  6320. var stringNodes = this.getRootNodes().map(function (node) { return stringifyNode(node); });
  6321. if (options === null || options === void 0 ? void 0 : options.raw)
  6322. return stringNodes.join('');
  6323. return stringNodes
  6324. .map(function (node) {
  6325. return beautify.html(node, {
  6326. unformatted: ['code', 'pre', 'em', 'strong', 'span'],
  6327. indent_inner_html: true,
  6328. indent_size: 2,
  6329. inline_custom_elements: false
  6330. // TODO the cast can be removed when @types/js-beautify will be up-to-date
  6331. });
  6332. })
  6333. .join('\n');
  6334. };
  6335. BaseWrapper.prototype.classes = function (className) {
  6336. var classes = isElement(this.element)
  6337. ? Array.from(this.element.classList)
  6338. : [];
  6339. if (className)
  6340. return classes.includes(className);
  6341. return classes;
  6342. };
  6343. BaseWrapper.prototype.attributes = function (key) {
  6344. var attributeMap = {};
  6345. if (isElement(this.element)) {
  6346. var attributes = Array.from(this.element.attributes);
  6347. for (var _i = 0, attributes_1 = attributes; _i < attributes_1.length; _i++) {
  6348. var attribute = attributes_1[_i];
  6349. attributeMap[attribute.localName] = attribute.value;
  6350. }
  6351. }
  6352. return key ? attributeMap[key] : attributeMap;
  6353. };
  6354. BaseWrapper.prototype.text = function () {
  6355. return this.getRootNodes().map(textContent).join('');
  6356. };
  6357. BaseWrapper.prototype.exists = function () {
  6358. return true;
  6359. };
  6360. BaseWrapper.prototype.get = function (selector) {
  6361. var result = this.find(selector);
  6362. if (result.exists()) {
  6363. return result;
  6364. }
  6365. throw new Error("Unable to get ".concat(selector, " within: ").concat(this.html()));
  6366. };
  6367. BaseWrapper.prototype.getComponent = function (selector) {
  6368. var result = this.findComponent(selector);
  6369. if (result.exists()) {
  6370. return result;
  6371. }
  6372. var message = 'Unable to get ';
  6373. if (typeof selector === 'string') {
  6374. message += "component with selector ".concat(selector);
  6375. }
  6376. else if ('name' in selector) {
  6377. message += "component with name ".concat(selector.name);
  6378. }
  6379. else if ('ref' in selector) {
  6380. message += "component with ref ".concat(selector.ref);
  6381. }
  6382. else {
  6383. message += 'specified component';
  6384. }
  6385. message += " within: ".concat(this.html());
  6386. throw new Error(message);
  6387. };
  6388. BaseWrapper.prototype.isVisible = function () {
  6389. return isElement(this.element) && isElementVisible(this.element);
  6390. };
  6391. BaseWrapper.prototype.trigger = function (eventString, options) {
  6392. return __awaiter(this, void 0, void 0, function () {
  6393. var event_1;
  6394. return __generator(this, function (_a) {
  6395. if (options && options['target']) {
  6396. throw Error("[vue-test-utils]: you cannot set the target value of an event. See the notes section " +
  6397. "of the docs for more details\u2014" +
  6398. "https://vue-test-utils.vuejs.org/api/wrapper/trigger.html");
  6399. }
  6400. if (this.element && !this.isDisabled()) {
  6401. event_1 = createDOMEvent(eventString, options);
  6402. // see https://github.com/vuejs/test-utils/issues/1854
  6403. // fakeTimers provoke an issue as Date.now() always return the same value
  6404. // and Vue relies on it to determine if the handler should be invoked
  6405. // see https://github.com/vuejs/core/blob/5ee40532a63e0b792e0c1eccf3cf68546a4e23e9/packages/runtime-dom/src/modules/events.ts#L100-L104
  6406. // we workaround this issue by manually setting _vts to Date.now() + 1
  6407. // thus making sure the event handler is invoked
  6408. event_1._vts = Date.now() + 1;
  6409. this.element.dispatchEvent(event_1);
  6410. }
  6411. return [2 /*return*/, nextTick()];
  6412. });
  6413. });
  6414. };
  6415. return BaseWrapper;
  6416. }());
  6417. var DOMWrapper = /** @class */ (function (_super) {
  6418. __extends(DOMWrapper, _super);
  6419. function DOMWrapper(element) {
  6420. var _this = this;
  6421. if (!element) {
  6422. return createWrapperError('DOMWrapper');
  6423. }
  6424. _this = _super.call(this, element) || this;
  6425. // plugins hook
  6426. config.plugins.DOMWrapper.extend(_this);
  6427. return _this;
  6428. }
  6429. DOMWrapper.prototype.getRootNodes = function () {
  6430. return [this.wrapperElement];
  6431. };
  6432. DOMWrapper.prototype.getCurrentComponent = function () {
  6433. var _a;
  6434. var component = this.element.__vueParentComponent;
  6435. while (((_a = component === null || component === void 0 ? void 0 : component.parent) === null || _a === void 0 ? void 0 : _a.vnode.el) === this.element) {
  6436. component = component.parent;
  6437. }
  6438. return component;
  6439. };
  6440. DOMWrapper.prototype.find = function (selector) {
  6441. var result = _super.prototype.find.call(this, selector);
  6442. if (result.exists() && isRefSelector(selector)) {
  6443. return this.element.contains(result.element)
  6444. ? result
  6445. : createWrapperError('DOMWrapper');
  6446. }
  6447. return result;
  6448. };
  6449. DOMWrapper.prototype.findAll = function (selector) {
  6450. if (!(this.wrapperElement instanceof Element)) {
  6451. return [];
  6452. }
  6453. return Array.from(this.wrapperElement.querySelectorAll(selector), createDOMWrapper);
  6454. };
  6455. DOMWrapper.prototype.findAllComponents = function (selector) {
  6456. var _this = this;
  6457. var results = _super.prototype.findAllComponents.call(this, selector);
  6458. return results.filter(function (r) { return _this.element.contains(r.element); });
  6459. };
  6460. DOMWrapper.prototype.setChecked = function () {
  6461. return __awaiter(this, arguments, void 0, function (checked) {
  6462. var element, type;
  6463. if (checked === void 0) { checked = true; }
  6464. return __generator(this, function (_a) {
  6465. element = this.element;
  6466. type = this.attributes().type;
  6467. if (type === 'radio' && !checked) {
  6468. throw Error("wrapper.setChecked() cannot be called with parameter false on a '<input type=\"radio\" /> element.");
  6469. }
  6470. // we do not want to trigger an event if the user
  6471. // attempting set the same value twice
  6472. // this is because in a browser setting checked = true when it is
  6473. // already true is a no-op; no change event is triggered
  6474. if (checked === element.checked) {
  6475. return [2 /*return*/];
  6476. }
  6477. element.checked = checked;
  6478. this.trigger('input');
  6479. return [2 /*return*/, this.trigger('change')];
  6480. });
  6481. });
  6482. };
  6483. DOMWrapper.prototype.setValue = function (value) {
  6484. var element = this.element;
  6485. var tagName = element.tagName;
  6486. var type = this.attributes().type;
  6487. if (tagName === 'OPTION') {
  6488. this.setSelected();
  6489. return Promise.resolve();
  6490. }
  6491. else if (tagName === 'INPUT' && type === 'checkbox') {
  6492. return this.setChecked(value);
  6493. }
  6494. else if (tagName === 'INPUT' && type === 'radio') {
  6495. return this.setChecked(value);
  6496. }
  6497. else if (tagName === 'SELECT') {
  6498. if (Array.isArray(value)) {
  6499. var selectElement = element;
  6500. for (var i = 0; i < selectElement.options.length; i++) {
  6501. var option = selectElement.options[i];
  6502. option.selected = value.includes(option.value);
  6503. }
  6504. }
  6505. else {
  6506. element.value = value;
  6507. }
  6508. this.trigger('input');
  6509. return this.trigger('change');
  6510. }
  6511. else if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
  6512. element.value = value;
  6513. this.trigger('input');
  6514. // trigger `change` for `v-model.lazy`
  6515. return this.trigger('change');
  6516. }
  6517. else {
  6518. throw Error("wrapper.setValue() cannot be called on ".concat(tagName));
  6519. }
  6520. };
  6521. DOMWrapper.prototype.setSelected = function () {
  6522. var element = this.element;
  6523. if (element.selected) {
  6524. return;
  6525. }
  6526. // todo - review all non-null assertion operators in project
  6527. // search globally for `!.` and with regex `!$`
  6528. element.selected = true;
  6529. var parentElement = element.parentElement;
  6530. if (parentElement.tagName === 'OPTGROUP') {
  6531. parentElement = parentElement.parentElement;
  6532. }
  6533. var parentWrapper = new DOMWrapper(parentElement);
  6534. parentWrapper.trigger('input');
  6535. return parentWrapper.trigger('change');
  6536. };
  6537. return DOMWrapper;
  6538. }(BaseWrapper));
  6539. registerFactory(WrapperType.DOMWrapper, function (element) { return new DOMWrapper(element); });
  6540. function getRootNodes(vnode) {
  6541. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6542. return [vnode.el];
  6543. }
  6544. else if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6545. var subTree = vnode.component.subTree;
  6546. return getRootNodes(subTree);
  6547. }
  6548. else if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6549. return getRootNodes(vnode.suspense.activeBranch);
  6550. }
  6551. else if (vnode.shapeFlag &
  6552. (8 /* ShapeFlags.TEXT_CHILDREN */ | 64 /* ShapeFlags.TELEPORT */)) {
  6553. // static node optimization, subTree.children will be static string and will not help us
  6554. var result = [vnode.el];
  6555. if (vnode.anchor) {
  6556. var currentNode = result[0].nextSibling;
  6557. while (currentNode && currentNode.previousSibling !== vnode.anchor) {
  6558. result.push(currentNode);
  6559. currentNode = currentNode.nextSibling;
  6560. }
  6561. }
  6562. return result;
  6563. }
  6564. else if (vnode.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6565. var children = vnode.children.flat();
  6566. return children
  6567. .flatMap(function (vnode) { return getRootNodes(vnode); })
  6568. .filter(isNotNullOrUndefined);
  6569. }
  6570. // Missing cases which do not need special handling:
  6571. // ShapeFlags.SLOTS_CHILDREN comes with ShapeFlags.ELEMENT
  6572. // Will hit this default when ShapeFlags is 0
  6573. // This is the case for example for unresolved async component without loader
  6574. return [];
  6575. }
  6576. var events = {};
  6577. function emitted(vm, eventName) {
  6578. var cid = vm.$.uid;
  6579. var vmEvents = events[cid] || {};
  6580. if (eventName) {
  6581. return vmEvents ? vmEvents[eventName] : undefined;
  6582. }
  6583. return vmEvents;
  6584. }
  6585. var attachEmitListener = function () {
  6586. var target = getGlobalThis$1();
  6587. // override emit to capture events when devtools is defined
  6588. if (target.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
  6589. var _emit_1 = target.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit;
  6590. target.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit = function (eventType) {
  6591. var payload = [];
  6592. for (var _i = 1; _i < arguments.length; _i++) {
  6593. payload[_i - 1] = arguments[_i];
  6594. }
  6595. _emit_1.call.apply(_emit_1, __spreadArray([target.__VUE_DEVTOOLS_GLOBAL_HOOK__, eventType], payload, false));
  6596. captureDevtoolsVueComponentEmitEvent(eventType, payload);
  6597. };
  6598. }
  6599. else {
  6600. // use devtools to capture this "emit"
  6601. setDevtoolsHook(createDevTools(), {});
  6602. }
  6603. };
  6604. function captureDevtoolsVueComponentEmitEvent(eventType, payload) {
  6605. if (eventType === "component:emit" /* DevtoolsHooks.COMPONENT_EMIT */) {
  6606. payload[0]; var componentVM = payload[1], event_1 = payload[2], eventArgs = payload[3];
  6607. recordEvent(componentVM, event_1, eventArgs);
  6608. }
  6609. }
  6610. // devtools hook only catches Vue component custom events
  6611. function createDevTools() {
  6612. return {
  6613. emit: function (eventType) {
  6614. var payload = [];
  6615. for (var _i = 1; _i < arguments.length; _i++) {
  6616. payload[_i - 1] = arguments[_i];
  6617. }
  6618. captureDevtoolsVueComponentEmitEvent(eventType, payload);
  6619. }
  6620. };
  6621. }
  6622. var recordEvent = function (vm, event, args) {
  6623. // Functional component wrapper creates a parent component
  6624. var wrapperVm = vm;
  6625. while (typeof (wrapperVm === null || wrapperVm === void 0 ? void 0 : wrapperVm.type) === 'function')
  6626. wrapperVm = wrapperVm.parent;
  6627. var cid = wrapperVm.uid;
  6628. if (!(cid in events)) {
  6629. events[cid] = {};
  6630. }
  6631. if (!(event in events[cid])) {
  6632. events[cid][event] = [];
  6633. }
  6634. // Record the event message sent by the emit
  6635. events[cid][event].push(args);
  6636. };
  6637. var removeEventHistory = function (vm) {
  6638. var cid = vm.$.uid;
  6639. delete events[cid];
  6640. };
  6641. /**
  6642. * Creates a proxy around the VM instance.
  6643. * This proxy returns the value from the setupState if there is one, or the one from the VM if not.
  6644. * See https://github.com/vuejs/core/issues/7103
  6645. */
  6646. function createVMProxy(vm, setupState) {
  6647. return new Proxy(vm, {
  6648. get: function (vm, key, receiver) {
  6649. if (vm.$.exposed && vm.$.exposeProxy && key in vm.$.exposeProxy) {
  6650. // first if the key is exposed
  6651. return Reflect.get(vm.$.exposeProxy, key, receiver);
  6652. }
  6653. else if (key in setupState) {
  6654. // second if the key is acccessible from the setupState
  6655. return Reflect.get(setupState, key, receiver);
  6656. }
  6657. else {
  6658. // vm.$.ctx is the internal context of the vm
  6659. // with all variables, methods and props
  6660. return vm.$.ctx[key];
  6661. }
  6662. },
  6663. set: function (vm, key, value, receiver) {
  6664. if (key in setupState) {
  6665. return Reflect.set(setupState, key, value, receiver);
  6666. }
  6667. else {
  6668. return Reflect.set(vm, key, value, receiver);
  6669. }
  6670. },
  6671. has: function (vm, property) {
  6672. return Reflect.has(setupState, property) || Reflect.has(vm, property);
  6673. },
  6674. defineProperty: function (vm, key, attributes) {
  6675. if (key in setupState) {
  6676. return Reflect.defineProperty(setupState, key, attributes);
  6677. }
  6678. else {
  6679. return Reflect.defineProperty(vm, key, attributes);
  6680. }
  6681. },
  6682. getOwnPropertyDescriptor: function (vm, property) {
  6683. if (property in setupState) {
  6684. return Reflect.getOwnPropertyDescriptor(setupState, property);
  6685. }
  6686. else {
  6687. return Reflect.getOwnPropertyDescriptor(vm, property);
  6688. }
  6689. },
  6690. deleteProperty: function (vm, property) {
  6691. if (property in setupState) {
  6692. return Reflect.deleteProperty(setupState, property);
  6693. }
  6694. else {
  6695. return Reflect.deleteProperty(vm, property);
  6696. }
  6697. }
  6698. });
  6699. }
  6700. var VueWrapper = /** @class */ (function (_super) {
  6701. __extends(VueWrapper, _super);
  6702. function VueWrapper(app, vm, setProps) {
  6703. var _this = _super.call(this, vm === null || vm === void 0 ? void 0 : vm.$el) || this;
  6704. _this.cleanUpCallbacks = [];
  6705. _this.__app = app;
  6706. // root is null on functional components
  6707. _this.rootVM = vm === null || vm === void 0 ? void 0 : vm.$root;
  6708. // `vm.$.setupState` is what the template has access to
  6709. // so even if the component is closed (as they are by default for `script setup`)
  6710. // a test will still be able to do something like
  6711. // `expect(wrapper.vm.count).toBe(1)`
  6712. // if we return it as `vm`
  6713. // This does not work for functional components though (as they have no vm)
  6714. // or for components with a setup that returns a render function (as they have an empty proxy)
  6715. // in both cases, we return `vm` directly instead
  6716. if (hasSetupState(vm)) {
  6717. _this.componentVM = createVMProxy(vm, vm.$.setupState);
  6718. }
  6719. else {
  6720. _this.componentVM = vm;
  6721. }
  6722. _this.__setProps = setProps;
  6723. _this.attachNativeEventListener();
  6724. config.plugins.VueWrapper.extend(_this);
  6725. return _this;
  6726. }
  6727. Object.defineProperty(VueWrapper.prototype, "hasMultipleRoots", {
  6728. get: function () {
  6729. // Recursive check subtree for nested root elements
  6730. // <template>
  6731. // <WithMultipleRoots />
  6732. // </template>
  6733. var checkTree = function (subTree) {
  6734. var _a;
  6735. // if the subtree is an array of children, we have multiple root nodes
  6736. if (subTree.shapeFlag === 16 /* ShapeFlags.ARRAY_CHILDREN */)
  6737. return true;
  6738. if (subTree.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ ||
  6739. subTree.shapeFlag & 2 /* ShapeFlags.FUNCTIONAL_COMPONENT */) {
  6740. // We are rendering other component, check it's tree instead
  6741. if ((_a = subTree.component) === null || _a === void 0 ? void 0 : _a.subTree) {
  6742. return checkTree(subTree.component.subTree);
  6743. }
  6744. // Component has multiple children
  6745. if (subTree.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6746. return true;
  6747. }
  6748. }
  6749. return false;
  6750. };
  6751. return checkTree(this.vm.$.subTree);
  6752. },
  6753. enumerable: false,
  6754. configurable: true
  6755. });
  6756. VueWrapper.prototype.getRootNodes = function () {
  6757. return getRootNodes(this.vm.$.vnode);
  6758. };
  6759. Object.defineProperty(VueWrapper.prototype, "parentElement", {
  6760. get: function () {
  6761. return this.vm.$el.parentElement;
  6762. },
  6763. enumerable: false,
  6764. configurable: true
  6765. });
  6766. VueWrapper.prototype.getCurrentComponent = function () {
  6767. return this.vm.$;
  6768. };
  6769. VueWrapper.prototype.exists = function () {
  6770. return !this.getCurrentComponent().isUnmounted;
  6771. };
  6772. VueWrapper.prototype.findAll = function (selector) {
  6773. return this.findAllDOMElements(selector).map(createDOMWrapper);
  6774. };
  6775. VueWrapper.prototype.attachNativeEventListener = function () {
  6776. var vm = this.vm;
  6777. if (!vm)
  6778. return;
  6779. var emits = vm.$options.emits
  6780. ? // if emits is declared as an array
  6781. Array.isArray(vm.$options.emits)
  6782. ? // use it
  6783. vm.$options.emits
  6784. : // otherwise it's declared as an object
  6785. // and we only need the keys
  6786. Object.keys(vm.$options.emits)
  6787. : [];
  6788. var elementRoots = this.getRootNodes().filter(function (node) { return node instanceof Element; });
  6789. if (elementRoots.length !== 1) {
  6790. return;
  6791. }
  6792. var element = elementRoots[0];
  6793. var _loop_1 = function (eventName) {
  6794. // if a component includes events in 'emits' with the same name as native
  6795. // events, the native events with that name should be ignored
  6796. // @see https://github.com/vuejs/rfcs/blob/master/active-rfcs/0030-emits-option.md#fallthrough-control
  6797. if (emits.includes(eventName))
  6798. return "continue";
  6799. var eventListener = function () {
  6800. var args = [];
  6801. for (var _i = 0; _i < arguments.length; _i++) {
  6802. args[_i] = arguments[_i];
  6803. }
  6804. recordEvent(vm.$, eventName, args);
  6805. };
  6806. element.addEventListener(eventName, eventListener);
  6807. this_1.cleanUpCallbacks.push(function () {
  6808. element.removeEventListener(eventName, eventListener);
  6809. });
  6810. };
  6811. var this_1 = this;
  6812. for (var _i = 0, _a = Object.keys(domEvents); _i < _a.length; _i++) {
  6813. var eventName = _a[_i];
  6814. _loop_1(eventName);
  6815. }
  6816. };
  6817. Object.defineProperty(VueWrapper.prototype, "element", {
  6818. get: function () {
  6819. // if the component has multiple root elements, we use the parent's element
  6820. return this.hasMultipleRoots ? this.parentElement : this.vm.$el;
  6821. },
  6822. enumerable: false,
  6823. configurable: true
  6824. });
  6825. Object.defineProperty(VueWrapper.prototype, "vm", {
  6826. get: function () {
  6827. return this.componentVM;
  6828. },
  6829. enumerable: false,
  6830. configurable: true
  6831. });
  6832. VueWrapper.prototype.props = function (selector) {
  6833. var props = this.componentVM.$props;
  6834. return selector ? props[selector] : props;
  6835. };
  6836. VueWrapper.prototype.emitted = function (eventName) {
  6837. return emitted(this.vm, eventName);
  6838. };
  6839. VueWrapper.prototype.isVisible = function () {
  6840. var domWrapper = createDOMWrapper(this.element);
  6841. return domWrapper.isVisible();
  6842. };
  6843. VueWrapper.prototype.setData = function (data) {
  6844. mergeDeep(this.componentVM.$data, data);
  6845. return nextTick();
  6846. };
  6847. VueWrapper.prototype.setProps = function (props) {
  6848. // if this VM's parent is not the root or if setProps does not exist, error out
  6849. if (this.vm.$parent !== this.rootVM || !this.__setProps) {
  6850. throw Error('You can only use setProps on your mounted component');
  6851. }
  6852. this.__setProps(props);
  6853. return nextTick();
  6854. };
  6855. VueWrapper.prototype.setValue = function (value, prop) {
  6856. var propEvent = prop || 'modelValue';
  6857. this.vm.$emit("update:".concat(propEvent), value);
  6858. return this.vm.$nextTick();
  6859. };
  6860. VueWrapper.prototype.unmount = function () {
  6861. // preventing dispose of child component
  6862. if (!this.__app) {
  6863. throw new Error("wrapper.unmount() can only be called by the root wrapper");
  6864. }
  6865. // Clear emitted events cache for this component instance
  6866. removeEventHistory(this.vm);
  6867. this.cleanUpCallbacks.forEach(function (cb) { return cb(); });
  6868. this.cleanUpCallbacks = [];
  6869. this.__app.unmount();
  6870. };
  6871. return VueWrapper;
  6872. }(BaseWrapper));
  6873. registerFactory(WrapperType.VueWrapper, function (app, vm, setProps) { return new VueWrapper(app, vm, setProps); });
  6874. /**
  6875. * @vue/shared v3.4.21
  6876. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  6877. * @license MIT
  6878. **/
  6879. function makeMap(str, expectsLowerCase) {
  6880. const set = new Set(str.split(","));
  6881. return expectsLowerCase ? (val) => set.has(val.toLowerCase()) : (val) => set.has(val);
  6882. }
  6883. const EMPTY_OBJ = Object.freeze({}) ;
  6884. const NOOP = () => {
  6885. };
  6886. const NO = () => false;
  6887. const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && // uppercase letter
  6888. (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
  6889. const extend = Object.assign;
  6890. const isArray = Array.isArray;
  6891. const isFunction = (val) => typeof val === "function";
  6892. const isString = (val) => typeof val === "string";
  6893. const isSymbol = (val) => typeof val === "symbol";
  6894. const isObject = (val) => val !== null && typeof val === "object";
  6895. const isPromise = (val) => {
  6896. return (isObject(val) || isFunction(val)) && isFunction(val.then) && isFunction(val.catch);
  6897. };
  6898. const isReservedProp = /* @__PURE__ */ makeMap(
  6899. // the leading comma is intentional so empty string "" is also included
  6900. ",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"
  6901. );
  6902. const isBuiltInDirective = /* @__PURE__ */ makeMap(
  6903. "bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"
  6904. );
  6905. const cacheStringFunction = (fn) => {
  6906. const cache = /* @__PURE__ */ Object.create(null);
  6907. return (str) => {
  6908. const hit = cache[str];
  6909. return hit || (cache[str] = fn(str));
  6910. };
  6911. };
  6912. const camelizeRE = /-(\w)/g;
  6913. const camelize = cacheStringFunction((str) => {
  6914. return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
  6915. });
  6916. const hyphenateRE = /\B([A-Z])/g;
  6917. const hyphenate = cacheStringFunction(
  6918. (str) => str.replace(hyphenateRE, "-$1").toLowerCase()
  6919. );
  6920. const capitalize = cacheStringFunction((str) => {
  6921. return str.charAt(0).toUpperCase() + str.slice(1);
  6922. });
  6923. const toHandlerKey = cacheStringFunction((str) => {
  6924. const s = str ? `on${capitalize(str)}` : ``;
  6925. return s;
  6926. });
  6927. let _globalThis;
  6928. const getGlobalThis = () => {
  6929. return _globalThis || (_globalThis = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {});
  6930. };
  6931. const PatchFlagNames = {
  6932. [1]: `TEXT`,
  6933. [2]: `CLASS`,
  6934. [4]: `STYLE`,
  6935. [8]: `PROPS`,
  6936. [16]: `FULL_PROPS`,
  6937. [32]: `NEED_HYDRATION`,
  6938. [64]: `STABLE_FRAGMENT`,
  6939. [128]: `KEYED_FRAGMENT`,
  6940. [256]: `UNKEYED_FRAGMENT`,
  6941. [512]: `NEED_PATCH`,
  6942. [1024]: `DYNAMIC_SLOTS`,
  6943. [2048]: `DEV_ROOT_FRAGMENT`,
  6944. [-1]: `HOISTED`,
  6945. [-2]: `BAIL`
  6946. };
  6947. const slotFlagsText = {
  6948. [1]: "STABLE",
  6949. [2]: "DYNAMIC",
  6950. [3]: "FORWARDED"
  6951. };
  6952. function normalizeStyle(value) {
  6953. if (isArray(value)) {
  6954. const res = {};
  6955. for (let i = 0; i < value.length; i++) {
  6956. const item = value[i];
  6957. const normalized = isString(item) ? parseStringStyle(item) : normalizeStyle(item);
  6958. if (normalized) {
  6959. for (const key in normalized) {
  6960. res[key] = normalized[key];
  6961. }
  6962. }
  6963. }
  6964. return res;
  6965. } else if (isString(value) || isObject(value)) {
  6966. return value;
  6967. }
  6968. }
  6969. const listDelimiterRE = /;(?![^(]*\))/g;
  6970. const propertyDelimiterRE = /:([^]+)/;
  6971. const styleCommentRE = /\/\*[^]*?\*\//g;
  6972. function parseStringStyle(cssText) {
  6973. const ret = {};
  6974. cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
  6975. if (item) {
  6976. const tmp = item.split(propertyDelimiterRE);
  6977. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  6978. }
  6979. });
  6980. return ret;
  6981. }
  6982. function stringifyStyle(styles) {
  6983. let ret = "";
  6984. if (!styles || isString(styles)) {
  6985. return ret;
  6986. }
  6987. for (const key in styles) {
  6988. const value = styles[key];
  6989. const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
  6990. if (isString(value) || typeof value === "number") {
  6991. ret += `${normalizedKey}:${value};`;
  6992. }
  6993. }
  6994. return ret;
  6995. }
  6996. function normalizeClass(value) {
  6997. let res = "";
  6998. if (isString(value)) {
  6999. res = value;
  7000. } else if (isArray(value)) {
  7001. for (let i = 0; i < value.length; i++) {
  7002. const normalized = normalizeClass(value[i]);
  7003. if (normalized) {
  7004. res += normalized + " ";
  7005. }
  7006. }
  7007. } else if (isObject(value)) {
  7008. for (const name in value) {
  7009. if (value[name]) {
  7010. res += name + " ";
  7011. }
  7012. }
  7013. }
  7014. return res.trim();
  7015. }
  7016. const HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot";
  7017. const SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
  7018. const MATH_TAGS = "annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics";
  7019. const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
  7020. const isHTMLTag = /* @__PURE__ */ makeMap(HTML_TAGS);
  7021. const isSVGTag = /* @__PURE__ */ makeMap(SVG_TAGS);
  7022. const isMathMLTag = /* @__PURE__ */ makeMap(MATH_TAGS);
  7023. const isVoidTag = /* @__PURE__ */ makeMap(VOID_TAGS);
  7024. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  7025. const isBooleanAttr = /* @__PURE__ */ makeMap(
  7026. specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`
  7027. );
  7028. function includeBooleanAttr(value) {
  7029. return !!value || value === "";
  7030. }
  7031. const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/;
  7032. const attrValidationCache = {};
  7033. function isSSRSafeAttrName(name) {
  7034. if (attrValidationCache.hasOwnProperty(name)) {
  7035. return attrValidationCache[name];
  7036. }
  7037. const isUnsafe = unsafeAttrCharRE.test(name);
  7038. if (isUnsafe) {
  7039. console.error(`unsafe attribute name: ${name}`);
  7040. }
  7041. return attrValidationCache[name] = !isUnsafe;
  7042. }
  7043. const propsToAttrMap = {
  7044. acceptCharset: "accept-charset",
  7045. className: "class",
  7046. htmlFor: "for",
  7047. httpEquiv: "http-equiv"
  7048. };
  7049. function isRenderableAttrValue(value) {
  7050. if (value == null) {
  7051. return false;
  7052. }
  7053. const type = typeof value;
  7054. return type === "string" || type === "number" || type === "boolean";
  7055. }
  7056. const escapeRE = /["'&<>]/;
  7057. function escapeHtml(string) {
  7058. const str = "" + string;
  7059. const match = escapeRE.exec(str);
  7060. if (!match) {
  7061. return str;
  7062. }
  7063. let html = "";
  7064. let escaped;
  7065. let index;
  7066. let lastIndex = 0;
  7067. for (index = match.index; index < str.length; index++) {
  7068. switch (str.charCodeAt(index)) {
  7069. case 34:
  7070. escaped = "&quot;";
  7071. break;
  7072. case 38:
  7073. escaped = "&amp;";
  7074. break;
  7075. case 39:
  7076. escaped = "&#39;";
  7077. break;
  7078. case 60:
  7079. escaped = "&lt;";
  7080. break;
  7081. case 62:
  7082. escaped = "&gt;";
  7083. break;
  7084. default:
  7085. continue;
  7086. }
  7087. if (lastIndex !== index) {
  7088. html += str.slice(lastIndex, index);
  7089. }
  7090. lastIndex = index + 1;
  7091. html += escaped;
  7092. }
  7093. return lastIndex !== index ? html + str.slice(lastIndex, index) : html;
  7094. }
  7095. const commentStripRE = /^-?>|<!--|-->|--!>|<!-$/g;
  7096. function escapeHtmlComment(src) {
  7097. return src.replace(commentStripRE, "");
  7098. }
  7099. /**
  7100. * @vue/compiler-core v3.4.21
  7101. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  7102. * @license MIT
  7103. **/
  7104. const FRAGMENT = Symbol(`Fragment` );
  7105. const TELEPORT = Symbol(`Teleport` );
  7106. const SUSPENSE = Symbol(`Suspense` );
  7107. const KEEP_ALIVE = Symbol(`KeepAlive` );
  7108. const BASE_TRANSITION = Symbol(`BaseTransition` );
  7109. const OPEN_BLOCK = Symbol(`openBlock` );
  7110. const CREATE_BLOCK = Symbol(`createBlock` );
  7111. const CREATE_ELEMENT_BLOCK = Symbol(`createElementBlock` );
  7112. const CREATE_VNODE = Symbol(`createVNode` );
  7113. const CREATE_ELEMENT_VNODE = Symbol(`createElementVNode` );
  7114. const CREATE_COMMENT = Symbol(`createCommentVNode` );
  7115. const CREATE_TEXT = Symbol(`createTextVNode` );
  7116. const CREATE_STATIC = Symbol(`createStaticVNode` );
  7117. const RESOLVE_COMPONENT = Symbol(`resolveComponent` );
  7118. const RESOLVE_DYNAMIC_COMPONENT = Symbol(
  7119. `resolveDynamicComponent`
  7120. );
  7121. const RESOLVE_DIRECTIVE = Symbol(`resolveDirective` );
  7122. const RESOLVE_FILTER = Symbol(`resolveFilter` );
  7123. const WITH_DIRECTIVES = Symbol(`withDirectives` );
  7124. const RENDER_LIST = Symbol(`renderList` );
  7125. const RENDER_SLOT = Symbol(`renderSlot` );
  7126. const CREATE_SLOTS = Symbol(`createSlots` );
  7127. const TO_DISPLAY_STRING = Symbol(`toDisplayString` );
  7128. const MERGE_PROPS = Symbol(`mergeProps` );
  7129. const NORMALIZE_CLASS = Symbol(`normalizeClass` );
  7130. const NORMALIZE_STYLE = Symbol(`normalizeStyle` );
  7131. const NORMALIZE_PROPS = Symbol(`normalizeProps` );
  7132. const GUARD_REACTIVE_PROPS = Symbol(`guardReactiveProps` );
  7133. const TO_HANDLERS = Symbol(`toHandlers` );
  7134. const CAMELIZE = Symbol(`camelize` );
  7135. const CAPITALIZE = Symbol(`capitalize` );
  7136. const TO_HANDLER_KEY = Symbol(`toHandlerKey` );
  7137. const SET_BLOCK_TRACKING = Symbol(`setBlockTracking` );
  7138. const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
  7139. const POP_SCOPE_ID = Symbol(`popScopeId` );
  7140. const WITH_CTX = Symbol(`withCtx` );
  7141. const UNREF = Symbol(`unref` );
  7142. const IS_REF = Symbol(`isRef` );
  7143. const WITH_MEMO = Symbol(`withMemo` );
  7144. const IS_MEMO_SAME = Symbol(`isMemoSame` );
  7145. const helperNameMap = {
  7146. [FRAGMENT]: `Fragment`,
  7147. [TELEPORT]: `Teleport`,
  7148. [SUSPENSE]: `Suspense`,
  7149. [KEEP_ALIVE]: `KeepAlive`,
  7150. [BASE_TRANSITION]: `BaseTransition`,
  7151. [OPEN_BLOCK]: `openBlock`,
  7152. [CREATE_BLOCK]: `createBlock`,
  7153. [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
  7154. [CREATE_VNODE]: `createVNode`,
  7155. [CREATE_ELEMENT_VNODE]: `createElementVNode`,
  7156. [CREATE_COMMENT]: `createCommentVNode`,
  7157. [CREATE_TEXT]: `createTextVNode`,
  7158. [CREATE_STATIC]: `createStaticVNode`,
  7159. [RESOLVE_COMPONENT]: `resolveComponent`,
  7160. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  7161. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  7162. [RESOLVE_FILTER]: `resolveFilter`,
  7163. [WITH_DIRECTIVES]: `withDirectives`,
  7164. [RENDER_LIST]: `renderList`,
  7165. [RENDER_SLOT]: `renderSlot`,
  7166. [CREATE_SLOTS]: `createSlots`,
  7167. [TO_DISPLAY_STRING]: `toDisplayString`,
  7168. [MERGE_PROPS]: `mergeProps`,
  7169. [NORMALIZE_CLASS]: `normalizeClass`,
  7170. [NORMALIZE_STYLE]: `normalizeStyle`,
  7171. [NORMALIZE_PROPS]: `normalizeProps`,
  7172. [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
  7173. [TO_HANDLERS]: `toHandlers`,
  7174. [CAMELIZE]: `camelize`,
  7175. [CAPITALIZE]: `capitalize`,
  7176. [TO_HANDLER_KEY]: `toHandlerKey`,
  7177. [SET_BLOCK_TRACKING]: `setBlockTracking`,
  7178. [PUSH_SCOPE_ID]: `pushScopeId`,
  7179. [POP_SCOPE_ID]: `popScopeId`,
  7180. [WITH_CTX]: `withCtx`,
  7181. [UNREF]: `unref`,
  7182. [IS_REF]: `isRef`,
  7183. [WITH_MEMO]: `withMemo`,
  7184. [IS_MEMO_SAME]: `isMemoSame`
  7185. };
  7186. function registerRuntimeHelpers(helpers) {
  7187. Object.getOwnPropertySymbols(helpers).forEach((s) => {
  7188. helperNameMap[s] = helpers[s];
  7189. });
  7190. }
  7191. const locStub = {
  7192. start: { line: 1, column: 1, offset: 0 },
  7193. end: { line: 1, column: 1, offset: 0 },
  7194. source: ""
  7195. };
  7196. function createRoot(children, source = "") {
  7197. return {
  7198. type: 0,
  7199. source,
  7200. children,
  7201. helpers: /* @__PURE__ */ new Set(),
  7202. components: [],
  7203. directives: [],
  7204. hoists: [],
  7205. imports: [],
  7206. cached: 0,
  7207. temps: 0,
  7208. codegenNode: void 0,
  7209. loc: locStub
  7210. };
  7211. }
  7212. function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
  7213. if (context) {
  7214. if (isBlock) {
  7215. context.helper(OPEN_BLOCK);
  7216. context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
  7217. } else {
  7218. context.helper(getVNodeHelper(context.inSSR, isComponent));
  7219. }
  7220. if (directives) {
  7221. context.helper(WITH_DIRECTIVES);
  7222. }
  7223. }
  7224. return {
  7225. type: 13,
  7226. tag,
  7227. props,
  7228. children,
  7229. patchFlag,
  7230. dynamicProps,
  7231. directives,
  7232. isBlock,
  7233. disableTracking,
  7234. isComponent,
  7235. loc
  7236. };
  7237. }
  7238. function createArrayExpression(elements, loc = locStub) {
  7239. return {
  7240. type: 17,
  7241. loc,
  7242. elements
  7243. };
  7244. }
  7245. function createObjectExpression(properties, loc = locStub) {
  7246. return {
  7247. type: 15,
  7248. loc,
  7249. properties
  7250. };
  7251. }
  7252. function createObjectProperty(key, value) {
  7253. return {
  7254. type: 16,
  7255. loc: locStub,
  7256. key: isString(key) ? createSimpleExpression(key, true) : key,
  7257. value
  7258. };
  7259. }
  7260. function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
  7261. return {
  7262. type: 4,
  7263. loc,
  7264. content,
  7265. isStatic,
  7266. constType: isStatic ? 3 : constType
  7267. };
  7268. }
  7269. function createCompoundExpression(children, loc = locStub) {
  7270. return {
  7271. type: 8,
  7272. loc,
  7273. children
  7274. };
  7275. }
  7276. function createCallExpression(callee, args = [], loc = locStub) {
  7277. return {
  7278. type: 14,
  7279. loc,
  7280. callee,
  7281. arguments: args
  7282. };
  7283. }
  7284. function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
  7285. return {
  7286. type: 18,
  7287. params,
  7288. returns,
  7289. newline,
  7290. isSlot,
  7291. loc
  7292. };
  7293. }
  7294. function createConditionalExpression(test, consequent, alternate, newline = true) {
  7295. return {
  7296. type: 19,
  7297. test,
  7298. consequent,
  7299. alternate,
  7300. newline,
  7301. loc: locStub
  7302. };
  7303. }
  7304. function createCacheExpression(index, value, isVNode = false) {
  7305. return {
  7306. type: 20,
  7307. index,
  7308. value,
  7309. isVNode,
  7310. loc: locStub
  7311. };
  7312. }
  7313. function createBlockStatement(body) {
  7314. return {
  7315. type: 21,
  7316. body,
  7317. loc: locStub
  7318. };
  7319. }
  7320. function getVNodeHelper(ssr, isComponent) {
  7321. return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
  7322. }
  7323. function getVNodeBlockHelper(ssr, isComponent) {
  7324. return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
  7325. }
  7326. function convertToBlock(node, { helper, removeHelper, inSSR }) {
  7327. if (!node.isBlock) {
  7328. node.isBlock = true;
  7329. removeHelper(getVNodeHelper(inSSR, node.isComponent));
  7330. helper(OPEN_BLOCK);
  7331. helper(getVNodeBlockHelper(inSSR, node.isComponent));
  7332. }
  7333. }
  7334. const defaultDelimitersOpen = new Uint8Array([123, 123]);
  7335. const defaultDelimitersClose = new Uint8Array([125, 125]);
  7336. function isTagStartChar(c) {
  7337. return c >= 97 && c <= 122 || c >= 65 && c <= 90;
  7338. }
  7339. function isWhitespace(c) {
  7340. return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
  7341. }
  7342. function isEndOfTagSection(c) {
  7343. return c === 47 || c === 62 || isWhitespace(c);
  7344. }
  7345. function toCharCodes(str) {
  7346. const ret = new Uint8Array(str.length);
  7347. for (let i = 0; i < str.length; i++) {
  7348. ret[i] = str.charCodeAt(i);
  7349. }
  7350. return ret;
  7351. }
  7352. const Sequences = {
  7353. Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
  7354. // CDATA[
  7355. CdataEnd: new Uint8Array([93, 93, 62]),
  7356. // ]]>
  7357. CommentEnd: new Uint8Array([45, 45, 62]),
  7358. // `-->`
  7359. ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
  7360. // `<\/script`
  7361. StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
  7362. // `</style`
  7363. TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
  7364. // `</title`
  7365. TextareaEnd: new Uint8Array([
  7366. 60,
  7367. 47,
  7368. 116,
  7369. 101,
  7370. 120,
  7371. 116,
  7372. 97,
  7373. 114,
  7374. 101,
  7375. 97
  7376. ])
  7377. // `</textarea
  7378. };
  7379. class Tokenizer {
  7380. constructor(stack, cbs) {
  7381. this.stack = stack;
  7382. this.cbs = cbs;
  7383. /** The current state the tokenizer is in. */
  7384. this.state = 1;
  7385. /** The read buffer. */
  7386. this.buffer = "";
  7387. /** The beginning of the section that is currently being read. */
  7388. this.sectionStart = 0;
  7389. /** The index within the buffer that we are currently looking at. */
  7390. this.index = 0;
  7391. /** The start of the last entity. */
  7392. this.entityStart = 0;
  7393. /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
  7394. this.baseState = 1;
  7395. /** For special parsing behavior inside of script and style tags. */
  7396. this.inRCDATA = false;
  7397. /** For disabling RCDATA tags handling */
  7398. this.inXML = false;
  7399. /** For disabling interpolation parsing in v-pre */
  7400. this.inVPre = false;
  7401. /** Record newline positions for fast line / column calculation */
  7402. this.newlines = [];
  7403. this.mode = 0;
  7404. this.delimiterOpen = defaultDelimitersOpen;
  7405. this.delimiterClose = defaultDelimitersClose;
  7406. this.delimiterIndex = -1;
  7407. this.currentSequence = void 0;
  7408. this.sequenceIndex = 0;
  7409. }
  7410. get inSFCRoot() {
  7411. return this.mode === 2 && this.stack.length === 0;
  7412. }
  7413. reset() {
  7414. this.state = 1;
  7415. this.mode = 0;
  7416. this.buffer = "";
  7417. this.sectionStart = 0;
  7418. this.index = 0;
  7419. this.baseState = 1;
  7420. this.inRCDATA = false;
  7421. this.currentSequence = void 0;
  7422. this.newlines.length = 0;
  7423. this.delimiterOpen = defaultDelimitersOpen;
  7424. this.delimiterClose = defaultDelimitersClose;
  7425. }
  7426. /**
  7427. * Generate Position object with line / column information using recorded
  7428. * newline positions. We know the index is always going to be an already
  7429. * processed index, so all the newlines up to this index should have been
  7430. * recorded.
  7431. */
  7432. getPos(index) {
  7433. let line = 1;
  7434. let column = index + 1;
  7435. for (let i = this.newlines.length - 1; i >= 0; i--) {
  7436. const newlineIndex = this.newlines[i];
  7437. if (index > newlineIndex) {
  7438. line = i + 2;
  7439. column = index - newlineIndex;
  7440. break;
  7441. }
  7442. }
  7443. return {
  7444. column,
  7445. line,
  7446. offset: index
  7447. };
  7448. }
  7449. peek() {
  7450. return this.buffer.charCodeAt(this.index + 1);
  7451. }
  7452. stateText(c) {
  7453. if (c === 60) {
  7454. if (this.index > this.sectionStart) {
  7455. this.cbs.ontext(this.sectionStart, this.index);
  7456. }
  7457. this.state = 5;
  7458. this.sectionStart = this.index;
  7459. } else if (!this.inVPre && c === this.delimiterOpen[0]) {
  7460. this.state = 2;
  7461. this.delimiterIndex = 0;
  7462. this.stateInterpolationOpen(c);
  7463. }
  7464. }
  7465. stateInterpolationOpen(c) {
  7466. if (c === this.delimiterOpen[this.delimiterIndex]) {
  7467. if (this.delimiterIndex === this.delimiterOpen.length - 1) {
  7468. const start = this.index + 1 - this.delimiterOpen.length;
  7469. if (start > this.sectionStart) {
  7470. this.cbs.ontext(this.sectionStart, start);
  7471. }
  7472. this.state = 3;
  7473. this.sectionStart = start;
  7474. } else {
  7475. this.delimiterIndex++;
  7476. }
  7477. } else if (this.inRCDATA) {
  7478. this.state = 32;
  7479. this.stateInRCDATA(c);
  7480. } else {
  7481. this.state = 1;
  7482. this.stateText(c);
  7483. }
  7484. }
  7485. stateInterpolation(c) {
  7486. if (c === this.delimiterClose[0]) {
  7487. this.state = 4;
  7488. this.delimiterIndex = 0;
  7489. this.stateInterpolationClose(c);
  7490. }
  7491. }
  7492. stateInterpolationClose(c) {
  7493. if (c === this.delimiterClose[this.delimiterIndex]) {
  7494. if (this.delimiterIndex === this.delimiterClose.length - 1) {
  7495. this.cbs.oninterpolation(this.sectionStart, this.index + 1);
  7496. if (this.inRCDATA) {
  7497. this.state = 32;
  7498. } else {
  7499. this.state = 1;
  7500. }
  7501. this.sectionStart = this.index + 1;
  7502. } else {
  7503. this.delimiterIndex++;
  7504. }
  7505. } else {
  7506. this.state = 3;
  7507. this.stateInterpolation(c);
  7508. }
  7509. }
  7510. stateSpecialStartSequence(c) {
  7511. const isEnd = this.sequenceIndex === this.currentSequence.length;
  7512. const isMatch = isEnd ? (
  7513. // If we are at the end of the sequence, make sure the tag name has ended
  7514. isEndOfTagSection(c)
  7515. ) : (
  7516. // Otherwise, do a case-insensitive comparison
  7517. (c | 32) === this.currentSequence[this.sequenceIndex]
  7518. );
  7519. if (!isMatch) {
  7520. this.inRCDATA = false;
  7521. } else if (!isEnd) {
  7522. this.sequenceIndex++;
  7523. return;
  7524. }
  7525. this.sequenceIndex = 0;
  7526. this.state = 6;
  7527. this.stateInTagName(c);
  7528. }
  7529. /** Look for an end tag. For <title> and <textarea>, also decode entities. */
  7530. stateInRCDATA(c) {
  7531. if (this.sequenceIndex === this.currentSequence.length) {
  7532. if (c === 62 || isWhitespace(c)) {
  7533. const endOfText = this.index - this.currentSequence.length;
  7534. if (this.sectionStart < endOfText) {
  7535. const actualIndex = this.index;
  7536. this.index = endOfText;
  7537. this.cbs.ontext(this.sectionStart, endOfText);
  7538. this.index = actualIndex;
  7539. }
  7540. this.sectionStart = endOfText + 2;
  7541. this.stateInClosingTagName(c);
  7542. this.inRCDATA = false;
  7543. return;
  7544. }
  7545. this.sequenceIndex = 0;
  7546. }
  7547. if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
  7548. this.sequenceIndex += 1;
  7549. } else if (this.sequenceIndex === 0) {
  7550. if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
  7551. if (c === this.delimiterOpen[0]) {
  7552. this.state = 2;
  7553. this.delimiterIndex = 0;
  7554. this.stateInterpolationOpen(c);
  7555. }
  7556. } else if (this.fastForwardTo(60)) {
  7557. this.sequenceIndex = 1;
  7558. }
  7559. } else {
  7560. this.sequenceIndex = Number(c === 60);
  7561. }
  7562. }
  7563. stateCDATASequence(c) {
  7564. if (c === Sequences.Cdata[this.sequenceIndex]) {
  7565. if (++this.sequenceIndex === Sequences.Cdata.length) {
  7566. this.state = 28;
  7567. this.currentSequence = Sequences.CdataEnd;
  7568. this.sequenceIndex = 0;
  7569. this.sectionStart = this.index + 1;
  7570. }
  7571. } else {
  7572. this.sequenceIndex = 0;
  7573. this.state = 23;
  7574. this.stateInDeclaration(c);
  7575. }
  7576. }
  7577. /**
  7578. * When we wait for one specific character, we can speed things up
  7579. * by skipping through the buffer until we find it.
  7580. *
  7581. * @returns Whether the character was found.
  7582. */
  7583. fastForwardTo(c) {
  7584. while (++this.index < this.buffer.length) {
  7585. const cc = this.buffer.charCodeAt(this.index);
  7586. if (cc === 10) {
  7587. this.newlines.push(this.index);
  7588. }
  7589. if (cc === c) {
  7590. return true;
  7591. }
  7592. }
  7593. this.index = this.buffer.length - 1;
  7594. return false;
  7595. }
  7596. /**
  7597. * Comments and CDATA end with `-->` and `]]>`.
  7598. *
  7599. * Their common qualities are:
  7600. * - Their end sequences have a distinct character they start with.
  7601. * - That character is then repeated, so we have to check multiple repeats.
  7602. * - All characters but the start character of the sequence can be skipped.
  7603. */
  7604. stateInCommentLike(c) {
  7605. if (c === this.currentSequence[this.sequenceIndex]) {
  7606. if (++this.sequenceIndex === this.currentSequence.length) {
  7607. if (this.currentSequence === Sequences.CdataEnd) {
  7608. this.cbs.oncdata(this.sectionStart, this.index - 2);
  7609. } else {
  7610. this.cbs.oncomment(this.sectionStart, this.index - 2);
  7611. }
  7612. this.sequenceIndex = 0;
  7613. this.sectionStart = this.index + 1;
  7614. this.state = 1;
  7615. }
  7616. } else if (this.sequenceIndex === 0) {
  7617. if (this.fastForwardTo(this.currentSequence[0])) {
  7618. this.sequenceIndex = 1;
  7619. }
  7620. } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
  7621. this.sequenceIndex = 0;
  7622. }
  7623. }
  7624. startSpecial(sequence, offset) {
  7625. this.enterRCDATA(sequence, offset);
  7626. this.state = 31;
  7627. }
  7628. enterRCDATA(sequence, offset) {
  7629. this.inRCDATA = true;
  7630. this.currentSequence = sequence;
  7631. this.sequenceIndex = offset;
  7632. }
  7633. stateBeforeTagName(c) {
  7634. if (c === 33) {
  7635. this.state = 22;
  7636. this.sectionStart = this.index + 1;
  7637. } else if (c === 63) {
  7638. this.state = 24;
  7639. this.sectionStart = this.index + 1;
  7640. } else if (isTagStartChar(c)) {
  7641. this.sectionStart = this.index;
  7642. if (this.mode === 0) {
  7643. this.state = 6;
  7644. } else if (this.inSFCRoot) {
  7645. this.state = 34;
  7646. } else if (!this.inXML) {
  7647. if (c === 116) {
  7648. this.state = 30;
  7649. } else {
  7650. this.state = c === 115 ? 29 : 6;
  7651. }
  7652. } else {
  7653. this.state = 6;
  7654. }
  7655. } else if (c === 47) {
  7656. this.state = 8;
  7657. } else {
  7658. this.state = 1;
  7659. this.stateText(c);
  7660. }
  7661. }
  7662. stateInTagName(c) {
  7663. if (isEndOfTagSection(c)) {
  7664. this.handleTagName(c);
  7665. }
  7666. }
  7667. stateInSFCRootTagName(c) {
  7668. if (isEndOfTagSection(c)) {
  7669. const tag = this.buffer.slice(this.sectionStart, this.index);
  7670. if (tag !== "template") {
  7671. this.enterRCDATA(toCharCodes(`</` + tag), 0);
  7672. }
  7673. this.handleTagName(c);
  7674. }
  7675. }
  7676. handleTagName(c) {
  7677. this.cbs.onopentagname(this.sectionStart, this.index);
  7678. this.sectionStart = -1;
  7679. this.state = 11;
  7680. this.stateBeforeAttrName(c);
  7681. }
  7682. stateBeforeClosingTagName(c) {
  7683. if (isWhitespace(c)) ; else if (c === 62) {
  7684. {
  7685. this.cbs.onerr(14, this.index);
  7686. }
  7687. this.state = 1;
  7688. this.sectionStart = this.index + 1;
  7689. } else {
  7690. this.state = isTagStartChar(c) ? 9 : 27;
  7691. this.sectionStart = this.index;
  7692. }
  7693. }
  7694. stateInClosingTagName(c) {
  7695. if (c === 62 || isWhitespace(c)) {
  7696. this.cbs.onclosetag(this.sectionStart, this.index);
  7697. this.sectionStart = -1;
  7698. this.state = 10;
  7699. this.stateAfterClosingTagName(c);
  7700. }
  7701. }
  7702. stateAfterClosingTagName(c) {
  7703. if (c === 62) {
  7704. this.state = 1;
  7705. this.sectionStart = this.index + 1;
  7706. }
  7707. }
  7708. stateBeforeAttrName(c) {
  7709. if (c === 62) {
  7710. this.cbs.onopentagend(this.index);
  7711. if (this.inRCDATA) {
  7712. this.state = 32;
  7713. } else {
  7714. this.state = 1;
  7715. }
  7716. this.sectionStart = this.index + 1;
  7717. } else if (c === 47) {
  7718. this.state = 7;
  7719. if (this.peek() !== 62) {
  7720. this.cbs.onerr(22, this.index);
  7721. }
  7722. } else if (c === 60 && this.peek() === 47) {
  7723. this.cbs.onopentagend(this.index);
  7724. this.state = 5;
  7725. this.sectionStart = this.index;
  7726. } else if (!isWhitespace(c)) {
  7727. if (c === 61) {
  7728. this.cbs.onerr(
  7729. 19,
  7730. this.index
  7731. );
  7732. }
  7733. this.handleAttrStart(c);
  7734. }
  7735. }
  7736. handleAttrStart(c) {
  7737. if (c === 118 && this.peek() === 45) {
  7738. this.state = 13;
  7739. this.sectionStart = this.index;
  7740. } else if (c === 46 || c === 58 || c === 64 || c === 35) {
  7741. this.cbs.ondirname(this.index, this.index + 1);
  7742. this.state = 14;
  7743. this.sectionStart = this.index + 1;
  7744. } else {
  7745. this.state = 12;
  7746. this.sectionStart = this.index;
  7747. }
  7748. }
  7749. stateInSelfClosingTag(c) {
  7750. if (c === 62) {
  7751. this.cbs.onselfclosingtag(this.index);
  7752. this.state = 1;
  7753. this.sectionStart = this.index + 1;
  7754. this.inRCDATA = false;
  7755. } else if (!isWhitespace(c)) {
  7756. this.state = 11;
  7757. this.stateBeforeAttrName(c);
  7758. }
  7759. }
  7760. stateInAttrName(c) {
  7761. if (c === 61 || isEndOfTagSection(c)) {
  7762. this.cbs.onattribname(this.sectionStart, this.index);
  7763. this.handleAttrNameEnd(c);
  7764. } else if ((c === 34 || c === 39 || c === 60)) {
  7765. this.cbs.onerr(
  7766. 17,
  7767. this.index
  7768. );
  7769. }
  7770. }
  7771. stateInDirName(c) {
  7772. if (c === 61 || isEndOfTagSection(c)) {
  7773. this.cbs.ondirname(this.sectionStart, this.index);
  7774. this.handleAttrNameEnd(c);
  7775. } else if (c === 58) {
  7776. this.cbs.ondirname(this.sectionStart, this.index);
  7777. this.state = 14;
  7778. this.sectionStart = this.index + 1;
  7779. } else if (c === 46) {
  7780. this.cbs.ondirname(this.sectionStart, this.index);
  7781. this.state = 16;
  7782. this.sectionStart = this.index + 1;
  7783. }
  7784. }
  7785. stateInDirArg(c) {
  7786. if (c === 61 || isEndOfTagSection(c)) {
  7787. this.cbs.ondirarg(this.sectionStart, this.index);
  7788. this.handleAttrNameEnd(c);
  7789. } else if (c === 91) {
  7790. this.state = 15;
  7791. } else if (c === 46) {
  7792. this.cbs.ondirarg(this.sectionStart, this.index);
  7793. this.state = 16;
  7794. this.sectionStart = this.index + 1;
  7795. }
  7796. }
  7797. stateInDynamicDirArg(c) {
  7798. if (c === 93) {
  7799. this.state = 14;
  7800. } else if (c === 61 || isEndOfTagSection(c)) {
  7801. this.cbs.ondirarg(this.sectionStart, this.index + 1);
  7802. this.handleAttrNameEnd(c);
  7803. {
  7804. this.cbs.onerr(
  7805. 27,
  7806. this.index
  7807. );
  7808. }
  7809. }
  7810. }
  7811. stateInDirModifier(c) {
  7812. if (c === 61 || isEndOfTagSection(c)) {
  7813. this.cbs.ondirmodifier(this.sectionStart, this.index);
  7814. this.handleAttrNameEnd(c);
  7815. } else if (c === 46) {
  7816. this.cbs.ondirmodifier(this.sectionStart, this.index);
  7817. this.sectionStart = this.index + 1;
  7818. }
  7819. }
  7820. handleAttrNameEnd(c) {
  7821. this.sectionStart = this.index;
  7822. this.state = 17;
  7823. this.cbs.onattribnameend(this.index);
  7824. this.stateAfterAttrName(c);
  7825. }
  7826. stateAfterAttrName(c) {
  7827. if (c === 61) {
  7828. this.state = 18;
  7829. } else if (c === 47 || c === 62) {
  7830. this.cbs.onattribend(0, this.sectionStart);
  7831. this.sectionStart = -1;
  7832. this.state = 11;
  7833. this.stateBeforeAttrName(c);
  7834. } else if (!isWhitespace(c)) {
  7835. this.cbs.onattribend(0, this.sectionStart);
  7836. this.handleAttrStart(c);
  7837. }
  7838. }
  7839. stateBeforeAttrValue(c) {
  7840. if (c === 34) {
  7841. this.state = 19;
  7842. this.sectionStart = this.index + 1;
  7843. } else if (c === 39) {
  7844. this.state = 20;
  7845. this.sectionStart = this.index + 1;
  7846. } else if (!isWhitespace(c)) {
  7847. this.sectionStart = this.index;
  7848. this.state = 21;
  7849. this.stateInAttrValueNoQuotes(c);
  7850. }
  7851. }
  7852. handleInAttrValue(c, quote) {
  7853. if (c === quote || this.fastForwardTo(quote)) {
  7854. this.cbs.onattribdata(this.sectionStart, this.index);
  7855. this.sectionStart = -1;
  7856. this.cbs.onattribend(
  7857. quote === 34 ? 3 : 2,
  7858. this.index + 1
  7859. );
  7860. this.state = 11;
  7861. }
  7862. }
  7863. stateInAttrValueDoubleQuotes(c) {
  7864. this.handleInAttrValue(c, 34);
  7865. }
  7866. stateInAttrValueSingleQuotes(c) {
  7867. this.handleInAttrValue(c, 39);
  7868. }
  7869. stateInAttrValueNoQuotes(c) {
  7870. if (isWhitespace(c) || c === 62) {
  7871. this.cbs.onattribdata(this.sectionStart, this.index);
  7872. this.sectionStart = -1;
  7873. this.cbs.onattribend(1, this.index);
  7874. this.state = 11;
  7875. this.stateBeforeAttrName(c);
  7876. } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
  7877. this.cbs.onerr(
  7878. 18,
  7879. this.index
  7880. );
  7881. } else ;
  7882. }
  7883. stateBeforeDeclaration(c) {
  7884. if (c === 91) {
  7885. this.state = 26;
  7886. this.sequenceIndex = 0;
  7887. } else {
  7888. this.state = c === 45 ? 25 : 23;
  7889. }
  7890. }
  7891. stateInDeclaration(c) {
  7892. if (c === 62 || this.fastForwardTo(62)) {
  7893. this.state = 1;
  7894. this.sectionStart = this.index + 1;
  7895. }
  7896. }
  7897. stateInProcessingInstruction(c) {
  7898. if (c === 62 || this.fastForwardTo(62)) {
  7899. this.cbs.onprocessinginstruction(this.sectionStart, this.index);
  7900. this.state = 1;
  7901. this.sectionStart = this.index + 1;
  7902. }
  7903. }
  7904. stateBeforeComment(c) {
  7905. if (c === 45) {
  7906. this.state = 28;
  7907. this.currentSequence = Sequences.CommentEnd;
  7908. this.sequenceIndex = 2;
  7909. this.sectionStart = this.index + 1;
  7910. } else {
  7911. this.state = 23;
  7912. }
  7913. }
  7914. stateInSpecialComment(c) {
  7915. if (c === 62 || this.fastForwardTo(62)) {
  7916. this.cbs.oncomment(this.sectionStart, this.index);
  7917. this.state = 1;
  7918. this.sectionStart = this.index + 1;
  7919. }
  7920. }
  7921. stateBeforeSpecialS(c) {
  7922. if (c === Sequences.ScriptEnd[3]) {
  7923. this.startSpecial(Sequences.ScriptEnd, 4);
  7924. } else if (c === Sequences.StyleEnd[3]) {
  7925. this.startSpecial(Sequences.StyleEnd, 4);
  7926. } else {
  7927. this.state = 6;
  7928. this.stateInTagName(c);
  7929. }
  7930. }
  7931. stateBeforeSpecialT(c) {
  7932. if (c === Sequences.TitleEnd[3]) {
  7933. this.startSpecial(Sequences.TitleEnd, 4);
  7934. } else if (c === Sequences.TextareaEnd[3]) {
  7935. this.startSpecial(Sequences.TextareaEnd, 4);
  7936. } else {
  7937. this.state = 6;
  7938. this.stateInTagName(c);
  7939. }
  7940. }
  7941. startEntity() {
  7942. }
  7943. stateInEntity() {
  7944. }
  7945. /**
  7946. * Iterates through the buffer, calling the function corresponding to the current state.
  7947. *
  7948. * States that are more likely to be hit are higher up, as a performance improvement.
  7949. */
  7950. parse(input) {
  7951. this.buffer = input;
  7952. while (this.index < this.buffer.length) {
  7953. const c = this.buffer.charCodeAt(this.index);
  7954. if (c === 10) {
  7955. this.newlines.push(this.index);
  7956. }
  7957. switch (this.state) {
  7958. case 1: {
  7959. this.stateText(c);
  7960. break;
  7961. }
  7962. case 2: {
  7963. this.stateInterpolationOpen(c);
  7964. break;
  7965. }
  7966. case 3: {
  7967. this.stateInterpolation(c);
  7968. break;
  7969. }
  7970. case 4: {
  7971. this.stateInterpolationClose(c);
  7972. break;
  7973. }
  7974. case 31: {
  7975. this.stateSpecialStartSequence(c);
  7976. break;
  7977. }
  7978. case 32: {
  7979. this.stateInRCDATA(c);
  7980. break;
  7981. }
  7982. case 26: {
  7983. this.stateCDATASequence(c);
  7984. break;
  7985. }
  7986. case 19: {
  7987. this.stateInAttrValueDoubleQuotes(c);
  7988. break;
  7989. }
  7990. case 12: {
  7991. this.stateInAttrName(c);
  7992. break;
  7993. }
  7994. case 13: {
  7995. this.stateInDirName(c);
  7996. break;
  7997. }
  7998. case 14: {
  7999. this.stateInDirArg(c);
  8000. break;
  8001. }
  8002. case 15: {
  8003. this.stateInDynamicDirArg(c);
  8004. break;
  8005. }
  8006. case 16: {
  8007. this.stateInDirModifier(c);
  8008. break;
  8009. }
  8010. case 28: {
  8011. this.stateInCommentLike(c);
  8012. break;
  8013. }
  8014. case 27: {
  8015. this.stateInSpecialComment(c);
  8016. break;
  8017. }
  8018. case 11: {
  8019. this.stateBeforeAttrName(c);
  8020. break;
  8021. }
  8022. case 6: {
  8023. this.stateInTagName(c);
  8024. break;
  8025. }
  8026. case 34: {
  8027. this.stateInSFCRootTagName(c);
  8028. break;
  8029. }
  8030. case 9: {
  8031. this.stateInClosingTagName(c);
  8032. break;
  8033. }
  8034. case 5: {
  8035. this.stateBeforeTagName(c);
  8036. break;
  8037. }
  8038. case 17: {
  8039. this.stateAfterAttrName(c);
  8040. break;
  8041. }
  8042. case 20: {
  8043. this.stateInAttrValueSingleQuotes(c);
  8044. break;
  8045. }
  8046. case 18: {
  8047. this.stateBeforeAttrValue(c);
  8048. break;
  8049. }
  8050. case 8: {
  8051. this.stateBeforeClosingTagName(c);
  8052. break;
  8053. }
  8054. case 10: {
  8055. this.stateAfterClosingTagName(c);
  8056. break;
  8057. }
  8058. case 29: {
  8059. this.stateBeforeSpecialS(c);
  8060. break;
  8061. }
  8062. case 30: {
  8063. this.stateBeforeSpecialT(c);
  8064. break;
  8065. }
  8066. case 21: {
  8067. this.stateInAttrValueNoQuotes(c);
  8068. break;
  8069. }
  8070. case 7: {
  8071. this.stateInSelfClosingTag(c);
  8072. break;
  8073. }
  8074. case 23: {
  8075. this.stateInDeclaration(c);
  8076. break;
  8077. }
  8078. case 22: {
  8079. this.stateBeforeDeclaration(c);
  8080. break;
  8081. }
  8082. case 25: {
  8083. this.stateBeforeComment(c);
  8084. break;
  8085. }
  8086. case 24: {
  8087. this.stateInProcessingInstruction(c);
  8088. break;
  8089. }
  8090. case 33: {
  8091. this.stateInEntity();
  8092. break;
  8093. }
  8094. }
  8095. this.index++;
  8096. }
  8097. this.cleanup();
  8098. this.finish();
  8099. }
  8100. /**
  8101. * Remove data that has already been consumed from the buffer.
  8102. */
  8103. cleanup() {
  8104. if (this.sectionStart !== this.index) {
  8105. if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
  8106. this.cbs.ontext(this.sectionStart, this.index);
  8107. this.sectionStart = this.index;
  8108. } else if (this.state === 19 || this.state === 20 || this.state === 21) {
  8109. this.cbs.onattribdata(this.sectionStart, this.index);
  8110. this.sectionStart = this.index;
  8111. }
  8112. }
  8113. }
  8114. finish() {
  8115. this.handleTrailingData();
  8116. this.cbs.onend();
  8117. }
  8118. /** Handle any trailing data. */
  8119. handleTrailingData() {
  8120. const endIndex = this.buffer.length;
  8121. if (this.sectionStart >= endIndex) {
  8122. return;
  8123. }
  8124. if (this.state === 28) {
  8125. if (this.currentSequence === Sequences.CdataEnd) {
  8126. this.cbs.oncdata(this.sectionStart, endIndex);
  8127. } else {
  8128. this.cbs.oncomment(this.sectionStart, endIndex);
  8129. }
  8130. } 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 {
  8131. this.cbs.ontext(this.sectionStart, endIndex);
  8132. }
  8133. }
  8134. emitCodePoint(cp, consumed) {
  8135. }
  8136. }
  8137. const deprecationData = {
  8138. ["COMPILER_IS_ON_ELEMENT"]: {
  8139. 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:".`,
  8140. link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
  8141. },
  8142. ["COMPILER_V_BIND_SYNC"]: {
  8143. 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}\`.`,
  8144. link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
  8145. },
  8146. ["COMPILER_V_BIND_OBJECT_ORDER"]: {
  8147. 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.`,
  8148. link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
  8149. },
  8150. ["COMPILER_V_ON_NATIVE"]: {
  8151. message: `.native modifier for v-on has been removed as is no longer necessary.`,
  8152. link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
  8153. },
  8154. ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
  8155. 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.`,
  8156. link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
  8157. },
  8158. ["COMPILER_NATIVE_TEMPLATE"]: {
  8159. message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
  8160. },
  8161. ["COMPILER_INLINE_TEMPLATE"]: {
  8162. message: `"inline-template" has been removed in Vue 3.`,
  8163. link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
  8164. },
  8165. ["COMPILER_FILTERS"]: {
  8166. 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.`,
  8167. link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
  8168. }
  8169. };
  8170. function getCompatValue(key, { compatConfig }) {
  8171. const value = compatConfig && compatConfig[key];
  8172. if (key === "MODE") {
  8173. return value || 3;
  8174. } else {
  8175. return value;
  8176. }
  8177. }
  8178. function isCompatEnabled(key, context) {
  8179. const mode = getCompatValue("MODE", context);
  8180. const value = getCompatValue(key, context);
  8181. return mode === 3 ? value === true : value !== false;
  8182. }
  8183. function checkCompatEnabled(key, context, loc, ...args) {
  8184. const enabled = isCompatEnabled(key, context);
  8185. if (enabled) {
  8186. warnDeprecation(key, context, loc, ...args);
  8187. }
  8188. return enabled;
  8189. }
  8190. function warnDeprecation(key, context, loc, ...args) {
  8191. const val = getCompatValue(key, context);
  8192. if (val === "suppress-warning") {
  8193. return;
  8194. }
  8195. const { message, link } = deprecationData[key];
  8196. const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
  8197. Details: ${link}` : ``}`;
  8198. const err = new SyntaxError(msg);
  8199. err.code = key;
  8200. if (loc)
  8201. err.loc = loc;
  8202. context.onWarn(err);
  8203. }
  8204. function defaultOnError(error) {
  8205. throw error;
  8206. }
  8207. function defaultOnWarn(msg) {
  8208. console.warn(`[Vue warn] ${msg.message}`);
  8209. }
  8210. function createCompilerError(code, loc, messages, additionalMessage) {
  8211. const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
  8212. const error = new SyntaxError(String(msg));
  8213. error.code = code;
  8214. error.loc = loc;
  8215. return error;
  8216. }
  8217. const errorMessages = {
  8218. // parse errors
  8219. [0]: "Illegal comment.",
  8220. [1]: "CDATA section is allowed only in XML context.",
  8221. [2]: "Duplicate attribute.",
  8222. [3]: "End tag cannot have attributes.",
  8223. [4]: "Illegal '/' in tags.",
  8224. [5]: "Unexpected EOF in tag.",
  8225. [6]: "Unexpected EOF in CDATA section.",
  8226. [7]: "Unexpected EOF in comment.",
  8227. [8]: "Unexpected EOF in script.",
  8228. [9]: "Unexpected EOF in tag.",
  8229. [10]: "Incorrectly closed comment.",
  8230. [11]: "Incorrectly opened comment.",
  8231. [12]: "Illegal tag name. Use '&lt;' to print '<'.",
  8232. [13]: "Attribute value was expected.",
  8233. [14]: "End tag name was expected.",
  8234. [15]: "Whitespace was expected.",
  8235. [16]: "Unexpected '<!--' in comment.",
  8236. [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
  8237. [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
  8238. [19]: "Attribute name cannot start with '='.",
  8239. [21]: "'<?' is allowed only in XML context.",
  8240. [20]: `Unexpected null character.`,
  8241. [22]: "Illegal '/' in tags.",
  8242. // Vue-specific parse errors
  8243. [23]: "Invalid end tag.",
  8244. [24]: "Element is missing end tag.",
  8245. [25]: "Interpolation end sign was not found.",
  8246. [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
  8247. [26]: "Legal directive name was expected.",
  8248. // transform errors
  8249. [28]: `v-if/v-else-if is missing expression.`,
  8250. [29]: `v-if/else branches must use unique keys.`,
  8251. [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
  8252. [31]: `v-for is missing expression.`,
  8253. [32]: `v-for has invalid expression.`,
  8254. [33]: `<template v-for> key should be placed on the <template> tag.`,
  8255. [34]: `v-bind is missing expression.`,
  8256. [52]: `v-bind with same-name shorthand only allows static argument.`,
  8257. [35]: `v-on is missing expression.`,
  8258. [36]: `Unexpected custom directive on <slot> outlet.`,
  8259. [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.`,
  8260. [38]: `Duplicate slot names found. `,
  8261. [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
  8262. [40]: `v-slot can only be used on components or <template> tags.`,
  8263. [41]: `v-model is missing expression.`,
  8264. [42]: `v-model value must be a valid JavaScript member expression.`,
  8265. [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
  8266. [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
  8267. Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
  8268. [45]: `Error parsing JavaScript expression: `,
  8269. [46]: `<KeepAlive> expects exactly one child component.`,
  8270. [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.`,
  8271. // generic errors
  8272. [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
  8273. [48]: `ES module mode is not supported in this build of compiler.`,
  8274. [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
  8275. [50]: `"scopeId" option is only supported in module mode.`,
  8276. // just to fulfill types
  8277. [53]: ``
  8278. };
  8279. const isStaticExp = (p) => p.type === 4 && p.isStatic;
  8280. function isCoreComponent(tag) {
  8281. switch (tag) {
  8282. case "Teleport":
  8283. case "teleport":
  8284. return TELEPORT;
  8285. case "Suspense":
  8286. case "suspense":
  8287. return SUSPENSE;
  8288. case "KeepAlive":
  8289. case "keep-alive":
  8290. return KEEP_ALIVE;
  8291. case "BaseTransition":
  8292. case "base-transition":
  8293. return BASE_TRANSITION;
  8294. }
  8295. }
  8296. const nonIdentifierRE = /^\d|[^\$\w]/;
  8297. const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
  8298. const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
  8299. const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
  8300. const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
  8301. const isMemberExpressionBrowser = (path) => {
  8302. path = path.trim().replace(whitespaceRE, (s) => s.trim());
  8303. let state = 0 /* inMemberExp */;
  8304. let stateStack = [];
  8305. let currentOpenBracketCount = 0;
  8306. let currentOpenParensCount = 0;
  8307. let currentStringType = null;
  8308. for (let i = 0; i < path.length; i++) {
  8309. const char = path.charAt(i);
  8310. switch (state) {
  8311. case 0 /* inMemberExp */:
  8312. if (char === "[") {
  8313. stateStack.push(state);
  8314. state = 1 /* inBrackets */;
  8315. currentOpenBracketCount++;
  8316. } else if (char === "(") {
  8317. stateStack.push(state);
  8318. state = 2 /* inParens */;
  8319. currentOpenParensCount++;
  8320. } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
  8321. return false;
  8322. }
  8323. break;
  8324. case 1 /* inBrackets */:
  8325. if (char === `'` || char === `"` || char === "`") {
  8326. stateStack.push(state);
  8327. state = 3 /* inString */;
  8328. currentStringType = char;
  8329. } else if (char === `[`) {
  8330. currentOpenBracketCount++;
  8331. } else if (char === `]`) {
  8332. if (!--currentOpenBracketCount) {
  8333. state = stateStack.pop();
  8334. }
  8335. }
  8336. break;
  8337. case 2 /* inParens */:
  8338. if (char === `'` || char === `"` || char === "`") {
  8339. stateStack.push(state);
  8340. state = 3 /* inString */;
  8341. currentStringType = char;
  8342. } else if (char === `(`) {
  8343. currentOpenParensCount++;
  8344. } else if (char === `)`) {
  8345. if (i === path.length - 1) {
  8346. return false;
  8347. }
  8348. if (!--currentOpenParensCount) {
  8349. state = stateStack.pop();
  8350. }
  8351. }
  8352. break;
  8353. case 3 /* inString */:
  8354. if (char === currentStringType) {
  8355. state = stateStack.pop();
  8356. currentStringType = null;
  8357. }
  8358. break;
  8359. }
  8360. }
  8361. return !currentOpenBracketCount && !currentOpenParensCount;
  8362. };
  8363. const isMemberExpression = isMemberExpressionBrowser ;
  8364. function assert(condition, msg) {
  8365. if (!condition) {
  8366. throw new Error(msg || `unexpected compiler condition`);
  8367. }
  8368. }
  8369. function findDir(node, name, allowEmpty = false) {
  8370. for (let i = 0; i < node.props.length; i++) {
  8371. const p = node.props[i];
  8372. if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) {
  8373. return p;
  8374. }
  8375. }
  8376. }
  8377. function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
  8378. for (let i = 0; i < node.props.length; i++) {
  8379. const p = node.props[i];
  8380. if (p.type === 6) {
  8381. if (dynamicOnly)
  8382. continue;
  8383. if (p.name === name && (p.value || allowEmpty)) {
  8384. return p;
  8385. }
  8386. } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
  8387. return p;
  8388. }
  8389. }
  8390. }
  8391. function isStaticArgOf(arg, name) {
  8392. return !!(arg && isStaticExp(arg) && arg.content === name);
  8393. }
  8394. function hasDynamicKeyVBind(node) {
  8395. return node.props.some(
  8396. (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
  8397. p.arg.type !== 4 || // v-bind:[_ctx.foo]
  8398. !p.arg.isStatic)
  8399. // v-bind:[foo]
  8400. );
  8401. }
  8402. function isText$1(node) {
  8403. return node.type === 5 || node.type === 2;
  8404. }
  8405. function isVSlot(p) {
  8406. return p.type === 7 && p.name === "slot";
  8407. }
  8408. function isTemplateNode(node) {
  8409. return node.type === 1 && node.tagType === 3;
  8410. }
  8411. function isSlotOutlet(node) {
  8412. return node.type === 1 && node.tagType === 2;
  8413. }
  8414. const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
  8415. function getUnnormalizedProps(props, callPath = []) {
  8416. if (props && !isString(props) && props.type === 14) {
  8417. const callee = props.callee;
  8418. if (!isString(callee) && propsHelperSet.has(callee)) {
  8419. return getUnnormalizedProps(
  8420. props.arguments[0],
  8421. callPath.concat(props)
  8422. );
  8423. }
  8424. }
  8425. return [props, callPath];
  8426. }
  8427. function injectProp(node, prop, context) {
  8428. let propsWithInjection;
  8429. let props = node.type === 13 ? node.props : node.arguments[2];
  8430. let callPath = [];
  8431. let parentCall;
  8432. if (props && !isString(props) && props.type === 14) {
  8433. const ret = getUnnormalizedProps(props);
  8434. props = ret[0];
  8435. callPath = ret[1];
  8436. parentCall = callPath[callPath.length - 1];
  8437. }
  8438. if (props == null || isString(props)) {
  8439. propsWithInjection = createObjectExpression([prop]);
  8440. } else if (props.type === 14) {
  8441. const first = props.arguments[0];
  8442. if (!isString(first) && first.type === 15) {
  8443. if (!hasProp(prop, first)) {
  8444. first.properties.unshift(prop);
  8445. }
  8446. } else {
  8447. if (props.callee === TO_HANDLERS) {
  8448. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  8449. createObjectExpression([prop]),
  8450. props
  8451. ]);
  8452. } else {
  8453. props.arguments.unshift(createObjectExpression([prop]));
  8454. }
  8455. }
  8456. !propsWithInjection && (propsWithInjection = props);
  8457. } else if (props.type === 15) {
  8458. if (!hasProp(prop, props)) {
  8459. props.properties.unshift(prop);
  8460. }
  8461. propsWithInjection = props;
  8462. } else {
  8463. propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
  8464. createObjectExpression([prop]),
  8465. props
  8466. ]);
  8467. if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
  8468. parentCall = callPath[callPath.length - 2];
  8469. }
  8470. }
  8471. if (node.type === 13) {
  8472. if (parentCall) {
  8473. parentCall.arguments[0] = propsWithInjection;
  8474. } else {
  8475. node.props = propsWithInjection;
  8476. }
  8477. } else {
  8478. if (parentCall) {
  8479. parentCall.arguments[0] = propsWithInjection;
  8480. } else {
  8481. node.arguments[2] = propsWithInjection;
  8482. }
  8483. }
  8484. }
  8485. function hasProp(prop, props) {
  8486. let result = false;
  8487. if (prop.key.type === 4) {
  8488. const propKeyName = prop.key.content;
  8489. result = props.properties.some(
  8490. (p) => p.key.type === 4 && p.key.content === propKeyName
  8491. );
  8492. }
  8493. return result;
  8494. }
  8495. function toValidAssetId(name, type) {
  8496. return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
  8497. return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
  8498. })}`;
  8499. }
  8500. function getMemoedVNodeCall(node) {
  8501. if (node.type === 14 && node.callee === WITH_MEMO) {
  8502. return node.arguments[1].returns;
  8503. } else {
  8504. return node;
  8505. }
  8506. }
  8507. const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  8508. const defaultParserOptions = {
  8509. parseMode: "base",
  8510. ns: 0,
  8511. delimiters: [`{{`, `}}`],
  8512. getNamespace: () => 0,
  8513. isVoidTag: NO,
  8514. isPreTag: NO,
  8515. isCustomElement: NO,
  8516. onError: defaultOnError,
  8517. onWarn: defaultOnWarn,
  8518. comments: !!(true !== "production"),
  8519. prefixIdentifiers: false
  8520. };
  8521. let currentOptions = defaultParserOptions;
  8522. let currentRoot = null;
  8523. let currentInput = "";
  8524. let currentOpenTag = null;
  8525. let currentProp = null;
  8526. let currentAttrValue = "";
  8527. let currentAttrStartIndex = -1;
  8528. let currentAttrEndIndex = -1;
  8529. let inPre = 0;
  8530. let inVPre = false;
  8531. let currentVPreBoundary = null;
  8532. const stack = [];
  8533. const tokenizer = new Tokenizer(stack, {
  8534. onerr: emitError,
  8535. ontext(start, end) {
  8536. onText(getSlice(start, end), start, end);
  8537. },
  8538. ontextentity(char, start, end) {
  8539. onText(char, start, end);
  8540. },
  8541. oninterpolation(start, end) {
  8542. if (inVPre) {
  8543. return onText(getSlice(start, end), start, end);
  8544. }
  8545. let innerStart = start + tokenizer.delimiterOpen.length;
  8546. let innerEnd = end - tokenizer.delimiterClose.length;
  8547. while (isWhitespace(currentInput.charCodeAt(innerStart))) {
  8548. innerStart++;
  8549. }
  8550. while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
  8551. innerEnd--;
  8552. }
  8553. let exp = getSlice(innerStart, innerEnd);
  8554. if (exp.includes("&")) {
  8555. {
  8556. exp = currentOptions.decodeEntities(exp, false);
  8557. }
  8558. }
  8559. addNode({
  8560. type: 5,
  8561. content: createExp(exp, false, getLoc(innerStart, innerEnd)),
  8562. loc: getLoc(start, end)
  8563. });
  8564. },
  8565. onopentagname(start, end) {
  8566. const name = getSlice(start, end);
  8567. currentOpenTag = {
  8568. type: 1,
  8569. tag: name,
  8570. ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
  8571. tagType: 0,
  8572. // will be refined on tag close
  8573. props: [],
  8574. children: [],
  8575. loc: getLoc(start - 1, end),
  8576. codegenNode: void 0
  8577. };
  8578. },
  8579. onopentagend(end) {
  8580. endOpenTag(end);
  8581. },
  8582. onclosetag(start, end) {
  8583. const name = getSlice(start, end);
  8584. if (!currentOptions.isVoidTag(name)) {
  8585. let found = false;
  8586. for (let i = 0; i < stack.length; i++) {
  8587. const e = stack[i];
  8588. if (e.tag.toLowerCase() === name.toLowerCase()) {
  8589. found = true;
  8590. if (i > 0) {
  8591. emitError(24, stack[0].loc.start.offset);
  8592. }
  8593. for (let j = 0; j <= i; j++) {
  8594. const el = stack.shift();
  8595. onCloseTag(el, end, j < i);
  8596. }
  8597. break;
  8598. }
  8599. }
  8600. if (!found) {
  8601. emitError(23, backTrack(start, 60));
  8602. }
  8603. }
  8604. },
  8605. onselfclosingtag(end) {
  8606. var _a;
  8607. const name = currentOpenTag.tag;
  8608. currentOpenTag.isSelfClosing = true;
  8609. endOpenTag(end);
  8610. if (((_a = stack[0]) == null ? void 0 : _a.tag) === name) {
  8611. onCloseTag(stack.shift(), end);
  8612. }
  8613. },
  8614. onattribname(start, end) {
  8615. currentProp = {
  8616. type: 6,
  8617. name: getSlice(start, end),
  8618. nameLoc: getLoc(start, end),
  8619. value: void 0,
  8620. loc: getLoc(start)
  8621. };
  8622. },
  8623. ondirname(start, end) {
  8624. const raw = getSlice(start, end);
  8625. const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
  8626. if (!inVPre && name === "") {
  8627. emitError(26, start);
  8628. }
  8629. if (inVPre || name === "") {
  8630. currentProp = {
  8631. type: 6,
  8632. name: raw,
  8633. nameLoc: getLoc(start, end),
  8634. value: void 0,
  8635. loc: getLoc(start)
  8636. };
  8637. } else {
  8638. currentProp = {
  8639. type: 7,
  8640. name,
  8641. rawName: raw,
  8642. exp: void 0,
  8643. arg: void 0,
  8644. modifiers: raw === "." ? ["prop"] : [],
  8645. loc: getLoc(start)
  8646. };
  8647. if (name === "pre") {
  8648. inVPre = tokenizer.inVPre = true;
  8649. currentVPreBoundary = currentOpenTag;
  8650. const props = currentOpenTag.props;
  8651. for (let i = 0; i < props.length; i++) {
  8652. if (props[i].type === 7) {
  8653. props[i] = dirToAttr(props[i]);
  8654. }
  8655. }
  8656. }
  8657. }
  8658. },
  8659. ondirarg(start, end) {
  8660. if (start === end)
  8661. return;
  8662. const arg = getSlice(start, end);
  8663. if (inVPre) {
  8664. currentProp.name += arg;
  8665. setLocEnd(currentProp.nameLoc, end);
  8666. } else {
  8667. const isStatic = arg[0] !== `[`;
  8668. currentProp.arg = createExp(
  8669. isStatic ? arg : arg.slice(1, -1),
  8670. isStatic,
  8671. getLoc(start, end),
  8672. isStatic ? 3 : 0
  8673. );
  8674. }
  8675. },
  8676. ondirmodifier(start, end) {
  8677. const mod = getSlice(start, end);
  8678. if (inVPre) {
  8679. currentProp.name += "." + mod;
  8680. setLocEnd(currentProp.nameLoc, end);
  8681. } else if (currentProp.name === "slot") {
  8682. const arg = currentProp.arg;
  8683. if (arg) {
  8684. arg.content += "." + mod;
  8685. setLocEnd(arg.loc, end);
  8686. }
  8687. } else {
  8688. currentProp.modifiers.push(mod);
  8689. }
  8690. },
  8691. onattribdata(start, end) {
  8692. currentAttrValue += getSlice(start, end);
  8693. if (currentAttrStartIndex < 0)
  8694. currentAttrStartIndex = start;
  8695. currentAttrEndIndex = end;
  8696. },
  8697. onattribentity(char, start, end) {
  8698. currentAttrValue += char;
  8699. if (currentAttrStartIndex < 0)
  8700. currentAttrStartIndex = start;
  8701. currentAttrEndIndex = end;
  8702. },
  8703. onattribnameend(end) {
  8704. const start = currentProp.loc.start.offset;
  8705. const name = getSlice(start, end);
  8706. if (currentProp.type === 7) {
  8707. currentProp.rawName = name;
  8708. }
  8709. if (currentOpenTag.props.some(
  8710. (p) => (p.type === 7 ? p.rawName : p.name) === name
  8711. )) {
  8712. emitError(2, start);
  8713. }
  8714. },
  8715. onattribend(quote, end) {
  8716. if (currentOpenTag && currentProp) {
  8717. setLocEnd(currentProp.loc, end);
  8718. if (quote !== 0) {
  8719. if (currentAttrValue.includes("&")) {
  8720. currentAttrValue = currentOptions.decodeEntities(
  8721. currentAttrValue,
  8722. true
  8723. );
  8724. }
  8725. if (currentProp.type === 6) {
  8726. if (currentProp.name === "class") {
  8727. currentAttrValue = condense(currentAttrValue).trim();
  8728. }
  8729. if (quote === 1 && !currentAttrValue) {
  8730. emitError(13, end);
  8731. }
  8732. currentProp.value = {
  8733. type: 2,
  8734. content: currentAttrValue,
  8735. loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
  8736. };
  8737. if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
  8738. tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
  8739. }
  8740. } else {
  8741. let expParseMode = 0 /* Normal */;
  8742. currentProp.exp = createExp(
  8743. currentAttrValue,
  8744. false,
  8745. getLoc(currentAttrStartIndex, currentAttrEndIndex),
  8746. 0,
  8747. expParseMode
  8748. );
  8749. if (currentProp.name === "for") {
  8750. currentProp.forParseResult = parseForExpression(currentProp.exp);
  8751. }
  8752. let syncIndex = -1;
  8753. if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.indexOf("sync")) > -1 && checkCompatEnabled(
  8754. "COMPILER_V_BIND_SYNC",
  8755. currentOptions,
  8756. currentProp.loc,
  8757. currentProp.rawName
  8758. )) {
  8759. currentProp.name = "model";
  8760. currentProp.modifiers.splice(syncIndex, 1);
  8761. }
  8762. }
  8763. }
  8764. if (currentProp.type !== 7 || currentProp.name !== "pre") {
  8765. currentOpenTag.props.push(currentProp);
  8766. }
  8767. }
  8768. currentAttrValue = "";
  8769. currentAttrStartIndex = currentAttrEndIndex = -1;
  8770. },
  8771. oncomment(start, end) {
  8772. if (currentOptions.comments) {
  8773. addNode({
  8774. type: 3,
  8775. content: getSlice(start, end),
  8776. loc: getLoc(start - 4, end + 3)
  8777. });
  8778. }
  8779. },
  8780. onend() {
  8781. const end = currentInput.length;
  8782. if (tokenizer.state !== 1) {
  8783. switch (tokenizer.state) {
  8784. case 5:
  8785. case 8:
  8786. emitError(5, end);
  8787. break;
  8788. case 3:
  8789. case 4:
  8790. emitError(
  8791. 25,
  8792. tokenizer.sectionStart
  8793. );
  8794. break;
  8795. case 28:
  8796. if (tokenizer.currentSequence === Sequences.CdataEnd) {
  8797. emitError(6, end);
  8798. } else {
  8799. emitError(7, end);
  8800. }
  8801. break;
  8802. case 6:
  8803. case 7:
  8804. case 9:
  8805. case 11:
  8806. case 12:
  8807. case 13:
  8808. case 14:
  8809. case 15:
  8810. case 16:
  8811. case 17:
  8812. case 18:
  8813. case 19:
  8814. case 20:
  8815. case 21:
  8816. emitError(9, end);
  8817. break;
  8818. }
  8819. }
  8820. for (let index = 0; index < stack.length; index++) {
  8821. onCloseTag(stack[index], end - 1);
  8822. emitError(24, stack[index].loc.start.offset);
  8823. }
  8824. },
  8825. oncdata(start, end) {
  8826. if (stack[0].ns !== 0) {
  8827. onText(getSlice(start, end), start, end);
  8828. } else {
  8829. emitError(1, start - 9);
  8830. }
  8831. },
  8832. onprocessinginstruction(start) {
  8833. if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  8834. emitError(
  8835. 21,
  8836. start - 1
  8837. );
  8838. }
  8839. }
  8840. });
  8841. const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  8842. const stripParensRE = /^\(|\)$/g;
  8843. function parseForExpression(input) {
  8844. const loc = input.loc;
  8845. const exp = input.content;
  8846. const inMatch = exp.match(forAliasRE);
  8847. if (!inMatch)
  8848. return;
  8849. const [, LHS, RHS] = inMatch;
  8850. const createAliasExpression = (content, offset, asParam = false) => {
  8851. const start = loc.start.offset + offset;
  8852. const end = start + content.length;
  8853. return createExp(
  8854. content,
  8855. false,
  8856. getLoc(start, end),
  8857. 0,
  8858. asParam ? 1 /* Params */ : 0 /* Normal */
  8859. );
  8860. };
  8861. const result = {
  8862. source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
  8863. value: void 0,
  8864. key: void 0,
  8865. index: void 0,
  8866. finalized: false
  8867. };
  8868. let valueContent = LHS.trim().replace(stripParensRE, "").trim();
  8869. const trimmedOffset = LHS.indexOf(valueContent);
  8870. const iteratorMatch = valueContent.match(forIteratorRE);
  8871. if (iteratorMatch) {
  8872. valueContent = valueContent.replace(forIteratorRE, "").trim();
  8873. const keyContent = iteratorMatch[1].trim();
  8874. let keyOffset;
  8875. if (keyContent) {
  8876. keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
  8877. result.key = createAliasExpression(keyContent, keyOffset, true);
  8878. }
  8879. if (iteratorMatch[2]) {
  8880. const indexContent = iteratorMatch[2].trim();
  8881. if (indexContent) {
  8882. result.index = createAliasExpression(
  8883. indexContent,
  8884. exp.indexOf(
  8885. indexContent,
  8886. result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
  8887. ),
  8888. true
  8889. );
  8890. }
  8891. }
  8892. }
  8893. if (valueContent) {
  8894. result.value = createAliasExpression(valueContent, trimmedOffset, true);
  8895. }
  8896. return result;
  8897. }
  8898. function getSlice(start, end) {
  8899. return currentInput.slice(start, end);
  8900. }
  8901. function endOpenTag(end) {
  8902. if (tokenizer.inSFCRoot) {
  8903. currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
  8904. }
  8905. addNode(currentOpenTag);
  8906. const { tag, ns } = currentOpenTag;
  8907. if (ns === 0 && currentOptions.isPreTag(tag)) {
  8908. inPre++;
  8909. }
  8910. if (currentOptions.isVoidTag(tag)) {
  8911. onCloseTag(currentOpenTag, end);
  8912. } else {
  8913. stack.unshift(currentOpenTag);
  8914. if (ns === 1 || ns === 2) {
  8915. tokenizer.inXML = true;
  8916. }
  8917. }
  8918. currentOpenTag = null;
  8919. }
  8920. function onText(content, start, end) {
  8921. var _a;
  8922. {
  8923. const tag = (_a = stack[0]) == null ? void 0 : _a.tag;
  8924. if (tag !== "script" && tag !== "style" && content.includes("&")) {
  8925. content = currentOptions.decodeEntities(content, false);
  8926. }
  8927. }
  8928. const parent = stack[0] || currentRoot;
  8929. const lastNode = parent.children[parent.children.length - 1];
  8930. if ((lastNode == null ? void 0 : lastNode.type) === 2) {
  8931. lastNode.content += content;
  8932. setLocEnd(lastNode.loc, end);
  8933. } else {
  8934. parent.children.push({
  8935. type: 2,
  8936. content,
  8937. loc: getLoc(start, end)
  8938. });
  8939. }
  8940. }
  8941. function onCloseTag(el, end, isImplied = false) {
  8942. if (isImplied) {
  8943. setLocEnd(el.loc, backTrack(end, 60));
  8944. } else {
  8945. setLocEnd(el.loc, end + 1);
  8946. }
  8947. if (tokenizer.inSFCRoot) {
  8948. if (el.children.length) {
  8949. el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
  8950. } else {
  8951. el.innerLoc.end = extend({}, el.innerLoc.start);
  8952. }
  8953. el.innerLoc.source = getSlice(
  8954. el.innerLoc.start.offset,
  8955. el.innerLoc.end.offset
  8956. );
  8957. }
  8958. const { tag, ns } = el;
  8959. if (!inVPre) {
  8960. if (tag === "slot") {
  8961. el.tagType = 2;
  8962. } else if (isFragmentTemplate(el)) {
  8963. el.tagType = 3;
  8964. } else if (isComponent(el)) {
  8965. el.tagType = 1;
  8966. }
  8967. }
  8968. if (!tokenizer.inRCDATA) {
  8969. el.children = condenseWhitespace(el.children, el.tag);
  8970. }
  8971. if (ns === 0 && currentOptions.isPreTag(tag)) {
  8972. inPre--;
  8973. }
  8974. if (currentVPreBoundary === el) {
  8975. inVPre = tokenizer.inVPre = false;
  8976. currentVPreBoundary = null;
  8977. }
  8978. if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
  8979. tokenizer.inXML = false;
  8980. }
  8981. {
  8982. const props = el.props;
  8983. if (isCompatEnabled(
  8984. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  8985. currentOptions
  8986. )) {
  8987. let hasIf = false;
  8988. let hasFor = false;
  8989. for (let i = 0; i < props.length; i++) {
  8990. const p = props[i];
  8991. if (p.type === 7) {
  8992. if (p.name === "if") {
  8993. hasIf = true;
  8994. } else if (p.name === "for") {
  8995. hasFor = true;
  8996. }
  8997. }
  8998. if (hasIf && hasFor) {
  8999. warnDeprecation(
  9000. "COMPILER_V_IF_V_FOR_PRECEDENCE",
  9001. currentOptions,
  9002. el.loc
  9003. );
  9004. break;
  9005. }
  9006. }
  9007. }
  9008. if (!tokenizer.inSFCRoot && isCompatEnabled(
  9009. "COMPILER_NATIVE_TEMPLATE",
  9010. currentOptions
  9011. ) && el.tag === "template" && !isFragmentTemplate(el)) {
  9012. warnDeprecation(
  9013. "COMPILER_NATIVE_TEMPLATE",
  9014. currentOptions,
  9015. el.loc
  9016. );
  9017. const parent = stack[0] || currentRoot;
  9018. const index = parent.children.indexOf(el);
  9019. parent.children.splice(index, 1, ...el.children);
  9020. }
  9021. const inlineTemplateProp = props.find(
  9022. (p) => p.type === 6 && p.name === "inline-template"
  9023. );
  9024. if (inlineTemplateProp && checkCompatEnabled(
  9025. "COMPILER_INLINE_TEMPLATE",
  9026. currentOptions,
  9027. inlineTemplateProp.loc
  9028. ) && el.children.length) {
  9029. inlineTemplateProp.value = {
  9030. type: 2,
  9031. content: getSlice(
  9032. el.children[0].loc.start.offset,
  9033. el.children[el.children.length - 1].loc.end.offset
  9034. ),
  9035. loc: inlineTemplateProp.loc
  9036. };
  9037. }
  9038. }
  9039. }
  9040. function backTrack(index, c) {
  9041. let i = index;
  9042. while (currentInput.charCodeAt(i) !== c && i >= 0)
  9043. i--;
  9044. return i;
  9045. }
  9046. const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
  9047. function isFragmentTemplate({ tag, props }) {
  9048. if (tag === "template") {
  9049. for (let i = 0; i < props.length; i++) {
  9050. if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
  9051. return true;
  9052. }
  9053. }
  9054. }
  9055. return false;
  9056. }
  9057. function isComponent({ tag, props }) {
  9058. var _a;
  9059. if (currentOptions.isCustomElement(tag)) {
  9060. return false;
  9061. }
  9062. if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || ((_a = currentOptions.isBuiltInComponent) == null ? void 0 : _a.call(currentOptions, tag)) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
  9063. return true;
  9064. }
  9065. for (let i = 0; i < props.length; i++) {
  9066. const p = props[i];
  9067. if (p.type === 6) {
  9068. if (p.name === "is" && p.value) {
  9069. if (p.value.content.startsWith("vue:")) {
  9070. return true;
  9071. } else if (checkCompatEnabled(
  9072. "COMPILER_IS_ON_ELEMENT",
  9073. currentOptions,
  9074. p.loc
  9075. )) {
  9076. return true;
  9077. }
  9078. }
  9079. } else if (// :is on plain element - only treat as component in compat mode
  9080. p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
  9081. "COMPILER_IS_ON_ELEMENT",
  9082. currentOptions,
  9083. p.loc
  9084. )) {
  9085. return true;
  9086. }
  9087. }
  9088. return false;
  9089. }
  9090. function isUpperCase(c) {
  9091. return c > 64 && c < 91;
  9092. }
  9093. const windowsNewlineRE = /\r\n/g;
  9094. function condenseWhitespace(nodes, tag) {
  9095. var _a, _b;
  9096. const shouldCondense = currentOptions.whitespace !== "preserve";
  9097. let removedWhitespace = false;
  9098. for (let i = 0; i < nodes.length; i++) {
  9099. const node = nodes[i];
  9100. if (node.type === 2) {
  9101. if (!inPre) {
  9102. if (isAllWhitespace(node.content)) {
  9103. const prev = (_a = nodes[i - 1]) == null ? void 0 : _a.type;
  9104. const next = (_b = nodes[i + 1]) == null ? void 0 : _b.type;
  9105. if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
  9106. removedWhitespace = true;
  9107. nodes[i] = null;
  9108. } else {
  9109. node.content = " ";
  9110. }
  9111. } else if (shouldCondense) {
  9112. node.content = condense(node.content);
  9113. }
  9114. } else {
  9115. node.content = node.content.replace(windowsNewlineRE, "\n");
  9116. }
  9117. }
  9118. }
  9119. if (inPre && tag && currentOptions.isPreTag(tag)) {
  9120. const first = nodes[0];
  9121. if (first && first.type === 2) {
  9122. first.content = first.content.replace(/^\r?\n/, "");
  9123. }
  9124. }
  9125. return removedWhitespace ? nodes.filter(Boolean) : nodes;
  9126. }
  9127. function isAllWhitespace(str) {
  9128. for (let i = 0; i < str.length; i++) {
  9129. if (!isWhitespace(str.charCodeAt(i))) {
  9130. return false;
  9131. }
  9132. }
  9133. return true;
  9134. }
  9135. function hasNewlineChar(str) {
  9136. for (let i = 0; i < str.length; i++) {
  9137. const c = str.charCodeAt(i);
  9138. if (c === 10 || c === 13) {
  9139. return true;
  9140. }
  9141. }
  9142. return false;
  9143. }
  9144. function condense(str) {
  9145. let ret = "";
  9146. let prevCharIsWhitespace = false;
  9147. for (let i = 0; i < str.length; i++) {
  9148. if (isWhitespace(str.charCodeAt(i))) {
  9149. if (!prevCharIsWhitespace) {
  9150. ret += " ";
  9151. prevCharIsWhitespace = true;
  9152. }
  9153. } else {
  9154. ret += str[i];
  9155. prevCharIsWhitespace = false;
  9156. }
  9157. }
  9158. return ret;
  9159. }
  9160. function addNode(node) {
  9161. (stack[0] || currentRoot).children.push(node);
  9162. }
  9163. function getLoc(start, end) {
  9164. return {
  9165. start: tokenizer.getPos(start),
  9166. // @ts-expect-error allow late attachment
  9167. end: end == null ? end : tokenizer.getPos(end),
  9168. // @ts-expect-error allow late attachment
  9169. source: end == null ? end : getSlice(start, end)
  9170. };
  9171. }
  9172. function setLocEnd(loc, end) {
  9173. loc.end = tokenizer.getPos(end);
  9174. loc.source = getSlice(loc.start.offset, end);
  9175. }
  9176. function dirToAttr(dir) {
  9177. const attr = {
  9178. type: 6,
  9179. name: dir.rawName,
  9180. nameLoc: getLoc(
  9181. dir.loc.start.offset,
  9182. dir.loc.start.offset + dir.rawName.length
  9183. ),
  9184. value: void 0,
  9185. loc: dir.loc
  9186. };
  9187. if (dir.exp) {
  9188. const loc = dir.exp.loc;
  9189. if (loc.end.offset < dir.loc.end.offset) {
  9190. loc.start.offset--;
  9191. loc.start.column--;
  9192. loc.end.offset++;
  9193. loc.end.column++;
  9194. }
  9195. attr.value = {
  9196. type: 2,
  9197. content: dir.exp.content,
  9198. loc
  9199. };
  9200. }
  9201. return attr;
  9202. }
  9203. function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
  9204. const exp = createSimpleExpression(content, isStatic, loc, constType);
  9205. return exp;
  9206. }
  9207. function emitError(code, index, message) {
  9208. currentOptions.onError(
  9209. createCompilerError(code, getLoc(index, index), void 0, message)
  9210. );
  9211. }
  9212. function reset() {
  9213. tokenizer.reset();
  9214. currentOpenTag = null;
  9215. currentProp = null;
  9216. currentAttrValue = "";
  9217. currentAttrStartIndex = -1;
  9218. currentAttrEndIndex = -1;
  9219. stack.length = 0;
  9220. }
  9221. function baseParse(input, options) {
  9222. reset();
  9223. currentInput = input;
  9224. currentOptions = extend({}, defaultParserOptions);
  9225. if (options) {
  9226. let key;
  9227. for (key in options) {
  9228. if (options[key] != null) {
  9229. currentOptions[key] = options[key];
  9230. }
  9231. }
  9232. }
  9233. {
  9234. if (!currentOptions.decodeEntities) {
  9235. throw new Error(
  9236. `[@vue/compiler-core] decodeEntities option is required in browser builds.`
  9237. );
  9238. }
  9239. }
  9240. tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
  9241. tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
  9242. const delimiters = options == null ? void 0 : options.delimiters;
  9243. if (delimiters) {
  9244. tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
  9245. tokenizer.delimiterClose = toCharCodes(delimiters[1]);
  9246. }
  9247. const root = currentRoot = createRoot([], input);
  9248. tokenizer.parse(currentInput);
  9249. root.loc = getLoc(0, input.length);
  9250. root.children = condenseWhitespace(root.children);
  9251. currentRoot = null;
  9252. return root;
  9253. }
  9254. function hoistStatic(root, context) {
  9255. walk(
  9256. root,
  9257. context,
  9258. // Root node is unfortunately non-hoistable due to potential parent
  9259. // fallthrough attributes.
  9260. isSingleElementRoot(root, root.children[0])
  9261. );
  9262. }
  9263. function isSingleElementRoot(root, child) {
  9264. const { children } = root;
  9265. return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
  9266. }
  9267. function walk(node, context, doNotHoistNode = false) {
  9268. const { children } = node;
  9269. const originalCount = children.length;
  9270. let hoistedCount = 0;
  9271. for (let i = 0; i < children.length; i++) {
  9272. const child = children[i];
  9273. if (child.type === 1 && child.tagType === 0) {
  9274. const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
  9275. if (constantType > 0) {
  9276. if (constantType >= 2) {
  9277. child.codegenNode.patchFlag = -1 + (` /* HOISTED */` );
  9278. child.codegenNode = context.hoist(child.codegenNode);
  9279. hoistedCount++;
  9280. continue;
  9281. }
  9282. } else {
  9283. const codegenNode = child.codegenNode;
  9284. if (codegenNode.type === 13) {
  9285. const flag = getPatchFlag(codegenNode);
  9286. if ((!flag || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
  9287. const props = getNodeProps(child);
  9288. if (props) {
  9289. codegenNode.props = context.hoist(props);
  9290. }
  9291. }
  9292. if (codegenNode.dynamicProps) {
  9293. codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
  9294. }
  9295. }
  9296. }
  9297. }
  9298. if (child.type === 1) {
  9299. const isComponent = child.tagType === 1;
  9300. if (isComponent) {
  9301. context.scopes.vSlot++;
  9302. }
  9303. walk(child, context);
  9304. if (isComponent) {
  9305. context.scopes.vSlot--;
  9306. }
  9307. } else if (child.type === 11) {
  9308. walk(child, context, child.children.length === 1);
  9309. } else if (child.type === 9) {
  9310. for (let i2 = 0; i2 < child.branches.length; i2++) {
  9311. walk(
  9312. child.branches[i2],
  9313. context,
  9314. child.branches[i2].children.length === 1
  9315. );
  9316. }
  9317. }
  9318. }
  9319. if (hoistedCount && context.transformHoist) {
  9320. context.transformHoist(children, context, node);
  9321. }
  9322. if (hoistedCount && hoistedCount === originalCount && node.type === 1 && node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
  9323. const hoisted = context.hoist(
  9324. createArrayExpression(node.codegenNode.children)
  9325. );
  9326. if (context.hmr) {
  9327. hoisted.content = `[...${hoisted.content}]`;
  9328. }
  9329. node.codegenNode.children = hoisted;
  9330. }
  9331. }
  9332. function getConstantType(node, context) {
  9333. const { constantCache } = context;
  9334. switch (node.type) {
  9335. case 1:
  9336. if (node.tagType !== 0) {
  9337. return 0;
  9338. }
  9339. const cached = constantCache.get(node);
  9340. if (cached !== void 0) {
  9341. return cached;
  9342. }
  9343. const codegenNode = node.codegenNode;
  9344. if (codegenNode.type !== 13) {
  9345. return 0;
  9346. }
  9347. if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
  9348. return 0;
  9349. }
  9350. const flag = getPatchFlag(codegenNode);
  9351. if (!flag) {
  9352. let returnType2 = 3;
  9353. const generatedPropsType = getGeneratedPropsConstantType(node, context);
  9354. if (generatedPropsType === 0) {
  9355. constantCache.set(node, 0);
  9356. return 0;
  9357. }
  9358. if (generatedPropsType < returnType2) {
  9359. returnType2 = generatedPropsType;
  9360. }
  9361. for (let i = 0; i < node.children.length; i++) {
  9362. const childType = getConstantType(node.children[i], context);
  9363. if (childType === 0) {
  9364. constantCache.set(node, 0);
  9365. return 0;
  9366. }
  9367. if (childType < returnType2) {
  9368. returnType2 = childType;
  9369. }
  9370. }
  9371. if (returnType2 > 1) {
  9372. for (let i = 0; i < node.props.length; i++) {
  9373. const p = node.props[i];
  9374. if (p.type === 7 && p.name === "bind" && p.exp) {
  9375. const expType = getConstantType(p.exp, context);
  9376. if (expType === 0) {
  9377. constantCache.set(node, 0);
  9378. return 0;
  9379. }
  9380. if (expType < returnType2) {
  9381. returnType2 = expType;
  9382. }
  9383. }
  9384. }
  9385. }
  9386. if (codegenNode.isBlock) {
  9387. for (let i = 0; i < node.props.length; i++) {
  9388. const p = node.props[i];
  9389. if (p.type === 7) {
  9390. constantCache.set(node, 0);
  9391. return 0;
  9392. }
  9393. }
  9394. context.removeHelper(OPEN_BLOCK);
  9395. context.removeHelper(
  9396. getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
  9397. );
  9398. codegenNode.isBlock = false;
  9399. context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
  9400. }
  9401. constantCache.set(node, returnType2);
  9402. return returnType2;
  9403. } else {
  9404. constantCache.set(node, 0);
  9405. return 0;
  9406. }
  9407. case 2:
  9408. case 3:
  9409. return 3;
  9410. case 9:
  9411. case 11:
  9412. case 10:
  9413. return 0;
  9414. case 5:
  9415. case 12:
  9416. return getConstantType(node.content, context);
  9417. case 4:
  9418. return node.constType;
  9419. case 8:
  9420. let returnType = 3;
  9421. for (let i = 0; i < node.children.length; i++) {
  9422. const child = node.children[i];
  9423. if (isString(child) || isSymbol(child)) {
  9424. continue;
  9425. }
  9426. const childType = getConstantType(child, context);
  9427. if (childType === 0) {
  9428. return 0;
  9429. } else if (childType < returnType) {
  9430. returnType = childType;
  9431. }
  9432. }
  9433. return returnType;
  9434. default:
  9435. return 0;
  9436. }
  9437. }
  9438. const allowHoistedHelperSet = /* @__PURE__ */ new Set([
  9439. NORMALIZE_CLASS,
  9440. NORMALIZE_STYLE,
  9441. NORMALIZE_PROPS,
  9442. GUARD_REACTIVE_PROPS
  9443. ]);
  9444. function getConstantTypeOfHelperCall(value, context) {
  9445. if (value.type === 14 && !isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
  9446. const arg = value.arguments[0];
  9447. if (arg.type === 4) {
  9448. return getConstantType(arg, context);
  9449. } else if (arg.type === 14) {
  9450. return getConstantTypeOfHelperCall(arg, context);
  9451. }
  9452. }
  9453. return 0;
  9454. }
  9455. function getGeneratedPropsConstantType(node, context) {
  9456. let returnType = 3;
  9457. const props = getNodeProps(node);
  9458. if (props && props.type === 15) {
  9459. const { properties } = props;
  9460. for (let i = 0; i < properties.length; i++) {
  9461. const { key, value } = properties[i];
  9462. const keyType = getConstantType(key, context);
  9463. if (keyType === 0) {
  9464. return keyType;
  9465. }
  9466. if (keyType < returnType) {
  9467. returnType = keyType;
  9468. }
  9469. let valueType;
  9470. if (value.type === 4) {
  9471. valueType = getConstantType(value, context);
  9472. } else if (value.type === 14) {
  9473. valueType = getConstantTypeOfHelperCall(value, context);
  9474. } else {
  9475. valueType = 0;
  9476. }
  9477. if (valueType === 0) {
  9478. return valueType;
  9479. }
  9480. if (valueType < returnType) {
  9481. returnType = valueType;
  9482. }
  9483. }
  9484. }
  9485. return returnType;
  9486. }
  9487. function getNodeProps(node) {
  9488. const codegenNode = node.codegenNode;
  9489. if (codegenNode.type === 13) {
  9490. return codegenNode.props;
  9491. }
  9492. }
  9493. function getPatchFlag(node) {
  9494. const flag = node.patchFlag;
  9495. return flag ? parseInt(flag, 10) : void 0;
  9496. }
  9497. function createTransformContext(root, {
  9498. filename = "",
  9499. prefixIdentifiers = false,
  9500. hoistStatic: hoistStatic2 = false,
  9501. hmr = false,
  9502. cacheHandlers = false,
  9503. nodeTransforms = [],
  9504. directiveTransforms = {},
  9505. transformHoist = null,
  9506. isBuiltInComponent = NOOP,
  9507. isCustomElement = NOOP,
  9508. expressionPlugins = [],
  9509. scopeId = null,
  9510. slotted = true,
  9511. ssr = false,
  9512. inSSR = false,
  9513. ssrCssVars = ``,
  9514. bindingMetadata = EMPTY_OBJ,
  9515. inline = false,
  9516. isTS = false,
  9517. onError = defaultOnError,
  9518. onWarn = defaultOnWarn,
  9519. compatConfig
  9520. }) {
  9521. const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
  9522. const context = {
  9523. // options
  9524. filename,
  9525. selfName: nameMatch && capitalize(camelize(nameMatch[1])),
  9526. prefixIdentifiers,
  9527. hoistStatic: hoistStatic2,
  9528. hmr,
  9529. cacheHandlers,
  9530. nodeTransforms,
  9531. directiveTransforms,
  9532. transformHoist,
  9533. isBuiltInComponent,
  9534. isCustomElement,
  9535. expressionPlugins,
  9536. scopeId,
  9537. slotted,
  9538. ssr,
  9539. inSSR,
  9540. ssrCssVars,
  9541. bindingMetadata,
  9542. inline,
  9543. isTS,
  9544. onError,
  9545. onWarn,
  9546. compatConfig,
  9547. // state
  9548. root,
  9549. helpers: /* @__PURE__ */ new Map(),
  9550. components: /* @__PURE__ */ new Set(),
  9551. directives: /* @__PURE__ */ new Set(),
  9552. hoists: [],
  9553. imports: [],
  9554. constantCache: /* @__PURE__ */ new WeakMap(),
  9555. temps: 0,
  9556. cached: 0,
  9557. identifiers: /* @__PURE__ */ Object.create(null),
  9558. scopes: {
  9559. vFor: 0,
  9560. vSlot: 0,
  9561. vPre: 0,
  9562. vOnce: 0
  9563. },
  9564. parent: null,
  9565. currentNode: root,
  9566. childIndex: 0,
  9567. inVOnce: false,
  9568. // methods
  9569. helper(name) {
  9570. const count = context.helpers.get(name) || 0;
  9571. context.helpers.set(name, count + 1);
  9572. return name;
  9573. },
  9574. removeHelper(name) {
  9575. const count = context.helpers.get(name);
  9576. if (count) {
  9577. const currentCount = count - 1;
  9578. if (!currentCount) {
  9579. context.helpers.delete(name);
  9580. } else {
  9581. context.helpers.set(name, currentCount);
  9582. }
  9583. }
  9584. },
  9585. helperString(name) {
  9586. return `_${helperNameMap[context.helper(name)]}`;
  9587. },
  9588. replaceNode(node) {
  9589. {
  9590. if (!context.currentNode) {
  9591. throw new Error(`Node being replaced is already removed.`);
  9592. }
  9593. if (!context.parent) {
  9594. throw new Error(`Cannot replace root node.`);
  9595. }
  9596. }
  9597. context.parent.children[context.childIndex] = context.currentNode = node;
  9598. },
  9599. removeNode(node) {
  9600. if (!context.parent) {
  9601. throw new Error(`Cannot remove root node.`);
  9602. }
  9603. const list = context.parent.children;
  9604. const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
  9605. if (removalIndex < 0) {
  9606. throw new Error(`node being removed is not a child of current parent`);
  9607. }
  9608. if (!node || node === context.currentNode) {
  9609. context.currentNode = null;
  9610. context.onNodeRemoved();
  9611. } else {
  9612. if (context.childIndex > removalIndex) {
  9613. context.childIndex--;
  9614. context.onNodeRemoved();
  9615. }
  9616. }
  9617. context.parent.children.splice(removalIndex, 1);
  9618. },
  9619. onNodeRemoved: NOOP,
  9620. addIdentifiers(exp) {
  9621. },
  9622. removeIdentifiers(exp) {
  9623. },
  9624. hoist(exp) {
  9625. if (isString(exp))
  9626. exp = createSimpleExpression(exp);
  9627. context.hoists.push(exp);
  9628. const identifier = createSimpleExpression(
  9629. `_hoisted_${context.hoists.length}`,
  9630. false,
  9631. exp.loc,
  9632. 2
  9633. );
  9634. identifier.hoisted = exp;
  9635. return identifier;
  9636. },
  9637. cache(exp, isVNode = false) {
  9638. return createCacheExpression(context.cached++, exp, isVNode);
  9639. }
  9640. };
  9641. {
  9642. context.filters = /* @__PURE__ */ new Set();
  9643. }
  9644. return context;
  9645. }
  9646. function transform(root, options) {
  9647. const context = createTransformContext(root, options);
  9648. traverseNode(root, context);
  9649. if (options.hoistStatic) {
  9650. hoistStatic(root, context);
  9651. }
  9652. if (!options.ssr) {
  9653. createRootCodegen(root, context);
  9654. }
  9655. root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
  9656. root.components = [...context.components];
  9657. root.directives = [...context.directives];
  9658. root.imports = context.imports;
  9659. root.hoists = context.hoists;
  9660. root.temps = context.temps;
  9661. root.cached = context.cached;
  9662. root.transformed = true;
  9663. {
  9664. root.filters = [...context.filters];
  9665. }
  9666. }
  9667. function createRootCodegen(root, context) {
  9668. const { helper } = context;
  9669. const { children } = root;
  9670. if (children.length === 1) {
  9671. const child = children[0];
  9672. if (isSingleElementRoot(root, child) && child.codegenNode) {
  9673. const codegenNode = child.codegenNode;
  9674. if (codegenNode.type === 13) {
  9675. convertToBlock(codegenNode, context);
  9676. }
  9677. root.codegenNode = codegenNode;
  9678. } else {
  9679. root.codegenNode = child;
  9680. }
  9681. } else if (children.length > 1) {
  9682. let patchFlag = 64;
  9683. let patchFlagText = PatchFlagNames[64];
  9684. if (children.filter((c) => c.type !== 3).length === 1) {
  9685. patchFlag |= 2048;
  9686. patchFlagText += `, ${PatchFlagNames[2048]}`;
  9687. }
  9688. root.codegenNode = createVNodeCall(
  9689. context,
  9690. helper(FRAGMENT),
  9691. void 0,
  9692. root.children,
  9693. patchFlag + (` /* ${patchFlagText} */` ),
  9694. void 0,
  9695. void 0,
  9696. true,
  9697. void 0,
  9698. false
  9699. );
  9700. } else ;
  9701. }
  9702. function traverseChildren(parent, context) {
  9703. let i = 0;
  9704. const nodeRemoved = () => {
  9705. i--;
  9706. };
  9707. for (; i < parent.children.length; i++) {
  9708. const child = parent.children[i];
  9709. if (isString(child))
  9710. continue;
  9711. context.parent = parent;
  9712. context.childIndex = i;
  9713. context.onNodeRemoved = nodeRemoved;
  9714. traverseNode(child, context);
  9715. }
  9716. }
  9717. function traverseNode(node, context) {
  9718. context.currentNode = node;
  9719. const { nodeTransforms } = context;
  9720. const exitFns = [];
  9721. for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
  9722. const onExit = nodeTransforms[i2](node, context);
  9723. if (onExit) {
  9724. if (isArray(onExit)) {
  9725. exitFns.push(...onExit);
  9726. } else {
  9727. exitFns.push(onExit);
  9728. }
  9729. }
  9730. if (!context.currentNode) {
  9731. return;
  9732. } else {
  9733. node = context.currentNode;
  9734. }
  9735. }
  9736. switch (node.type) {
  9737. case 3:
  9738. if (!context.ssr) {
  9739. context.helper(CREATE_COMMENT);
  9740. }
  9741. break;
  9742. case 5:
  9743. if (!context.ssr) {
  9744. context.helper(TO_DISPLAY_STRING);
  9745. }
  9746. break;
  9747. case 9:
  9748. for (let i2 = 0; i2 < node.branches.length; i2++) {
  9749. traverseNode(node.branches[i2], context);
  9750. }
  9751. break;
  9752. case 10:
  9753. case 11:
  9754. case 1:
  9755. case 0:
  9756. traverseChildren(node, context);
  9757. break;
  9758. }
  9759. context.currentNode = node;
  9760. let i = exitFns.length;
  9761. while (i--) {
  9762. exitFns[i]();
  9763. }
  9764. }
  9765. function createStructuralDirectiveTransform(name, fn) {
  9766. const matches = isString(name) ? (n) => n === name : (n) => name.test(n);
  9767. return (node, context) => {
  9768. if (node.type === 1) {
  9769. const { props } = node;
  9770. if (node.tagType === 3 && props.some(isVSlot)) {
  9771. return;
  9772. }
  9773. const exitFns = [];
  9774. for (let i = 0; i < props.length; i++) {
  9775. const prop = props[i];
  9776. if (prop.type === 7 && matches(prop.name)) {
  9777. props.splice(i, 1);
  9778. i--;
  9779. const onExit = fn(node, prop, context);
  9780. if (onExit)
  9781. exitFns.push(onExit);
  9782. }
  9783. }
  9784. return exitFns;
  9785. }
  9786. };
  9787. }
  9788. const PURE_ANNOTATION = `/*#__PURE__*/`;
  9789. const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
  9790. function createCodegenContext(ast, {
  9791. mode = "function",
  9792. prefixIdentifiers = mode === "module",
  9793. sourceMap = false,
  9794. filename = `template.vue.html`,
  9795. scopeId = null,
  9796. optimizeImports = false,
  9797. runtimeGlobalName = `Vue`,
  9798. runtimeModuleName = `vue`,
  9799. ssrRuntimeModuleName = "vue/server-renderer",
  9800. ssr = false,
  9801. isTS = false,
  9802. inSSR = false
  9803. }) {
  9804. const context = {
  9805. mode,
  9806. prefixIdentifiers,
  9807. sourceMap,
  9808. filename,
  9809. scopeId,
  9810. optimizeImports,
  9811. runtimeGlobalName,
  9812. runtimeModuleName,
  9813. ssrRuntimeModuleName,
  9814. ssr,
  9815. isTS,
  9816. inSSR,
  9817. source: ast.source,
  9818. code: ``,
  9819. column: 1,
  9820. line: 1,
  9821. offset: 0,
  9822. indentLevel: 0,
  9823. pure: false,
  9824. map: void 0,
  9825. helper(key) {
  9826. return `_${helperNameMap[key]}`;
  9827. },
  9828. push(code, newlineIndex = -2 /* None */, node) {
  9829. context.code += code;
  9830. },
  9831. indent() {
  9832. newline(++context.indentLevel);
  9833. },
  9834. deindent(withoutNewLine = false) {
  9835. if (withoutNewLine) {
  9836. --context.indentLevel;
  9837. } else {
  9838. newline(--context.indentLevel);
  9839. }
  9840. },
  9841. newline() {
  9842. newline(context.indentLevel);
  9843. }
  9844. };
  9845. function newline(n) {
  9846. context.push("\n" + ` `.repeat(n), 0 /* Start */);
  9847. }
  9848. return context;
  9849. }
  9850. function generate(ast, options = {}) {
  9851. const context = createCodegenContext(ast, options);
  9852. if (options.onContextCreated)
  9853. options.onContextCreated(context);
  9854. const {
  9855. mode,
  9856. push,
  9857. prefixIdentifiers,
  9858. indent,
  9859. deindent,
  9860. newline,
  9861. scopeId,
  9862. ssr
  9863. } = context;
  9864. const helpers = Array.from(ast.helpers);
  9865. const hasHelpers = helpers.length > 0;
  9866. const useWithBlock = !prefixIdentifiers && mode !== "module";
  9867. const preambleContext = context;
  9868. {
  9869. genFunctionPreamble(ast, preambleContext);
  9870. }
  9871. const functionName = ssr ? `ssrRender` : `render`;
  9872. const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
  9873. const signature = args.join(", ");
  9874. {
  9875. push(`function ${functionName}(${signature}) {`);
  9876. }
  9877. indent();
  9878. if (useWithBlock) {
  9879. push(`with (_ctx) {`);
  9880. indent();
  9881. if (hasHelpers) {
  9882. push(
  9883. `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
  9884. `,
  9885. -1 /* End */
  9886. );
  9887. newline();
  9888. }
  9889. }
  9890. if (ast.components.length) {
  9891. genAssets(ast.components, "component", context);
  9892. if (ast.directives.length || ast.temps > 0) {
  9893. newline();
  9894. }
  9895. }
  9896. if (ast.directives.length) {
  9897. genAssets(ast.directives, "directive", context);
  9898. if (ast.temps > 0) {
  9899. newline();
  9900. }
  9901. }
  9902. if (ast.filters && ast.filters.length) {
  9903. newline();
  9904. genAssets(ast.filters, "filter", context);
  9905. newline();
  9906. }
  9907. if (ast.temps > 0) {
  9908. push(`let `);
  9909. for (let i = 0; i < ast.temps; i++) {
  9910. push(`${i > 0 ? `, ` : ``}_temp${i}`);
  9911. }
  9912. }
  9913. if (ast.components.length || ast.directives.length || ast.temps) {
  9914. push(`
  9915. `, 0 /* Start */);
  9916. newline();
  9917. }
  9918. if (!ssr) {
  9919. push(`return `);
  9920. }
  9921. if (ast.codegenNode) {
  9922. genNode(ast.codegenNode, context);
  9923. } else {
  9924. push(`null`);
  9925. }
  9926. if (useWithBlock) {
  9927. deindent();
  9928. push(`}`);
  9929. }
  9930. deindent();
  9931. push(`}`);
  9932. return {
  9933. ast,
  9934. code: context.code,
  9935. preamble: ``,
  9936. map: context.map ? context.map.toJSON() : void 0
  9937. };
  9938. }
  9939. function genFunctionPreamble(ast, context) {
  9940. const {
  9941. ssr,
  9942. prefixIdentifiers,
  9943. push,
  9944. newline,
  9945. runtimeModuleName,
  9946. runtimeGlobalName,
  9947. ssrRuntimeModuleName
  9948. } = context;
  9949. const VueBinding = runtimeGlobalName;
  9950. const helpers = Array.from(ast.helpers);
  9951. if (helpers.length > 0) {
  9952. {
  9953. push(`const _Vue = ${VueBinding}
  9954. `, -1 /* End */);
  9955. if (ast.hoists.length) {
  9956. const staticHelpers = [
  9957. CREATE_VNODE,
  9958. CREATE_ELEMENT_VNODE,
  9959. CREATE_COMMENT,
  9960. CREATE_TEXT,
  9961. CREATE_STATIC
  9962. ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
  9963. push(`const { ${staticHelpers} } = _Vue
  9964. `, -1 /* End */);
  9965. }
  9966. }
  9967. }
  9968. genHoists(ast.hoists, context);
  9969. newline();
  9970. push(`return `);
  9971. }
  9972. function genAssets(assets, type, { helper, push, newline, isTS }) {
  9973. const resolver = helper(
  9974. type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
  9975. );
  9976. for (let i = 0; i < assets.length; i++) {
  9977. let id = assets[i];
  9978. const maybeSelfReference = id.endsWith("__self");
  9979. if (maybeSelfReference) {
  9980. id = id.slice(0, -6);
  9981. }
  9982. push(
  9983. `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
  9984. );
  9985. if (i < assets.length - 1) {
  9986. newline();
  9987. }
  9988. }
  9989. }
  9990. function genHoists(hoists, context) {
  9991. if (!hoists.length) {
  9992. return;
  9993. }
  9994. context.pure = true;
  9995. const { push, newline, helper, scopeId, mode } = context;
  9996. newline();
  9997. for (let i = 0; i < hoists.length; i++) {
  9998. const exp = hoists[i];
  9999. if (exp) {
  10000. push(
  10001. `const _hoisted_${i + 1} = ${``}`
  10002. );
  10003. genNode(exp, context);
  10004. newline();
  10005. }
  10006. }
  10007. context.pure = false;
  10008. }
  10009. function isText(n) {
  10010. return isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
  10011. }
  10012. function genNodeListAsArray(nodes, context) {
  10013. const multilines = nodes.length > 3 || nodes.some((n) => isArray(n) || !isText(n));
  10014. context.push(`[`);
  10015. multilines && context.indent();
  10016. genNodeList(nodes, context, multilines);
  10017. multilines && context.deindent();
  10018. context.push(`]`);
  10019. }
  10020. function genNodeList(nodes, context, multilines = false, comma = true) {
  10021. const { push, newline } = context;
  10022. for (let i = 0; i < nodes.length; i++) {
  10023. const node = nodes[i];
  10024. if (isString(node)) {
  10025. push(node, -3 /* Unknown */);
  10026. } else if (isArray(node)) {
  10027. genNodeListAsArray(node, context);
  10028. } else {
  10029. genNode(node, context);
  10030. }
  10031. if (i < nodes.length - 1) {
  10032. if (multilines) {
  10033. comma && push(",");
  10034. newline();
  10035. } else {
  10036. comma && push(", ");
  10037. }
  10038. }
  10039. }
  10040. }
  10041. function genNode(node, context) {
  10042. if (isString(node)) {
  10043. context.push(node, -3 /* Unknown */);
  10044. return;
  10045. }
  10046. if (isSymbol(node)) {
  10047. context.push(context.helper(node));
  10048. return;
  10049. }
  10050. switch (node.type) {
  10051. case 1:
  10052. case 9:
  10053. case 11:
  10054. assert(
  10055. node.codegenNode != null,
  10056. `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
  10057. );
  10058. genNode(node.codegenNode, context);
  10059. break;
  10060. case 2:
  10061. genText(node, context);
  10062. break;
  10063. case 4:
  10064. genExpression(node, context);
  10065. break;
  10066. case 5:
  10067. genInterpolation(node, context);
  10068. break;
  10069. case 12:
  10070. genNode(node.codegenNode, context);
  10071. break;
  10072. case 8:
  10073. genCompoundExpression(node, context);
  10074. break;
  10075. case 3:
  10076. genComment(node, context);
  10077. break;
  10078. case 13:
  10079. genVNodeCall(node, context);
  10080. break;
  10081. case 14:
  10082. genCallExpression(node, context);
  10083. break;
  10084. case 15:
  10085. genObjectExpression(node, context);
  10086. break;
  10087. case 17:
  10088. genArrayExpression(node, context);
  10089. break;
  10090. case 18:
  10091. genFunctionExpression(node, context);
  10092. break;
  10093. case 19:
  10094. genConditionalExpression(node, context);
  10095. break;
  10096. case 20:
  10097. genCacheExpression(node, context);
  10098. break;
  10099. case 21:
  10100. genNodeList(node.body, context, true, false);
  10101. break;
  10102. case 22:
  10103. break;
  10104. case 23:
  10105. break;
  10106. case 24:
  10107. break;
  10108. case 25:
  10109. break;
  10110. case 26:
  10111. break;
  10112. case 10:
  10113. break;
  10114. default:
  10115. {
  10116. assert(false, `unhandled codegen node type: ${node.type}`);
  10117. const exhaustiveCheck = node;
  10118. return exhaustiveCheck;
  10119. }
  10120. }
  10121. }
  10122. function genText(node, context) {
  10123. context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
  10124. }
  10125. function genExpression(node, context) {
  10126. const { content, isStatic } = node;
  10127. context.push(
  10128. isStatic ? JSON.stringify(content) : content,
  10129. -3 /* Unknown */,
  10130. node
  10131. );
  10132. }
  10133. function genInterpolation(node, context) {
  10134. const { push, helper, pure } = context;
  10135. if (pure)
  10136. push(PURE_ANNOTATION);
  10137. push(`${helper(TO_DISPLAY_STRING)}(`);
  10138. genNode(node.content, context);
  10139. push(`)`);
  10140. }
  10141. function genCompoundExpression(node, context) {
  10142. for (let i = 0; i < node.children.length; i++) {
  10143. const child = node.children[i];
  10144. if (isString(child)) {
  10145. context.push(child, -3 /* Unknown */);
  10146. } else {
  10147. genNode(child, context);
  10148. }
  10149. }
  10150. }
  10151. function genExpressionAsPropertyKey(node, context) {
  10152. const { push } = context;
  10153. if (node.type === 8) {
  10154. push(`[`);
  10155. genCompoundExpression(node, context);
  10156. push(`]`);
  10157. } else if (node.isStatic) {
  10158. const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
  10159. push(text, -2 /* None */, node);
  10160. } else {
  10161. push(`[${node.content}]`, -3 /* Unknown */, node);
  10162. }
  10163. }
  10164. function genComment(node, context) {
  10165. const { push, helper, pure } = context;
  10166. if (pure) {
  10167. push(PURE_ANNOTATION);
  10168. }
  10169. push(
  10170. `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
  10171. -3 /* Unknown */,
  10172. node
  10173. );
  10174. }
  10175. function genVNodeCall(node, context) {
  10176. const { push, helper, pure } = context;
  10177. const {
  10178. tag,
  10179. props,
  10180. children,
  10181. patchFlag,
  10182. dynamicProps,
  10183. directives,
  10184. isBlock,
  10185. disableTracking,
  10186. isComponent
  10187. } = node;
  10188. if (directives) {
  10189. push(helper(WITH_DIRECTIVES) + `(`);
  10190. }
  10191. if (isBlock) {
  10192. push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
  10193. }
  10194. if (pure) {
  10195. push(PURE_ANNOTATION);
  10196. }
  10197. const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
  10198. push(helper(callHelper) + `(`, -2 /* None */, node);
  10199. genNodeList(
  10200. genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
  10201. context
  10202. );
  10203. push(`)`);
  10204. if (isBlock) {
  10205. push(`)`);
  10206. }
  10207. if (directives) {
  10208. push(`, `);
  10209. genNode(directives, context);
  10210. push(`)`);
  10211. }
  10212. }
  10213. function genNullableArgs(args) {
  10214. let i = args.length;
  10215. while (i--) {
  10216. if (args[i] != null)
  10217. break;
  10218. }
  10219. return args.slice(0, i + 1).map((arg) => arg || `null`);
  10220. }
  10221. function genCallExpression(node, context) {
  10222. const { push, helper, pure } = context;
  10223. const callee = isString(node.callee) ? node.callee : helper(node.callee);
  10224. if (pure) {
  10225. push(PURE_ANNOTATION);
  10226. }
  10227. push(callee + `(`, -2 /* None */, node);
  10228. genNodeList(node.arguments, context);
  10229. push(`)`);
  10230. }
  10231. function genObjectExpression(node, context) {
  10232. const { push, indent, deindent, newline } = context;
  10233. const { properties } = node;
  10234. if (!properties.length) {
  10235. push(`{}`, -2 /* None */, node);
  10236. return;
  10237. }
  10238. const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
  10239. push(multilines ? `{` : `{ `);
  10240. multilines && indent();
  10241. for (let i = 0; i < properties.length; i++) {
  10242. const { key, value } = properties[i];
  10243. genExpressionAsPropertyKey(key, context);
  10244. push(`: `);
  10245. genNode(value, context);
  10246. if (i < properties.length - 1) {
  10247. push(`,`);
  10248. newline();
  10249. }
  10250. }
  10251. multilines && deindent();
  10252. push(multilines ? `}` : ` }`);
  10253. }
  10254. function genArrayExpression(node, context) {
  10255. genNodeListAsArray(node.elements, context);
  10256. }
  10257. function genFunctionExpression(node, context) {
  10258. const { push, indent, deindent } = context;
  10259. const { params, returns, body, newline, isSlot } = node;
  10260. if (isSlot) {
  10261. push(`_${helperNameMap[WITH_CTX]}(`);
  10262. }
  10263. push(`(`, -2 /* None */, node);
  10264. if (isArray(params)) {
  10265. genNodeList(params, context);
  10266. } else if (params) {
  10267. genNode(params, context);
  10268. }
  10269. push(`) => `);
  10270. if (newline || body) {
  10271. push(`{`);
  10272. indent();
  10273. }
  10274. if (returns) {
  10275. if (newline) {
  10276. push(`return `);
  10277. }
  10278. if (isArray(returns)) {
  10279. genNodeListAsArray(returns, context);
  10280. } else {
  10281. genNode(returns, context);
  10282. }
  10283. } else if (body) {
  10284. genNode(body, context);
  10285. }
  10286. if (newline || body) {
  10287. deindent();
  10288. push(`}`);
  10289. }
  10290. if (isSlot) {
  10291. if (node.isNonScopedSlot) {
  10292. push(`, undefined, true`);
  10293. }
  10294. push(`)`);
  10295. }
  10296. }
  10297. function genConditionalExpression(node, context) {
  10298. const { test, consequent, alternate, newline: needNewline } = node;
  10299. const { push, indent, deindent, newline } = context;
  10300. if (test.type === 4) {
  10301. const needsParens = !isSimpleIdentifier(test.content);
  10302. needsParens && push(`(`);
  10303. genExpression(test, context);
  10304. needsParens && push(`)`);
  10305. } else {
  10306. push(`(`);
  10307. genNode(test, context);
  10308. push(`)`);
  10309. }
  10310. needNewline && indent();
  10311. context.indentLevel++;
  10312. needNewline || push(` `);
  10313. push(`? `);
  10314. genNode(consequent, context);
  10315. context.indentLevel--;
  10316. needNewline && newline();
  10317. needNewline || push(` `);
  10318. push(`: `);
  10319. const isNested = alternate.type === 19;
  10320. if (!isNested) {
  10321. context.indentLevel++;
  10322. }
  10323. genNode(alternate, context);
  10324. if (!isNested) {
  10325. context.indentLevel--;
  10326. }
  10327. needNewline && deindent(
  10328. true
  10329. /* without newline */
  10330. );
  10331. }
  10332. function genCacheExpression(node, context) {
  10333. const { push, helper, indent, deindent, newline } = context;
  10334. push(`_cache[${node.index}] || (`);
  10335. if (node.isVNode) {
  10336. indent();
  10337. push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
  10338. newline();
  10339. }
  10340. push(`_cache[${node.index}] = `);
  10341. genNode(node.value, context);
  10342. if (node.isVNode) {
  10343. push(`,`);
  10344. newline();
  10345. push(`${helper(SET_BLOCK_TRACKING)}(1),`);
  10346. newline();
  10347. push(`_cache[${node.index}]`);
  10348. deindent();
  10349. }
  10350. push(`)`);
  10351. }
  10352. const prohibitedKeywordRE = new RegExp(
  10353. "\\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"
  10354. );
  10355. const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
  10356. function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
  10357. const exp = node.content;
  10358. if (!exp.trim()) {
  10359. return;
  10360. }
  10361. try {
  10362. new Function(
  10363. asRawStatements ? ` ${exp} ` : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`
  10364. );
  10365. } catch (e) {
  10366. let message = e.message;
  10367. const keywordMatch = exp.replace(stripStringRE, "").match(prohibitedKeywordRE);
  10368. if (keywordMatch) {
  10369. message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
  10370. }
  10371. context.onError(
  10372. createCompilerError(
  10373. 45,
  10374. node.loc,
  10375. void 0,
  10376. message
  10377. )
  10378. );
  10379. }
  10380. }
  10381. const transformExpression = (node, context) => {
  10382. if (node.type === 5) {
  10383. node.content = processExpression(
  10384. node.content,
  10385. context
  10386. );
  10387. } else if (node.type === 1) {
  10388. for (let i = 0; i < node.props.length; i++) {
  10389. const dir = node.props[i];
  10390. if (dir.type === 7 && dir.name !== "for") {
  10391. const exp = dir.exp;
  10392. const arg = dir.arg;
  10393. if (exp && exp.type === 4 && !(dir.name === "on" && arg)) {
  10394. dir.exp = processExpression(
  10395. exp,
  10396. context,
  10397. // slot args must be processed as function params
  10398. dir.name === "slot"
  10399. );
  10400. }
  10401. if (arg && arg.type === 4 && !arg.isStatic) {
  10402. dir.arg = processExpression(arg, context);
  10403. }
  10404. }
  10405. }
  10406. }
  10407. };
  10408. function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
  10409. {
  10410. {
  10411. validateBrowserExpression(node, context, asParams, asRawStatements);
  10412. }
  10413. return node;
  10414. }
  10415. }
  10416. const transformIf = createStructuralDirectiveTransform(
  10417. /^(if|else|else-if)$/,
  10418. (node, dir, context) => {
  10419. return processIf(node, dir, context, (ifNode, branch, isRoot) => {
  10420. const siblings = context.parent.children;
  10421. let i = siblings.indexOf(ifNode);
  10422. let key = 0;
  10423. while (i-- >= 0) {
  10424. const sibling = siblings[i];
  10425. if (sibling && sibling.type === 9) {
  10426. key += sibling.branches.length;
  10427. }
  10428. }
  10429. return () => {
  10430. if (isRoot) {
  10431. ifNode.codegenNode = createCodegenNodeForBranch(
  10432. branch,
  10433. key,
  10434. context
  10435. );
  10436. } else {
  10437. const parentCondition = getParentCondition(ifNode.codegenNode);
  10438. parentCondition.alternate = createCodegenNodeForBranch(
  10439. branch,
  10440. key + ifNode.branches.length - 1,
  10441. context
  10442. );
  10443. }
  10444. };
  10445. });
  10446. }
  10447. );
  10448. function processIf(node, dir, context, processCodegen) {
  10449. if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
  10450. const loc = dir.exp ? dir.exp.loc : node.loc;
  10451. context.onError(
  10452. createCompilerError(28, dir.loc)
  10453. );
  10454. dir.exp = createSimpleExpression(`true`, false, loc);
  10455. }
  10456. if (dir.exp) {
  10457. validateBrowserExpression(dir.exp, context);
  10458. }
  10459. if (dir.name === "if") {
  10460. const branch = createIfBranch(node, dir);
  10461. const ifNode = {
  10462. type: 9,
  10463. loc: node.loc,
  10464. branches: [branch]
  10465. };
  10466. context.replaceNode(ifNode);
  10467. if (processCodegen) {
  10468. return processCodegen(ifNode, branch, true);
  10469. }
  10470. } else {
  10471. const siblings = context.parent.children;
  10472. const comments = [];
  10473. let i = siblings.indexOf(node);
  10474. while (i-- >= -1) {
  10475. const sibling = siblings[i];
  10476. if (sibling && sibling.type === 3) {
  10477. context.removeNode(sibling);
  10478. comments.unshift(sibling);
  10479. continue;
  10480. }
  10481. if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
  10482. context.removeNode(sibling);
  10483. continue;
  10484. }
  10485. if (sibling && sibling.type === 9) {
  10486. if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
  10487. context.onError(
  10488. createCompilerError(30, node.loc)
  10489. );
  10490. }
  10491. context.removeNode();
  10492. const branch = createIfBranch(node, dir);
  10493. if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
  10494. !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
  10495. branch.children = [...comments, ...branch.children];
  10496. }
  10497. {
  10498. const key = branch.userKey;
  10499. if (key) {
  10500. sibling.branches.forEach(({ userKey }) => {
  10501. if (isSameKey(userKey, key)) {
  10502. context.onError(
  10503. createCompilerError(
  10504. 29,
  10505. branch.userKey.loc
  10506. )
  10507. );
  10508. }
  10509. });
  10510. }
  10511. }
  10512. sibling.branches.push(branch);
  10513. const onExit = processCodegen && processCodegen(sibling, branch, false);
  10514. traverseNode(branch, context);
  10515. if (onExit)
  10516. onExit();
  10517. context.currentNode = null;
  10518. } else {
  10519. context.onError(
  10520. createCompilerError(30, node.loc)
  10521. );
  10522. }
  10523. break;
  10524. }
  10525. }
  10526. }
  10527. function createIfBranch(node, dir) {
  10528. const isTemplateIf = node.tagType === 3;
  10529. return {
  10530. type: 10,
  10531. loc: node.loc,
  10532. condition: dir.name === "else" ? void 0 : dir.exp,
  10533. children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
  10534. userKey: findProp(node, `key`),
  10535. isTemplateIf
  10536. };
  10537. }
  10538. function createCodegenNodeForBranch(branch, keyIndex, context) {
  10539. if (branch.condition) {
  10540. return createConditionalExpression(
  10541. branch.condition,
  10542. createChildrenCodegenNode(branch, keyIndex, context),
  10543. // make sure to pass in asBlock: true so that the comment node call
  10544. // closes the current block.
  10545. createCallExpression(context.helper(CREATE_COMMENT), [
  10546. '"v-if"' ,
  10547. "true"
  10548. ])
  10549. );
  10550. } else {
  10551. return createChildrenCodegenNode(branch, keyIndex, context);
  10552. }
  10553. }
  10554. function createChildrenCodegenNode(branch, keyIndex, context) {
  10555. const { helper } = context;
  10556. const keyProperty = createObjectProperty(
  10557. `key`,
  10558. createSimpleExpression(
  10559. `${keyIndex}`,
  10560. false,
  10561. locStub,
  10562. 2
  10563. )
  10564. );
  10565. const { children } = branch;
  10566. const firstChild = children[0];
  10567. const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
  10568. if (needFragmentWrapper) {
  10569. if (children.length === 1 && firstChild.type === 11) {
  10570. const vnodeCall = firstChild.codegenNode;
  10571. injectProp(vnodeCall, keyProperty, context);
  10572. return vnodeCall;
  10573. } else {
  10574. let patchFlag = 64;
  10575. let patchFlagText = PatchFlagNames[64];
  10576. if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
  10577. patchFlag |= 2048;
  10578. patchFlagText += `, ${PatchFlagNames[2048]}`;
  10579. }
  10580. return createVNodeCall(
  10581. context,
  10582. helper(FRAGMENT),
  10583. createObjectExpression([keyProperty]),
  10584. children,
  10585. patchFlag + (` /* ${patchFlagText} */` ),
  10586. void 0,
  10587. void 0,
  10588. true,
  10589. false,
  10590. false,
  10591. branch.loc
  10592. );
  10593. }
  10594. } else {
  10595. const ret = firstChild.codegenNode;
  10596. const vnodeCall = getMemoedVNodeCall(ret);
  10597. if (vnodeCall.type === 13) {
  10598. convertToBlock(vnodeCall, context);
  10599. }
  10600. injectProp(vnodeCall, keyProperty, context);
  10601. return ret;
  10602. }
  10603. }
  10604. function isSameKey(a, b) {
  10605. if (!a || a.type !== b.type) {
  10606. return false;
  10607. }
  10608. if (a.type === 6) {
  10609. if (a.value.content !== b.value.content) {
  10610. return false;
  10611. }
  10612. } else {
  10613. const exp = a.exp;
  10614. const branchExp = b.exp;
  10615. if (exp.type !== branchExp.type) {
  10616. return false;
  10617. }
  10618. if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
  10619. return false;
  10620. }
  10621. }
  10622. return true;
  10623. }
  10624. function getParentCondition(node) {
  10625. while (true) {
  10626. if (node.type === 19) {
  10627. if (node.alternate.type === 19) {
  10628. node = node.alternate;
  10629. } else {
  10630. return node;
  10631. }
  10632. } else if (node.type === 20) {
  10633. node = node.value;
  10634. }
  10635. }
  10636. }
  10637. const transformFor = createStructuralDirectiveTransform(
  10638. "for",
  10639. (node, dir, context) => {
  10640. const { helper, removeHelper } = context;
  10641. return processFor(node, dir, context, (forNode) => {
  10642. const renderExp = createCallExpression(helper(RENDER_LIST), [
  10643. forNode.source
  10644. ]);
  10645. const isTemplate = isTemplateNode(node);
  10646. const memo = findDir(node, "memo");
  10647. const keyProp = findProp(node, `key`);
  10648. const keyExp = keyProp && (keyProp.type === 6 ? createSimpleExpression(keyProp.value.content, true) : keyProp.exp);
  10649. const keyProperty = keyProp ? createObjectProperty(`key`, keyExp) : null;
  10650. const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
  10651. const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
  10652. forNode.codegenNode = createVNodeCall(
  10653. context,
  10654. helper(FRAGMENT),
  10655. void 0,
  10656. renderExp,
  10657. fragmentFlag + (` /* ${PatchFlagNames[fragmentFlag]} */` ),
  10658. void 0,
  10659. void 0,
  10660. true,
  10661. !isStableFragment,
  10662. false,
  10663. node.loc
  10664. );
  10665. return () => {
  10666. let childBlock;
  10667. const { children } = forNode;
  10668. if (isTemplate) {
  10669. node.children.some((c) => {
  10670. if (c.type === 1) {
  10671. const key = findProp(c, "key");
  10672. if (key) {
  10673. context.onError(
  10674. createCompilerError(
  10675. 33,
  10676. key.loc
  10677. )
  10678. );
  10679. return true;
  10680. }
  10681. }
  10682. });
  10683. }
  10684. const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
  10685. const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
  10686. if (slotOutlet) {
  10687. childBlock = slotOutlet.codegenNode;
  10688. if (isTemplate && keyProperty) {
  10689. injectProp(childBlock, keyProperty, context);
  10690. }
  10691. } else if (needFragmentWrapper) {
  10692. childBlock = createVNodeCall(
  10693. context,
  10694. helper(FRAGMENT),
  10695. keyProperty ? createObjectExpression([keyProperty]) : void 0,
  10696. node.children,
  10697. 64 + (` /* ${PatchFlagNames[64]} */` ),
  10698. void 0,
  10699. void 0,
  10700. true,
  10701. void 0,
  10702. false
  10703. );
  10704. } else {
  10705. childBlock = children[0].codegenNode;
  10706. if (isTemplate && keyProperty) {
  10707. injectProp(childBlock, keyProperty, context);
  10708. }
  10709. if (childBlock.isBlock !== !isStableFragment) {
  10710. if (childBlock.isBlock) {
  10711. removeHelper(OPEN_BLOCK);
  10712. removeHelper(
  10713. getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
  10714. );
  10715. } else {
  10716. removeHelper(
  10717. getVNodeHelper(context.inSSR, childBlock.isComponent)
  10718. );
  10719. }
  10720. }
  10721. childBlock.isBlock = !isStableFragment;
  10722. if (childBlock.isBlock) {
  10723. helper(OPEN_BLOCK);
  10724. helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
  10725. } else {
  10726. helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
  10727. }
  10728. }
  10729. if (memo) {
  10730. const loop = createFunctionExpression(
  10731. createForLoopParams(forNode.parseResult, [
  10732. createSimpleExpression(`_cached`)
  10733. ])
  10734. );
  10735. loop.body = createBlockStatement([
  10736. createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
  10737. createCompoundExpression([
  10738. `if (_cached`,
  10739. ...keyExp ? [` && _cached.key === `, keyExp] : [],
  10740. ` && ${context.helperString(
  10741. IS_MEMO_SAME
  10742. )}(_cached, _memo)) return _cached`
  10743. ]),
  10744. createCompoundExpression([`const _item = `, childBlock]),
  10745. createSimpleExpression(`_item.memo = _memo`),
  10746. createSimpleExpression(`return _item`)
  10747. ]);
  10748. renderExp.arguments.push(
  10749. loop,
  10750. createSimpleExpression(`_cache`),
  10751. createSimpleExpression(String(context.cached++))
  10752. );
  10753. } else {
  10754. renderExp.arguments.push(
  10755. createFunctionExpression(
  10756. createForLoopParams(forNode.parseResult),
  10757. childBlock,
  10758. true
  10759. )
  10760. );
  10761. }
  10762. };
  10763. });
  10764. }
  10765. );
  10766. function processFor(node, dir, context, processCodegen) {
  10767. if (!dir.exp) {
  10768. context.onError(
  10769. createCompilerError(31, dir.loc)
  10770. );
  10771. return;
  10772. }
  10773. const parseResult = dir.forParseResult;
  10774. if (!parseResult) {
  10775. context.onError(
  10776. createCompilerError(32, dir.loc)
  10777. );
  10778. return;
  10779. }
  10780. finalizeForParseResult(parseResult, context);
  10781. const { addIdentifiers, removeIdentifiers, scopes } = context;
  10782. const { source, value, key, index } = parseResult;
  10783. const forNode = {
  10784. type: 11,
  10785. loc: dir.loc,
  10786. source,
  10787. valueAlias: value,
  10788. keyAlias: key,
  10789. objectIndexAlias: index,
  10790. parseResult,
  10791. children: isTemplateNode(node) ? node.children : [node]
  10792. };
  10793. context.replaceNode(forNode);
  10794. scopes.vFor++;
  10795. const onExit = processCodegen && processCodegen(forNode);
  10796. return () => {
  10797. scopes.vFor--;
  10798. if (onExit)
  10799. onExit();
  10800. };
  10801. }
  10802. function finalizeForParseResult(result, context) {
  10803. if (result.finalized)
  10804. return;
  10805. {
  10806. validateBrowserExpression(result.source, context);
  10807. if (result.key) {
  10808. validateBrowserExpression(
  10809. result.key,
  10810. context,
  10811. true
  10812. );
  10813. }
  10814. if (result.index) {
  10815. validateBrowserExpression(
  10816. result.index,
  10817. context,
  10818. true
  10819. );
  10820. }
  10821. if (result.value) {
  10822. validateBrowserExpression(
  10823. result.value,
  10824. context,
  10825. true
  10826. );
  10827. }
  10828. }
  10829. result.finalized = true;
  10830. }
  10831. function createForLoopParams({ value, key, index }, memoArgs = []) {
  10832. return createParamsList([value, key, index, ...memoArgs]);
  10833. }
  10834. function createParamsList(args) {
  10835. let i = args.length;
  10836. while (i--) {
  10837. if (args[i])
  10838. break;
  10839. }
  10840. return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
  10841. }
  10842. const defaultFallback = createSimpleExpression(`undefined`, false);
  10843. const trackSlotScopes = (node, context) => {
  10844. if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
  10845. const vSlot = findDir(node, "slot");
  10846. if (vSlot) {
  10847. vSlot.exp;
  10848. context.scopes.vSlot++;
  10849. return () => {
  10850. context.scopes.vSlot--;
  10851. };
  10852. }
  10853. }
  10854. };
  10855. const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
  10856. props,
  10857. children,
  10858. false,
  10859. true,
  10860. children.length ? children[0].loc : loc
  10861. );
  10862. function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
  10863. context.helper(WITH_CTX);
  10864. const { children, loc } = node;
  10865. const slotsProperties = [];
  10866. const dynamicSlots = [];
  10867. let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
  10868. const onComponentSlot = findDir(node, "slot", true);
  10869. if (onComponentSlot) {
  10870. const { arg, exp } = onComponentSlot;
  10871. if (arg && !isStaticExp(arg)) {
  10872. hasDynamicSlots = true;
  10873. }
  10874. slotsProperties.push(
  10875. createObjectProperty(
  10876. arg || createSimpleExpression("default", true),
  10877. buildSlotFn(exp, void 0, children, loc)
  10878. )
  10879. );
  10880. }
  10881. let hasTemplateSlots = false;
  10882. let hasNamedDefaultSlot = false;
  10883. const implicitDefaultChildren = [];
  10884. const seenSlotNames = /* @__PURE__ */ new Set();
  10885. let conditionalBranchIndex = 0;
  10886. for (let i = 0; i < children.length; i++) {
  10887. const slotElement = children[i];
  10888. let slotDir;
  10889. if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
  10890. if (slotElement.type !== 3) {
  10891. implicitDefaultChildren.push(slotElement);
  10892. }
  10893. continue;
  10894. }
  10895. if (onComponentSlot) {
  10896. context.onError(
  10897. createCompilerError(37, slotDir.loc)
  10898. );
  10899. break;
  10900. }
  10901. hasTemplateSlots = true;
  10902. const { children: slotChildren, loc: slotLoc } = slotElement;
  10903. const {
  10904. arg: slotName = createSimpleExpression(`default`, true),
  10905. exp: slotProps,
  10906. loc: dirLoc
  10907. } = slotDir;
  10908. let staticSlotName;
  10909. if (isStaticExp(slotName)) {
  10910. staticSlotName = slotName ? slotName.content : `default`;
  10911. } else {
  10912. hasDynamicSlots = true;
  10913. }
  10914. const vFor = findDir(slotElement, "for");
  10915. const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
  10916. let vIf;
  10917. let vElse;
  10918. if (vIf = findDir(slotElement, "if")) {
  10919. hasDynamicSlots = true;
  10920. dynamicSlots.push(
  10921. createConditionalExpression(
  10922. vIf.exp,
  10923. buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
  10924. defaultFallback
  10925. )
  10926. );
  10927. } else if (vElse = findDir(
  10928. slotElement,
  10929. /^else(-if)?$/,
  10930. true
  10931. /* allowEmpty */
  10932. )) {
  10933. let j = i;
  10934. let prev;
  10935. while (j--) {
  10936. prev = children[j];
  10937. if (prev.type !== 3) {
  10938. break;
  10939. }
  10940. }
  10941. if (prev && isTemplateNode(prev) && findDir(prev, "if")) {
  10942. children.splice(i, 1);
  10943. i--;
  10944. let conditional = dynamicSlots[dynamicSlots.length - 1];
  10945. while (conditional.alternate.type === 19) {
  10946. conditional = conditional.alternate;
  10947. }
  10948. conditional.alternate = vElse.exp ? createConditionalExpression(
  10949. vElse.exp,
  10950. buildDynamicSlot(
  10951. slotName,
  10952. slotFunction,
  10953. conditionalBranchIndex++
  10954. ),
  10955. defaultFallback
  10956. ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
  10957. } else {
  10958. context.onError(
  10959. createCompilerError(30, vElse.loc)
  10960. );
  10961. }
  10962. } else if (vFor) {
  10963. hasDynamicSlots = true;
  10964. const parseResult = vFor.forParseResult;
  10965. if (parseResult) {
  10966. finalizeForParseResult(parseResult, context);
  10967. dynamicSlots.push(
  10968. createCallExpression(context.helper(RENDER_LIST), [
  10969. parseResult.source,
  10970. createFunctionExpression(
  10971. createForLoopParams(parseResult),
  10972. buildDynamicSlot(slotName, slotFunction),
  10973. true
  10974. )
  10975. ])
  10976. );
  10977. } else {
  10978. context.onError(
  10979. createCompilerError(
  10980. 32,
  10981. vFor.loc
  10982. )
  10983. );
  10984. }
  10985. } else {
  10986. if (staticSlotName) {
  10987. if (seenSlotNames.has(staticSlotName)) {
  10988. context.onError(
  10989. createCompilerError(
  10990. 38,
  10991. dirLoc
  10992. )
  10993. );
  10994. continue;
  10995. }
  10996. seenSlotNames.add(staticSlotName);
  10997. if (staticSlotName === "default") {
  10998. hasNamedDefaultSlot = true;
  10999. }
  11000. }
  11001. slotsProperties.push(createObjectProperty(slotName, slotFunction));
  11002. }
  11003. }
  11004. if (!onComponentSlot) {
  11005. const buildDefaultSlotProperty = (props, children2) => {
  11006. const fn = buildSlotFn(props, void 0, children2, loc);
  11007. if (context.compatConfig) {
  11008. fn.isNonScopedSlot = true;
  11009. }
  11010. return createObjectProperty(`default`, fn);
  11011. };
  11012. if (!hasTemplateSlots) {
  11013. slotsProperties.push(buildDefaultSlotProperty(void 0, children));
  11014. } else if (implicitDefaultChildren.length && // #3766
  11015. // with whitespace: 'preserve', whitespaces between slots will end up in
  11016. // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
  11017. implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
  11018. if (hasNamedDefaultSlot) {
  11019. context.onError(
  11020. createCompilerError(
  11021. 39,
  11022. implicitDefaultChildren[0].loc
  11023. )
  11024. );
  11025. } else {
  11026. slotsProperties.push(
  11027. buildDefaultSlotProperty(void 0, implicitDefaultChildren)
  11028. );
  11029. }
  11030. }
  11031. }
  11032. const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
  11033. let slots = createObjectExpression(
  11034. slotsProperties.concat(
  11035. createObjectProperty(
  11036. `_`,
  11037. // 2 = compiled but dynamic = can skip normalization, but must run diff
  11038. // 1 = compiled and static = can skip normalization AND diff as optimized
  11039. createSimpleExpression(
  11040. slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
  11041. false
  11042. )
  11043. )
  11044. ),
  11045. loc
  11046. );
  11047. if (dynamicSlots.length) {
  11048. slots = createCallExpression(context.helper(CREATE_SLOTS), [
  11049. slots,
  11050. createArrayExpression(dynamicSlots)
  11051. ]);
  11052. }
  11053. return {
  11054. slots,
  11055. hasDynamicSlots
  11056. };
  11057. }
  11058. function buildDynamicSlot(name, fn, index) {
  11059. const props = [
  11060. createObjectProperty(`name`, name),
  11061. createObjectProperty(`fn`, fn)
  11062. ];
  11063. if (index != null) {
  11064. props.push(
  11065. createObjectProperty(`key`, createSimpleExpression(String(index), true))
  11066. );
  11067. }
  11068. return createObjectExpression(props);
  11069. }
  11070. function hasForwardedSlots(children) {
  11071. for (let i = 0; i < children.length; i++) {
  11072. const child = children[i];
  11073. switch (child.type) {
  11074. case 1:
  11075. if (child.tagType === 2 || hasForwardedSlots(child.children)) {
  11076. return true;
  11077. }
  11078. break;
  11079. case 9:
  11080. if (hasForwardedSlots(child.branches))
  11081. return true;
  11082. break;
  11083. case 10:
  11084. case 11:
  11085. if (hasForwardedSlots(child.children))
  11086. return true;
  11087. break;
  11088. }
  11089. }
  11090. return false;
  11091. }
  11092. function isNonWhitespaceContent(node) {
  11093. if (node.type !== 2 && node.type !== 12)
  11094. return true;
  11095. return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
  11096. }
  11097. const directiveImportMap = /* @__PURE__ */ new WeakMap();
  11098. const transformElement = (node, context) => {
  11099. return function postTransformElement() {
  11100. node = context.currentNode;
  11101. if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
  11102. return;
  11103. }
  11104. const { tag, props } = node;
  11105. const isComponent = node.tagType === 1;
  11106. let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
  11107. const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
  11108. let vnodeProps;
  11109. let vnodeChildren;
  11110. let vnodePatchFlag;
  11111. let patchFlag = 0;
  11112. let vnodeDynamicProps;
  11113. let dynamicPropNames;
  11114. let vnodeDirectives;
  11115. let shouldUseBlock = (
  11116. // dynamic component may resolve to plain elements
  11117. isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
  11118. // updates inside get proper isSVG flag at runtime. (#639, #643)
  11119. // This is technically web-specific, but splitting the logic out of core
  11120. // leads to too much unnecessary complexity.
  11121. (tag === "svg" || tag === "foreignObject")
  11122. );
  11123. if (props.length > 0) {
  11124. const propsBuildResult = buildProps(
  11125. node,
  11126. context,
  11127. void 0,
  11128. isComponent,
  11129. isDynamicComponent
  11130. );
  11131. vnodeProps = propsBuildResult.props;
  11132. patchFlag = propsBuildResult.patchFlag;
  11133. dynamicPropNames = propsBuildResult.dynamicPropNames;
  11134. const directives = propsBuildResult.directives;
  11135. vnodeDirectives = directives && directives.length ? createArrayExpression(
  11136. directives.map((dir) => buildDirectiveArgs(dir, context))
  11137. ) : void 0;
  11138. if (propsBuildResult.shouldUseBlock) {
  11139. shouldUseBlock = true;
  11140. }
  11141. }
  11142. if (node.children.length > 0) {
  11143. if (vnodeTag === KEEP_ALIVE) {
  11144. shouldUseBlock = true;
  11145. patchFlag |= 1024;
  11146. if (node.children.length > 1) {
  11147. context.onError(
  11148. createCompilerError(46, {
  11149. start: node.children[0].loc.start,
  11150. end: node.children[node.children.length - 1].loc.end,
  11151. source: ""
  11152. })
  11153. );
  11154. }
  11155. }
  11156. const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
  11157. vnodeTag !== TELEPORT && // explained above.
  11158. vnodeTag !== KEEP_ALIVE;
  11159. if (shouldBuildAsSlots) {
  11160. const { slots, hasDynamicSlots } = buildSlots(node, context);
  11161. vnodeChildren = slots;
  11162. if (hasDynamicSlots) {
  11163. patchFlag |= 1024;
  11164. }
  11165. } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
  11166. const child = node.children[0];
  11167. const type = child.type;
  11168. const hasDynamicTextChild = type === 5 || type === 8;
  11169. if (hasDynamicTextChild && getConstantType(child, context) === 0) {
  11170. patchFlag |= 1;
  11171. }
  11172. if (hasDynamicTextChild || type === 2) {
  11173. vnodeChildren = child;
  11174. } else {
  11175. vnodeChildren = node.children;
  11176. }
  11177. } else {
  11178. vnodeChildren = node.children;
  11179. }
  11180. }
  11181. if (patchFlag !== 0) {
  11182. {
  11183. if (patchFlag < 0) {
  11184. vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
  11185. } else {
  11186. const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
  11187. vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
  11188. }
  11189. }
  11190. if (dynamicPropNames && dynamicPropNames.length) {
  11191. vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
  11192. }
  11193. }
  11194. node.codegenNode = createVNodeCall(
  11195. context,
  11196. vnodeTag,
  11197. vnodeProps,
  11198. vnodeChildren,
  11199. vnodePatchFlag,
  11200. vnodeDynamicProps,
  11201. vnodeDirectives,
  11202. !!shouldUseBlock,
  11203. false,
  11204. isComponent,
  11205. node.loc
  11206. );
  11207. };
  11208. };
  11209. function resolveComponentType(node, context, ssr = false) {
  11210. let { tag } = node;
  11211. const isExplicitDynamic = isComponentTag(tag);
  11212. const isProp = findProp(node, "is");
  11213. if (isProp) {
  11214. if (isExplicitDynamic || isCompatEnabled(
  11215. "COMPILER_IS_ON_ELEMENT",
  11216. context
  11217. )) {
  11218. const exp = isProp.type === 6 ? isProp.value && createSimpleExpression(isProp.value.content, true) : isProp.exp;
  11219. if (exp) {
  11220. return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
  11221. exp
  11222. ]);
  11223. }
  11224. } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
  11225. tag = isProp.value.content.slice(4);
  11226. }
  11227. }
  11228. const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
  11229. if (builtIn) {
  11230. if (!ssr)
  11231. context.helper(builtIn);
  11232. return builtIn;
  11233. }
  11234. context.helper(RESOLVE_COMPONENT);
  11235. context.components.add(tag);
  11236. return toValidAssetId(tag, `component`);
  11237. }
  11238. function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
  11239. const { tag, loc: elementLoc, children } = node;
  11240. let properties = [];
  11241. const mergeArgs = [];
  11242. const runtimeDirectives = [];
  11243. const hasChildren = children.length > 0;
  11244. let shouldUseBlock = false;
  11245. let patchFlag = 0;
  11246. let hasRef = false;
  11247. let hasClassBinding = false;
  11248. let hasStyleBinding = false;
  11249. let hasHydrationEventBinding = false;
  11250. let hasDynamicKeys = false;
  11251. let hasVnodeHook = false;
  11252. const dynamicPropNames = [];
  11253. const pushMergeArg = (arg) => {
  11254. if (properties.length) {
  11255. mergeArgs.push(
  11256. createObjectExpression(dedupeProperties(properties), elementLoc)
  11257. );
  11258. properties = [];
  11259. }
  11260. if (arg)
  11261. mergeArgs.push(arg);
  11262. };
  11263. const analyzePatchFlag = ({ key, value }) => {
  11264. if (isStaticExp(key)) {
  11265. const name = key.content;
  11266. const isEventHandler = isOn(name);
  11267. if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
  11268. // dedicated fast path.
  11269. name.toLowerCase() !== "onclick" && // omit v-model handlers
  11270. name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
  11271. !isReservedProp(name)) {
  11272. hasHydrationEventBinding = true;
  11273. }
  11274. if (isEventHandler && isReservedProp(name)) {
  11275. hasVnodeHook = true;
  11276. }
  11277. if (isEventHandler && value.type === 14) {
  11278. value = value.arguments[0];
  11279. }
  11280. if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
  11281. return;
  11282. }
  11283. if (name === "ref") {
  11284. hasRef = true;
  11285. } else if (name === "class") {
  11286. hasClassBinding = true;
  11287. } else if (name === "style") {
  11288. hasStyleBinding = true;
  11289. } else if (name !== "key" && !dynamicPropNames.includes(name)) {
  11290. dynamicPropNames.push(name);
  11291. }
  11292. if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
  11293. dynamicPropNames.push(name);
  11294. }
  11295. } else {
  11296. hasDynamicKeys = true;
  11297. }
  11298. };
  11299. for (let i = 0; i < props.length; i++) {
  11300. const prop = props[i];
  11301. if (prop.type === 6) {
  11302. const { loc, name, nameLoc, value } = prop;
  11303. let isStatic = true;
  11304. if (name === "ref") {
  11305. hasRef = true;
  11306. if (context.scopes.vFor > 0) {
  11307. properties.push(
  11308. createObjectProperty(
  11309. createSimpleExpression("ref_for", true),
  11310. createSimpleExpression("true")
  11311. )
  11312. );
  11313. }
  11314. }
  11315. if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
  11316. "COMPILER_IS_ON_ELEMENT",
  11317. context
  11318. ))) {
  11319. continue;
  11320. }
  11321. properties.push(
  11322. createObjectProperty(
  11323. createSimpleExpression(name, true, nameLoc),
  11324. createSimpleExpression(
  11325. value ? value.content : "",
  11326. isStatic,
  11327. value ? value.loc : loc
  11328. )
  11329. )
  11330. );
  11331. } else {
  11332. const { name, arg, exp, loc, modifiers } = prop;
  11333. const isVBind = name === "bind";
  11334. const isVOn = name === "on";
  11335. if (name === "slot") {
  11336. if (!isComponent) {
  11337. context.onError(
  11338. createCompilerError(40, loc)
  11339. );
  11340. }
  11341. continue;
  11342. }
  11343. if (name === "once" || name === "memo") {
  11344. continue;
  11345. }
  11346. if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
  11347. "COMPILER_IS_ON_ELEMENT",
  11348. context
  11349. ))) {
  11350. continue;
  11351. }
  11352. if (isVOn && ssr) {
  11353. continue;
  11354. }
  11355. if (
  11356. // #938: elements with dynamic keys should be forced into blocks
  11357. isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
  11358. // before children
  11359. isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
  11360. ) {
  11361. shouldUseBlock = true;
  11362. }
  11363. if (isVBind && isStaticArgOf(arg, "ref") && context.scopes.vFor > 0) {
  11364. properties.push(
  11365. createObjectProperty(
  11366. createSimpleExpression("ref_for", true),
  11367. createSimpleExpression("true")
  11368. )
  11369. );
  11370. }
  11371. if (!arg && (isVBind || isVOn)) {
  11372. hasDynamicKeys = true;
  11373. if (exp) {
  11374. if (isVBind) {
  11375. pushMergeArg();
  11376. {
  11377. {
  11378. const hasOverridableKeys = mergeArgs.some((arg2) => {
  11379. if (arg2.type === 15) {
  11380. return arg2.properties.some(({ key }) => {
  11381. if (key.type !== 4 || !key.isStatic) {
  11382. return true;
  11383. }
  11384. return key.content !== "class" && key.content !== "style" && !isOn(key.content);
  11385. });
  11386. } else {
  11387. return true;
  11388. }
  11389. });
  11390. if (hasOverridableKeys) {
  11391. checkCompatEnabled(
  11392. "COMPILER_V_BIND_OBJECT_ORDER",
  11393. context,
  11394. loc
  11395. );
  11396. }
  11397. }
  11398. if (isCompatEnabled(
  11399. "COMPILER_V_BIND_OBJECT_ORDER",
  11400. context
  11401. )) {
  11402. mergeArgs.unshift(exp);
  11403. continue;
  11404. }
  11405. }
  11406. mergeArgs.push(exp);
  11407. } else {
  11408. pushMergeArg({
  11409. type: 14,
  11410. loc,
  11411. callee: context.helper(TO_HANDLERS),
  11412. arguments: isComponent ? [exp] : [exp, `true`]
  11413. });
  11414. }
  11415. } else {
  11416. context.onError(
  11417. createCompilerError(
  11418. isVBind ? 34 : 35,
  11419. loc
  11420. )
  11421. );
  11422. }
  11423. continue;
  11424. }
  11425. if (isVBind && modifiers.includes("prop")) {
  11426. patchFlag |= 32;
  11427. }
  11428. const directiveTransform = context.directiveTransforms[name];
  11429. if (directiveTransform) {
  11430. const { props: props2, needRuntime } = directiveTransform(prop, node, context);
  11431. !ssr && props2.forEach(analyzePatchFlag);
  11432. if (isVOn && arg && !isStaticExp(arg)) {
  11433. pushMergeArg(createObjectExpression(props2, elementLoc));
  11434. } else {
  11435. properties.push(...props2);
  11436. }
  11437. if (needRuntime) {
  11438. runtimeDirectives.push(prop);
  11439. if (isSymbol(needRuntime)) {
  11440. directiveImportMap.set(prop, needRuntime);
  11441. }
  11442. }
  11443. } else if (!isBuiltInDirective(name)) {
  11444. runtimeDirectives.push(prop);
  11445. if (hasChildren) {
  11446. shouldUseBlock = true;
  11447. }
  11448. }
  11449. }
  11450. }
  11451. let propsExpression = void 0;
  11452. if (mergeArgs.length) {
  11453. pushMergeArg();
  11454. if (mergeArgs.length > 1) {
  11455. propsExpression = createCallExpression(
  11456. context.helper(MERGE_PROPS),
  11457. mergeArgs,
  11458. elementLoc
  11459. );
  11460. } else {
  11461. propsExpression = mergeArgs[0];
  11462. }
  11463. } else if (properties.length) {
  11464. propsExpression = createObjectExpression(
  11465. dedupeProperties(properties),
  11466. elementLoc
  11467. );
  11468. }
  11469. if (hasDynamicKeys) {
  11470. patchFlag |= 16;
  11471. } else {
  11472. if (hasClassBinding && !isComponent) {
  11473. patchFlag |= 2;
  11474. }
  11475. if (hasStyleBinding && !isComponent) {
  11476. patchFlag |= 4;
  11477. }
  11478. if (dynamicPropNames.length) {
  11479. patchFlag |= 8;
  11480. }
  11481. if (hasHydrationEventBinding) {
  11482. patchFlag |= 32;
  11483. }
  11484. }
  11485. if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
  11486. patchFlag |= 512;
  11487. }
  11488. if (!context.inSSR && propsExpression) {
  11489. switch (propsExpression.type) {
  11490. case 15:
  11491. let classKeyIndex = -1;
  11492. let styleKeyIndex = -1;
  11493. let hasDynamicKey = false;
  11494. for (let i = 0; i < propsExpression.properties.length; i++) {
  11495. const key = propsExpression.properties[i].key;
  11496. if (isStaticExp(key)) {
  11497. if (key.content === "class") {
  11498. classKeyIndex = i;
  11499. } else if (key.content === "style") {
  11500. styleKeyIndex = i;
  11501. }
  11502. } else if (!key.isHandlerKey) {
  11503. hasDynamicKey = true;
  11504. }
  11505. }
  11506. const classProp = propsExpression.properties[classKeyIndex];
  11507. const styleProp = propsExpression.properties[styleKeyIndex];
  11508. if (!hasDynamicKey) {
  11509. if (classProp && !isStaticExp(classProp.value)) {
  11510. classProp.value = createCallExpression(
  11511. context.helper(NORMALIZE_CLASS),
  11512. [classProp.value]
  11513. );
  11514. }
  11515. if (styleProp && // the static style is compiled into an object,
  11516. // so use `hasStyleBinding` to ensure that it is a dynamic style binding
  11517. (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
  11518. // v-bind:style with static literal object
  11519. styleProp.value.type === 17)) {
  11520. styleProp.value = createCallExpression(
  11521. context.helper(NORMALIZE_STYLE),
  11522. [styleProp.value]
  11523. );
  11524. }
  11525. } else {
  11526. propsExpression = createCallExpression(
  11527. context.helper(NORMALIZE_PROPS),
  11528. [propsExpression]
  11529. );
  11530. }
  11531. break;
  11532. case 14:
  11533. break;
  11534. default:
  11535. propsExpression = createCallExpression(
  11536. context.helper(NORMALIZE_PROPS),
  11537. [
  11538. createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
  11539. propsExpression
  11540. ])
  11541. ]
  11542. );
  11543. break;
  11544. }
  11545. }
  11546. return {
  11547. props: propsExpression,
  11548. directives: runtimeDirectives,
  11549. patchFlag,
  11550. dynamicPropNames,
  11551. shouldUseBlock
  11552. };
  11553. }
  11554. function dedupeProperties(properties) {
  11555. const knownProps = /* @__PURE__ */ new Map();
  11556. const deduped = [];
  11557. for (let i = 0; i < properties.length; i++) {
  11558. const prop = properties[i];
  11559. if (prop.key.type === 8 || !prop.key.isStatic) {
  11560. deduped.push(prop);
  11561. continue;
  11562. }
  11563. const name = prop.key.content;
  11564. const existing = knownProps.get(name);
  11565. if (existing) {
  11566. if (name === "style" || name === "class" || isOn(name)) {
  11567. mergeAsArray(existing, prop);
  11568. }
  11569. } else {
  11570. knownProps.set(name, prop);
  11571. deduped.push(prop);
  11572. }
  11573. }
  11574. return deduped;
  11575. }
  11576. function mergeAsArray(existing, incoming) {
  11577. if (existing.value.type === 17) {
  11578. existing.value.elements.push(incoming.value);
  11579. } else {
  11580. existing.value = createArrayExpression(
  11581. [existing.value, incoming.value],
  11582. existing.loc
  11583. );
  11584. }
  11585. }
  11586. function buildDirectiveArgs(dir, context) {
  11587. const dirArgs = [];
  11588. const runtime = directiveImportMap.get(dir);
  11589. if (runtime) {
  11590. dirArgs.push(context.helperString(runtime));
  11591. } else {
  11592. {
  11593. context.helper(RESOLVE_DIRECTIVE);
  11594. context.directives.add(dir.name);
  11595. dirArgs.push(toValidAssetId(dir.name, `directive`));
  11596. }
  11597. }
  11598. const { loc } = dir;
  11599. if (dir.exp)
  11600. dirArgs.push(dir.exp);
  11601. if (dir.arg) {
  11602. if (!dir.exp) {
  11603. dirArgs.push(`void 0`);
  11604. }
  11605. dirArgs.push(dir.arg);
  11606. }
  11607. if (Object.keys(dir.modifiers).length) {
  11608. if (!dir.arg) {
  11609. if (!dir.exp) {
  11610. dirArgs.push(`void 0`);
  11611. }
  11612. dirArgs.push(`void 0`);
  11613. }
  11614. const trueExpression = createSimpleExpression(`true`, false, loc);
  11615. dirArgs.push(
  11616. createObjectExpression(
  11617. dir.modifiers.map(
  11618. (modifier) => createObjectProperty(modifier, trueExpression)
  11619. ),
  11620. loc
  11621. )
  11622. );
  11623. }
  11624. return createArrayExpression(dirArgs, dir.loc);
  11625. }
  11626. function stringifyDynamicPropNames(props) {
  11627. let propsNamesString = `[`;
  11628. for (let i = 0, l = props.length; i < l; i++) {
  11629. propsNamesString += JSON.stringify(props[i]);
  11630. if (i < l - 1)
  11631. propsNamesString += ", ";
  11632. }
  11633. return propsNamesString + `]`;
  11634. }
  11635. function isComponentTag(tag) {
  11636. return tag === "component" || tag === "Component";
  11637. }
  11638. const transformSlotOutlet = (node, context) => {
  11639. if (isSlotOutlet(node)) {
  11640. const { children, loc } = node;
  11641. const { slotName, slotProps } = processSlotOutlet(node, context);
  11642. const slotArgs = [
  11643. context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
  11644. slotName,
  11645. "{}",
  11646. "undefined",
  11647. "true"
  11648. ];
  11649. let expectedLen = 2;
  11650. if (slotProps) {
  11651. slotArgs[2] = slotProps;
  11652. expectedLen = 3;
  11653. }
  11654. if (children.length) {
  11655. slotArgs[3] = createFunctionExpression([], children, false, false, loc);
  11656. expectedLen = 4;
  11657. }
  11658. if (context.scopeId && !context.slotted) {
  11659. expectedLen = 5;
  11660. }
  11661. slotArgs.splice(expectedLen);
  11662. node.codegenNode = createCallExpression(
  11663. context.helper(RENDER_SLOT),
  11664. slotArgs,
  11665. loc
  11666. );
  11667. }
  11668. };
  11669. function processSlotOutlet(node, context) {
  11670. let slotName = `"default"`;
  11671. let slotProps = void 0;
  11672. const nonNameProps = [];
  11673. for (let i = 0; i < node.props.length; i++) {
  11674. const p = node.props[i];
  11675. if (p.type === 6) {
  11676. if (p.value) {
  11677. if (p.name === "name") {
  11678. slotName = JSON.stringify(p.value.content);
  11679. } else {
  11680. p.name = camelize(p.name);
  11681. nonNameProps.push(p);
  11682. }
  11683. }
  11684. } else {
  11685. if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
  11686. if (p.exp) {
  11687. slotName = p.exp;
  11688. } else if (p.arg && p.arg.type === 4) {
  11689. const name = camelize(p.arg.content);
  11690. slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
  11691. }
  11692. } else {
  11693. if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
  11694. p.arg.content = camelize(p.arg.content);
  11695. }
  11696. nonNameProps.push(p);
  11697. }
  11698. }
  11699. }
  11700. if (nonNameProps.length > 0) {
  11701. const { props, directives } = buildProps(
  11702. node,
  11703. context,
  11704. nonNameProps,
  11705. false,
  11706. false
  11707. );
  11708. slotProps = props;
  11709. if (directives.length) {
  11710. context.onError(
  11711. createCompilerError(
  11712. 36,
  11713. directives[0].loc
  11714. )
  11715. );
  11716. }
  11717. }
  11718. return {
  11719. slotName,
  11720. slotProps
  11721. };
  11722. }
  11723. const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
  11724. const transformOn$1 = (dir, node, context, augmentor) => {
  11725. const { loc, modifiers, arg } = dir;
  11726. if (!dir.exp && !modifiers.length) {
  11727. context.onError(createCompilerError(35, loc));
  11728. }
  11729. let eventName;
  11730. if (arg.type === 4) {
  11731. if (arg.isStatic) {
  11732. let rawName = arg.content;
  11733. if (rawName.startsWith("vnode")) {
  11734. context.onError(createCompilerError(51, arg.loc));
  11735. }
  11736. if (rawName.startsWith("vue:")) {
  11737. rawName = `vnode-${rawName.slice(4)}`;
  11738. }
  11739. const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
  11740. // for non-element and vnode lifecycle event listeners, auto convert
  11741. // it to camelCase. See issue #2249
  11742. toHandlerKey(camelize(rawName))
  11743. ) : (
  11744. // preserve case for plain element listeners that have uppercase
  11745. // letters, as these may be custom elements' custom events
  11746. `on:${rawName}`
  11747. );
  11748. eventName = createSimpleExpression(eventString, true, arg.loc);
  11749. } else {
  11750. eventName = createCompoundExpression([
  11751. `${context.helperString(TO_HANDLER_KEY)}(`,
  11752. arg,
  11753. `)`
  11754. ]);
  11755. }
  11756. } else {
  11757. eventName = arg;
  11758. eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
  11759. eventName.children.push(`)`);
  11760. }
  11761. let exp = dir.exp;
  11762. if (exp && !exp.content.trim()) {
  11763. exp = void 0;
  11764. }
  11765. let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
  11766. if (exp) {
  11767. const isMemberExp = isMemberExpression(exp.content);
  11768. const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
  11769. const hasMultipleStatements = exp.content.includes(`;`);
  11770. {
  11771. validateBrowserExpression(
  11772. exp,
  11773. context,
  11774. false,
  11775. hasMultipleStatements
  11776. );
  11777. }
  11778. if (isInlineStatement || shouldCache && isMemberExp) {
  11779. exp = createCompoundExpression([
  11780. `${isInlineStatement ? `$event` : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
  11781. exp,
  11782. hasMultipleStatements ? `}` : `)`
  11783. ]);
  11784. }
  11785. }
  11786. let ret = {
  11787. props: [
  11788. createObjectProperty(
  11789. eventName,
  11790. exp || createSimpleExpression(`() => {}`, false, loc)
  11791. )
  11792. ]
  11793. };
  11794. if (augmentor) {
  11795. ret = augmentor(ret);
  11796. }
  11797. if (shouldCache) {
  11798. ret.props[0].value = context.cache(ret.props[0].value);
  11799. }
  11800. ret.props.forEach((p) => p.key.isHandlerKey = true);
  11801. return ret;
  11802. };
  11803. const transformBind = (dir, _node, context) => {
  11804. const { modifiers, loc } = dir;
  11805. const arg = dir.arg;
  11806. let { exp } = dir;
  11807. if (exp && exp.type === 4 && !exp.content.trim()) {
  11808. {
  11809. exp = void 0;
  11810. }
  11811. }
  11812. if (!exp) {
  11813. if (arg.type !== 4 || !arg.isStatic) {
  11814. context.onError(
  11815. createCompilerError(
  11816. 52,
  11817. arg.loc
  11818. )
  11819. );
  11820. return {
  11821. props: [
  11822. createObjectProperty(arg, createSimpleExpression("", true, loc))
  11823. ]
  11824. };
  11825. }
  11826. const propName = camelize(arg.content);
  11827. exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
  11828. }
  11829. if (arg.type !== 4) {
  11830. arg.children.unshift(`(`);
  11831. arg.children.push(`) || ""`);
  11832. } else if (!arg.isStatic) {
  11833. arg.content = `${arg.content} || ""`;
  11834. }
  11835. if (modifiers.includes("camel")) {
  11836. if (arg.type === 4) {
  11837. if (arg.isStatic) {
  11838. arg.content = camelize(arg.content);
  11839. } else {
  11840. arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
  11841. }
  11842. } else {
  11843. arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
  11844. arg.children.push(`)`);
  11845. }
  11846. }
  11847. if (!context.inSSR) {
  11848. if (modifiers.includes("prop")) {
  11849. injectPrefix(arg, ".");
  11850. }
  11851. if (modifiers.includes("attr")) {
  11852. injectPrefix(arg, "^");
  11853. }
  11854. }
  11855. return {
  11856. props: [createObjectProperty(arg, exp)]
  11857. };
  11858. };
  11859. const injectPrefix = (arg, prefix) => {
  11860. if (arg.type === 4) {
  11861. if (arg.isStatic) {
  11862. arg.content = prefix + arg.content;
  11863. } else {
  11864. arg.content = `\`${prefix}\${${arg.content}}\``;
  11865. }
  11866. } else {
  11867. arg.children.unshift(`'${prefix}' + (`);
  11868. arg.children.push(`)`);
  11869. }
  11870. };
  11871. const transformText = (node, context) => {
  11872. if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
  11873. return () => {
  11874. const children = node.children;
  11875. let currentContainer = void 0;
  11876. let hasText = false;
  11877. for (let i = 0; i < children.length; i++) {
  11878. const child = children[i];
  11879. if (isText$1(child)) {
  11880. hasText = true;
  11881. for (let j = i + 1; j < children.length; j++) {
  11882. const next = children[j];
  11883. if (isText$1(next)) {
  11884. if (!currentContainer) {
  11885. currentContainer = children[i] = createCompoundExpression(
  11886. [child],
  11887. child.loc
  11888. );
  11889. }
  11890. currentContainer.children.push(` + `, next);
  11891. children.splice(j, 1);
  11892. j--;
  11893. } else {
  11894. currentContainer = void 0;
  11895. break;
  11896. }
  11897. }
  11898. }
  11899. }
  11900. if (!hasText || // if this is a plain element with a single text child, leave it
  11901. // as-is since the runtime has dedicated fast path for this by directly
  11902. // setting textContent of the element.
  11903. // for component root it's always normalized anyway.
  11904. children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
  11905. // custom directives can potentially add DOM elements arbitrarily,
  11906. // we need to avoid setting textContent of the element at runtime
  11907. // to avoid accidentally overwriting the DOM elements added
  11908. // by the user through custom directives.
  11909. !node.props.find(
  11910. (p) => p.type === 7 && !context.directiveTransforms[p.name]
  11911. ) && // in compat mode, <template> tags with no special directives
  11912. // will be rendered as a fragment so its children must be
  11913. // converted into vnodes.
  11914. !(node.tag === "template"))) {
  11915. return;
  11916. }
  11917. for (let i = 0; i < children.length; i++) {
  11918. const child = children[i];
  11919. if (isText$1(child) || child.type === 8) {
  11920. const callArgs = [];
  11921. if (child.type !== 2 || child.content !== " ") {
  11922. callArgs.push(child);
  11923. }
  11924. if (!context.ssr && getConstantType(child, context) === 0) {
  11925. callArgs.push(
  11926. 1 + (` /* ${PatchFlagNames[1]} */` )
  11927. );
  11928. }
  11929. children[i] = {
  11930. type: 12,
  11931. content: child,
  11932. loc: child.loc,
  11933. codegenNode: createCallExpression(
  11934. context.helper(CREATE_TEXT),
  11935. callArgs
  11936. )
  11937. };
  11938. }
  11939. }
  11940. };
  11941. }
  11942. };
  11943. const seen$1 = /* @__PURE__ */ new WeakSet();
  11944. const transformOnce = (node, context) => {
  11945. if (node.type === 1 && findDir(node, "once", true)) {
  11946. if (seen$1.has(node) || context.inVOnce || context.inSSR) {
  11947. return;
  11948. }
  11949. seen$1.add(node);
  11950. context.inVOnce = true;
  11951. context.helper(SET_BLOCK_TRACKING);
  11952. return () => {
  11953. context.inVOnce = false;
  11954. const cur = context.currentNode;
  11955. if (cur.codegenNode) {
  11956. cur.codegenNode = context.cache(
  11957. cur.codegenNode,
  11958. true
  11959. /* isVNode */
  11960. );
  11961. }
  11962. };
  11963. }
  11964. };
  11965. const transformModel$1 = (dir, node, context) => {
  11966. const { exp, arg } = dir;
  11967. if (!exp) {
  11968. context.onError(
  11969. createCompilerError(41, dir.loc)
  11970. );
  11971. return createTransformProps();
  11972. }
  11973. const rawExp = exp.loc.source;
  11974. const expString = exp.type === 4 ? exp.content : rawExp;
  11975. const bindingType = context.bindingMetadata[rawExp];
  11976. if (bindingType === "props" || bindingType === "props-aliased") {
  11977. context.onError(createCompilerError(44, exp.loc));
  11978. return createTransformProps();
  11979. }
  11980. const maybeRef = false;
  11981. if (!expString.trim() || !isMemberExpression(expString) && !maybeRef) {
  11982. context.onError(
  11983. createCompilerError(42, exp.loc)
  11984. );
  11985. return createTransformProps();
  11986. }
  11987. const propName = arg ? arg : createSimpleExpression("modelValue", true);
  11988. const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
  11989. let assignmentExp;
  11990. const eventArg = context.isTS ? `($event: any)` : `$event`;
  11991. {
  11992. assignmentExp = createCompoundExpression([
  11993. `${eventArg} => ((`,
  11994. exp,
  11995. `) = $event)`
  11996. ]);
  11997. }
  11998. const props = [
  11999. // modelValue: foo
  12000. createObjectProperty(propName, dir.exp),
  12001. // "onUpdate:modelValue": $event => (foo = $event)
  12002. createObjectProperty(eventName, assignmentExp)
  12003. ];
  12004. if (dir.modifiers.length && node.tagType === 1) {
  12005. const modifiers = dir.modifiers.map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
  12006. const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
  12007. props.push(
  12008. createObjectProperty(
  12009. modifiersKey,
  12010. createSimpleExpression(
  12011. `{ ${modifiers} }`,
  12012. false,
  12013. dir.loc,
  12014. 2
  12015. )
  12016. )
  12017. );
  12018. }
  12019. return createTransformProps(props);
  12020. };
  12021. function createTransformProps(props = []) {
  12022. return { props };
  12023. }
  12024. const validDivisionCharRE = /[\w).+\-_$\]]/;
  12025. const transformFilter = (node, context) => {
  12026. if (!isCompatEnabled("COMPILER_FILTERS", context)) {
  12027. return;
  12028. }
  12029. if (node.type === 5) {
  12030. rewriteFilter(node.content, context);
  12031. }
  12032. if (node.type === 1) {
  12033. node.props.forEach((prop) => {
  12034. if (prop.type === 7 && prop.name !== "for" && prop.exp) {
  12035. rewriteFilter(prop.exp, context);
  12036. }
  12037. });
  12038. }
  12039. };
  12040. function rewriteFilter(node, context) {
  12041. if (node.type === 4) {
  12042. parseFilter(node, context);
  12043. } else {
  12044. for (let i = 0; i < node.children.length; i++) {
  12045. const child = node.children[i];
  12046. if (typeof child !== "object")
  12047. continue;
  12048. if (child.type === 4) {
  12049. parseFilter(child, context);
  12050. } else if (child.type === 8) {
  12051. rewriteFilter(node, context);
  12052. } else if (child.type === 5) {
  12053. rewriteFilter(child.content, context);
  12054. }
  12055. }
  12056. }
  12057. }
  12058. function parseFilter(node, context) {
  12059. const exp = node.content;
  12060. let inSingle = false;
  12061. let inDouble = false;
  12062. let inTemplateString = false;
  12063. let inRegex = false;
  12064. let curly = 0;
  12065. let square = 0;
  12066. let paren = 0;
  12067. let lastFilterIndex = 0;
  12068. let c, prev, i, expression, filters = [];
  12069. for (i = 0; i < exp.length; i++) {
  12070. prev = c;
  12071. c = exp.charCodeAt(i);
  12072. if (inSingle) {
  12073. if (c === 39 && prev !== 92)
  12074. inSingle = false;
  12075. } else if (inDouble) {
  12076. if (c === 34 && prev !== 92)
  12077. inDouble = false;
  12078. } else if (inTemplateString) {
  12079. if (c === 96 && prev !== 92)
  12080. inTemplateString = false;
  12081. } else if (inRegex) {
  12082. if (c === 47 && prev !== 92)
  12083. inRegex = false;
  12084. } else if (c === 124 && // pipe
  12085. exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
  12086. if (expression === void 0) {
  12087. lastFilterIndex = i + 1;
  12088. expression = exp.slice(0, i).trim();
  12089. } else {
  12090. pushFilter();
  12091. }
  12092. } else {
  12093. switch (c) {
  12094. case 34:
  12095. inDouble = true;
  12096. break;
  12097. case 39:
  12098. inSingle = true;
  12099. break;
  12100. case 96:
  12101. inTemplateString = true;
  12102. break;
  12103. case 40:
  12104. paren++;
  12105. break;
  12106. case 41:
  12107. paren--;
  12108. break;
  12109. case 91:
  12110. square++;
  12111. break;
  12112. case 93:
  12113. square--;
  12114. break;
  12115. case 123:
  12116. curly++;
  12117. break;
  12118. case 125:
  12119. curly--;
  12120. break;
  12121. }
  12122. if (c === 47) {
  12123. let j = i - 1;
  12124. let p;
  12125. for (; j >= 0; j--) {
  12126. p = exp.charAt(j);
  12127. if (p !== " ")
  12128. break;
  12129. }
  12130. if (!p || !validDivisionCharRE.test(p)) {
  12131. inRegex = true;
  12132. }
  12133. }
  12134. }
  12135. }
  12136. if (expression === void 0) {
  12137. expression = exp.slice(0, i).trim();
  12138. } else if (lastFilterIndex !== 0) {
  12139. pushFilter();
  12140. }
  12141. function pushFilter() {
  12142. filters.push(exp.slice(lastFilterIndex, i).trim());
  12143. lastFilterIndex = i + 1;
  12144. }
  12145. if (filters.length) {
  12146. warnDeprecation(
  12147. "COMPILER_FILTERS",
  12148. context,
  12149. node.loc
  12150. );
  12151. for (i = 0; i < filters.length; i++) {
  12152. expression = wrapFilter(expression, filters[i], context);
  12153. }
  12154. node.content = expression;
  12155. }
  12156. }
  12157. function wrapFilter(exp, filter, context) {
  12158. context.helper(RESOLVE_FILTER);
  12159. const i = filter.indexOf("(");
  12160. if (i < 0) {
  12161. context.filters.add(filter);
  12162. return `${toValidAssetId(filter, "filter")}(${exp})`;
  12163. } else {
  12164. const name = filter.slice(0, i);
  12165. const args = filter.slice(i + 1);
  12166. context.filters.add(name);
  12167. return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
  12168. }
  12169. }
  12170. const seen = /* @__PURE__ */ new WeakSet();
  12171. const transformMemo = (node, context) => {
  12172. if (node.type === 1) {
  12173. const dir = findDir(node, "memo");
  12174. if (!dir || seen.has(node)) {
  12175. return;
  12176. }
  12177. seen.add(node);
  12178. return () => {
  12179. const codegenNode = node.codegenNode || context.currentNode.codegenNode;
  12180. if (codegenNode && codegenNode.type === 13) {
  12181. if (node.tagType !== 1) {
  12182. convertToBlock(codegenNode, context);
  12183. }
  12184. node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
  12185. dir.exp,
  12186. createFunctionExpression(void 0, codegenNode),
  12187. `_cache`,
  12188. String(context.cached++)
  12189. ]);
  12190. }
  12191. };
  12192. }
  12193. };
  12194. function getBaseTransformPreset(prefixIdentifiers) {
  12195. return [
  12196. [
  12197. transformOnce,
  12198. transformIf,
  12199. transformMemo,
  12200. transformFor,
  12201. ...[transformFilter] ,
  12202. ...[transformExpression] ,
  12203. transformSlotOutlet,
  12204. transformElement,
  12205. trackSlotScopes,
  12206. transformText
  12207. ],
  12208. {
  12209. on: transformOn$1,
  12210. bind: transformBind,
  12211. model: transformModel$1
  12212. }
  12213. ];
  12214. }
  12215. function baseCompile(source, options = {}) {
  12216. const onError = options.onError || defaultOnError;
  12217. const isModuleMode = options.mode === "module";
  12218. {
  12219. if (options.prefixIdentifiers === true) {
  12220. onError(createCompilerError(47));
  12221. } else if (isModuleMode) {
  12222. onError(createCompilerError(48));
  12223. }
  12224. }
  12225. const prefixIdentifiers = false;
  12226. if (options.cacheHandlers) {
  12227. onError(createCompilerError(49));
  12228. }
  12229. if (options.scopeId && !isModuleMode) {
  12230. onError(createCompilerError(50));
  12231. }
  12232. const resolvedOptions = extend({}, options, {
  12233. prefixIdentifiers
  12234. });
  12235. const ast = isString(source) ? baseParse(source, resolvedOptions) : source;
  12236. const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
  12237. transform(
  12238. ast,
  12239. extend({}, resolvedOptions, {
  12240. nodeTransforms: [
  12241. ...nodeTransforms,
  12242. ...options.nodeTransforms || []
  12243. // user transforms
  12244. ],
  12245. directiveTransforms: extend(
  12246. {},
  12247. directiveTransforms,
  12248. options.directiveTransforms || {}
  12249. // user transforms
  12250. )
  12251. })
  12252. );
  12253. return generate(ast, resolvedOptions);
  12254. }
  12255. const noopDirectiveTransform = () => ({ props: [] });
  12256. /**
  12257. * @vue/compiler-dom v3.4.21
  12258. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  12259. * @license MIT
  12260. **/
  12261. const V_MODEL_RADIO = Symbol(`vModelRadio` );
  12262. const V_MODEL_CHECKBOX = Symbol(`vModelCheckbox` );
  12263. const V_MODEL_TEXT = Symbol(`vModelText` );
  12264. const V_MODEL_SELECT = Symbol(`vModelSelect` );
  12265. const V_MODEL_DYNAMIC = Symbol(`vModelDynamic` );
  12266. const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard` );
  12267. const V_ON_WITH_KEYS = Symbol(`vOnKeysGuard` );
  12268. const V_SHOW = Symbol(`vShow` );
  12269. const TRANSITION = Symbol(`Transition` );
  12270. const TRANSITION_GROUP = Symbol(`TransitionGroup` );
  12271. registerRuntimeHelpers({
  12272. [V_MODEL_RADIO]: `vModelRadio`,
  12273. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  12274. [V_MODEL_TEXT]: `vModelText`,
  12275. [V_MODEL_SELECT]: `vModelSelect`,
  12276. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  12277. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  12278. [V_ON_WITH_KEYS]: `withKeys`,
  12279. [V_SHOW]: `vShow`,
  12280. [TRANSITION]: `Transition`,
  12281. [TRANSITION_GROUP]: `TransitionGroup`
  12282. });
  12283. let decoder;
  12284. function decodeHtmlBrowser(raw, asAttr = false) {
  12285. if (!decoder) {
  12286. decoder = document.createElement("div");
  12287. }
  12288. if (asAttr) {
  12289. decoder.innerHTML = `<div foo="${raw.replace(/"/g, "&quot;")}">`;
  12290. return decoder.children[0].getAttribute("foo");
  12291. } else {
  12292. decoder.innerHTML = raw;
  12293. return decoder.textContent;
  12294. }
  12295. }
  12296. const parserOptions = {
  12297. parseMode: "html",
  12298. isVoidTag,
  12299. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
  12300. isPreTag: (tag) => tag === "pre",
  12301. decodeEntities: decodeHtmlBrowser ,
  12302. isBuiltInComponent: (tag) => {
  12303. if (tag === "Transition" || tag === "transition") {
  12304. return TRANSITION;
  12305. } else if (tag === "TransitionGroup" || tag === "transition-group") {
  12306. return TRANSITION_GROUP;
  12307. }
  12308. },
  12309. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  12310. getNamespace(tag, parent, rootNamespace) {
  12311. let ns = parent ? parent.ns : rootNamespace;
  12312. if (parent && ns === 2) {
  12313. if (parent.tag === "annotation-xml") {
  12314. if (tag === "svg") {
  12315. return 1;
  12316. }
  12317. if (parent.props.some(
  12318. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  12319. )) {
  12320. ns = 0;
  12321. }
  12322. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  12323. ns = 0;
  12324. }
  12325. } else if (parent && ns === 1) {
  12326. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  12327. ns = 0;
  12328. }
  12329. }
  12330. if (ns === 0) {
  12331. if (tag === "svg") {
  12332. return 1;
  12333. }
  12334. if (tag === "math") {
  12335. return 2;
  12336. }
  12337. }
  12338. return ns;
  12339. }
  12340. };
  12341. const transformStyle = (node) => {
  12342. if (node.type === 1) {
  12343. node.props.forEach((p, i) => {
  12344. if (p.type === 6 && p.name === "style" && p.value) {
  12345. node.props[i] = {
  12346. type: 7,
  12347. name: `bind`,
  12348. arg: createSimpleExpression(`style`, true, p.loc),
  12349. exp: parseInlineCSS(p.value.content, p.loc),
  12350. modifiers: [],
  12351. loc: p.loc
  12352. };
  12353. }
  12354. });
  12355. }
  12356. };
  12357. const parseInlineCSS = (cssText, loc) => {
  12358. const normalized = parseStringStyle(cssText);
  12359. return createSimpleExpression(
  12360. JSON.stringify(normalized),
  12361. false,
  12362. loc,
  12363. 3
  12364. );
  12365. };
  12366. function createDOMCompilerError(code, loc) {
  12367. return createCompilerError(
  12368. code,
  12369. loc,
  12370. DOMErrorMessages
  12371. );
  12372. }
  12373. const DOMErrorMessages = {
  12374. [53]: `v-html is missing expression.`,
  12375. [54]: `v-html will override element children.`,
  12376. [55]: `v-text is missing expression.`,
  12377. [56]: `v-text will override element children.`,
  12378. [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  12379. [58]: `v-model argument is not supported on plain elements.`,
  12380. [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  12381. [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  12382. [61]: `v-show is missing expression.`,
  12383. [62]: `<Transition> expects exactly one child element or component.`,
  12384. [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  12385. };
  12386. const transformVHtml = (dir, node, context) => {
  12387. const { exp, loc } = dir;
  12388. if (!exp) {
  12389. context.onError(
  12390. createDOMCompilerError(53, loc)
  12391. );
  12392. }
  12393. if (node.children.length) {
  12394. context.onError(
  12395. createDOMCompilerError(54, loc)
  12396. );
  12397. node.children.length = 0;
  12398. }
  12399. return {
  12400. props: [
  12401. createObjectProperty(
  12402. createSimpleExpression(`innerHTML`, true, loc),
  12403. exp || createSimpleExpression("", true)
  12404. )
  12405. ]
  12406. };
  12407. };
  12408. const transformVText = (dir, node, context) => {
  12409. const { exp, loc } = dir;
  12410. if (!exp) {
  12411. context.onError(
  12412. createDOMCompilerError(55, loc)
  12413. );
  12414. }
  12415. if (node.children.length) {
  12416. context.onError(
  12417. createDOMCompilerError(56, loc)
  12418. );
  12419. node.children.length = 0;
  12420. }
  12421. return {
  12422. props: [
  12423. createObjectProperty(
  12424. createSimpleExpression(`textContent`, true),
  12425. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  12426. context.helperString(TO_DISPLAY_STRING),
  12427. [exp],
  12428. loc
  12429. ) : createSimpleExpression("", true)
  12430. )
  12431. ]
  12432. };
  12433. };
  12434. const transformModel = (dir, node, context) => {
  12435. const baseResult = transformModel$1(dir, node, context);
  12436. if (!baseResult.props.length || node.tagType === 1) {
  12437. return baseResult;
  12438. }
  12439. if (dir.arg) {
  12440. context.onError(
  12441. createDOMCompilerError(
  12442. 58,
  12443. dir.arg.loc
  12444. )
  12445. );
  12446. }
  12447. function checkDuplicatedValue() {
  12448. const value = findDir(node, "bind");
  12449. if (value && isStaticArgOf(value.arg, "value")) {
  12450. context.onError(
  12451. createDOMCompilerError(
  12452. 60,
  12453. value.loc
  12454. )
  12455. );
  12456. }
  12457. }
  12458. const { tag } = node;
  12459. const isCustomElement = context.isCustomElement(tag);
  12460. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  12461. let directiveToUse = V_MODEL_TEXT;
  12462. let isInvalidType = false;
  12463. if (tag === "input" || isCustomElement) {
  12464. const type = findProp(node, `type`);
  12465. if (type) {
  12466. if (type.type === 7) {
  12467. directiveToUse = V_MODEL_DYNAMIC;
  12468. } else if (type.value) {
  12469. switch (type.value.content) {
  12470. case "radio":
  12471. directiveToUse = V_MODEL_RADIO;
  12472. break;
  12473. case "checkbox":
  12474. directiveToUse = V_MODEL_CHECKBOX;
  12475. break;
  12476. case "file":
  12477. isInvalidType = true;
  12478. context.onError(
  12479. createDOMCompilerError(
  12480. 59,
  12481. dir.loc
  12482. )
  12483. );
  12484. break;
  12485. default:
  12486. checkDuplicatedValue();
  12487. break;
  12488. }
  12489. }
  12490. } else if (hasDynamicKeyVBind(node)) {
  12491. directiveToUse = V_MODEL_DYNAMIC;
  12492. } else {
  12493. checkDuplicatedValue();
  12494. }
  12495. } else if (tag === "select") {
  12496. directiveToUse = V_MODEL_SELECT;
  12497. } else {
  12498. checkDuplicatedValue();
  12499. }
  12500. if (!isInvalidType) {
  12501. baseResult.needRuntime = context.helper(directiveToUse);
  12502. }
  12503. } else {
  12504. context.onError(
  12505. createDOMCompilerError(
  12506. 57,
  12507. dir.loc
  12508. )
  12509. );
  12510. }
  12511. baseResult.props = baseResult.props.filter(
  12512. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  12513. );
  12514. return baseResult;
  12515. };
  12516. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  12517. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  12518. // event propagation management
  12519. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  12520. );
  12521. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  12522. const isKeyboardEvent = /* @__PURE__ */ makeMap(
  12523. `onkeyup,onkeydown,onkeypress`,
  12524. true
  12525. );
  12526. const resolveModifiers = (key, modifiers, context, loc) => {
  12527. const keyModifiers = [];
  12528. const nonKeyModifiers = [];
  12529. const eventOptionModifiers = [];
  12530. for (let i = 0; i < modifiers.length; i++) {
  12531. const modifier = modifiers[i];
  12532. if (modifier === "native" && checkCompatEnabled(
  12533. "COMPILER_V_ON_NATIVE",
  12534. context,
  12535. loc
  12536. )) {
  12537. eventOptionModifiers.push(modifier);
  12538. } else if (isEventOptionModifier(modifier)) {
  12539. eventOptionModifiers.push(modifier);
  12540. } else {
  12541. if (maybeKeyModifier(modifier)) {
  12542. if (isStaticExp(key)) {
  12543. if (isKeyboardEvent(key.content)) {
  12544. keyModifiers.push(modifier);
  12545. } else {
  12546. nonKeyModifiers.push(modifier);
  12547. }
  12548. } else {
  12549. keyModifiers.push(modifier);
  12550. nonKeyModifiers.push(modifier);
  12551. }
  12552. } else {
  12553. if (isNonKeyModifier(modifier)) {
  12554. nonKeyModifiers.push(modifier);
  12555. } else {
  12556. keyModifiers.push(modifier);
  12557. }
  12558. }
  12559. }
  12560. }
  12561. return {
  12562. keyModifiers,
  12563. nonKeyModifiers,
  12564. eventOptionModifiers
  12565. };
  12566. };
  12567. const transformClick = (key, event) => {
  12568. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  12569. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  12570. `(`,
  12571. key,
  12572. `) === "onClick" ? "${event}" : (`,
  12573. key,
  12574. `)`
  12575. ]) : key;
  12576. };
  12577. const transformOn = (dir, node, context) => {
  12578. return transformOn$1(dir, node, context, (baseResult) => {
  12579. const { modifiers } = dir;
  12580. if (!modifiers.length)
  12581. return baseResult;
  12582. let { key, value: handlerExp } = baseResult.props[0];
  12583. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  12584. if (nonKeyModifiers.includes("right")) {
  12585. key = transformClick(key, `onContextmenu`);
  12586. }
  12587. if (nonKeyModifiers.includes("middle")) {
  12588. key = transformClick(key, `onMouseup`);
  12589. }
  12590. if (nonKeyModifiers.length) {
  12591. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  12592. handlerExp,
  12593. JSON.stringify(nonKeyModifiers)
  12594. ]);
  12595. }
  12596. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  12597. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  12598. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  12599. handlerExp,
  12600. JSON.stringify(keyModifiers)
  12601. ]);
  12602. }
  12603. if (eventOptionModifiers.length) {
  12604. const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
  12605. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  12606. }
  12607. return {
  12608. props: [createObjectProperty(key, handlerExp)]
  12609. };
  12610. });
  12611. };
  12612. const transformShow = (dir, node, context) => {
  12613. const { exp, loc } = dir;
  12614. if (!exp) {
  12615. context.onError(
  12616. createDOMCompilerError(61, loc)
  12617. );
  12618. }
  12619. return {
  12620. props: [],
  12621. needRuntime: context.helper(V_SHOW)
  12622. };
  12623. };
  12624. const transformTransition = (node, context) => {
  12625. if (node.type === 1 && node.tagType === 1) {
  12626. const component = context.isBuiltInComponent(node.tag);
  12627. if (component === TRANSITION) {
  12628. return () => {
  12629. if (!node.children.length) {
  12630. return;
  12631. }
  12632. if (hasMultipleChildren(node)) {
  12633. context.onError(
  12634. createDOMCompilerError(
  12635. 62,
  12636. {
  12637. start: node.children[0].loc.start,
  12638. end: node.children[node.children.length - 1].loc.end,
  12639. source: ""
  12640. }
  12641. )
  12642. );
  12643. }
  12644. const child = node.children[0];
  12645. if (child.type === 1) {
  12646. for (const p of child.props) {
  12647. if (p.type === 7 && p.name === "show") {
  12648. node.props.push({
  12649. type: 6,
  12650. name: "persisted",
  12651. nameLoc: node.loc,
  12652. value: void 0,
  12653. loc: node.loc
  12654. });
  12655. }
  12656. }
  12657. }
  12658. };
  12659. }
  12660. }
  12661. };
  12662. function hasMultipleChildren(node) {
  12663. const children = node.children = node.children.filter(
  12664. (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
  12665. );
  12666. const child = children[0];
  12667. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  12668. }
  12669. const ignoreSideEffectTags = (node, context) => {
  12670. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  12671. context.onError(
  12672. createDOMCompilerError(
  12673. 63,
  12674. node.loc
  12675. )
  12676. );
  12677. context.removeNode();
  12678. }
  12679. };
  12680. const DOMNodeTransforms = [
  12681. transformStyle,
  12682. ...[transformTransition]
  12683. ];
  12684. const DOMDirectiveTransforms = {
  12685. cloak: noopDirectiveTransform,
  12686. html: transformVHtml,
  12687. text: transformVText,
  12688. model: transformModel,
  12689. // override compiler-core
  12690. on: transformOn,
  12691. // override compiler-core
  12692. show: transformShow
  12693. };
  12694. function compile(src, options = {}) {
  12695. return baseCompile(
  12696. src,
  12697. extend({}, parserOptions, options, {
  12698. nodeTransforms: [
  12699. // ignore <script> and <tag>
  12700. // this is not put inside DOMNodeTransforms because that list is used
  12701. // by compiler-ssr to generate vnode fallback branches
  12702. ignoreSideEffectTags,
  12703. ...DOMNodeTransforms,
  12704. ...options.nodeTransforms || []
  12705. ],
  12706. directiveTransforms: extend(
  12707. {},
  12708. DOMDirectiveTransforms,
  12709. options.directiveTransforms || {}
  12710. ),
  12711. transformHoist: null
  12712. })
  12713. );
  12714. }
  12715. function processSlot(source, Vue$1) {
  12716. if (source === void 0) { source = ''; }
  12717. if (Vue$1 === void 0) { Vue$1 = Vue; }
  12718. var template = source.trim();
  12719. var hasWrappingTemplate = template && template.startsWith('<template');
  12720. // allow content without `template` tag, for easier testing
  12721. if (!hasWrappingTemplate) {
  12722. template = "<template #default=\"params\">".concat(template, "</template>");
  12723. }
  12724. // Vue does not provide an easy way to compile template in "slot" mode
  12725. // Since we do not want to rely on compiler internals and specify
  12726. // transforms manually we create fake component invocation with the slot we
  12727. // need and pick slots param from render function later. Fake component will
  12728. // never be instantiated but it requires to be a component so compile
  12729. // properly generate invocation. Since we do not want to monkey-patch
  12730. // `resolveComponent` function we are just using one of built-in components:
  12731. // transition
  12732. var code = compile("<transition>".concat(template, "</transition>"), {
  12733. mode: 'function',
  12734. prefixIdentifiers: true
  12735. }).code;
  12736. var createRenderFunction = new Function('Vue', "'use strict';\n".concat(code) );
  12737. var renderFn = createRenderFunction(Vue$1);
  12738. return function (ctx) {
  12739. if (ctx === void 0) { ctx = {}; }
  12740. var result = renderFn(ctx);
  12741. var slotName = Object.keys(result.children)[0];
  12742. return result.children[slotName](ctx);
  12743. };
  12744. }
  12745. var isTeleport = function (type) { return type.__isTeleport; };
  12746. var isKeepAlive = function (type) { return type.__isKeepAlive; };
  12747. var isRootComponent = function (rootComponents, type, instance) {
  12748. return !!(!instance ||
  12749. // Don't stub mounted component on root level
  12750. (rootComponents.component === type && !(instance === null || instance === void 0 ? void 0 : instance.parent)) ||
  12751. // Don't stub component with compat wrapper
  12752. (rootComponents.functional && rootComponents.functional === type));
  12753. };
  12754. var createVNodeTransformer = function (_a) {
  12755. var rootComponents = _a.rootComponents, transformers = _a.transformers;
  12756. var transformationCache = new WeakMap();
  12757. return function (args, instance) {
  12758. var originalType = args[0], props = args[1], children = args[2], restVNodeArgs = args.slice(3);
  12759. if (!isComponent$1(originalType)) {
  12760. return __spreadArray([originalType, props, children], restVNodeArgs, true);
  12761. }
  12762. var componentType = originalType;
  12763. var cachedTransformation = transformationCache.get(originalType);
  12764. if (cachedTransformation &&
  12765. // Don't use cache for root component, as it could use stubbed recursive component
  12766. !isRootComponent(rootComponents, componentType, instance) &&
  12767. !isTeleport(originalType) &&
  12768. !isKeepAlive(originalType)) {
  12769. return __spreadArray([cachedTransformation, props, children], restVNodeArgs, true);
  12770. }
  12771. var transformedType = transformers.reduce(function (type, transformer) { return transformer(type, instance); }, componentType);
  12772. if (originalType !== transformedType) {
  12773. transformationCache.set(originalType, transformedType);
  12774. registerStub({ source: originalType, stub: transformedType });
  12775. // https://github.com/vuejs/test-utils/issues/1829 & https://github.com/vuejs/test-utils/issues/1888
  12776. // Teleport/KeepAlive should return child nodes as a function
  12777. if (isTeleport(originalType) || isKeepAlive(originalType)) {
  12778. return __spreadArray([transformedType, props, function () { return children; }], restVNodeArgs, true);
  12779. }
  12780. }
  12781. return __spreadArray([transformedType, props, children], restVNodeArgs, true);
  12782. };
  12783. };
  12784. var normalizeStubProps = function (props) {
  12785. // props are always normalized to object syntax
  12786. var $props = props;
  12787. return Object.keys($props).reduce(function (acc, key) {
  12788. var _a, _b, _c;
  12789. var _d;
  12790. if (typeof $props[key] === 'symbol') {
  12791. return __assign(__assign({}, acc), (_a = {}, _a[key] = (_d = $props[key]) === null || _d === void 0 ? void 0 : _d.toString(), _a));
  12792. }
  12793. if (typeof $props[key] === 'function') {
  12794. return __assign(__assign({}, acc), (_b = {}, _b[key] = '[Function]', _b));
  12795. }
  12796. return __assign(__assign({}, acc), (_c = {}, _c[key] = $props[key], _c));
  12797. }, {});
  12798. };
  12799. var clearAndUpper = function (text) { return text.replace(/-/, '').toUpperCase(); };
  12800. var kebabToPascalCase = function (tag) {
  12801. return tag.replace(/(^\w|-\w)/g, clearAndUpper);
  12802. };
  12803. var DEFAULT_STUBS = {
  12804. teleport: isTeleport,
  12805. 'keep-alive': isKeepAlive,
  12806. transition: function (type) { return type === Transition || type === BaseTransition; },
  12807. 'transition-group': function (type) { return type === TransitionGroup; }
  12808. };
  12809. var createDefaultStub = function (kebabTag, predicate, type, stubs) {
  12810. var pascalTag = kebabToPascalCase(kebabTag);
  12811. if (predicate(type) && (pascalTag in stubs || kebabTag in stubs)) {
  12812. if (kebabTag in stubs && stubs[kebabTag] === false)
  12813. return type;
  12814. if (pascalTag in stubs && stubs[pascalTag] === false)
  12815. return type;
  12816. if (stubs[kebabTag] === true || stubs[pascalTag] === true) {
  12817. return createStub({
  12818. name: kebabTag,
  12819. type: type,
  12820. renderStubDefaultSlot: true
  12821. });
  12822. }
  12823. }
  12824. };
  12825. var createStub = function (_a) {
  12826. var name = _a.name, type = _a.type, renderStubDefaultSlot = _a.renderStubDefaultSlot;
  12827. var anonName = 'anonymous-stub';
  12828. var tag = name ? "".concat(hyphenate$1(name), "-stub") : anonName;
  12829. var componentOptions = type
  12830. ? unwrapLegacyVueExtendComponent(type) || {}
  12831. : {};
  12832. var stub = defineComponent({
  12833. name: name || anonName,
  12834. props: componentOptions.props || {},
  12835. // fix #1550 - respect old-style v-model for shallow mounted components with @vue/compat
  12836. // @ts-expect-error
  12837. model: componentOptions.model,
  12838. setup: function (props, _a) {
  12839. var slots = _a.slots;
  12840. return function () {
  12841. // https://github.com/vuejs/test-utils/issues/1076
  12842. // Passing a symbol as a static prop is not legal, since Vue will try to do
  12843. // something like `el.setAttribute('val', Symbol())` which is not valid and
  12844. // causes an error.
  12845. // Only a problem when shallow mounting. For this reason we iterate of the
  12846. // props that will be passed and stringify any that are symbols.
  12847. // Also having function text as attribute is useless and annoying so
  12848. // we replace it with "[Function]""
  12849. var stubProps = normalizeStubProps(props);
  12850. return h(tag, stubProps, renderStubDefaultSlot ? slots : undefined);
  12851. };
  12852. }
  12853. });
  12854. var asyncLoader = type.__asyncLoader;
  12855. if (asyncLoader) {
  12856. asyncLoader().then(function () {
  12857. registerStub({
  12858. source: type.__asyncResolved,
  12859. stub: stub
  12860. });
  12861. });
  12862. }
  12863. return stub;
  12864. };
  12865. var resolveComponentStubByName = function (componentName, stubs) {
  12866. for (var _i = 0, _a = Object.entries(stubs); _i < _a.length; _i++) {
  12867. var _b = _a[_i], stubKey = _b[0], value = _b[1];
  12868. if (matchName(componentName, stubKey)) {
  12869. return value;
  12870. }
  12871. }
  12872. };
  12873. function createStubComponentsTransformer(_a) {
  12874. var rootComponents = _a.rootComponents, _b = _a.stubs, stubs = _b === void 0 ? {} : _b, _c = _a.shallow, shallow = _c === void 0 ? false : _c, _d = _a.renderStubDefaultSlot, renderStubDefaultSlot = _d === void 0 ? false : _d;
  12875. return function componentsTransformer(type, instance) {
  12876. var _a, _b, _c;
  12877. for (var tag in DEFAULT_STUBS) {
  12878. var predicate = DEFAULT_STUBS[tag];
  12879. var defaultStub = createDefaultStub(tag, predicate, type, stubs);
  12880. if (defaultStub)
  12881. return defaultStub;
  12882. }
  12883. // Don't stub root components
  12884. if (isRootComponent(rootComponents, type, instance)) {
  12885. return type;
  12886. }
  12887. var registeredName = getComponentRegisteredName(instance, type);
  12888. var componentName = getComponentName(instance, type);
  12889. var stub = null;
  12890. var name = null;
  12891. // Prio 1 using the key in locally registered components in the parent
  12892. if (registeredName) {
  12893. stub = resolveComponentStubByName(registeredName, stubs);
  12894. if (stub) {
  12895. name = registeredName;
  12896. }
  12897. }
  12898. // Prio 2 using the name attribute in the component
  12899. if (!stub && componentName) {
  12900. stub = resolveComponentStubByName(componentName, stubs);
  12901. if (stub) {
  12902. name = componentName;
  12903. }
  12904. }
  12905. // case 2: custom implementation
  12906. if (isComponent$1(stub)) {
  12907. var unwrappedStub = unwrapLegacyVueExtendComponent(stub);
  12908. var stubFn_1 = isFunctionalComponent(unwrappedStub) ? unwrappedStub : null;
  12909. // Edge case: stub is component, we will not render stub but instead will create
  12910. // a new "copy" of stub component definition, but we want user still to be able
  12911. // to find our component by stub definition, so we register it manually
  12912. registerStub({ source: type, stub: stub });
  12913. var specializedStubComponent = stubFn_1
  12914. ? function () {
  12915. var args = [];
  12916. for (var _i = 0; _i < arguments.length; _i++) {
  12917. args[_i] = arguments[_i];
  12918. }
  12919. return stubFn_1.apply(void 0, args);
  12920. }
  12921. : __assign({}, unwrappedStub);
  12922. specializedStubComponent.props = unwrappedStub.props;
  12923. return specializedStubComponent;
  12924. }
  12925. if (stub === false) {
  12926. // we explicitly opt out of stubbing this component
  12927. return type;
  12928. }
  12929. // we return a stub by matching Vue's `h` function
  12930. // where the signature is h(Component, props, slots)
  12931. // case 1: default stub
  12932. if (stub === true || shallow) {
  12933. // Set name when using shallow without stub
  12934. var stubName = name || registeredName || componentName;
  12935. return ((_c = (_b = (_a = config.plugins).createStubs) === null || _b === void 0 ? void 0 : _b.call(_a, {
  12936. name: stubName,
  12937. component: type,
  12938. registerStub: registerStub
  12939. })) !== null && _c !== void 0 ? _c : createStub({
  12940. name: stubName,
  12941. type: type,
  12942. renderStubDefaultSlot: renderStubDefaultSlot
  12943. }));
  12944. }
  12945. return type;
  12946. };
  12947. }
  12948. var noop = function () { };
  12949. function createStubDirectivesTransformer(_a) {
  12950. var _b = _a.directives, directives = _b === void 0 ? {} : _b;
  12951. if (Object.keys(directives).length === 0) {
  12952. return function (type) { return type; };
  12953. }
  12954. return function directivesTransformer(type) {
  12955. if (isObjectComponent(type) && type.directives) {
  12956. // We want to change component types as rarely as possible
  12957. // So first we check if there are any directives we should stub
  12958. var directivesToPatch = Object.keys(type.directives).filter(function (key) { return key in directives; });
  12959. if (!directivesToPatch.length) {
  12960. return type;
  12961. }
  12962. var replacementDirectives = Object.fromEntries(directivesToPatch.map(function (name) {
  12963. var directive = directives[name];
  12964. return [name, typeof directive === 'boolean' ? noop : directive];
  12965. }));
  12966. return __assign(__assign({}, type), { directives: __assign(__assign({}, type.directives), replacementDirectives) });
  12967. }
  12968. return type;
  12969. };
  12970. }
  12971. var MOUNT_OPTIONS = [
  12972. 'attachTo',
  12973. 'attrs',
  12974. 'data',
  12975. 'props',
  12976. 'slots',
  12977. 'global',
  12978. 'shallow'
  12979. ];
  12980. function getInstanceOptions(options) {
  12981. if (options.methods) {
  12982. console.warn("Passing a `methods` option to mount was deprecated on Vue Test Utils v1, and it won't have any effect on v2. For additional info: https://vue-test-utils.vuejs.org/upgrading-to-v1/#setmethods-and-mountingoptions-methods");
  12983. delete options.methods;
  12984. }
  12985. var resultOptions = __assign({}, options);
  12986. for (var _i = 0, _a = Object.keys(options); _i < _a.length; _i++) {
  12987. var key = _a[_i];
  12988. if (MOUNT_OPTIONS.includes(key)) {
  12989. delete resultOptions[key];
  12990. }
  12991. }
  12992. return resultOptions;
  12993. }
  12994. // implementation
  12995. function createInstance(inputComponent, options) {
  12996. // normalize the incoming component
  12997. var originalComponent = unwrapLegacyVueExtendComponent(inputComponent);
  12998. var component;
  12999. var instanceOptions = getInstanceOptions(options !== null && options !== void 0 ? options : {});
  13000. var rootComponents = {};
  13001. if (isFunctionalComponent(originalComponent) ||
  13002. isLegacyFunctionalComponent(originalComponent)) {
  13003. component = defineComponent(__assign({ compatConfig: {
  13004. MODE: 3,
  13005. INSTANCE_LISTENERS: false,
  13006. INSTANCE_ATTRS_CLASS_STYLE: false,
  13007. COMPONENT_FUNCTIONAL: isLegacyFunctionalComponent(originalComponent)
  13008. ? 'suppress-warning'
  13009. : false
  13010. }, props: originalComponent.props || {}, setup: function (props, _a) {
  13011. var attrs = _a.attrs, slots = _a.slots;
  13012. return function () {
  13013. return h(originalComponent, __assign(__assign({}, props), attrs), slots);
  13014. };
  13015. } }, instanceOptions));
  13016. rootComponents.functional = originalComponent;
  13017. }
  13018. else if (isObjectComponent(originalComponent)) {
  13019. component = __assign(__assign({}, originalComponent), instanceOptions);
  13020. }
  13021. else {
  13022. component = originalComponent;
  13023. }
  13024. rootComponents.component = component;
  13025. // We've just replaced our component with its copy
  13026. // Let's register it as a stub so user can find it
  13027. registerStub({ source: originalComponent, stub: component });
  13028. function slotToFunction(slot) {
  13029. switch (typeof slot) {
  13030. case 'function':
  13031. return slot;
  13032. case 'object':
  13033. return function () { return h(slot); };
  13034. case 'string':
  13035. return processSlot(slot);
  13036. default:
  13037. throw Error("Invalid slot received.");
  13038. }
  13039. }
  13040. // handle any slots passed via mounting options
  13041. var slots = (options === null || options === void 0 ? void 0 : options.slots) &&
  13042. Object.entries(options.slots).reduce(function (acc, _a) {
  13043. var name = _a[0], slot = _a[1];
  13044. if (Array.isArray(slot)) {
  13045. var normalized_1 = slot.map(slotToFunction);
  13046. acc[name] = function (args) { return normalized_1.map(function (f) { return f(args); }); };
  13047. return acc;
  13048. }
  13049. acc[name] = slotToFunction(slot);
  13050. return acc;
  13051. }, {});
  13052. // override component data with mounting options data
  13053. if (options === null || options === void 0 ? void 0 : options.data) {
  13054. var providedData_1 = options.data();
  13055. if (isObjectComponent(originalComponent)) {
  13056. // component is guaranteed to be the same type as originalComponent
  13057. var objectComponent = component;
  13058. var originalDataFn_1 = originalComponent.data || (function () { return ({}); });
  13059. objectComponent.data = function (vm) { return (__assign(__assign({}, originalDataFn_1.call(vm, vm)), providedData_1)); };
  13060. }
  13061. else {
  13062. throw new Error('data() option is not supported on functional and class components');
  13063. }
  13064. }
  13065. var MOUNT_COMPONENT_REF = 'VTU_COMPONENT';
  13066. // we define props as reactive so that way when we update them with `setProps`
  13067. // Vue's reactivity system will cause a rerender.
  13068. var refs = shallowReactive({});
  13069. var props = reactive({});
  13070. Object.entries(__assign(__assign(__assign(__assign({}, options === null || options === void 0 ? void 0 : options.attrs), options === null || options === void 0 ? void 0 : options.propsData), options === null || options === void 0 ? void 0 : options.props), { ref: MOUNT_COMPONENT_REF })).forEach(function (_a) {
  13071. var k = _a[0], v = _a[1];
  13072. if (isDeepRef(v)) {
  13073. refs[k] = v;
  13074. }
  13075. else {
  13076. props[k] = v;
  13077. }
  13078. });
  13079. var global = mergeGlobalProperties(options === null || options === void 0 ? void 0 : options.global);
  13080. if (isObjectComponent(component)) {
  13081. component.components = __assign(__assign({}, component.components), global.components);
  13082. }
  13083. var componentRef = ref(null);
  13084. // create the wrapper component
  13085. var Parent = defineComponent({
  13086. name: 'VTU_ROOT',
  13087. setup: function () {
  13088. var _a;
  13089. return _a = {},
  13090. _a[MOUNT_COMPONENT_REF] = componentRef,
  13091. _a;
  13092. },
  13093. render: function () {
  13094. return h(component, __assign(__assign({}, props), refs), slots);
  13095. }
  13096. });
  13097. // create the app
  13098. var app = createApp(Parent);
  13099. // add tracking for emitted events
  13100. // this must be done after `createApp`: https://github.com/vuejs/test-utils/issues/436
  13101. attachEmitListener();
  13102. // global mocks mixin
  13103. if (global === null || global === void 0 ? void 0 : global.mocks) {
  13104. var mixin = {
  13105. beforeCreate: function () {
  13106. // we need to differentiate components that are or not not `script setup`
  13107. // otherwise we run into a proxy set error
  13108. // due to https://github.com/vuejs/core/commit/f73925d76a76ee259749b8b48cb68895f539a00f#diff-ea4d1ddabb7e22e17e80ada458eef70679af4005df2a1a6b73418fec897603ceR404
  13109. // introduced in Vue v3.2.45
  13110. // Also ensures not to include option API components in this block
  13111. // since they can also have setup state but need to be patched using
  13112. // the regular method.
  13113. if (isScriptSetup(this)) {
  13114. // add the mocks to setupState
  13115. for (var _i = 0, _a = Object.entries(global.mocks); _i < _a.length; _i++) {
  13116. var _b = _a[_i], k = _b[0], v = _b[1];
  13117. // we do this in a try/catch, as some properties might be read-only
  13118. try {
  13119. this.$.setupState[k] = v;
  13120. // eslint-disable-next-line no-empty
  13121. }
  13122. catch (e) { }
  13123. }
  13124. this.$.proxy = new Proxy(this.$.proxy, {
  13125. get: function (target, key) {
  13126. if (key in global.mocks) {
  13127. return global.mocks[key];
  13128. }
  13129. return target[key];
  13130. }
  13131. });
  13132. }
  13133. else {
  13134. for (var _c = 0, _d = Object.entries(global.mocks); _c < _d.length; _c++) {
  13135. var _e = _d[_c], k = _e[0], v = _e[1];
  13136. this[k] = v;
  13137. }
  13138. }
  13139. }
  13140. };
  13141. app.mixin(mixin);
  13142. }
  13143. // AppConfig
  13144. if (global.config) {
  13145. for (var _i = 0, _a = Object.entries(global.config); _i < _a.length; _i++) {
  13146. var _b = _a[_i], k = _b[0], v = _b[1];
  13147. app.config[k] = isObject$1(app.config[k])
  13148. ? Object.assign(app.config[k], v)
  13149. : v;
  13150. }
  13151. }
  13152. // use and plugins from mounting options
  13153. if (global.plugins) {
  13154. for (var _c = 0, _d = global.plugins; _c < _d.length; _c++) {
  13155. var plugin = _d[_c];
  13156. if (Array.isArray(plugin)) {
  13157. app.use.apply(app, __spreadArray([plugin[0]], plugin.slice(1), false));
  13158. continue;
  13159. }
  13160. app.use(plugin);
  13161. }
  13162. }
  13163. // use any mixins from mounting options
  13164. if (global.mixins) {
  13165. for (var _e = 0, _f = global.mixins; _e < _f.length; _e++) {
  13166. var mixin = _f[_e];
  13167. app.mixin(mixin);
  13168. }
  13169. }
  13170. if (global.components) {
  13171. for (var _g = 0, _h = Object.keys(global.components); _g < _h.length; _g++) {
  13172. var key = _h[_g];
  13173. // avoid registering components that are stubbed twice
  13174. if (!(key in global.stubs)) {
  13175. app.component(key, global.components[key]);
  13176. }
  13177. }
  13178. }
  13179. if (global.directives) {
  13180. for (var _j = 0, _k = Object.keys(global.directives); _j < _k.length; _j++) {
  13181. var key = _k[_j];
  13182. app.directive(key, global.directives[key]);
  13183. }
  13184. }
  13185. // provide any values passed via provides mounting option
  13186. if (global.provide) {
  13187. for (var _l = 0, _m = Reflect.ownKeys(global.provide); _l < _m.length; _l++) {
  13188. var key = _m[_l];
  13189. // @ts-ignore: https://github.com/microsoft/TypeScript/issues/1863
  13190. app.provide(key, global.provide[key]);
  13191. }
  13192. }
  13193. // stubs
  13194. // even if we are using `mount`, we will still
  13195. // stub out Transition and Transition Group by default.
  13196. transformVNodeArgs(createVNodeTransformer({
  13197. rootComponents: rootComponents,
  13198. transformers: [
  13199. createStubComponentsTransformer({
  13200. rootComponents: rootComponents,
  13201. stubs: getComponentsFromStubs(global.stubs),
  13202. shallow: options === null || options === void 0 ? void 0 : options.shallow,
  13203. renderStubDefaultSlot: global.renderStubDefaultSlot
  13204. }),
  13205. createStubDirectivesTransformer({
  13206. directives: getDirectivesFromStubs(global.stubs)
  13207. })
  13208. ]
  13209. }));
  13210. // users expect stubs to work with globally registered
  13211. // components so we register stubs as global components to avoid
  13212. // warning about not being able to resolve component
  13213. //
  13214. // component implementation provided here will never be called
  13215. // but we need name to make sure that stubComponents will
  13216. // properly stub this later by matching stub name
  13217. //
  13218. // ref: https://github.com/vuejs/test-utils/issues/249
  13219. // ref: https://github.com/vuejs/test-utils/issues/425
  13220. if (global === null || global === void 0 ? void 0 : global.stubs) {
  13221. for (var _o = 0, _p = Object.keys(getComponentsFromStubs(global.stubs)); _o < _p.length; _o++) {
  13222. var name_1 = _p[_o];
  13223. if (!app.component(name_1)) {
  13224. app.component(name_1, { name: name_1 });
  13225. }
  13226. }
  13227. }
  13228. return {
  13229. app: app,
  13230. props: props,
  13231. componentRef: componentRef
  13232. };
  13233. }
  13234. var isEnabled = false;
  13235. var wrapperInstances = [];
  13236. function disableAutoUnmount() {
  13237. isEnabled = false;
  13238. wrapperInstances.length = 0;
  13239. }
  13240. function enableAutoUnmount(hook) {
  13241. if (isEnabled) {
  13242. throw new Error('enableAutoUnmount cannot be called more than once');
  13243. }
  13244. isEnabled = true;
  13245. hook(function () {
  13246. wrapperInstances.forEach(function (wrapper) {
  13247. wrapper.unmount();
  13248. });
  13249. wrapperInstances.length = 0;
  13250. });
  13251. }
  13252. function trackInstance(wrapper) {
  13253. if (!isEnabled)
  13254. return;
  13255. wrapperInstances.push(wrapper);
  13256. }
  13257. // implementation
  13258. function mount(inputComponent, options) {
  13259. var _a = createInstance(inputComponent, options), app = _a.app, props = _a.props, componentRef = _a.componentRef;
  13260. var setProps = function (newProps) {
  13261. for (var _i = 0, _a = Object.entries(newProps); _i < _a.length; _i++) {
  13262. var _b = _a[_i], k = _b[0], v = _b[1];
  13263. props[k] = v;
  13264. }
  13265. return vm.$nextTick();
  13266. };
  13267. // Workaround for https://github.com/vuejs/core/issues/7020
  13268. var originalErrorHandler = app.config.errorHandler;
  13269. var errorOnMount = null;
  13270. app.config.errorHandler = function (err, instance, info) {
  13271. errorOnMount = err;
  13272. return originalErrorHandler === null || originalErrorHandler === void 0 ? void 0 : originalErrorHandler(err, instance, info);
  13273. };
  13274. // mount the app!
  13275. var el = document.createElement('div');
  13276. if (options === null || options === void 0 ? void 0 : options.attachTo) {
  13277. var to = void 0;
  13278. if (typeof options.attachTo === 'string') {
  13279. to = document.querySelector(options.attachTo);
  13280. if (!to) {
  13281. throw new Error("Unable to find the element matching the selector ".concat(options.attachTo, " given as the `attachTo` option"));
  13282. }
  13283. }
  13284. else {
  13285. to = options.attachTo;
  13286. }
  13287. to.appendChild(el);
  13288. }
  13289. var vm = app.mount(el);
  13290. if (errorOnMount) {
  13291. throw errorOnMount;
  13292. }
  13293. app.config.errorHandler = originalErrorHandler;
  13294. var appRef = componentRef.value;
  13295. // we add `hasOwnProperty` so Jest can spy on the proxied vm without throwing
  13296. // note that this is not necessary with Jest v27+ or Vitest, but is kept for compatibility with older Jest versions
  13297. if (!app.hasOwnProperty) {
  13298. appRef.hasOwnProperty = function (property) {
  13299. return Reflect.has(appRef, property);
  13300. };
  13301. }
  13302. var wrapper = createVueWrapper(app, appRef, setProps);
  13303. trackInstance(wrapper);
  13304. return wrapper;
  13305. }
  13306. var shallowMount = function (component, options) {
  13307. return mount(component, __assign(__assign({}, options), { shallow: true }));
  13308. };
  13309. /**
  13310. * @vue/server-renderer v3.4.21
  13311. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  13312. * @license MIT
  13313. **/
  13314. const shouldIgnoreProp = makeMap(
  13315. `,key,ref,innerHTML,textContent,ref_key,ref_for`
  13316. );
  13317. function ssrRenderAttrs(props, tag) {
  13318. let ret = "";
  13319. for (const key in props) {
  13320. if (shouldIgnoreProp(key) || isOn(key) || tag === "textarea" && key === "value") {
  13321. continue;
  13322. }
  13323. const value = props[key];
  13324. if (key === "class") {
  13325. ret += ` class="${ssrRenderClass(value)}"`;
  13326. } else if (key === "style") {
  13327. ret += ` style="${ssrRenderStyle(value)}"`;
  13328. } else {
  13329. ret += ssrRenderDynamicAttr(key, value, tag);
  13330. }
  13331. }
  13332. return ret;
  13333. }
  13334. function ssrRenderDynamicAttr(key, value, tag) {
  13335. if (!isRenderableAttrValue(value)) {
  13336. return ``;
  13337. }
  13338. const attrKey = tag && (tag.indexOf("-") > 0 || isSVGTag(tag)) ? key : propsToAttrMap[key] || key.toLowerCase();
  13339. if (isBooleanAttr(attrKey)) {
  13340. return includeBooleanAttr(value) ? ` ${attrKey}` : ``;
  13341. } else if (isSSRSafeAttrName(attrKey)) {
  13342. return value === "" ? ` ${attrKey}` : ` ${attrKey}="${escapeHtml(value)}"`;
  13343. } else {
  13344. console.warn(
  13345. `[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`
  13346. );
  13347. return ``;
  13348. }
  13349. }
  13350. function ssrRenderClass(raw) {
  13351. return escapeHtml(normalizeClass(raw));
  13352. }
  13353. function ssrRenderStyle(raw) {
  13354. if (!raw) {
  13355. return "";
  13356. }
  13357. if (isString(raw)) {
  13358. return escapeHtml(raw);
  13359. }
  13360. const styles = normalizeStyle(raw);
  13361. return escapeHtml(stringifyStyle(styles));
  13362. }
  13363. function ssrRenderTeleport(parentPush, contentRenderFn, target, disabled, parentComponent) {
  13364. parentPush("<!--teleport start-->");
  13365. const context = parentComponent.appContext.provides[ssrContextKey];
  13366. const teleportBuffers = context.__teleportBuffers || (context.__teleportBuffers = {});
  13367. const targetBuffer = teleportBuffers[target] || (teleportBuffers[target] = []);
  13368. const bufferIndex = targetBuffer.length;
  13369. let teleportContent;
  13370. if (disabled) {
  13371. contentRenderFn(parentPush);
  13372. teleportContent = `<!--teleport anchor-->`;
  13373. } else {
  13374. const { getBuffer, push } = createBuffer();
  13375. contentRenderFn(push);
  13376. push(`<!--teleport anchor-->`);
  13377. teleportContent = getBuffer();
  13378. }
  13379. targetBuffer.splice(bufferIndex, 0, teleportContent);
  13380. parentPush("<!--teleport end-->");
  13381. }
  13382. {
  13383. const g = getGlobalThis();
  13384. const registerGlobalSetter = (key, setter) => {
  13385. let setters;
  13386. if (!(setters = g[key]))
  13387. setters = g[key] = [];
  13388. setters.push(setter);
  13389. return (v) => {
  13390. if (setters.length > 1)
  13391. setters.forEach((set) => set(v));
  13392. else
  13393. setters[0](v);
  13394. };
  13395. };
  13396. registerGlobalSetter(
  13397. `__VUE_INSTANCE_SETTERS__`,
  13398. (v) => v
  13399. );
  13400. registerGlobalSetter(
  13401. `__VUE_SSR_SETTERS__`,
  13402. (v) => v
  13403. );
  13404. }
  13405. function ssrCompile(template, instance) {
  13406. {
  13407. throw new Error(
  13408. `On-the-fly template compilation is not supported in the ESM build of @vue/server-renderer. All templates must be pre-compiled into render functions.`
  13409. );
  13410. }
  13411. }
  13412. const {
  13413. createComponentInstance,
  13414. setCurrentRenderingInstance,
  13415. setupComponent,
  13416. renderComponentRoot,
  13417. normalizeVNode
  13418. } = ssrUtils;
  13419. function createBuffer() {
  13420. let appendable = false;
  13421. const buffer = [];
  13422. return {
  13423. getBuffer() {
  13424. return buffer;
  13425. },
  13426. push(item) {
  13427. const isStringItem = isString(item);
  13428. if (appendable && isStringItem) {
  13429. buffer[buffer.length - 1] += item;
  13430. } else {
  13431. buffer.push(item);
  13432. }
  13433. appendable = isStringItem;
  13434. if (isPromise(item) || isArray(item) && item.hasAsync) {
  13435. buffer.hasAsync = true;
  13436. }
  13437. }
  13438. };
  13439. }
  13440. function renderComponentVNode(vnode, parentComponent = null, slotScopeId) {
  13441. const instance = createComponentInstance(vnode, parentComponent, null);
  13442. const res = setupComponent(
  13443. instance,
  13444. true
  13445. /* isSSR */
  13446. );
  13447. const hasAsyncSetup = isPromise(res);
  13448. const prefetches = instance.sp;
  13449. if (hasAsyncSetup || prefetches) {
  13450. let p = hasAsyncSetup ? res : Promise.resolve();
  13451. if (prefetches) {
  13452. p = p.then(
  13453. () => Promise.all(
  13454. prefetches.map((prefetch) => prefetch.call(instance.proxy))
  13455. )
  13456. ).catch(NOOP);
  13457. }
  13458. return p.then(() => renderComponentSubTree(instance, slotScopeId));
  13459. } else {
  13460. return renderComponentSubTree(instance, slotScopeId);
  13461. }
  13462. }
  13463. function renderComponentSubTree(instance, slotScopeId) {
  13464. const comp = instance.type;
  13465. const { getBuffer, push } = createBuffer();
  13466. if (isFunction(comp)) {
  13467. let root = renderComponentRoot(instance);
  13468. if (!comp.props) {
  13469. for (const key in instance.attrs) {
  13470. if (key.startsWith(`data-v-`)) {
  13471. (root.props || (root.props = {}))[key] = ``;
  13472. }
  13473. }
  13474. }
  13475. renderVNode(push, instance.subTree = root, instance, slotScopeId);
  13476. } else {
  13477. if ((!instance.render || instance.render === NOOP) && !instance.ssrRender && !comp.ssrRender && isString(comp.template)) {
  13478. comp.ssrRender = ssrCompile(comp.template);
  13479. }
  13480. for (const e of instance.scope.effects) {
  13481. if (e.computed) {
  13482. e.computed._dirty = true;
  13483. e.computed._cacheable = true;
  13484. }
  13485. }
  13486. const ssrRender = instance.ssrRender || comp.ssrRender;
  13487. if (ssrRender) {
  13488. let attrs = instance.inheritAttrs !== false ? instance.attrs : void 0;
  13489. let hasCloned = false;
  13490. let cur = instance;
  13491. while (true) {
  13492. const scopeId = cur.vnode.scopeId;
  13493. if (scopeId) {
  13494. if (!hasCloned) {
  13495. attrs = { ...attrs };
  13496. hasCloned = true;
  13497. }
  13498. attrs[scopeId] = "";
  13499. }
  13500. const parent = cur.parent;
  13501. if (parent && parent.subTree && parent.subTree === cur.vnode) {
  13502. cur = parent;
  13503. } else {
  13504. break;
  13505. }
  13506. }
  13507. if (slotScopeId) {
  13508. if (!hasCloned)
  13509. attrs = { ...attrs };
  13510. attrs[slotScopeId.trim()] = "";
  13511. }
  13512. const prev = setCurrentRenderingInstance(instance);
  13513. try {
  13514. ssrRender(
  13515. instance.proxy,
  13516. push,
  13517. instance,
  13518. attrs,
  13519. // compiler-optimized bindings
  13520. instance.props,
  13521. instance.setupState,
  13522. instance.data,
  13523. instance.ctx
  13524. );
  13525. } finally {
  13526. setCurrentRenderingInstance(prev);
  13527. }
  13528. } else if (instance.render && instance.render !== NOOP) {
  13529. renderVNode(
  13530. push,
  13531. instance.subTree = renderComponentRoot(instance),
  13532. instance,
  13533. slotScopeId
  13534. );
  13535. } else {
  13536. const componentName = comp.name || comp.__file || `<Anonymous>`;
  13537. warn(`Component ${componentName} is missing template or render function.`);
  13538. push(`<!---->`);
  13539. }
  13540. }
  13541. return getBuffer();
  13542. }
  13543. function renderVNode(push, vnode, parentComponent, slotScopeId) {
  13544. const { type, shapeFlag, children } = vnode;
  13545. switch (type) {
  13546. case Text:
  13547. push(escapeHtml(children));
  13548. break;
  13549. case Comment:
  13550. push(
  13551. children ? `<!--${escapeHtmlComment(children)}-->` : `<!---->`
  13552. );
  13553. break;
  13554. case Static:
  13555. push(children);
  13556. break;
  13557. case Fragment:
  13558. if (vnode.slotScopeIds) {
  13559. slotScopeId = (slotScopeId ? slotScopeId + " " : "") + vnode.slotScopeIds.join(" ");
  13560. }
  13561. push(`<!--[-->`);
  13562. renderVNodeChildren(
  13563. push,
  13564. children,
  13565. parentComponent,
  13566. slotScopeId
  13567. );
  13568. push(`<!--]-->`);
  13569. break;
  13570. default:
  13571. if (shapeFlag & 1) {
  13572. renderElementVNode(push, vnode, parentComponent, slotScopeId);
  13573. } else if (shapeFlag & 6) {
  13574. push(renderComponentVNode(vnode, parentComponent, slotScopeId));
  13575. } else if (shapeFlag & 64) {
  13576. renderTeleportVNode(push, vnode, parentComponent, slotScopeId);
  13577. } else if (shapeFlag & 128) {
  13578. renderVNode(push, vnode.ssContent, parentComponent, slotScopeId);
  13579. } else {
  13580. warn(
  13581. "[@vue/server-renderer] Invalid VNode type:",
  13582. type,
  13583. `(${typeof type})`
  13584. );
  13585. }
  13586. }
  13587. }
  13588. function renderVNodeChildren(push, children, parentComponent, slotScopeId) {
  13589. for (let i = 0; i < children.length; i++) {
  13590. renderVNode(push, normalizeVNode(children[i]), parentComponent, slotScopeId);
  13591. }
  13592. }
  13593. function renderElementVNode(push, vnode, parentComponent, slotScopeId) {
  13594. const tag = vnode.type;
  13595. let { props, children, shapeFlag, scopeId, dirs } = vnode;
  13596. let openTag = `<${tag}`;
  13597. if (dirs) {
  13598. props = applySSRDirectives(vnode, props, dirs);
  13599. }
  13600. if (props) {
  13601. openTag += ssrRenderAttrs(props, tag);
  13602. }
  13603. if (scopeId) {
  13604. openTag += ` ${scopeId}`;
  13605. }
  13606. let curParent = parentComponent;
  13607. let curVnode = vnode;
  13608. while (curParent && curVnode === curParent.subTree) {
  13609. curVnode = curParent.vnode;
  13610. if (curVnode.scopeId) {
  13611. openTag += ` ${curVnode.scopeId}`;
  13612. }
  13613. curParent = curParent.parent;
  13614. }
  13615. if (slotScopeId) {
  13616. openTag += ` ${slotScopeId}`;
  13617. }
  13618. push(openTag + `>`);
  13619. if (!isVoidTag(tag)) {
  13620. let hasChildrenOverride = false;
  13621. if (props) {
  13622. if (props.innerHTML) {
  13623. hasChildrenOverride = true;
  13624. push(props.innerHTML);
  13625. } else if (props.textContent) {
  13626. hasChildrenOverride = true;
  13627. push(escapeHtml(props.textContent));
  13628. } else if (tag === "textarea" && props.value) {
  13629. hasChildrenOverride = true;
  13630. push(escapeHtml(props.value));
  13631. }
  13632. }
  13633. if (!hasChildrenOverride) {
  13634. if (shapeFlag & 8) {
  13635. push(escapeHtml(children));
  13636. } else if (shapeFlag & 16) {
  13637. renderVNodeChildren(
  13638. push,
  13639. children,
  13640. parentComponent,
  13641. slotScopeId
  13642. );
  13643. }
  13644. }
  13645. push(`</${tag}>`);
  13646. }
  13647. }
  13648. function applySSRDirectives(vnode, rawProps, dirs) {
  13649. const toMerge = [];
  13650. for (let i = 0; i < dirs.length; i++) {
  13651. const binding = dirs[i];
  13652. const {
  13653. dir: { getSSRProps }
  13654. } = binding;
  13655. if (getSSRProps) {
  13656. const props = getSSRProps(binding, vnode);
  13657. if (props)
  13658. toMerge.push(props);
  13659. }
  13660. }
  13661. return mergeProps(rawProps || {}, ...toMerge);
  13662. }
  13663. function renderTeleportVNode(push, vnode, parentComponent, slotScopeId) {
  13664. const target = vnode.props && vnode.props.to;
  13665. const disabled = vnode.props && vnode.props.disabled;
  13666. if (!target) {
  13667. if (!disabled) {
  13668. warn(`[@vue/server-renderer] Teleport is missing target prop.`);
  13669. }
  13670. return [];
  13671. }
  13672. if (!isString(target)) {
  13673. warn(
  13674. `[@vue/server-renderer] Teleport target must be a query selector string.`
  13675. );
  13676. return [];
  13677. }
  13678. ssrRenderTeleport(
  13679. push,
  13680. (push2) => {
  13681. renderVNodeChildren(
  13682. push2,
  13683. vnode.children,
  13684. parentComponent,
  13685. slotScopeId
  13686. );
  13687. },
  13688. target,
  13689. disabled || disabled === "",
  13690. parentComponent
  13691. );
  13692. }
  13693. const { isVNode: isVNode$1 } = ssrUtils;
  13694. async function unrollBuffer$1(buffer) {
  13695. if (buffer.hasAsync) {
  13696. let ret = "";
  13697. for (let i = 0; i < buffer.length; i++) {
  13698. let item = buffer[i];
  13699. if (isPromise(item)) {
  13700. item = await item;
  13701. }
  13702. if (isString(item)) {
  13703. ret += item;
  13704. } else {
  13705. ret += await unrollBuffer$1(item);
  13706. }
  13707. }
  13708. return ret;
  13709. } else {
  13710. return unrollBufferSync$1(buffer);
  13711. }
  13712. }
  13713. function unrollBufferSync$1(buffer) {
  13714. let ret = "";
  13715. for (let i = 0; i < buffer.length; i++) {
  13716. let item = buffer[i];
  13717. if (isString(item)) {
  13718. ret += item;
  13719. } else {
  13720. ret += unrollBufferSync$1(item);
  13721. }
  13722. }
  13723. return ret;
  13724. }
  13725. async function renderToString$1(input, context = {}) {
  13726. if (isVNode$1(input)) {
  13727. return renderToString$1(createApp({ render: () => input }), context);
  13728. }
  13729. const vnode = createVNode(input._component, input._props);
  13730. vnode.appContext = input._context;
  13731. input.provide(ssrContextKey, context);
  13732. const buffer = await renderComponentVNode(vnode);
  13733. const result = await unrollBuffer$1(buffer);
  13734. await resolveTeleports(context);
  13735. if (context.__watcherHandles) {
  13736. for (const unwatch of context.__watcherHandles) {
  13737. unwatch();
  13738. }
  13739. }
  13740. return result;
  13741. }
  13742. async function resolveTeleports(context) {
  13743. if (context.__teleportBuffers) {
  13744. context.teleports = context.teleports || {};
  13745. for (const key in context.__teleportBuffers) {
  13746. context.teleports[key] = await unrollBuffer$1(
  13747. await Promise.all([context.__teleportBuffers[key]])
  13748. );
  13749. }
  13750. }
  13751. }
  13752. initDirectivesForSSR();
  13753. function renderToString(component, options) {
  13754. if (options === null || options === void 0 ? void 0 : options.attachTo) {
  13755. console.warn('attachTo option is not available for renderToString');
  13756. }
  13757. var app = createInstance(component, options).app;
  13758. return renderToString$1(app);
  13759. }
  13760. // match return type of router.resolve: RouteLocation & { href: string }
  13761. var defaultRoute = {
  13762. path: '/',
  13763. name: undefined,
  13764. redirectedFrom: undefined,
  13765. params: {},
  13766. query: {},
  13767. hash: '',
  13768. fullPath: '/',
  13769. matched: [],
  13770. meta: {},
  13771. href: '/'
  13772. };
  13773. // TODO: Borrow typings from vue-router-next
  13774. var RouterLinkStub = defineComponent({
  13775. name: 'RouterLinkStub',
  13776. compatConfig: { MODE: 3 },
  13777. props: {
  13778. to: {
  13779. type: [String, Object],
  13780. required: true
  13781. },
  13782. custom: {
  13783. type: Boolean,
  13784. default: false
  13785. }
  13786. },
  13787. render: function () {
  13788. var _this = this;
  13789. var _a, _b;
  13790. var route = computed(function () { return defaultRoute; });
  13791. // mock reasonable return values to mimic vue-router's useLink
  13792. var children = (_b = (_a = this.$slots) === null || _a === void 0 ? void 0 : _a.default) === null || _b === void 0 ? void 0 : _b.call(_a, {
  13793. route: route,
  13794. href: computed(function () { return route.value.href; }),
  13795. isActive: computed(function () { return false; }),
  13796. isExactActive: computed(function () { return false; }),
  13797. navigate: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
  13798. return [2 /*return*/];
  13799. }); }); }
  13800. });
  13801. return this.custom ? children : h('a', undefined, children);
  13802. }
  13803. });
  13804. var scheduler = typeof setImmediate === 'function' ? setImmediate : setTimeout;
  13805. // Credit to: https://github.com/kentor/flush-promises
  13806. function flushPromises() {
  13807. return new Promise(function (resolve) {
  13808. scheduler(resolve, 0);
  13809. });
  13810. }
  13811. export { BaseWrapper, DOMWrapper, RouterLinkStub, VueWrapper, config, createWrapperError, disableAutoUnmount, enableAutoUnmount, flushPromises, mount, renderToString, shallowMount };