vue-test-utils.browser.js 329 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479
  1. /**
  2. * @vue/test-utils v2.4.5
  3. * (c) 2024 Lachlan Miller
  4. * Released under the MIT License
  5. */
  6. var VueTestUtils = (function (exports, Vue, compilerDom, serverRenderer) {
  7. 'use strict';
  8. function _interopNamespaceDefault(e) {
  9. var n = Object.create(null);
  10. if (e) {
  11. Object.keys(e).forEach(function (k) {
  12. if (k !== 'default') {
  13. var d = Object.getOwnPropertyDescriptor(e, k);
  14. Object.defineProperty(n, k, d.get ? d : {
  15. enumerable: true,
  16. get: function () { return e[k]; }
  17. });
  18. }
  19. });
  20. }
  21. n.default = e;
  22. return Object.freeze(n);
  23. }
  24. var Vue__namespace = /*#__PURE__*/_interopNamespaceDefault(Vue);
  25. /******************************************************************************
  26. Copyright (c) Microsoft Corporation.
  27. Permission to use, copy, modify, and/or distribute this software for any
  28. purpose with or without fee is hereby granted.
  29. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  30. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  31. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  32. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  33. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  34. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  35. PERFORMANCE OF THIS SOFTWARE.
  36. ***************************************************************************** */
  37. /* global Reflect, Promise, SuppressedError, Symbol */
  38. var extendStatics = function(d, b) {
  39. extendStatics = Object.setPrototypeOf ||
  40. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  41. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  42. return extendStatics(d, b);
  43. };
  44. function __extends(d, b) {
  45. if (typeof b !== "function" && b !== null)
  46. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  47. extendStatics(d, b);
  48. function __() { this.constructor = d; }
  49. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  50. }
  51. var __assign = function() {
  52. __assign = Object.assign || function __assign(t) {
  53. for (var s, i = 1, n = arguments.length; i < n; i++) {
  54. s = arguments[i];
  55. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  56. }
  57. return t;
  58. };
  59. return __assign.apply(this, arguments);
  60. };
  61. function __awaiter(thisArg, _arguments, P, generator) {
  62. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  63. return new (P || (P = Promise))(function (resolve, reject) {
  64. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  65. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  66. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  67. step((generator = generator.apply(thisArg, _arguments || [])).next());
  68. });
  69. }
  70. function __generator(thisArg, body) {
  71. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  72. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  73. function verb(n) { return function (v) { return step([n, v]); }; }
  74. function step(op) {
  75. if (f) throw new TypeError("Generator is already executing.");
  76. while (g && (g = 0, op[0] && (_ = 0)), _) try {
  77. 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;
  78. if (y = 0, t) op = [op[0] & 2, t.value];
  79. switch (op[0]) {
  80. case 0: case 1: t = op; break;
  81. case 4: _.label++; return { value: op[1], done: false };
  82. case 5: _.label++; y = op[1]; op = [0]; continue;
  83. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  84. default:
  85. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  86. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  87. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  88. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  89. if (t[2]) _.ops.pop();
  90. _.trys.pop(); continue;
  91. }
  92. op = body.call(thisArg, _);
  93. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  94. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  95. }
  96. }
  97. function __spreadArray(to, from, pack) {
  98. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  99. if (ar || !(i in from)) {
  100. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  101. ar[i] = from[i];
  102. }
  103. }
  104. return to.concat(ar || Array.prototype.slice.call(from));
  105. }
  106. typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
  107. var e = new Error(message);
  108. return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
  109. };
  110. var Pluggable = /** @class */ (function () {
  111. function Pluggable() {
  112. this.installedPlugins = [];
  113. }
  114. Pluggable.prototype.install = function (handler, options) {
  115. if (typeof handler !== 'function') {
  116. console.error('plugin.install must receive a function');
  117. handler = function () { return ({}); };
  118. }
  119. this.installedPlugins.push({ handler: handler, options: options });
  120. };
  121. Pluggable.prototype.extend = function (instance) {
  122. var invokeSetup = function (_a) {
  123. var handler = _a.handler, options = _a.options;
  124. return handler(instance, options); // invoke the setup method passed to install
  125. };
  126. var bindProperty = function (_a) {
  127. var property = _a[0], value = _a[1];
  128. instance[property] =
  129. typeof value === 'function' ? value.bind(instance) : value;
  130. };
  131. var addAllPropertiesFromSetup = function (setupResult) {
  132. setupResult = typeof setupResult === 'object' ? setupResult : {};
  133. Object.entries(setupResult).forEach(bindProperty);
  134. };
  135. this.installedPlugins.map(invokeSetup).forEach(addAllPropertiesFromSetup);
  136. };
  137. /** For testing */
  138. Pluggable.prototype.reset = function () {
  139. this.installedPlugins = [];
  140. };
  141. return Pluggable;
  142. }());
  143. var config = {
  144. global: {
  145. stubs: {
  146. transition: true,
  147. 'transition-group': true
  148. },
  149. provide: {},
  150. components: {},
  151. config: {},
  152. directives: {},
  153. mixins: [],
  154. mocks: {},
  155. plugins: [],
  156. renderStubDefaultSlot: false
  157. },
  158. plugins: {
  159. VueWrapper: new Pluggable(),
  160. DOMWrapper: new Pluggable()
  161. }
  162. };
  163. function mergeStubs(target, source) {
  164. if (source.stubs) {
  165. if (Array.isArray(source.stubs)) {
  166. source.stubs.forEach(function (x) { return (target[x] = true); });
  167. }
  168. else {
  169. for (var _i = 0, _a = Object.entries(source.stubs); _i < _a.length; _i++) {
  170. var _b = _a[_i], k = _b[0], v = _b[1];
  171. target[k] = v;
  172. }
  173. }
  174. }
  175. }
  176. // perform 1-level-deep-pseudo-clone merge in order to prevent config leaks
  177. // example: vue-router overwrites globalProperties.$router
  178. function mergeAppConfig(configGlobalConfig, mountGlobalConfig) {
  179. 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) });
  180. }
  181. function mergeGlobalProperties(mountGlobal) {
  182. var _a, _b, _c;
  183. if (mountGlobal === void 0) { mountGlobal = {}; }
  184. var stubs = {};
  185. var configGlobal = (_a = config === null || config === void 0 ? void 0 : config.global) !== null && _a !== void 0 ? _a : {};
  186. mergeStubs(stubs, configGlobal);
  187. mergeStubs(stubs, mountGlobal);
  188. 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;
  189. if (config.renderStubDefaultSlot === true) {
  190. console.warn('config.renderStubDefaultSlot is deprecated, use config.global.renderStubDefaultSlot instead');
  191. }
  192. return {
  193. mixins: __spreadArray(__spreadArray([], (configGlobal.mixins || []), true), (mountGlobal.mixins || []), true),
  194. plugins: __spreadArray(__spreadArray([], (configGlobal.plugins || []), true), (mountGlobal.plugins || []), true),
  195. stubs: stubs,
  196. components: __assign(__assign({}, configGlobal.components), mountGlobal.components),
  197. provide: __assign(__assign({}, configGlobal.provide), mountGlobal.provide),
  198. mocks: __assign(__assign({}, configGlobal.mocks), mountGlobal.mocks),
  199. config: mergeAppConfig(configGlobal.config, mountGlobal.config),
  200. directives: __assign(__assign({}, configGlobal.directives), mountGlobal.directives),
  201. renderStubDefaultSlot: renderStubDefaultSlot
  202. };
  203. }
  204. var isObject = function (obj) {
  205. return !!obj && typeof obj === 'object';
  206. };
  207. function isClass(obj) {
  208. if (!(obj instanceof Object))
  209. return;
  210. var isCtorClass = obj.constructor && obj.constructor.toString().substring(0, 5) === 'class';
  211. if (!('prototype' in obj)) {
  212. return isCtorClass;
  213. }
  214. var prototype = obj.prototype;
  215. var isPrototypeCtorClass = prototype.constructor &&
  216. prototype.constructor.toString &&
  217. prototype.constructor.toString().substring(0, 5) === 'class';
  218. return isCtorClass || isPrototypeCtorClass;
  219. }
  220. // https://stackoverflow.com/a/48218209
  221. var mergeDeep = function (target, source) {
  222. var _a;
  223. if (!isObject(target) || !isObject(source)) {
  224. return source;
  225. }
  226. Object.keys(source)
  227. .concat(isClass(source)
  228. ? Object.getOwnPropertyNames((_a = Object.getPrototypeOf(source)) !== null && _a !== void 0 ? _a : {})
  229. : Object.getOwnPropertyNames(source))
  230. .forEach(function (key) {
  231. var targetValue = target[key];
  232. var sourceValue = source[key];
  233. if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
  234. target[key] = sourceValue;
  235. }
  236. else if (sourceValue instanceof Date) {
  237. target[key] = sourceValue;
  238. }
  239. else if (isObject(targetValue) && isObject(sourceValue)) {
  240. target[key] = mergeDeep(Object.assign({}, targetValue), sourceValue);
  241. }
  242. else {
  243. target[key] = sourceValue;
  244. }
  245. });
  246. return target;
  247. };
  248. function isClassComponent(component) {
  249. return typeof component === 'function' && '__vccOpts' in component;
  250. }
  251. function isComponent(component) {
  252. return Boolean(component &&
  253. (typeof component === 'object' || typeof component === 'function'));
  254. }
  255. function isFunctionalComponent(component) {
  256. return typeof component === 'function' && !isClassComponent(component);
  257. }
  258. function isObjectComponent(component) {
  259. return Boolean(component && typeof component === 'object');
  260. }
  261. function textContent(element) {
  262. var _a, _b;
  263. // we check if the element is a comment first
  264. // to return an empty string in that case, instead of the comment content
  265. return element.nodeType !== Node.COMMENT_NODE
  266. ? (_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : ''
  267. : '';
  268. }
  269. function hasOwnProperty(obj, prop) {
  270. return obj.hasOwnProperty(prop);
  271. }
  272. function isNotNullOrUndefined(obj) {
  273. return Boolean(obj);
  274. }
  275. function isRefSelector(selector) {
  276. return typeof selector === 'object' && 'ref' in selector;
  277. }
  278. function convertStubsToRecord(stubs) {
  279. if (Array.isArray(stubs)) {
  280. // ['Foo', 'Bar'] => { Foo: true, Bar: true }
  281. return stubs.reduce(function (acc, current) {
  282. acc[current] = true;
  283. return acc;
  284. }, {});
  285. }
  286. return stubs;
  287. }
  288. var isDirectiveKey = function (key) { return key.match(/^v[A-Z].*/); };
  289. function getComponentsFromStubs(stubs) {
  290. var normalizedStubs = convertStubsToRecord(stubs);
  291. return Object.fromEntries(Object.entries(normalizedStubs).filter(function (_a) {
  292. var key = _a[0];
  293. return !isDirectiveKey(key);
  294. }));
  295. }
  296. function getDirectivesFromStubs(stubs) {
  297. var normalizedStubs = convertStubsToRecord(stubs);
  298. return Object.fromEntries(Object.entries(normalizedStubs)
  299. .filter(function (_a) {
  300. var key = _a[0], value = _a[1];
  301. return isDirectiveKey(key) && value !== false;
  302. })
  303. .map(function (_a) {
  304. var key = _a[0], value = _a[1];
  305. return [key.substring(1), value];
  306. }));
  307. }
  308. function hasSetupState(vm) {
  309. return (vm &&
  310. vm.$.devtoolsRawSetupState);
  311. }
  312. function isScriptSetup(vm) {
  313. return (vm && vm.$.setupState.__isScriptSetup);
  314. }
  315. var _globalThis;
  316. var getGlobalThis = function () {
  317. return (_globalThis ||
  318. (_globalThis =
  319. typeof globalThis !== 'undefined'
  320. ? globalThis
  321. : typeof self !== 'undefined'
  322. ? self
  323. : typeof window !== 'undefined'
  324. ? window
  325. : typeof global !== 'undefined'
  326. ? global
  327. : {}));
  328. };
  329. /**
  330. * Checks if the given value is a DeepRef.
  331. *
  332. * For both arrays and objects, it will recursively check
  333. * if any of their values is a Ref.
  334. *
  335. * @param {DeepRef<T> | unknown} r - The value to check.
  336. * @returns {boolean} Returns true if the value is a DeepRef, false otherwise.
  337. */
  338. var isDeepRef = function (r) {
  339. return Vue.isRef(r) || (isObject(r) && Object.values(r).some(isDeepRef));
  340. };
  341. var ignorableKeyModifiers = [
  342. 'stop',
  343. 'prevent',
  344. 'self',
  345. 'exact',
  346. 'prevent',
  347. 'capture'
  348. ];
  349. var systemKeyModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  350. var mouseKeyModifiers = ['left', 'middle', 'right'];
  351. var keyCodesByKeyName = {
  352. backspace: 8,
  353. tab: 9,
  354. enter: 13,
  355. esc: 27,
  356. space: 32,
  357. pageup: 33,
  358. pagedown: 34,
  359. end: 35,
  360. home: 36,
  361. left: 37,
  362. up: 38,
  363. right: 39,
  364. down: 40,
  365. insert: 45,
  366. delete: 46
  367. };
  368. var domEvents = {
  369. abort: {
  370. eventInterface: 'Event',
  371. bubbles: false,
  372. cancelable: false
  373. },
  374. afterprint: {
  375. eventInterface: 'Event',
  376. bubbles: false,
  377. cancelable: false
  378. },
  379. animationend: {
  380. eventInterface: 'AnimationEvent',
  381. bubbles: true,
  382. cancelable: false
  383. },
  384. animationiteration: {
  385. eventInterface: 'AnimationEvent',
  386. bubbles: true,
  387. cancelable: false
  388. },
  389. animationstart: {
  390. eventInterface: 'AnimationEvent',
  391. bubbles: true,
  392. cancelable: false
  393. },
  394. appinstalled: {
  395. eventInterface: 'Event',
  396. bubbles: false,
  397. cancelable: false
  398. },
  399. /**
  400. * @deprecated
  401. */
  402. audioprocess: {
  403. eventInterface: 'AudioProcessingEvent',
  404. bubbles: false,
  405. cancelable: false
  406. },
  407. audioend: {
  408. eventInterface: 'Event',
  409. bubbles: false,
  410. cancelable: false
  411. },
  412. audiostart: {
  413. eventInterface: 'Event',
  414. bubbles: false,
  415. cancelable: false
  416. },
  417. beforeprint: {
  418. eventInterface: 'Event',
  419. bubbles: false,
  420. cancelable: false
  421. },
  422. beforeunload: {
  423. eventInterface: 'BeforeUnloadEvent',
  424. bubbles: false,
  425. cancelable: true
  426. },
  427. beginEvent: {
  428. eventInterface: 'TimeEvent',
  429. bubbles: false,
  430. cancelable: false
  431. },
  432. blur: {
  433. eventInterface: 'FocusEvent',
  434. bubbles: false,
  435. cancelable: false
  436. },
  437. boundary: {
  438. eventInterface: 'SpeechSynthesisEvent',
  439. bubbles: false,
  440. cancelable: false
  441. },
  442. cached: {
  443. eventInterface: 'Event',
  444. bubbles: false,
  445. cancelable: false
  446. },
  447. canplay: {
  448. eventInterface: 'Event',
  449. bubbles: false,
  450. cancelable: false
  451. },
  452. canplaythrough: {
  453. eventInterface: 'Event',
  454. bubbles: false,
  455. cancelable: false
  456. },
  457. change: {
  458. eventInterface: 'Event',
  459. bubbles: true,
  460. cancelable: false
  461. },
  462. chargingchange: {
  463. eventInterface: 'Event',
  464. bubbles: false,
  465. cancelable: false
  466. },
  467. chargingtimechange: {
  468. eventInterface: 'Event',
  469. bubbles: false,
  470. cancelable: false
  471. },
  472. checking: {
  473. eventInterface: 'Event',
  474. bubbles: false,
  475. cancelable: false
  476. },
  477. click: {
  478. eventInterface: 'MouseEvent',
  479. bubbles: true,
  480. cancelable: true
  481. },
  482. close: {
  483. eventInterface: 'Event',
  484. bubbles: false,
  485. cancelable: false
  486. },
  487. complete: {
  488. eventInterface: 'OfflineAudioCompletionEvent',
  489. bubbles: false,
  490. cancelable: false
  491. },
  492. compositionend: {
  493. eventInterface: 'CompositionEvent',
  494. bubbles: true,
  495. cancelable: true
  496. },
  497. compositionstart: {
  498. eventInterface: 'CompositionEvent',
  499. bubbles: true,
  500. cancelable: true
  501. },
  502. compositionupdate: {
  503. eventInterface: 'CompositionEvent',
  504. bubbles: true,
  505. cancelable: false
  506. },
  507. contextmenu: {
  508. eventInterface: 'MouseEvent',
  509. bubbles: true,
  510. cancelable: true
  511. },
  512. copy: {
  513. eventInterface: 'ClipboardEvent',
  514. bubbles: true,
  515. cancelable: true
  516. },
  517. cut: {
  518. eventInterface: 'ClipboardEvent',
  519. bubbles: true,
  520. cancelable: true
  521. },
  522. dblclick: {
  523. eventInterface: 'MouseEvent',
  524. bubbles: true,
  525. cancelable: true
  526. },
  527. devicechange: {
  528. eventInterface: 'Event',
  529. bubbles: false,
  530. cancelable: false
  531. },
  532. devicelight: {
  533. eventInterface: 'DeviceLightEvent',
  534. bubbles: false,
  535. cancelable: false
  536. },
  537. devicemotion: {
  538. eventInterface: 'DeviceMotionEvent',
  539. bubbles: false,
  540. cancelable: false
  541. },
  542. deviceorientation: {
  543. eventInterface: 'DeviceOrientationEvent',
  544. bubbles: false,
  545. cancelable: false
  546. },
  547. deviceproximity: {
  548. eventInterface: 'DeviceProximityEvent',
  549. bubbles: false,
  550. cancelable: false
  551. },
  552. dischargingtimechange: {
  553. eventInterface: 'Event',
  554. bubbles: false,
  555. cancelable: false
  556. },
  557. DOMActivate: {
  558. eventInterface: 'UIEvent',
  559. bubbles: true,
  560. cancelable: true
  561. },
  562. DOMAttributeNameChanged: {
  563. eventInterface: 'MutationNameEvent',
  564. bubbles: true,
  565. cancelable: true
  566. },
  567. DOMAttrModified: {
  568. eventInterface: 'MutationEvent',
  569. bubbles: true,
  570. cancelable: true
  571. },
  572. DOMCharacterDataModified: {
  573. eventInterface: 'MutationEvent',
  574. bubbles: true,
  575. cancelable: true
  576. },
  577. DOMContentLoaded: {
  578. eventInterface: 'Event',
  579. bubbles: true,
  580. cancelable: true
  581. },
  582. DOMElementNameChanged: {
  583. eventInterface: 'MutationNameEvent',
  584. bubbles: true,
  585. cancelable: true
  586. },
  587. DOMFocusIn: {
  588. eventInterface: 'FocusEvent',
  589. bubbles: true,
  590. cancelable: true
  591. },
  592. DOMFocusOut: {
  593. eventInterface: 'FocusEvent',
  594. bubbles: true,
  595. cancelable: true
  596. },
  597. DOMNodeInserted: {
  598. eventInterface: 'MutationEvent',
  599. bubbles: true,
  600. cancelable: true
  601. },
  602. DOMNodeInsertedIntoDocument: {
  603. eventInterface: 'MutationEvent',
  604. bubbles: true,
  605. cancelable: true
  606. },
  607. DOMNodeRemoved: {
  608. eventInterface: 'MutationEvent',
  609. bubbles: true,
  610. cancelable: true
  611. },
  612. DOMNodeRemovedFromDocument: {
  613. eventInterface: 'MutationEvent',
  614. bubbles: true,
  615. cancelable: true
  616. },
  617. /**
  618. * @deprecated
  619. */
  620. DOMSubtreeModified: {
  621. eventInterface: 'MutationEvent',
  622. bubbles: true,
  623. cancelable: false
  624. },
  625. downloading: {
  626. eventInterface: 'Event',
  627. bubbles: false,
  628. cancelable: false
  629. },
  630. drag: {
  631. eventInterface: 'DragEvent',
  632. bubbles: true,
  633. cancelable: true
  634. },
  635. dragend: {
  636. eventInterface: 'DragEvent',
  637. bubbles: true,
  638. cancelable: false
  639. },
  640. dragenter: {
  641. eventInterface: 'DragEvent',
  642. bubbles: true,
  643. cancelable: true
  644. },
  645. dragleave: {
  646. eventInterface: 'DragEvent',
  647. bubbles: true,
  648. cancelable: false
  649. },
  650. dragover: {
  651. eventInterface: 'DragEvent',
  652. bubbles: true,
  653. cancelable: true
  654. },
  655. dragstart: {
  656. eventInterface: 'DragEvent',
  657. bubbles: true,
  658. cancelable: true
  659. },
  660. drop: {
  661. eventInterface: 'DragEvent',
  662. bubbles: true,
  663. cancelable: true
  664. },
  665. durationchange: {
  666. eventInterface: 'Event',
  667. bubbles: false,
  668. cancelable: false
  669. },
  670. emptied: {
  671. eventInterface: 'Event',
  672. bubbles: false,
  673. cancelable: false
  674. },
  675. end: {
  676. eventInterface: 'Event',
  677. bubbles: false,
  678. cancelable: false
  679. },
  680. ended: {
  681. eventInterface: 'Event',
  682. bubbles: false,
  683. cancelable: false
  684. },
  685. endEvent: {
  686. eventInterface: 'TimeEvent',
  687. bubbles: false,
  688. cancelable: false
  689. },
  690. error: {
  691. eventInterface: 'Event',
  692. bubbles: false,
  693. cancelable: false
  694. },
  695. focus: {
  696. eventInterface: 'FocusEvent',
  697. bubbles: false,
  698. cancelable: false
  699. },
  700. focusin: {
  701. eventInterface: 'FocusEvent',
  702. bubbles: true,
  703. cancelable: false
  704. },
  705. focusout: {
  706. eventInterface: 'FocusEvent',
  707. bubbles: true,
  708. cancelable: false
  709. },
  710. fullscreenchange: {
  711. eventInterface: 'Event',
  712. bubbles: true,
  713. cancelable: false
  714. },
  715. fullscreenerror: {
  716. eventInterface: 'Event',
  717. bubbles: true,
  718. cancelable: false
  719. },
  720. gamepadconnected: {
  721. eventInterface: 'GamepadEvent',
  722. bubbles: false,
  723. cancelable: false
  724. },
  725. gamepaddisconnected: {
  726. eventInterface: 'GamepadEvent',
  727. bubbles: false,
  728. cancelable: false
  729. },
  730. gotpointercapture: {
  731. eventInterface: 'PointerEvent',
  732. bubbles: false,
  733. cancelable: false
  734. },
  735. hashchange: {
  736. eventInterface: 'HashChangeEvent',
  737. bubbles: true,
  738. cancelable: false
  739. },
  740. lostpointercapture: {
  741. eventInterface: 'PointerEvent',
  742. bubbles: false,
  743. cancelable: false
  744. },
  745. input: {
  746. eventInterface: 'Event',
  747. bubbles: true,
  748. cancelable: false
  749. },
  750. invalid: {
  751. eventInterface: 'Event',
  752. cancelable: true,
  753. bubbles: false
  754. },
  755. keydown: {
  756. eventInterface: 'KeyboardEvent',
  757. bubbles: true,
  758. cancelable: true
  759. },
  760. keypress: {
  761. eventInterface: 'KeyboardEvent',
  762. bubbles: true,
  763. cancelable: true
  764. },
  765. keyup: {
  766. eventInterface: 'KeyboardEvent',
  767. bubbles: true,
  768. cancelable: true
  769. },
  770. languagechange: {
  771. eventInterface: 'Event',
  772. bubbles: false,
  773. cancelable: false
  774. },
  775. levelchange: {
  776. eventInterface: 'Event',
  777. bubbles: false,
  778. cancelable: false
  779. },
  780. load: {
  781. eventInterface: 'UIEvent',
  782. bubbles: false,
  783. cancelable: false
  784. },
  785. loadeddata: {
  786. eventInterface: 'Event',
  787. bubbles: false,
  788. cancelable: false
  789. },
  790. loadedmetadata: {
  791. eventInterface: 'Event',
  792. bubbles: false,
  793. cancelable: false
  794. },
  795. loadend: {
  796. eventInterface: 'ProgressEvent',
  797. bubbles: false,
  798. cancelable: false
  799. },
  800. loadstart: {
  801. eventInterface: 'ProgressEvent',
  802. bubbles: false,
  803. cancelable: false
  804. },
  805. mark: {
  806. eventInterface: 'SpeechSynthesisEvent',
  807. bubbles: false,
  808. cancelable: false
  809. },
  810. message: {
  811. eventInterface: 'MessageEvent',
  812. bubbles: false,
  813. cancelable: false
  814. },
  815. messageerror: {
  816. eventInterface: 'MessageEvent',
  817. bubbles: false,
  818. cancelable: false
  819. },
  820. mousedown: {
  821. eventInterface: 'MouseEvent',
  822. bubbles: true,
  823. cancelable: true
  824. },
  825. mouseenter: {
  826. eventInterface: 'MouseEvent',
  827. bubbles: false,
  828. cancelable: false
  829. },
  830. mouseleave: {
  831. eventInterface: 'MouseEvent',
  832. bubbles: false,
  833. cancelable: false
  834. },
  835. mousemove: {
  836. eventInterface: 'MouseEvent',
  837. bubbles: true,
  838. cancelable: true
  839. },
  840. mouseout: {
  841. eventInterface: 'MouseEvent',
  842. bubbles: true,
  843. cancelable: true
  844. },
  845. mouseover: {
  846. eventInterface: 'MouseEvent',
  847. bubbles: true,
  848. cancelable: true
  849. },
  850. mouseup: {
  851. eventInterface: 'MouseEvent',
  852. bubbles: true,
  853. cancelable: true
  854. },
  855. nomatch: {
  856. eventInterface: 'SpeechRecognitionEvent',
  857. bubbles: false,
  858. cancelable: false
  859. },
  860. notificationclick: {
  861. eventInterface: 'NotificationEvent',
  862. bubbles: false,
  863. cancelable: false
  864. },
  865. noupdate: {
  866. eventInterface: 'Event',
  867. bubbles: false,
  868. cancelable: false
  869. },
  870. obsolete: {
  871. eventInterface: 'Event',
  872. bubbles: false,
  873. cancelable: false
  874. },
  875. offline: {
  876. eventInterface: 'Event',
  877. bubbles: false,
  878. cancelable: false
  879. },
  880. online: {
  881. eventInterface: 'Event',
  882. bubbles: false,
  883. cancelable: false
  884. },
  885. open: {
  886. eventInterface: 'Event',
  887. bubbles: false,
  888. cancelable: false
  889. },
  890. orientationchange: {
  891. eventInterface: 'Event',
  892. bubbles: false,
  893. cancelable: false
  894. },
  895. pagehide: {
  896. eventInterface: 'PageTransitionEvent',
  897. bubbles: false,
  898. cancelable: false
  899. },
  900. pageshow: {
  901. eventInterface: 'PageTransitionEvent',
  902. bubbles: false,
  903. cancelable: false
  904. },
  905. paste: {
  906. eventInterface: 'ClipboardEvent',
  907. bubbles: true,
  908. cancelable: true
  909. },
  910. pause: {
  911. eventInterface: 'SpeechSynthesisEvent',
  912. bubbles: false,
  913. cancelable: false
  914. },
  915. pointercancel: {
  916. eventInterface: 'PointerEvent',
  917. bubbles: true,
  918. cancelable: false
  919. },
  920. pointerdown: {
  921. eventInterface: 'PointerEvent',
  922. bubbles: true,
  923. cancelable: true
  924. },
  925. pointerenter: {
  926. eventInterface: 'PointerEvent',
  927. bubbles: false,
  928. cancelable: false
  929. },
  930. pointerleave: {
  931. eventInterface: 'PointerEvent',
  932. bubbles: false,
  933. cancelable: false
  934. },
  935. pointerlockchange: {
  936. eventInterface: 'Event',
  937. bubbles: true,
  938. cancelable: false
  939. },
  940. pointerlockerror: {
  941. eventInterface: 'Event',
  942. bubbles: true,
  943. cancelable: false
  944. },
  945. pointermove: {
  946. eventInterface: 'PointerEvent',
  947. bubbles: true,
  948. cancelable: true
  949. },
  950. pointerout: {
  951. eventInterface: 'PointerEvent',
  952. bubbles: true,
  953. cancelable: true
  954. },
  955. pointerover: {
  956. eventInterface: 'PointerEvent',
  957. bubbles: true,
  958. cancelable: true
  959. },
  960. pointerup: {
  961. eventInterface: 'PointerEvent',
  962. bubbles: true,
  963. cancelable: true
  964. },
  965. play: {
  966. eventInterface: 'Event',
  967. bubbles: false,
  968. cancelable: false
  969. },
  970. playing: {
  971. eventInterface: 'Event',
  972. bubbles: false,
  973. cancelable: false
  974. },
  975. popstate: {
  976. eventInterface: 'PopStateEvent',
  977. bubbles: true,
  978. cancelable: false
  979. },
  980. progress: {
  981. eventInterface: 'ProgressEvent',
  982. bubbles: false,
  983. cancelable: false
  984. },
  985. push: {
  986. eventInterface: 'PushEvent',
  987. bubbles: false,
  988. cancelable: false
  989. },
  990. pushsubscriptionchange: {
  991. eventInterface: 'PushEvent',
  992. bubbles: false,
  993. cancelable: false
  994. },
  995. ratechange: {
  996. eventInterface: 'Event',
  997. bubbles: false,
  998. cancelable: false
  999. },
  1000. readystatechange: {
  1001. eventInterface: 'Event',
  1002. bubbles: false,
  1003. cancelable: false
  1004. },
  1005. repeatEvent: {
  1006. eventInterface: 'TimeEvent',
  1007. bubbles: false,
  1008. cancelable: false
  1009. },
  1010. reset: {
  1011. eventInterface: 'Event',
  1012. bubbles: true,
  1013. cancelable: true
  1014. },
  1015. resize: {
  1016. eventInterface: 'UIEvent',
  1017. bubbles: false,
  1018. cancelable: false
  1019. },
  1020. resourcetimingbufferfull: {
  1021. eventInterface: 'Performance',
  1022. bubbles: true,
  1023. cancelable: true
  1024. },
  1025. result: {
  1026. eventInterface: 'SpeechRecognitionEvent',
  1027. bubbles: false,
  1028. cancelable: false
  1029. },
  1030. resume: {
  1031. eventInterface: 'SpeechSynthesisEvent',
  1032. bubbles: false,
  1033. cancelable: false
  1034. },
  1035. scroll: {
  1036. eventInterface: 'UIEvent',
  1037. bubbles: false,
  1038. cancelable: false
  1039. },
  1040. seeked: {
  1041. eventInterface: 'Event',
  1042. bubbles: false,
  1043. cancelable: false
  1044. },
  1045. seeking: {
  1046. eventInterface: 'Event',
  1047. bubbles: false,
  1048. cancelable: false
  1049. },
  1050. select: {
  1051. eventInterface: 'UIEvent',
  1052. bubbles: true,
  1053. cancelable: false
  1054. },
  1055. selectstart: {
  1056. eventInterface: 'Event',
  1057. bubbles: true,
  1058. cancelable: true
  1059. },
  1060. selectionchange: {
  1061. eventInterface: 'Event',
  1062. bubbles: false,
  1063. cancelable: false
  1064. },
  1065. show: {
  1066. eventInterface: 'MouseEvent',
  1067. bubbles: false,
  1068. cancelable: false
  1069. },
  1070. slotchange: {
  1071. eventInterface: 'Event',
  1072. bubbles: true,
  1073. cancelable: false
  1074. },
  1075. soundend: {
  1076. eventInterface: 'Event',
  1077. bubbles: false,
  1078. cancelable: false
  1079. },
  1080. soundstart: {
  1081. eventInterface: 'Event',
  1082. bubbles: false,
  1083. cancelable: false
  1084. },
  1085. speechend: {
  1086. eventInterface: 'Event',
  1087. bubbles: false,
  1088. cancelable: false
  1089. },
  1090. speechstart: {
  1091. eventInterface: 'Event',
  1092. bubbles: false,
  1093. cancelable: false
  1094. },
  1095. stalled: {
  1096. eventInterface: 'Event',
  1097. bubbles: false,
  1098. cancelable: false
  1099. },
  1100. start: {
  1101. eventInterface: 'SpeechSynthesisEvent',
  1102. bubbles: false,
  1103. cancelable: false
  1104. },
  1105. storage: {
  1106. eventInterface: 'StorageEvent',
  1107. bubbles: false,
  1108. cancelable: false
  1109. },
  1110. submit: {
  1111. eventInterface: 'Event',
  1112. bubbles: true,
  1113. cancelable: true
  1114. },
  1115. success: {
  1116. eventInterface: 'Event',
  1117. bubbles: false,
  1118. cancelable: false
  1119. },
  1120. suspend: {
  1121. eventInterface: 'Event',
  1122. bubbles: false,
  1123. cancelable: false
  1124. },
  1125. SVGAbort: {
  1126. eventInterface: 'SVGEvent',
  1127. bubbles: true,
  1128. cancelable: false
  1129. },
  1130. SVGError: {
  1131. eventInterface: 'SVGEvent',
  1132. bubbles: true,
  1133. cancelable: false
  1134. },
  1135. SVGLoad: {
  1136. eventInterface: 'SVGEvent',
  1137. bubbles: false,
  1138. cancelable: false
  1139. },
  1140. SVGResize: {
  1141. eventInterface: 'SVGEvent',
  1142. bubbles: true,
  1143. cancelable: false
  1144. },
  1145. SVGScroll: {
  1146. eventInterface: 'SVGEvent',
  1147. bubbles: true,
  1148. cancelable: false
  1149. },
  1150. SVGUnload: {
  1151. eventInterface: 'SVGEvent',
  1152. bubbles: false,
  1153. cancelable: false
  1154. },
  1155. SVGZoom: {
  1156. eventInterface: 'SVGZoomEvent',
  1157. bubbles: true,
  1158. cancelable: false
  1159. },
  1160. timeout: {
  1161. eventInterface: 'ProgressEvent',
  1162. bubbles: false,
  1163. cancelable: false
  1164. },
  1165. timeupdate: {
  1166. eventInterface: 'Event',
  1167. bubbles: false,
  1168. cancelable: false
  1169. },
  1170. touchcancel: {
  1171. eventInterface: 'TouchEvent',
  1172. bubbles: true,
  1173. cancelable: false
  1174. },
  1175. touchend: {
  1176. eventInterface: 'TouchEvent',
  1177. bubbles: true,
  1178. cancelable: true
  1179. },
  1180. touchmove: {
  1181. eventInterface: 'TouchEvent',
  1182. bubbles: true,
  1183. cancelable: true
  1184. },
  1185. touchstart: {
  1186. eventInterface: 'TouchEvent',
  1187. bubbles: true,
  1188. cancelable: true
  1189. },
  1190. transitionend: {
  1191. eventInterface: 'TransitionEvent',
  1192. bubbles: true,
  1193. cancelable: true
  1194. },
  1195. unload: {
  1196. eventInterface: 'UIEvent',
  1197. bubbles: false,
  1198. cancelable: false
  1199. },
  1200. updateready: {
  1201. eventInterface: 'Event',
  1202. bubbles: false,
  1203. cancelable: false
  1204. },
  1205. userproximity: {
  1206. eventInterface: 'UserProximityEvent',
  1207. bubbles: false,
  1208. cancelable: false
  1209. },
  1210. voiceschanged: {
  1211. eventInterface: 'Event',
  1212. bubbles: false,
  1213. cancelable: false
  1214. },
  1215. visibilitychange: {
  1216. eventInterface: 'Event',
  1217. bubbles: true,
  1218. cancelable: false
  1219. },
  1220. volumechange: {
  1221. eventInterface: 'Event',
  1222. bubbles: false,
  1223. cancelable: false
  1224. },
  1225. waiting: {
  1226. eventInterface: 'Event',
  1227. bubbles: false,
  1228. cancelable: false
  1229. },
  1230. wheel: {
  1231. eventInterface: 'WheelEvent',
  1232. bubbles: true,
  1233. cancelable: true
  1234. }
  1235. };
  1236. /**
  1237. * Groups modifiers into lists
  1238. */
  1239. function generateModifiers(modifiers, isOnClick) {
  1240. var keyModifiers = [];
  1241. var systemModifiers = [];
  1242. for (var i = 0; i < modifiers.length; i++) {
  1243. var modifier = modifiers[i];
  1244. // addEventListener() options, e.g. .passive & .capture, that we dont need to handle
  1245. if (ignorableKeyModifiers.includes(modifier)) {
  1246. continue;
  1247. }
  1248. // modifiers that require special conversion
  1249. // if passed a left/right key modifier with onClick, add it here as well.
  1250. if (systemKeyModifiers.includes(modifier) ||
  1251. (mouseKeyModifiers.includes(modifier) &&
  1252. isOnClick)) {
  1253. systemModifiers.push(modifier);
  1254. }
  1255. else {
  1256. keyModifiers.push(modifier);
  1257. }
  1258. }
  1259. return {
  1260. keyModifiers: keyModifiers,
  1261. systemModifiers: systemModifiers
  1262. };
  1263. }
  1264. function getEventProperties(eventParams) {
  1265. var modifiers = eventParams.modifiers, _a = eventParams.options, options = _a === void 0 ? {} : _a, eventType = eventParams.eventType;
  1266. var isOnClick = eventType === 'click';
  1267. var _b = generateModifiers(modifiers, isOnClick), keyModifiers = _b.keyModifiers, systemModifiers = _b.systemModifiers;
  1268. if (isOnClick) {
  1269. // if it's a right click, it should fire a `contextmenu` event
  1270. if (systemModifiers.includes('right')) {
  1271. eventType = 'contextmenu';
  1272. options.button = 2;
  1273. // if its a middle click, fire a `mouseup` event
  1274. }
  1275. else if (systemModifiers.includes('middle')) {
  1276. eventType = 'mouseup';
  1277. options.button = 1;
  1278. }
  1279. }
  1280. var meta = domEvents[eventType] || {
  1281. eventInterface: 'Event',
  1282. cancelable: true,
  1283. bubbles: true
  1284. };
  1285. // convert `shift, ctrl` to `shiftKey, ctrlKey`
  1286. // allows trigger('keydown.shift.ctrl.n') directly
  1287. var systemModifiersMeta = systemModifiers.reduce(function (all, key) {
  1288. all["".concat(key, "Key")] = true;
  1289. return all;
  1290. }, {});
  1291. // get the keyCode for backwards compat
  1292. var keyCode = keyCodesByKeyName[keyModifiers[0]] ||
  1293. (options && (options.keyCode || options.code));
  1294. var eventProperties = __assign(__assign(__assign(__assign({}, systemModifiersMeta), options), { bubbles: meta.bubbles, cancelable: meta.cancelable,
  1295. // Any derived options should go here
  1296. keyCode: keyCode, code: keyCode }), (keyModifiers[0] ? { key: keyModifiers[0] } : {}));
  1297. return {
  1298. eventProperties: eventProperties,
  1299. meta: meta,
  1300. eventType: eventType
  1301. };
  1302. }
  1303. function createEvent(eventParams) {
  1304. var _a = getEventProperties(eventParams), eventProperties = _a.eventProperties, meta = _a.meta, eventType = _a.eventType;
  1305. // user defined eventInterface
  1306. var eventInterface = meta.eventInterface;
  1307. var metaEventInterface = window[eventInterface];
  1308. var SupportedEventInterface = typeof metaEventInterface === 'function' ? metaEventInterface : window.Event;
  1309. return new SupportedEventInterface(eventType,
  1310. // event properties can only be added when the event is instantiated
  1311. // custom properties must be added after the event has been instantiated
  1312. eventProperties);
  1313. }
  1314. function createDOMEvent(eventString, options) {
  1315. // split eventString like `keydown.ctrl.shift` into `keydown` and array of modifiers
  1316. var _a = eventString.split('.'), eventType = _a[0], modifiers = _a.slice(1);
  1317. var eventParams = {
  1318. eventType: eventType,
  1319. modifiers: modifiers,
  1320. options: options
  1321. };
  1322. var event = createEvent(eventParams);
  1323. var eventPrototype = Object.getPrototypeOf(event);
  1324. // attach custom options to the event, like `relatedTarget` and so on.
  1325. options &&
  1326. Object.keys(options).forEach(function (key) {
  1327. var propertyDescriptor = Object.getOwnPropertyDescriptor(eventPrototype, key);
  1328. var canSetProperty = !(propertyDescriptor && propertyDescriptor.set === undefined);
  1329. if (canSetProperty) {
  1330. event[key] = options[key];
  1331. }
  1332. });
  1333. return event;
  1334. }
  1335. // Stubbing occurs when in vnode transformer we're swapping
  1336. // component vnode type due to stubbing either component
  1337. // or directive on component
  1338. // In order to be able to find components we need to track pairs
  1339. // stub --> original component
  1340. // Having this as global might feel unsafe at first point
  1341. // One can assume that sharing stub map across mounts might
  1342. // lead to false matches, however our vnode mappers always
  1343. // produce new nodeTypes for each mount even if you're reusing
  1344. // same stub, so we're safe and do not need to pass these stubs
  1345. // for each mount operation
  1346. var stubs = new WeakMap();
  1347. function registerStub(_a) {
  1348. var source = _a.source, stub = _a.stub;
  1349. stubs.set(stub, source);
  1350. }
  1351. function getOriginalComponentFromStub(stub) {
  1352. return stubs.get(stub);
  1353. }
  1354. var cacheStringFunction = function (fn) {
  1355. var cache = Object.create(null);
  1356. return (function (str) {
  1357. var hit = cache[str];
  1358. return hit || (cache[str] = fn(str));
  1359. });
  1360. };
  1361. var camelizeRE = /-(\w)/g;
  1362. var camelize = cacheStringFunction(function (str) {
  1363. return str.replace(camelizeRE, function (_, c) { return (c ? c.toUpperCase() : ''); });
  1364. });
  1365. var capitalize = cacheStringFunction(function (str) {
  1366. return str.charAt(0).toUpperCase() + str.slice(1);
  1367. });
  1368. var hyphenateRE = /\B([A-Z])/g;
  1369. var hyphenate = cacheStringFunction(function (str) {
  1370. return str.replace(hyphenateRE, '-$1').toLowerCase();
  1371. });
  1372. function matchName(target, sourceName) {
  1373. var camelized = camelize(target);
  1374. var capitalized = capitalize(camelized);
  1375. return (!!sourceName &&
  1376. (sourceName === target ||
  1377. sourceName === camelized ||
  1378. sourceName === capitalized ||
  1379. capitalize(camelize(sourceName)) === capitalized));
  1380. }
  1381. function isCompatEnabled(key) {
  1382. var _a, _b;
  1383. return (_b = (_a = Vue__namespace.compatUtils) === null || _a === void 0 ? void 0 : _a.isCompatEnabled(key)) !== null && _b !== void 0 ? _b : false;
  1384. }
  1385. function isLegacyExtendedComponent(component) {
  1386. if (!isCompatEnabled('GLOBAL_EXTEND') || typeof component !== 'function') {
  1387. return false;
  1388. }
  1389. return (hasOwnProperty(component, 'super') &&
  1390. component.super.extend({}).super === component.super);
  1391. }
  1392. function unwrapLegacyVueExtendComponent(selector) {
  1393. return isLegacyExtendedComponent(selector) ? selector.options : selector;
  1394. }
  1395. function isLegacyFunctionalComponent(component) {
  1396. return Boolean(component &&
  1397. typeof component === 'object' &&
  1398. hasOwnProperty(component, 'functional') &&
  1399. component.functional);
  1400. }
  1401. var getComponentNameInSetup = function (instance, type) {
  1402. 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; });
  1403. };
  1404. var getComponentRegisteredName = function (instance, type) {
  1405. if (!instance || !instance.parent)
  1406. return null;
  1407. // try to infer the name based on local resolution
  1408. var registry = instance.type.components;
  1409. for (var key in registry) {
  1410. if (registry[key] === type) {
  1411. return key;
  1412. }
  1413. }
  1414. // try to retrieve name imported in script setup
  1415. return getComponentNameInSetup(instance.parent, type) || null;
  1416. };
  1417. var getComponentName = function (instance, type) {
  1418. if (isObjectComponent(type)) {
  1419. return (
  1420. // If the component we stub is a script setup component and is automatically
  1421. // imported by unplugin-vue-components we can only get its name through
  1422. // the `__name` property.
  1423. getComponentNameInSetup(instance, type) || type.name || type.__name || '');
  1424. }
  1425. if (isLegacyExtendedComponent(type)) {
  1426. return unwrapLegacyVueExtendComponent(type).name || '';
  1427. }
  1428. if (isFunctionalComponent(type)) {
  1429. return type.displayName || type.name;
  1430. }
  1431. return '';
  1432. };
  1433. /**
  1434. * Detect whether a selector matches a VNode
  1435. * @param node
  1436. * @param selector
  1437. * @return {boolean | ((value: any) => boolean)}
  1438. */
  1439. function matches(node, rawSelector) {
  1440. var _a, _b, _c;
  1441. var selector = unwrapLegacyVueExtendComponent(rawSelector);
  1442. // do not return none Vue components
  1443. if (!node.component)
  1444. return false;
  1445. var nodeType = node.type;
  1446. if (!isComponent(nodeType))
  1447. return false;
  1448. if (typeof selector === 'string') {
  1449. return (_b = (_a = node.el) === null || _a === void 0 ? void 0 : _a.matches) === null || _b === void 0 ? void 0 : _b.call(_a, selector);
  1450. }
  1451. // When we're using stubs we want user to be able to
  1452. // find stubbed components both by original component
  1453. // or stub definition. That's why we are trying to
  1454. // extract original component and also stub, which was
  1455. // used to create specialized stub for render
  1456. var nodeTypeCandidates = [
  1457. nodeType,
  1458. getOriginalComponentFromStub(nodeType)
  1459. ].filter(Boolean);
  1460. // our selector might be a stub itself
  1461. var target = (_c = getOriginalComponentFromStub(selector)) !== null && _c !== void 0 ? _c : selector;
  1462. if (nodeTypeCandidates.includes(target)) {
  1463. return true;
  1464. }
  1465. var componentName;
  1466. componentName = getComponentName(node.component, nodeType);
  1467. var selectorName = selector.name;
  1468. // the component and selector both have a name
  1469. if (componentName && selectorName) {
  1470. return matchName(selectorName, componentName);
  1471. }
  1472. componentName =
  1473. getComponentRegisteredName(node.component, nodeType) || undefined;
  1474. // if a name is missing, then check the locally registered components in the parent
  1475. if (node.component.parent) {
  1476. var registry = node.component.parent.type.components;
  1477. for (var key in registry) {
  1478. // is it the selector
  1479. if (!selectorName && registry[key] === selector) {
  1480. selectorName = key;
  1481. }
  1482. // is it the component
  1483. if (!componentName && registry[key] === nodeType) {
  1484. componentName = key;
  1485. }
  1486. }
  1487. }
  1488. if (selectorName && componentName) {
  1489. return matchName(selectorName, componentName);
  1490. }
  1491. return false;
  1492. }
  1493. /**
  1494. * Filters out the null, undefined and primitive values,
  1495. * to only keep VNode and VNodeArrayChildren values
  1496. * @param value
  1497. */
  1498. function nodesAsObject(value) {
  1499. return !!value && typeof value === 'object';
  1500. }
  1501. /**
  1502. * Collect all children
  1503. * @param nodes
  1504. * @param children
  1505. */
  1506. function aggregateChildren(nodes, children) {
  1507. if (children && Array.isArray(children)) {
  1508. var reversedNodes = __spreadArray([], children, true).reverse().filter(nodesAsObject);
  1509. reversedNodes.forEach(function (node) {
  1510. if (Array.isArray(node)) {
  1511. aggregateChildren(nodes, node);
  1512. }
  1513. else {
  1514. nodes.unshift(node);
  1515. }
  1516. });
  1517. }
  1518. }
  1519. function findAllVNodes(vnode, selector) {
  1520. var matchingNodes = [];
  1521. var nodes = [vnode];
  1522. while (nodes.length) {
  1523. var node = nodes.shift();
  1524. aggregateChildren(nodes, node.children);
  1525. if (node.component) {
  1526. aggregateChildren(nodes, [node.component.subTree]);
  1527. }
  1528. if (node.suspense) {
  1529. // match children if component is Suspense
  1530. var activeBranch = node.suspense.activeBranch;
  1531. aggregateChildren(nodes, [activeBranch]);
  1532. }
  1533. if (matches(node, selector) && !matchingNodes.includes(node)) {
  1534. matchingNodes.push(node);
  1535. }
  1536. }
  1537. return matchingNodes;
  1538. }
  1539. function find(root, selector) {
  1540. var matchingVNodes = findAllVNodes(root, selector);
  1541. if (typeof selector === 'string') {
  1542. // When searching by CSS selector we want only one (topmost) vnode for each el`
  1543. matchingVNodes = matchingVNodes.filter(function (vnode) { var _a; return ((_a = vnode.component.parent) === null || _a === void 0 ? void 0 : _a.vnode.el) !== vnode.el; });
  1544. }
  1545. return matchingVNodes.map(function (vnode) { return vnode.component; });
  1546. }
  1547. function createWrapperError(wrapperType) {
  1548. return new Proxy(Object.create(null), {
  1549. get: function (obj, prop) {
  1550. switch (prop) {
  1551. case 'then':
  1552. // allows for better errors when wrapping `find` in `await`
  1553. // https://github.com/vuejs/test-utils/issues/638
  1554. return;
  1555. case 'exists':
  1556. return function () { return false; };
  1557. default:
  1558. throw new Error("Cannot call ".concat(String(prop), " on an empty ").concat(wrapperType, "."));
  1559. }
  1560. }
  1561. });
  1562. }
  1563. /*!
  1564. * isElementVisible
  1565. * Adapted from https://github.com/testing-library/jest-dom
  1566. * Licensed under the MIT License.
  1567. */
  1568. function isStyleVisible(element) {
  1569. if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) {
  1570. return false;
  1571. }
  1572. var _a = getComputedStyle(element), display = _a.display, visibility = _a.visibility, opacity = _a.opacity;
  1573. return (display !== 'none' &&
  1574. visibility !== 'hidden' &&
  1575. visibility !== 'collapse' &&
  1576. opacity !== '0');
  1577. }
  1578. function isAttributeVisible(element) {
  1579. return (!element.hasAttribute('hidden') &&
  1580. (element.nodeName === 'DETAILS' ? element.hasAttribute('open') : true));
  1581. }
  1582. function isElementVisible(element) {
  1583. return (element.nodeName !== '#comment' &&
  1584. isStyleVisible(element) &&
  1585. isAttributeVisible(element) &&
  1586. (!element.parentElement || isElementVisible(element.parentElement)));
  1587. }
  1588. function isElement(element) {
  1589. return element instanceof Element;
  1590. }
  1591. var WrapperType;
  1592. (function (WrapperType) {
  1593. WrapperType[WrapperType["DOMWrapper"] = 0] = "DOMWrapper";
  1594. WrapperType[WrapperType["VueWrapper"] = 1] = "VueWrapper";
  1595. })(WrapperType || (WrapperType = {}));
  1596. var factories = {};
  1597. function registerFactory(type, fn) {
  1598. factories[type] = fn;
  1599. }
  1600. var createDOMWrapper = function (element) {
  1601. return factories[WrapperType.DOMWrapper](element);
  1602. };
  1603. var createVueWrapper = function (app, vm, setProps) {
  1604. return factories[WrapperType.VueWrapper](app, vm, setProps);
  1605. };
  1606. function stringifyNode(node) {
  1607. return node instanceof Element
  1608. ? node.outerHTML
  1609. : new XMLSerializer().serializeToString(node);
  1610. }
  1611. function getDefaultExportFromCjs (x) {
  1612. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  1613. }
  1614. var js = {exports: {}};
  1615. var src = {};
  1616. var javascript = {exports: {}};
  1617. var beautifier$2 = {};
  1618. var output = {};
  1619. /*jshint node:true */
  1620. var hasRequiredOutput;
  1621. function requireOutput () {
  1622. if (hasRequiredOutput) return output;
  1623. hasRequiredOutput = 1;
  1624. function OutputLine(parent) {
  1625. this.__parent = parent;
  1626. this.__character_count = 0;
  1627. // use indent_count as a marker for this.__lines that have preserved indentation
  1628. this.__indent_count = -1;
  1629. this.__alignment_count = 0;
  1630. this.__wrap_point_index = 0;
  1631. this.__wrap_point_character_count = 0;
  1632. this.__wrap_point_indent_count = -1;
  1633. this.__wrap_point_alignment_count = 0;
  1634. this.__items = [];
  1635. }
  1636. OutputLine.prototype.clone_empty = function() {
  1637. var line = new OutputLine(this.__parent);
  1638. line.set_indent(this.__indent_count, this.__alignment_count);
  1639. return line;
  1640. };
  1641. OutputLine.prototype.item = function(index) {
  1642. if (index < 0) {
  1643. return this.__items[this.__items.length + index];
  1644. } else {
  1645. return this.__items[index];
  1646. }
  1647. };
  1648. OutputLine.prototype.has_match = function(pattern) {
  1649. for (var lastCheckedOutput = this.__items.length - 1; lastCheckedOutput >= 0; lastCheckedOutput--) {
  1650. if (this.__items[lastCheckedOutput].match(pattern)) {
  1651. return true;
  1652. }
  1653. }
  1654. return false;
  1655. };
  1656. OutputLine.prototype.set_indent = function(indent, alignment) {
  1657. if (this.is_empty()) {
  1658. this.__indent_count = indent || 0;
  1659. this.__alignment_count = alignment || 0;
  1660. this.__character_count = this.__parent.get_indent_size(this.__indent_count, this.__alignment_count);
  1661. }
  1662. };
  1663. OutputLine.prototype._set_wrap_point = function() {
  1664. if (this.__parent.wrap_line_length) {
  1665. this.__wrap_point_index = this.__items.length;
  1666. this.__wrap_point_character_count = this.__character_count;
  1667. this.__wrap_point_indent_count = this.__parent.next_line.__indent_count;
  1668. this.__wrap_point_alignment_count = this.__parent.next_line.__alignment_count;
  1669. }
  1670. };
  1671. OutputLine.prototype._should_wrap = function() {
  1672. return this.__wrap_point_index &&
  1673. this.__character_count > this.__parent.wrap_line_length &&
  1674. this.__wrap_point_character_count > this.__parent.next_line.__character_count;
  1675. };
  1676. OutputLine.prototype._allow_wrap = function() {
  1677. if (this._should_wrap()) {
  1678. this.__parent.add_new_line();
  1679. var next = this.__parent.current_line;
  1680. next.set_indent(this.__wrap_point_indent_count, this.__wrap_point_alignment_count);
  1681. next.__items = this.__items.slice(this.__wrap_point_index);
  1682. this.__items = this.__items.slice(0, this.__wrap_point_index);
  1683. next.__character_count += this.__character_count - this.__wrap_point_character_count;
  1684. this.__character_count = this.__wrap_point_character_count;
  1685. if (next.__items[0] === " ") {
  1686. next.__items.splice(0, 1);
  1687. next.__character_count -= 1;
  1688. }
  1689. return true;
  1690. }
  1691. return false;
  1692. };
  1693. OutputLine.prototype.is_empty = function() {
  1694. return this.__items.length === 0;
  1695. };
  1696. OutputLine.prototype.last = function() {
  1697. if (!this.is_empty()) {
  1698. return this.__items[this.__items.length - 1];
  1699. } else {
  1700. return null;
  1701. }
  1702. };
  1703. OutputLine.prototype.push = function(item) {
  1704. this.__items.push(item);
  1705. var last_newline_index = item.lastIndexOf('\n');
  1706. if (last_newline_index !== -1) {
  1707. this.__character_count = item.length - last_newline_index;
  1708. } else {
  1709. this.__character_count += item.length;
  1710. }
  1711. };
  1712. OutputLine.prototype.pop = function() {
  1713. var item = null;
  1714. if (!this.is_empty()) {
  1715. item = this.__items.pop();
  1716. this.__character_count -= item.length;
  1717. }
  1718. return item;
  1719. };
  1720. OutputLine.prototype._remove_indent = function() {
  1721. if (this.__indent_count > 0) {
  1722. this.__indent_count -= 1;
  1723. this.__character_count -= this.__parent.indent_size;
  1724. }
  1725. };
  1726. OutputLine.prototype._remove_wrap_indent = function() {
  1727. if (this.__wrap_point_indent_count > 0) {
  1728. this.__wrap_point_indent_count -= 1;
  1729. }
  1730. };
  1731. OutputLine.prototype.trim = function() {
  1732. while (this.last() === ' ') {
  1733. this.__items.pop();
  1734. this.__character_count -= 1;
  1735. }
  1736. };
  1737. OutputLine.prototype.toString = function() {
  1738. var result = '';
  1739. if (this.is_empty()) {
  1740. if (this.__parent.indent_empty_lines) {
  1741. result = this.__parent.get_indent_string(this.__indent_count);
  1742. }
  1743. } else {
  1744. result = this.__parent.get_indent_string(this.__indent_count, this.__alignment_count);
  1745. result += this.__items.join('');
  1746. }
  1747. return result;
  1748. };
  1749. function IndentStringCache(options, baseIndentString) {
  1750. this.__cache = [''];
  1751. this.__indent_size = options.indent_size;
  1752. this.__indent_string = options.indent_char;
  1753. if (!options.indent_with_tabs) {
  1754. this.__indent_string = new Array(options.indent_size + 1).join(options.indent_char);
  1755. }
  1756. // Set to null to continue support for auto detection of base indent
  1757. baseIndentString = baseIndentString || '';
  1758. if (options.indent_level > 0) {
  1759. baseIndentString = new Array(options.indent_level + 1).join(this.__indent_string);
  1760. }
  1761. this.__base_string = baseIndentString;
  1762. this.__base_string_length = baseIndentString.length;
  1763. }
  1764. IndentStringCache.prototype.get_indent_size = function(indent, column) {
  1765. var result = this.__base_string_length;
  1766. column = column || 0;
  1767. if (indent < 0) {
  1768. result = 0;
  1769. }
  1770. result += indent * this.__indent_size;
  1771. result += column;
  1772. return result;
  1773. };
  1774. IndentStringCache.prototype.get_indent_string = function(indent_level, column) {
  1775. var result = this.__base_string;
  1776. column = column || 0;
  1777. if (indent_level < 0) {
  1778. indent_level = 0;
  1779. result = '';
  1780. }
  1781. column += indent_level * this.__indent_size;
  1782. this.__ensure_cache(column);
  1783. result += this.__cache[column];
  1784. return result;
  1785. };
  1786. IndentStringCache.prototype.__ensure_cache = function(column) {
  1787. while (column >= this.__cache.length) {
  1788. this.__add_column();
  1789. }
  1790. };
  1791. IndentStringCache.prototype.__add_column = function() {
  1792. var column = this.__cache.length;
  1793. var indent = 0;
  1794. var result = '';
  1795. if (this.__indent_size && column >= this.__indent_size) {
  1796. indent = Math.floor(column / this.__indent_size);
  1797. column -= indent * this.__indent_size;
  1798. result = new Array(indent + 1).join(this.__indent_string);
  1799. }
  1800. if (column) {
  1801. result += new Array(column + 1).join(' ');
  1802. }
  1803. this.__cache.push(result);
  1804. };
  1805. function Output(options, baseIndentString) {
  1806. this.__indent_cache = new IndentStringCache(options, baseIndentString);
  1807. this.raw = false;
  1808. this._end_with_newline = options.end_with_newline;
  1809. this.indent_size = options.indent_size;
  1810. this.wrap_line_length = options.wrap_line_length;
  1811. this.indent_empty_lines = options.indent_empty_lines;
  1812. this.__lines = [];
  1813. this.previous_line = null;
  1814. this.current_line = null;
  1815. this.next_line = new OutputLine(this);
  1816. this.space_before_token = false;
  1817. this.non_breaking_space = false;
  1818. this.previous_token_wrapped = false;
  1819. // initialize
  1820. this.__add_outputline();
  1821. }
  1822. Output.prototype.__add_outputline = function() {
  1823. this.previous_line = this.current_line;
  1824. this.current_line = this.next_line.clone_empty();
  1825. this.__lines.push(this.current_line);
  1826. };
  1827. Output.prototype.get_line_number = function() {
  1828. return this.__lines.length;
  1829. };
  1830. Output.prototype.get_indent_string = function(indent, column) {
  1831. return this.__indent_cache.get_indent_string(indent, column);
  1832. };
  1833. Output.prototype.get_indent_size = function(indent, column) {
  1834. return this.__indent_cache.get_indent_size(indent, column);
  1835. };
  1836. Output.prototype.is_empty = function() {
  1837. return !this.previous_line && this.current_line.is_empty();
  1838. };
  1839. Output.prototype.add_new_line = function(force_newline) {
  1840. // never newline at the start of file
  1841. // otherwise, newline only if we didn't just add one or we're forced
  1842. if (this.is_empty() ||
  1843. (!force_newline && this.just_added_newline())) {
  1844. return false;
  1845. }
  1846. // if raw output is enabled, don't print additional newlines,
  1847. // but still return True as though you had
  1848. if (!this.raw) {
  1849. this.__add_outputline();
  1850. }
  1851. return true;
  1852. };
  1853. Output.prototype.get_code = function(eol) {
  1854. this.trim(true);
  1855. // handle some edge cases where the last tokens
  1856. // has text that ends with newline(s)
  1857. var last_item = this.current_line.pop();
  1858. if (last_item) {
  1859. if (last_item[last_item.length - 1] === '\n') {
  1860. last_item = last_item.replace(/\n+$/g, '');
  1861. }
  1862. this.current_line.push(last_item);
  1863. }
  1864. if (this._end_with_newline) {
  1865. this.__add_outputline();
  1866. }
  1867. var sweet_code = this.__lines.join('\n');
  1868. if (eol !== '\n') {
  1869. sweet_code = sweet_code.replace(/[\n]/g, eol);
  1870. }
  1871. return sweet_code;
  1872. };
  1873. Output.prototype.set_wrap_point = function() {
  1874. this.current_line._set_wrap_point();
  1875. };
  1876. Output.prototype.set_indent = function(indent, alignment) {
  1877. indent = indent || 0;
  1878. alignment = alignment || 0;
  1879. // Next line stores alignment values
  1880. this.next_line.set_indent(indent, alignment);
  1881. // Never indent your first output indent at the start of the file
  1882. if (this.__lines.length > 1) {
  1883. this.current_line.set_indent(indent, alignment);
  1884. return true;
  1885. }
  1886. this.current_line.set_indent();
  1887. return false;
  1888. };
  1889. Output.prototype.add_raw_token = function(token) {
  1890. for (var x = 0; x < token.newlines; x++) {
  1891. this.__add_outputline();
  1892. }
  1893. this.current_line.set_indent(-1);
  1894. this.current_line.push(token.whitespace_before);
  1895. this.current_line.push(token.text);
  1896. this.space_before_token = false;
  1897. this.non_breaking_space = false;
  1898. this.previous_token_wrapped = false;
  1899. };
  1900. Output.prototype.add_token = function(printable_token) {
  1901. this.__add_space_before_token();
  1902. this.current_line.push(printable_token);
  1903. this.space_before_token = false;
  1904. this.non_breaking_space = false;
  1905. this.previous_token_wrapped = this.current_line._allow_wrap();
  1906. };
  1907. Output.prototype.__add_space_before_token = function() {
  1908. if (this.space_before_token && !this.just_added_newline()) {
  1909. if (!this.non_breaking_space) {
  1910. this.set_wrap_point();
  1911. }
  1912. this.current_line.push(' ');
  1913. }
  1914. };
  1915. Output.prototype.remove_indent = function(index) {
  1916. var output_length = this.__lines.length;
  1917. while (index < output_length) {
  1918. this.__lines[index]._remove_indent();
  1919. index++;
  1920. }
  1921. this.current_line._remove_wrap_indent();
  1922. };
  1923. Output.prototype.trim = function(eat_newlines) {
  1924. eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
  1925. this.current_line.trim();
  1926. while (eat_newlines && this.__lines.length > 1 &&
  1927. this.current_line.is_empty()) {
  1928. this.__lines.pop();
  1929. this.current_line = this.__lines[this.__lines.length - 1];
  1930. this.current_line.trim();
  1931. }
  1932. this.previous_line = this.__lines.length > 1 ?
  1933. this.__lines[this.__lines.length - 2] : null;
  1934. };
  1935. Output.prototype.just_added_newline = function() {
  1936. return this.current_line.is_empty();
  1937. };
  1938. Output.prototype.just_added_blankline = function() {
  1939. return this.is_empty() ||
  1940. (this.current_line.is_empty() && this.previous_line.is_empty());
  1941. };
  1942. Output.prototype.ensure_empty_line_above = function(starts_with, ends_with) {
  1943. var index = this.__lines.length - 2;
  1944. while (index >= 0) {
  1945. var potentialEmptyLine = this.__lines[index];
  1946. if (potentialEmptyLine.is_empty()) {
  1947. break;
  1948. } else if (potentialEmptyLine.item(0).indexOf(starts_with) !== 0 &&
  1949. potentialEmptyLine.item(-1) !== ends_with) {
  1950. this.__lines.splice(index + 1, 0, new OutputLine(this));
  1951. this.previous_line = this.__lines[this.__lines.length - 2];
  1952. break;
  1953. }
  1954. index--;
  1955. }
  1956. };
  1957. output.Output = Output;
  1958. return output;
  1959. }
  1960. var token = {};
  1961. /*jshint node:true */
  1962. var hasRequiredToken;
  1963. function requireToken () {
  1964. if (hasRequiredToken) return token;
  1965. hasRequiredToken = 1;
  1966. function Token(type, text, newlines, whitespace_before) {
  1967. this.type = type;
  1968. this.text = text;
  1969. // comments_before are
  1970. // comments that have a new line before them
  1971. // and may or may not have a newline after
  1972. // this is a set of comments before
  1973. this.comments_before = null; /* inline comment*/
  1974. // this.comments_after = new TokenStream(); // no new line before and newline after
  1975. this.newlines = newlines || 0;
  1976. this.whitespace_before = whitespace_before || '';
  1977. this.parent = null;
  1978. this.next = null;
  1979. this.previous = null;
  1980. this.opened = null;
  1981. this.closed = null;
  1982. this.directives = null;
  1983. }
  1984. token.Token = Token;
  1985. return token;
  1986. }
  1987. var acorn = {};
  1988. /* jshint node: true, curly: false */
  1989. var hasRequiredAcorn;
  1990. function requireAcorn () {
  1991. if (hasRequiredAcorn) return acorn;
  1992. hasRequiredAcorn = 1;
  1993. (function (exports) {
  1994. // acorn used char codes to squeeze the last bit of performance out
  1995. // Beautifier is okay without that, so we're using regex
  1996. // permit # (23), $ (36), and @ (64). @ is used in ES7 decorators.
  1997. // 65 through 91 are uppercase letters.
  1998. // permit _ (95).
  1999. // 97 through 123 are lowercase letters.
  2000. var baseASCIIidentifierStartChars = "\\x23\\x24\\x40\\x41-\\x5a\\x5f\\x61-\\x7a";
  2001. // inside an identifier @ is not allowed but 0-9 are.
  2002. var baseASCIIidentifierChars = "\\x24\\x30-\\x39\\x41-\\x5a\\x5f\\x61-\\x7a";
  2003. // Big ugly regular expressions that match characters in the
  2004. // whitespace, identifier, and identifier-start categories. These
  2005. // are only applied when a character is found to actually have a
  2006. // code point above 128.
  2007. 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";
  2008. 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";
  2009. //var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  2010. //var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  2011. var identifierStart = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierStartChars + nonASCIIidentifierStartChars + "])";
  2012. var identifierChars = "(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])*";
  2013. exports.identifier = new RegExp(identifierStart + identifierChars, 'g');
  2014. exports.identifierStart = new RegExp(identifierStart);
  2015. exports.identifierMatch = new RegExp("(?:\\\\u[0-9a-fA-F]{4}|[" + baseASCIIidentifierChars + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "])+");
  2016. // Whether a single character denotes a newline.
  2017. exports.newline = /[\n\r\u2028\u2029]/;
  2018. // Matches a whole line break (where CRLF is considered a single
  2019. // line break). Used to count lines.
  2020. // in javascript, these two differ
  2021. // in python they are the same, different methods are called on them
  2022. exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
  2023. exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
  2024. } (acorn));
  2025. return acorn;
  2026. }
  2027. var options$3 = {};
  2028. var options$2 = {};
  2029. /*jshint node:true */
  2030. var hasRequiredOptions$3;
  2031. function requireOptions$3 () {
  2032. if (hasRequiredOptions$3) return options$2;
  2033. hasRequiredOptions$3 = 1;
  2034. function Options(options, merge_child_field) {
  2035. this.raw_options = _mergeOpts(options, merge_child_field);
  2036. // Support passing the source text back with no change
  2037. this.disabled = this._get_boolean('disabled');
  2038. this.eol = this._get_characters('eol', 'auto');
  2039. this.end_with_newline = this._get_boolean('end_with_newline');
  2040. this.indent_size = this._get_number('indent_size', 4);
  2041. this.indent_char = this._get_characters('indent_char', ' ');
  2042. this.indent_level = this._get_number('indent_level');
  2043. this.preserve_newlines = this._get_boolean('preserve_newlines', true);
  2044. this.max_preserve_newlines = this._get_number('max_preserve_newlines', 32786);
  2045. if (!this.preserve_newlines) {
  2046. this.max_preserve_newlines = 0;
  2047. }
  2048. this.indent_with_tabs = this._get_boolean('indent_with_tabs', this.indent_char === '\t');
  2049. if (this.indent_with_tabs) {
  2050. this.indent_char = '\t';
  2051. // indent_size behavior changed after 1.8.6
  2052. // It used to be that indent_size would be
  2053. // set to 1 for indent_with_tabs. That is no longer needed and
  2054. // actually doesn't make sense - why not use spaces? Further,
  2055. // that might produce unexpected behavior - tabs being used
  2056. // for single-column alignment. So, when indent_with_tabs is true
  2057. // and indent_size is 1, reset indent_size to 4.
  2058. if (this.indent_size === 1) {
  2059. this.indent_size = 4;
  2060. }
  2061. }
  2062. // Backwards compat with 1.3.x
  2063. this.wrap_line_length = this._get_number('wrap_line_length', this._get_number('max_char'));
  2064. this.indent_empty_lines = this._get_boolean('indent_empty_lines');
  2065. // valid templating languages ['django', 'erb', 'handlebars', 'php', 'smarty']
  2066. // For now, 'auto' = all off for javascript, all on for html (and inline javascript).
  2067. // other values ignored
  2068. this.templating = this._get_selection_list('templating', ['auto', 'none', 'django', 'erb', 'handlebars', 'php', 'smarty'], ['auto']);
  2069. }
  2070. Options.prototype._get_array = function(name, default_value) {
  2071. var option_value = this.raw_options[name];
  2072. var result = default_value || [];
  2073. if (typeof option_value === 'object') {
  2074. if (option_value !== null && typeof option_value.concat === 'function') {
  2075. result = option_value.concat();
  2076. }
  2077. } else if (typeof option_value === 'string') {
  2078. result = option_value.split(/[^a-zA-Z0-9_\/\-]+/);
  2079. }
  2080. return result;
  2081. };
  2082. Options.prototype._get_boolean = function(name, default_value) {
  2083. var option_value = this.raw_options[name];
  2084. var result = option_value === undefined ? !!default_value : !!option_value;
  2085. return result;
  2086. };
  2087. Options.prototype._get_characters = function(name, default_value) {
  2088. var option_value = this.raw_options[name];
  2089. var result = default_value || '';
  2090. if (typeof option_value === 'string') {
  2091. result = option_value.replace(/\\r/, '\r').replace(/\\n/, '\n').replace(/\\t/, '\t');
  2092. }
  2093. return result;
  2094. };
  2095. Options.prototype._get_number = function(name, default_value) {
  2096. var option_value = this.raw_options[name];
  2097. default_value = parseInt(default_value, 10);
  2098. if (isNaN(default_value)) {
  2099. default_value = 0;
  2100. }
  2101. var result = parseInt(option_value, 10);
  2102. if (isNaN(result)) {
  2103. result = default_value;
  2104. }
  2105. return result;
  2106. };
  2107. Options.prototype._get_selection = function(name, selection_list, default_value) {
  2108. var result = this._get_selection_list(name, selection_list, default_value);
  2109. if (result.length !== 1) {
  2110. throw new Error(
  2111. "Invalid Option Value: The option '" + name + "' can only be one of the following values:\n" +
  2112. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  2113. }
  2114. return result[0];
  2115. };
  2116. Options.prototype._get_selection_list = function(name, selection_list, default_value) {
  2117. if (!selection_list || selection_list.length === 0) {
  2118. throw new Error("Selection list cannot be empty.");
  2119. }
  2120. default_value = default_value || [selection_list[0]];
  2121. if (!this._is_valid_selection(default_value, selection_list)) {
  2122. throw new Error("Invalid Default Value!");
  2123. }
  2124. var result = this._get_array(name, default_value);
  2125. if (!this._is_valid_selection(result, selection_list)) {
  2126. throw new Error(
  2127. "Invalid Option Value: The option '" + name + "' can contain only the following values:\n" +
  2128. selection_list + "\nYou passed in: '" + this.raw_options[name] + "'");
  2129. }
  2130. return result;
  2131. };
  2132. Options.prototype._is_valid_selection = function(result, selection_list) {
  2133. return result.length && selection_list.length &&
  2134. !result.some(function(item) { return selection_list.indexOf(item) === -1; });
  2135. };
  2136. // merges child options up with the parent options object
  2137. // Example: obj = {a: 1, b: {a: 2}}
  2138. // mergeOpts(obj, 'b')
  2139. //
  2140. // Returns: {a: 2}
  2141. function _mergeOpts(allOptions, childFieldName) {
  2142. var finalOpts = {};
  2143. allOptions = _normalizeOpts(allOptions);
  2144. var name;
  2145. for (name in allOptions) {
  2146. if (name !== childFieldName) {
  2147. finalOpts[name] = allOptions[name];
  2148. }
  2149. }
  2150. //merge in the per type settings for the childFieldName
  2151. if (childFieldName && allOptions[childFieldName]) {
  2152. for (name in allOptions[childFieldName]) {
  2153. finalOpts[name] = allOptions[childFieldName][name];
  2154. }
  2155. }
  2156. return finalOpts;
  2157. }
  2158. function _normalizeOpts(options) {
  2159. var convertedOpts = {};
  2160. var key;
  2161. for (key in options) {
  2162. var newKey = key.replace(/-/g, "_");
  2163. convertedOpts[newKey] = options[key];
  2164. }
  2165. return convertedOpts;
  2166. }
  2167. options$2.Options = Options;
  2168. options$2.normalizeOpts = _normalizeOpts;
  2169. options$2.mergeOpts = _mergeOpts;
  2170. return options$2;
  2171. }
  2172. /*jshint node:true */
  2173. var hasRequiredOptions$2;
  2174. function requireOptions$2 () {
  2175. if (hasRequiredOptions$2) return options$3;
  2176. hasRequiredOptions$2 = 1;
  2177. var BaseOptions = requireOptions$3().Options;
  2178. var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
  2179. function Options(options) {
  2180. BaseOptions.call(this, options, 'js');
  2181. // compatibility, re
  2182. var raw_brace_style = this.raw_options.brace_style || null;
  2183. if (raw_brace_style === "expand-strict") { //graceful handling of deprecated option
  2184. this.raw_options.brace_style = "expand";
  2185. } else if (raw_brace_style === "collapse-preserve-inline") { //graceful handling of deprecated option
  2186. this.raw_options.brace_style = "collapse,preserve-inline";
  2187. } else if (this.raw_options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
  2188. this.raw_options.brace_style = this.raw_options.braces_on_own_line ? "expand" : "collapse";
  2189. // } else if (!raw_brace_style) { //Nothing exists to set it
  2190. // raw_brace_style = "collapse";
  2191. }
  2192. //preserve-inline in delimited string will trigger brace_preserve_inline, everything
  2193. //else is considered a brace_style and the last one only will have an effect
  2194. var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
  2195. this.brace_preserve_inline = false; //Defaults in case one or other was not specified in meta-option
  2196. this.brace_style = "collapse";
  2197. for (var bs = 0; bs < brace_style_split.length; bs++) {
  2198. if (brace_style_split[bs] === "preserve-inline") {
  2199. this.brace_preserve_inline = true;
  2200. } else {
  2201. this.brace_style = brace_style_split[bs];
  2202. }
  2203. }
  2204. this.unindent_chained_methods = this._get_boolean('unindent_chained_methods');
  2205. this.break_chained_methods = this._get_boolean('break_chained_methods');
  2206. this.space_in_paren = this._get_boolean('space_in_paren');
  2207. this.space_in_empty_paren = this._get_boolean('space_in_empty_paren');
  2208. this.jslint_happy = this._get_boolean('jslint_happy');
  2209. this.space_after_anon_function = this._get_boolean('space_after_anon_function');
  2210. this.space_after_named_function = this._get_boolean('space_after_named_function');
  2211. this.keep_array_indentation = this._get_boolean('keep_array_indentation');
  2212. this.space_before_conditional = this._get_boolean('space_before_conditional', true);
  2213. this.unescape_strings = this._get_boolean('unescape_strings');
  2214. this.e4x = this._get_boolean('e4x');
  2215. this.comma_first = this._get_boolean('comma_first');
  2216. this.operator_position = this._get_selection('operator_position', validPositionValues);
  2217. // For testing of beautify preserve:start directive
  2218. this.test_output_raw = this._get_boolean('test_output_raw');
  2219. // force this._options.space_after_anon_function to true if this._options.jslint_happy
  2220. if (this.jslint_happy) {
  2221. this.space_after_anon_function = true;
  2222. }
  2223. }
  2224. Options.prototype = new BaseOptions();
  2225. options$3.Options = Options;
  2226. return options$3;
  2227. }
  2228. var tokenizer$2 = {};
  2229. var inputscanner = {};
  2230. /*jshint node:true */
  2231. var hasRequiredInputscanner;
  2232. function requireInputscanner () {
  2233. if (hasRequiredInputscanner) return inputscanner;
  2234. hasRequiredInputscanner = 1;
  2235. var regexp_has_sticky = RegExp.prototype.hasOwnProperty('sticky');
  2236. function InputScanner(input_string) {
  2237. this.__input = input_string || '';
  2238. this.__input_length = this.__input.length;
  2239. this.__position = 0;
  2240. }
  2241. InputScanner.prototype.restart = function() {
  2242. this.__position = 0;
  2243. };
  2244. InputScanner.prototype.back = function() {
  2245. if (this.__position > 0) {
  2246. this.__position -= 1;
  2247. }
  2248. };
  2249. InputScanner.prototype.hasNext = function() {
  2250. return this.__position < this.__input_length;
  2251. };
  2252. InputScanner.prototype.next = function() {
  2253. var val = null;
  2254. if (this.hasNext()) {
  2255. val = this.__input.charAt(this.__position);
  2256. this.__position += 1;
  2257. }
  2258. return val;
  2259. };
  2260. InputScanner.prototype.peek = function(index) {
  2261. var val = null;
  2262. index = index || 0;
  2263. index += this.__position;
  2264. if (index >= 0 && index < this.__input_length) {
  2265. val = this.__input.charAt(index);
  2266. }
  2267. return val;
  2268. };
  2269. // This is a JavaScript only helper function (not in python)
  2270. // Javascript doesn't have a match method
  2271. // and not all implementation support "sticky" flag.
  2272. // If they do not support sticky then both this.match() and this.test() method
  2273. // must get the match and check the index of the match.
  2274. // If sticky is supported and set, this method will use it.
  2275. // Otherwise it will check that global is set, and fall back to the slower method.
  2276. InputScanner.prototype.__match = function(pattern, index) {
  2277. pattern.lastIndex = index;
  2278. var pattern_match = pattern.exec(this.__input);
  2279. if (pattern_match && !(regexp_has_sticky && pattern.sticky)) {
  2280. if (pattern_match.index !== index) {
  2281. pattern_match = null;
  2282. }
  2283. }
  2284. return pattern_match;
  2285. };
  2286. InputScanner.prototype.test = function(pattern, index) {
  2287. index = index || 0;
  2288. index += this.__position;
  2289. if (index >= 0 && index < this.__input_length) {
  2290. return !!this.__match(pattern, index);
  2291. } else {
  2292. return false;
  2293. }
  2294. };
  2295. InputScanner.prototype.testChar = function(pattern, index) {
  2296. // test one character regex match
  2297. var val = this.peek(index);
  2298. pattern.lastIndex = 0;
  2299. return val !== null && pattern.test(val);
  2300. };
  2301. InputScanner.prototype.match = function(pattern) {
  2302. var pattern_match = this.__match(pattern, this.__position);
  2303. if (pattern_match) {
  2304. this.__position += pattern_match[0].length;
  2305. } else {
  2306. pattern_match = null;
  2307. }
  2308. return pattern_match;
  2309. };
  2310. InputScanner.prototype.read = function(starting_pattern, until_pattern, until_after) {
  2311. var val = '';
  2312. var match;
  2313. if (starting_pattern) {
  2314. match = this.match(starting_pattern);
  2315. if (match) {
  2316. val += match[0];
  2317. }
  2318. }
  2319. if (until_pattern && (match || !starting_pattern)) {
  2320. val += this.readUntil(until_pattern, until_after);
  2321. }
  2322. return val;
  2323. };
  2324. InputScanner.prototype.readUntil = function(pattern, until_after) {
  2325. var val = '';
  2326. var match_index = this.__position;
  2327. pattern.lastIndex = this.__position;
  2328. var pattern_match = pattern.exec(this.__input);
  2329. if (pattern_match) {
  2330. match_index = pattern_match.index;
  2331. if (until_after) {
  2332. match_index += pattern_match[0].length;
  2333. }
  2334. } else {
  2335. match_index = this.__input_length;
  2336. }
  2337. val = this.__input.substring(this.__position, match_index);
  2338. this.__position = match_index;
  2339. return val;
  2340. };
  2341. InputScanner.prototype.readUntilAfter = function(pattern) {
  2342. return this.readUntil(pattern, true);
  2343. };
  2344. InputScanner.prototype.get_regexp = function(pattern, match_from) {
  2345. var result = null;
  2346. var flags = 'g';
  2347. if (match_from && regexp_has_sticky) {
  2348. flags = 'y';
  2349. }
  2350. // strings are converted to regexp
  2351. if (typeof pattern === "string" && pattern !== '') {
  2352. // result = new RegExp(pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), flags);
  2353. result = new RegExp(pattern, flags);
  2354. } else if (pattern) {
  2355. result = new RegExp(pattern.source, flags);
  2356. }
  2357. return result;
  2358. };
  2359. InputScanner.prototype.get_literal_regexp = function(literal_string) {
  2360. return RegExp(literal_string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
  2361. };
  2362. /* css beautifier legacy helpers */
  2363. InputScanner.prototype.peekUntilAfter = function(pattern) {
  2364. var start = this.__position;
  2365. var val = this.readUntilAfter(pattern);
  2366. this.__position = start;
  2367. return val;
  2368. };
  2369. InputScanner.prototype.lookBack = function(testVal) {
  2370. var start = this.__position - 1;
  2371. return start >= testVal.length && this.__input.substring(start - testVal.length, start)
  2372. .toLowerCase() === testVal;
  2373. };
  2374. inputscanner.InputScanner = InputScanner;
  2375. return inputscanner;
  2376. }
  2377. var tokenizer$1 = {};
  2378. var tokenstream = {};
  2379. /*jshint node:true */
  2380. var hasRequiredTokenstream;
  2381. function requireTokenstream () {
  2382. if (hasRequiredTokenstream) return tokenstream;
  2383. hasRequiredTokenstream = 1;
  2384. function TokenStream(parent_token) {
  2385. // private
  2386. this.__tokens = [];
  2387. this.__tokens_length = this.__tokens.length;
  2388. this.__position = 0;
  2389. this.__parent_token = parent_token;
  2390. }
  2391. TokenStream.prototype.restart = function() {
  2392. this.__position = 0;
  2393. };
  2394. TokenStream.prototype.isEmpty = function() {
  2395. return this.__tokens_length === 0;
  2396. };
  2397. TokenStream.prototype.hasNext = function() {
  2398. return this.__position < this.__tokens_length;
  2399. };
  2400. TokenStream.prototype.next = function() {
  2401. var val = null;
  2402. if (this.hasNext()) {
  2403. val = this.__tokens[this.__position];
  2404. this.__position += 1;
  2405. }
  2406. return val;
  2407. };
  2408. TokenStream.prototype.peek = function(index) {
  2409. var val = null;
  2410. index = index || 0;
  2411. index += this.__position;
  2412. if (index >= 0 && index < this.__tokens_length) {
  2413. val = this.__tokens[index];
  2414. }
  2415. return val;
  2416. };
  2417. TokenStream.prototype.add = function(token) {
  2418. if (this.__parent_token) {
  2419. token.parent = this.__parent_token;
  2420. }
  2421. this.__tokens.push(token);
  2422. this.__tokens_length += 1;
  2423. };
  2424. tokenstream.TokenStream = TokenStream;
  2425. return tokenstream;
  2426. }
  2427. var whitespacepattern = {};
  2428. var pattern = {};
  2429. /*jshint node:true */
  2430. var hasRequiredPattern;
  2431. function requirePattern () {
  2432. if (hasRequiredPattern) return pattern;
  2433. hasRequiredPattern = 1;
  2434. function Pattern(input_scanner, parent) {
  2435. this._input = input_scanner;
  2436. this._starting_pattern = null;
  2437. this._match_pattern = null;
  2438. this._until_pattern = null;
  2439. this._until_after = false;
  2440. if (parent) {
  2441. this._starting_pattern = this._input.get_regexp(parent._starting_pattern, true);
  2442. this._match_pattern = this._input.get_regexp(parent._match_pattern, true);
  2443. this._until_pattern = this._input.get_regexp(parent._until_pattern);
  2444. this._until_after = parent._until_after;
  2445. }
  2446. }
  2447. Pattern.prototype.read = function() {
  2448. var result = this._input.read(this._starting_pattern);
  2449. if (!this._starting_pattern || result) {
  2450. result += this._input.read(this._match_pattern, this._until_pattern, this._until_after);
  2451. }
  2452. return result;
  2453. };
  2454. Pattern.prototype.read_match = function() {
  2455. return this._input.match(this._match_pattern);
  2456. };
  2457. Pattern.prototype.until_after = function(pattern) {
  2458. var result = this._create();
  2459. result._until_after = true;
  2460. result._until_pattern = this._input.get_regexp(pattern);
  2461. result._update();
  2462. return result;
  2463. };
  2464. Pattern.prototype.until = function(pattern) {
  2465. var result = this._create();
  2466. result._until_after = false;
  2467. result._until_pattern = this._input.get_regexp(pattern);
  2468. result._update();
  2469. return result;
  2470. };
  2471. Pattern.prototype.starting_with = function(pattern) {
  2472. var result = this._create();
  2473. result._starting_pattern = this._input.get_regexp(pattern, true);
  2474. result._update();
  2475. return result;
  2476. };
  2477. Pattern.prototype.matching = function(pattern) {
  2478. var result = this._create();
  2479. result._match_pattern = this._input.get_regexp(pattern, true);
  2480. result._update();
  2481. return result;
  2482. };
  2483. Pattern.prototype._create = function() {
  2484. return new Pattern(this._input, this);
  2485. };
  2486. Pattern.prototype._update = function() {};
  2487. pattern.Pattern = Pattern;
  2488. return pattern;
  2489. }
  2490. /*jshint node:true */
  2491. var hasRequiredWhitespacepattern;
  2492. function requireWhitespacepattern () {
  2493. if (hasRequiredWhitespacepattern) return whitespacepattern;
  2494. hasRequiredWhitespacepattern = 1;
  2495. var Pattern = requirePattern().Pattern;
  2496. function WhitespacePattern(input_scanner, parent) {
  2497. Pattern.call(this, input_scanner, parent);
  2498. if (parent) {
  2499. this._line_regexp = this._input.get_regexp(parent._line_regexp);
  2500. } else {
  2501. this.__set_whitespace_patterns('', '');
  2502. }
  2503. this.newline_count = 0;
  2504. this.whitespace_before_token = '';
  2505. }
  2506. WhitespacePattern.prototype = new Pattern();
  2507. WhitespacePattern.prototype.__set_whitespace_patterns = function(whitespace_chars, newline_chars) {
  2508. whitespace_chars += '\\t ';
  2509. newline_chars += '\\n\\r';
  2510. this._match_pattern = this._input.get_regexp(
  2511. '[' + whitespace_chars + newline_chars + ']+', true);
  2512. this._newline_regexp = this._input.get_regexp(
  2513. '\\r\\n|[' + newline_chars + ']');
  2514. };
  2515. WhitespacePattern.prototype.read = function() {
  2516. this.newline_count = 0;
  2517. this.whitespace_before_token = '';
  2518. var resulting_string = this._input.read(this._match_pattern);
  2519. if (resulting_string === ' ') {
  2520. this.whitespace_before_token = ' ';
  2521. } else if (resulting_string) {
  2522. var matches = this.__split(this._newline_regexp, resulting_string);
  2523. this.newline_count = matches.length - 1;
  2524. this.whitespace_before_token = matches[this.newline_count];
  2525. }
  2526. return resulting_string;
  2527. };
  2528. WhitespacePattern.prototype.matching = function(whitespace_chars, newline_chars) {
  2529. var result = this._create();
  2530. result.__set_whitespace_patterns(whitespace_chars, newline_chars);
  2531. result._update();
  2532. return result;
  2533. };
  2534. WhitespacePattern.prototype._create = function() {
  2535. return new WhitespacePattern(this._input, this);
  2536. };
  2537. WhitespacePattern.prototype.__split = function(regexp, input_string) {
  2538. regexp.lastIndex = 0;
  2539. var start_index = 0;
  2540. var result = [];
  2541. var next_match = regexp.exec(input_string);
  2542. while (next_match) {
  2543. result.push(input_string.substring(start_index, next_match.index));
  2544. start_index = next_match.index + next_match[0].length;
  2545. next_match = regexp.exec(input_string);
  2546. }
  2547. if (start_index < input_string.length) {
  2548. result.push(input_string.substring(start_index, input_string.length));
  2549. } else {
  2550. result.push('');
  2551. }
  2552. return result;
  2553. };
  2554. whitespacepattern.WhitespacePattern = WhitespacePattern;
  2555. return whitespacepattern;
  2556. }
  2557. /*jshint node:true */
  2558. var hasRequiredTokenizer$2;
  2559. function requireTokenizer$2 () {
  2560. if (hasRequiredTokenizer$2) return tokenizer$1;
  2561. hasRequiredTokenizer$2 = 1;
  2562. var InputScanner = requireInputscanner().InputScanner;
  2563. var Token = requireToken().Token;
  2564. var TokenStream = requireTokenstream().TokenStream;
  2565. var WhitespacePattern = requireWhitespacepattern().WhitespacePattern;
  2566. var TOKEN = {
  2567. START: 'TK_START',
  2568. RAW: 'TK_RAW',
  2569. EOF: 'TK_EOF'
  2570. };
  2571. var Tokenizer = function(input_string, options) {
  2572. this._input = new InputScanner(input_string);
  2573. this._options = options || {};
  2574. this.__tokens = null;
  2575. this._patterns = {};
  2576. this._patterns.whitespace = new WhitespacePattern(this._input);
  2577. };
  2578. Tokenizer.prototype.tokenize = function() {
  2579. this._input.restart();
  2580. this.__tokens = new TokenStream();
  2581. this._reset();
  2582. var current;
  2583. var previous = new Token(TOKEN.START, '');
  2584. var open_token = null;
  2585. var open_stack = [];
  2586. var comments = new TokenStream();
  2587. while (previous.type !== TOKEN.EOF) {
  2588. current = this._get_next_token(previous, open_token);
  2589. while (this._is_comment(current)) {
  2590. comments.add(current);
  2591. current = this._get_next_token(previous, open_token);
  2592. }
  2593. if (!comments.isEmpty()) {
  2594. current.comments_before = comments;
  2595. comments = new TokenStream();
  2596. }
  2597. current.parent = open_token;
  2598. if (this._is_opening(current)) {
  2599. open_stack.push(open_token);
  2600. open_token = current;
  2601. } else if (open_token && this._is_closing(current, open_token)) {
  2602. current.opened = open_token;
  2603. open_token.closed = current;
  2604. open_token = open_stack.pop();
  2605. current.parent = open_token;
  2606. }
  2607. current.previous = previous;
  2608. previous.next = current;
  2609. this.__tokens.add(current);
  2610. previous = current;
  2611. }
  2612. return this.__tokens;
  2613. };
  2614. Tokenizer.prototype._is_first_token = function() {
  2615. return this.__tokens.isEmpty();
  2616. };
  2617. Tokenizer.prototype._reset = function() {};
  2618. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  2619. this._readWhitespace();
  2620. var resulting_string = this._input.read(/.+/g);
  2621. if (resulting_string) {
  2622. return this._create_token(TOKEN.RAW, resulting_string);
  2623. } else {
  2624. return this._create_token(TOKEN.EOF, '');
  2625. }
  2626. };
  2627. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  2628. return false;
  2629. };
  2630. Tokenizer.prototype._is_opening = function(current_token) { // jshint unused:false
  2631. return false;
  2632. };
  2633. Tokenizer.prototype._is_closing = function(current_token, open_token) { // jshint unused:false
  2634. return false;
  2635. };
  2636. Tokenizer.prototype._create_token = function(type, text) {
  2637. var token = new Token(type, text,
  2638. this._patterns.whitespace.newline_count,
  2639. this._patterns.whitespace.whitespace_before_token);
  2640. return token;
  2641. };
  2642. Tokenizer.prototype._readWhitespace = function() {
  2643. return this._patterns.whitespace.read();
  2644. };
  2645. tokenizer$1.Tokenizer = Tokenizer;
  2646. tokenizer$1.TOKEN = TOKEN;
  2647. return tokenizer$1;
  2648. }
  2649. var directives = {};
  2650. /*jshint node:true */
  2651. var hasRequiredDirectives;
  2652. function requireDirectives () {
  2653. if (hasRequiredDirectives) return directives;
  2654. hasRequiredDirectives = 1;
  2655. function Directives(start_block_pattern, end_block_pattern) {
  2656. start_block_pattern = typeof start_block_pattern === 'string' ? start_block_pattern : start_block_pattern.source;
  2657. end_block_pattern = typeof end_block_pattern === 'string' ? end_block_pattern : end_block_pattern.source;
  2658. this.__directives_block_pattern = new RegExp(start_block_pattern + / beautify( \w+[:]\w+)+ /.source + end_block_pattern, 'g');
  2659. this.__directive_pattern = / (\w+)[:](\w+)/g;
  2660. this.__directives_end_ignore_pattern = new RegExp(start_block_pattern + /\sbeautify\signore:end\s/.source + end_block_pattern, 'g');
  2661. }
  2662. Directives.prototype.get_directives = function(text) {
  2663. if (!text.match(this.__directives_block_pattern)) {
  2664. return null;
  2665. }
  2666. var directives = {};
  2667. this.__directive_pattern.lastIndex = 0;
  2668. var directive_match = this.__directive_pattern.exec(text);
  2669. while (directive_match) {
  2670. directives[directive_match[1]] = directive_match[2];
  2671. directive_match = this.__directive_pattern.exec(text);
  2672. }
  2673. return directives;
  2674. };
  2675. Directives.prototype.readIgnored = function(input) {
  2676. return input.readUntilAfter(this.__directives_end_ignore_pattern);
  2677. };
  2678. directives.Directives = Directives;
  2679. return directives;
  2680. }
  2681. var templatablepattern = {};
  2682. /*jshint node:true */
  2683. var hasRequiredTemplatablepattern;
  2684. function requireTemplatablepattern () {
  2685. if (hasRequiredTemplatablepattern) return templatablepattern;
  2686. hasRequiredTemplatablepattern = 1;
  2687. var Pattern = requirePattern().Pattern;
  2688. var template_names = {
  2689. django: false,
  2690. erb: false,
  2691. handlebars: false,
  2692. php: false,
  2693. smarty: false
  2694. };
  2695. // This lets templates appear anywhere we would do a readUntil
  2696. // The cost is higher but it is pay to play.
  2697. function TemplatablePattern(input_scanner, parent) {
  2698. Pattern.call(this, input_scanner, parent);
  2699. this.__template_pattern = null;
  2700. this._disabled = Object.assign({}, template_names);
  2701. this._excluded = Object.assign({}, template_names);
  2702. if (parent) {
  2703. this.__template_pattern = this._input.get_regexp(parent.__template_pattern);
  2704. this._excluded = Object.assign(this._excluded, parent._excluded);
  2705. this._disabled = Object.assign(this._disabled, parent._disabled);
  2706. }
  2707. var pattern = new Pattern(input_scanner);
  2708. this.__patterns = {
  2709. handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
  2710. handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
  2711. handlebars: pattern.starting_with(/{{/).until_after(/}}/),
  2712. php: pattern.starting_with(/<\?(?:[= ]|php)/).until_after(/\?>/),
  2713. erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
  2714. // django coflicts with handlebars a bit.
  2715. django: pattern.starting_with(/{%/).until_after(/%}/),
  2716. django_value: pattern.starting_with(/{{/).until_after(/}}/),
  2717. django_comment: pattern.starting_with(/{#/).until_after(/#}/),
  2718. smarty: pattern.starting_with(/{(?=[^}{\s\n])/).until_after(/[^\s\n]}/),
  2719. smarty_comment: pattern.starting_with(/{\*/).until_after(/\*}/),
  2720. smarty_literal: pattern.starting_with(/{literal}/).until_after(/{\/literal}/)
  2721. };
  2722. }
  2723. TemplatablePattern.prototype = new Pattern();
  2724. TemplatablePattern.prototype._create = function() {
  2725. return new TemplatablePattern(this._input, this);
  2726. };
  2727. TemplatablePattern.prototype._update = function() {
  2728. this.__set_templated_pattern();
  2729. };
  2730. TemplatablePattern.prototype.disable = function(language) {
  2731. var result = this._create();
  2732. result._disabled[language] = true;
  2733. result._update();
  2734. return result;
  2735. };
  2736. TemplatablePattern.prototype.read_options = function(options) {
  2737. var result = this._create();
  2738. for (var language in template_names) {
  2739. result._disabled[language] = options.templating.indexOf(language) === -1;
  2740. }
  2741. result._update();
  2742. return result;
  2743. };
  2744. TemplatablePattern.prototype.exclude = function(language) {
  2745. var result = this._create();
  2746. result._excluded[language] = true;
  2747. result._update();
  2748. return result;
  2749. };
  2750. TemplatablePattern.prototype.read = function() {
  2751. var result = '';
  2752. if (this._match_pattern) {
  2753. result = this._input.read(this._starting_pattern);
  2754. } else {
  2755. result = this._input.read(this._starting_pattern, this.__template_pattern);
  2756. }
  2757. var next = this._read_template();
  2758. while (next) {
  2759. if (this._match_pattern) {
  2760. next += this._input.read(this._match_pattern);
  2761. } else {
  2762. next += this._input.readUntil(this.__template_pattern);
  2763. }
  2764. result += next;
  2765. next = this._read_template();
  2766. }
  2767. if (this._until_after) {
  2768. result += this._input.readUntilAfter(this._until_pattern);
  2769. }
  2770. return result;
  2771. };
  2772. TemplatablePattern.prototype.__set_templated_pattern = function() {
  2773. var items = [];
  2774. if (!this._disabled.php) {
  2775. items.push(this.__patterns.php._starting_pattern.source);
  2776. }
  2777. if (!this._disabled.handlebars) {
  2778. items.push(this.__patterns.handlebars._starting_pattern.source);
  2779. }
  2780. if (!this._disabled.erb) {
  2781. items.push(this.__patterns.erb._starting_pattern.source);
  2782. }
  2783. if (!this._disabled.django) {
  2784. items.push(this.__patterns.django._starting_pattern.source);
  2785. // The starting pattern for django is more complex because it has different
  2786. // patterns for value, comment, and other sections
  2787. items.push(this.__patterns.django_value._starting_pattern.source);
  2788. items.push(this.__patterns.django_comment._starting_pattern.source);
  2789. }
  2790. if (!this._disabled.smarty) {
  2791. items.push(this.__patterns.smarty._starting_pattern.source);
  2792. }
  2793. if (this._until_pattern) {
  2794. items.push(this._until_pattern.source);
  2795. }
  2796. this.__template_pattern = this._input.get_regexp('(?:' + items.join('|') + ')');
  2797. };
  2798. TemplatablePattern.prototype._read_template = function() {
  2799. var resulting_string = '';
  2800. var c = this._input.peek();
  2801. if (c === '<') {
  2802. var peek1 = this._input.peek(1);
  2803. //if we're in a comment, do something special
  2804. // We treat all comments as literals, even more than preformatted tags
  2805. // we just look for the appropriate close tag
  2806. if (!this._disabled.php && !this._excluded.php && peek1 === '?') {
  2807. resulting_string = resulting_string ||
  2808. this.__patterns.php.read();
  2809. }
  2810. if (!this._disabled.erb && !this._excluded.erb && peek1 === '%') {
  2811. resulting_string = resulting_string ||
  2812. this.__patterns.erb.read();
  2813. }
  2814. } else if (c === '{') {
  2815. if (!this._disabled.handlebars && !this._excluded.handlebars) {
  2816. resulting_string = resulting_string ||
  2817. this.__patterns.handlebars_comment.read();
  2818. resulting_string = resulting_string ||
  2819. this.__patterns.handlebars_unescaped.read();
  2820. resulting_string = resulting_string ||
  2821. this.__patterns.handlebars.read();
  2822. }
  2823. if (!this._disabled.django) {
  2824. // django coflicts with handlebars a bit.
  2825. if (!this._excluded.django && !this._excluded.handlebars) {
  2826. resulting_string = resulting_string ||
  2827. this.__patterns.django_value.read();
  2828. }
  2829. if (!this._excluded.django) {
  2830. resulting_string = resulting_string ||
  2831. this.__patterns.django_comment.read();
  2832. resulting_string = resulting_string ||
  2833. this.__patterns.django.read();
  2834. }
  2835. }
  2836. if (!this._disabled.smarty) {
  2837. // smarty cannot be enabled with django or handlebars enabled
  2838. if (this._disabled.django && this._disabled.handlebars) {
  2839. resulting_string = resulting_string ||
  2840. this.__patterns.smarty_comment.read();
  2841. resulting_string = resulting_string ||
  2842. this.__patterns.smarty_literal.read();
  2843. resulting_string = resulting_string ||
  2844. this.__patterns.smarty.read();
  2845. }
  2846. }
  2847. }
  2848. return resulting_string;
  2849. };
  2850. templatablepattern.TemplatablePattern = TemplatablePattern;
  2851. return templatablepattern;
  2852. }
  2853. /*jshint node:true */
  2854. var hasRequiredTokenizer$1;
  2855. function requireTokenizer$1 () {
  2856. if (hasRequiredTokenizer$1) return tokenizer$2;
  2857. hasRequiredTokenizer$1 = 1;
  2858. var InputScanner = requireInputscanner().InputScanner;
  2859. var BaseTokenizer = requireTokenizer$2().Tokenizer;
  2860. var BASETOKEN = requireTokenizer$2().TOKEN;
  2861. var Directives = requireDirectives().Directives;
  2862. var acorn = requireAcorn();
  2863. var Pattern = requirePattern().Pattern;
  2864. var TemplatablePattern = requireTemplatablepattern().TemplatablePattern;
  2865. function in_array(what, arr) {
  2866. return arr.indexOf(what) !== -1;
  2867. }
  2868. var TOKEN = {
  2869. START_EXPR: 'TK_START_EXPR',
  2870. END_EXPR: 'TK_END_EXPR',
  2871. START_BLOCK: 'TK_START_BLOCK',
  2872. END_BLOCK: 'TK_END_BLOCK',
  2873. WORD: 'TK_WORD',
  2874. RESERVED: 'TK_RESERVED',
  2875. SEMICOLON: 'TK_SEMICOLON',
  2876. STRING: 'TK_STRING',
  2877. EQUALS: 'TK_EQUALS',
  2878. OPERATOR: 'TK_OPERATOR',
  2879. COMMA: 'TK_COMMA',
  2880. BLOCK_COMMENT: 'TK_BLOCK_COMMENT',
  2881. COMMENT: 'TK_COMMENT',
  2882. DOT: 'TK_DOT',
  2883. UNKNOWN: 'TK_UNKNOWN',
  2884. START: BASETOKEN.START,
  2885. RAW: BASETOKEN.RAW,
  2886. EOF: BASETOKEN.EOF
  2887. };
  2888. var directives_core = new Directives(/\/\*/, /\*\//);
  2889. 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_]+)?/;
  2890. var digit = /[0-9]/;
  2891. // Dot "." must be distinguished from "..." and decimal
  2892. var dot_pattern = /[^\d\.]/;
  2893. var positionable_operators = (
  2894. ">>> === !== &&= ??= ||= " +
  2895. "<< && >= ** != == <= >> || ?? |> " +
  2896. "< / - + > : & % ? ^ | *").split(' ');
  2897. // IMPORTANT: this must be sorted longest to shortest or tokenizing many not work.
  2898. // Also, you must update possitionable operators separately from punct
  2899. var punct =
  2900. ">>>= " +
  2901. "... >>= <<= === >>> !== **= &&= ??= ||= " +
  2902. "=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
  2903. "= ! ? > < : / ^ - + * & % ~ |";
  2904. punct = punct.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
  2905. // ?. but not if followed by a number
  2906. punct = '\\?\\.(?!\\d) ' + punct;
  2907. punct = punct.replace(/ /g, '|');
  2908. var punct_pattern = new RegExp(punct);
  2909. // words which should always start on new line.
  2910. var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
  2911. var reserved_words = line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as', 'class', 'extends']);
  2912. var reserved_word_pattern = new RegExp('^(?:' + reserved_words.join('|') + ')$');
  2913. // var template_pattern = /(?:(?:<\?php|<\?=)[\s\S]*?\?>)|(?:<%[\s\S]*?%>)/g;
  2914. var in_html_comment;
  2915. var Tokenizer = function(input_string, options) {
  2916. BaseTokenizer.call(this, input_string, options);
  2917. this._patterns.whitespace = this._patterns.whitespace.matching(
  2918. /\u00A0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff/.source,
  2919. /\u2028\u2029/.source);
  2920. var pattern_reader = new Pattern(this._input);
  2921. var templatable = new TemplatablePattern(this._input)
  2922. .read_options(this._options);
  2923. this.__patterns = {
  2924. template: templatable,
  2925. identifier: templatable.starting_with(acorn.identifier).matching(acorn.identifierMatch),
  2926. number: pattern_reader.matching(number_pattern),
  2927. punct: pattern_reader.matching(punct_pattern),
  2928. // comment ends just before nearest linefeed or end of file
  2929. comment: pattern_reader.starting_with(/\/\//).until(/[\n\r\u2028\u2029]/),
  2930. // /* ... */ comment ends with nearest */ or end of file
  2931. block_comment: pattern_reader.starting_with(/\/\*/).until_after(/\*\//),
  2932. html_comment_start: pattern_reader.matching(/<!--/),
  2933. html_comment_end: pattern_reader.matching(/-->/),
  2934. include: pattern_reader.starting_with(/#include/).until_after(acorn.lineBreak),
  2935. shebang: pattern_reader.starting_with(/#!/).until_after(acorn.lineBreak),
  2936. 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*>/),
  2937. single_quote: templatable.until(/['\\\n\r\u2028\u2029]/),
  2938. double_quote: templatable.until(/["\\\n\r\u2028\u2029]/),
  2939. template_text: templatable.until(/[`\\$]/),
  2940. template_expression: templatable.until(/[`}\\]/)
  2941. };
  2942. };
  2943. Tokenizer.prototype = new BaseTokenizer();
  2944. Tokenizer.prototype._is_comment = function(current_token) {
  2945. return current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.BLOCK_COMMENT || current_token.type === TOKEN.UNKNOWN;
  2946. };
  2947. Tokenizer.prototype._is_opening = function(current_token) {
  2948. return current_token.type === TOKEN.START_BLOCK || current_token.type === TOKEN.START_EXPR;
  2949. };
  2950. Tokenizer.prototype._is_closing = function(current_token, open_token) {
  2951. return (current_token.type === TOKEN.END_BLOCK || current_token.type === TOKEN.END_EXPR) &&
  2952. (open_token && (
  2953. (current_token.text === ']' && open_token.text === '[') ||
  2954. (current_token.text === ')' && open_token.text === '(') ||
  2955. (current_token.text === '}' && open_token.text === '{')));
  2956. };
  2957. Tokenizer.prototype._reset = function() {
  2958. in_html_comment = false;
  2959. };
  2960. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  2961. var token = null;
  2962. this._readWhitespace();
  2963. var c = this._input.peek();
  2964. if (c === null) {
  2965. return this._create_token(TOKEN.EOF, '');
  2966. }
  2967. token = token || this._read_non_javascript(c);
  2968. token = token || this._read_string(c);
  2969. token = token || this._read_pair(c, this._input.peek(1)); // Issue #2062 hack for record type '#{'
  2970. token = token || this._read_word(previous_token);
  2971. token = token || this._read_singles(c);
  2972. token = token || this._read_comment(c);
  2973. token = token || this._read_regexp(c, previous_token);
  2974. token = token || this._read_xml(c, previous_token);
  2975. token = token || this._read_punctuation();
  2976. token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
  2977. return token;
  2978. };
  2979. Tokenizer.prototype._read_word = function(previous_token) {
  2980. var resulting_string;
  2981. resulting_string = this.__patterns.identifier.read();
  2982. if (resulting_string !== '') {
  2983. resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
  2984. if (!(previous_token.type === TOKEN.DOT ||
  2985. (previous_token.type === TOKEN.RESERVED && (previous_token.text === 'set' || previous_token.text === 'get'))) &&
  2986. reserved_word_pattern.test(resulting_string)) {
  2987. if ((resulting_string === 'in' || resulting_string === 'of') &&
  2988. (previous_token.type === TOKEN.WORD || previous_token.type === TOKEN.STRING)) { // hack for 'in' and 'of' operators
  2989. return this._create_token(TOKEN.OPERATOR, resulting_string);
  2990. }
  2991. return this._create_token(TOKEN.RESERVED, resulting_string);
  2992. }
  2993. return this._create_token(TOKEN.WORD, resulting_string);
  2994. }
  2995. resulting_string = this.__patterns.number.read();
  2996. if (resulting_string !== '') {
  2997. return this._create_token(TOKEN.WORD, resulting_string);
  2998. }
  2999. };
  3000. Tokenizer.prototype._read_singles = function(c) {
  3001. var token = null;
  3002. if (c === '(' || c === '[') {
  3003. token = this._create_token(TOKEN.START_EXPR, c);
  3004. } else if (c === ')' || c === ']') {
  3005. token = this._create_token(TOKEN.END_EXPR, c);
  3006. } else if (c === '{') {
  3007. token = this._create_token(TOKEN.START_BLOCK, c);
  3008. } else if (c === '}') {
  3009. token = this._create_token(TOKEN.END_BLOCK, c);
  3010. } else if (c === ';') {
  3011. token = this._create_token(TOKEN.SEMICOLON, c);
  3012. } else if (c === '.' && dot_pattern.test(this._input.peek(1))) {
  3013. token = this._create_token(TOKEN.DOT, c);
  3014. } else if (c === ',') {
  3015. token = this._create_token(TOKEN.COMMA, c);
  3016. }
  3017. if (token) {
  3018. this._input.next();
  3019. }
  3020. return token;
  3021. };
  3022. Tokenizer.prototype._read_pair = function(c, d) {
  3023. var token = null;
  3024. if (c === '#' && d === '{') {
  3025. token = this._create_token(TOKEN.START_BLOCK, c + d);
  3026. }
  3027. if (token) {
  3028. this._input.next();
  3029. this._input.next();
  3030. }
  3031. return token;
  3032. };
  3033. Tokenizer.prototype._read_punctuation = function() {
  3034. var resulting_string = this.__patterns.punct.read();
  3035. if (resulting_string !== '') {
  3036. if (resulting_string === '=') {
  3037. return this._create_token(TOKEN.EQUALS, resulting_string);
  3038. } else if (resulting_string === '?.') {
  3039. return this._create_token(TOKEN.DOT, resulting_string);
  3040. } else {
  3041. return this._create_token(TOKEN.OPERATOR, resulting_string);
  3042. }
  3043. }
  3044. };
  3045. Tokenizer.prototype._read_non_javascript = function(c) {
  3046. var resulting_string = '';
  3047. if (c === '#') {
  3048. if (this._is_first_token()) {
  3049. resulting_string = this.__patterns.shebang.read();
  3050. if (resulting_string) {
  3051. return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
  3052. }
  3053. }
  3054. // handles extendscript #includes
  3055. resulting_string = this.__patterns.include.read();
  3056. if (resulting_string) {
  3057. return this._create_token(TOKEN.UNKNOWN, resulting_string.trim() + '\n');
  3058. }
  3059. c = this._input.next();
  3060. // Spidermonkey-specific sharp variables for circular references. Considered obsolete.
  3061. var sharp = '#';
  3062. if (this._input.hasNext() && this._input.testChar(digit)) {
  3063. do {
  3064. c = this._input.next();
  3065. sharp += c;
  3066. } while (this._input.hasNext() && c !== '#' && c !== '=');
  3067. if (c === '#') ; else if (this._input.peek() === '[' && this._input.peek(1) === ']') {
  3068. sharp += '[]';
  3069. this._input.next();
  3070. this._input.next();
  3071. } else if (this._input.peek() === '{' && this._input.peek(1) === '}') {
  3072. sharp += '{}';
  3073. this._input.next();
  3074. this._input.next();
  3075. }
  3076. return this._create_token(TOKEN.WORD, sharp);
  3077. }
  3078. this._input.back();
  3079. } else if (c === '<' && this._is_first_token()) {
  3080. resulting_string = this.__patterns.html_comment_start.read();
  3081. if (resulting_string) {
  3082. while (this._input.hasNext() && !this._input.testChar(acorn.newline)) {
  3083. resulting_string += this._input.next();
  3084. }
  3085. in_html_comment = true;
  3086. return this._create_token(TOKEN.COMMENT, resulting_string);
  3087. }
  3088. } else if (in_html_comment && c === '-') {
  3089. resulting_string = this.__patterns.html_comment_end.read();
  3090. if (resulting_string) {
  3091. in_html_comment = false;
  3092. return this._create_token(TOKEN.COMMENT, resulting_string);
  3093. }
  3094. }
  3095. return null;
  3096. };
  3097. Tokenizer.prototype._read_comment = function(c) {
  3098. var token = null;
  3099. if (c === '/') {
  3100. var comment = '';
  3101. if (this._input.peek(1) === '*') {
  3102. // peek for comment /* ... */
  3103. comment = this.__patterns.block_comment.read();
  3104. var directives = directives_core.get_directives(comment);
  3105. if (directives && directives.ignore === 'start') {
  3106. comment += directives_core.readIgnored(this._input);
  3107. }
  3108. comment = comment.replace(acorn.allLineBreaks, '\n');
  3109. token = this._create_token(TOKEN.BLOCK_COMMENT, comment);
  3110. token.directives = directives;
  3111. } else if (this._input.peek(1) === '/') {
  3112. // peek for comment // ...
  3113. comment = this.__patterns.comment.read();
  3114. token = this._create_token(TOKEN.COMMENT, comment);
  3115. }
  3116. }
  3117. return token;
  3118. };
  3119. Tokenizer.prototype._read_string = function(c) {
  3120. if (c === '`' || c === "'" || c === '"') {
  3121. var resulting_string = this._input.next();
  3122. this.has_char_escapes = false;
  3123. if (c === '`') {
  3124. resulting_string += this._read_string_recursive('`', true, '${');
  3125. } else {
  3126. resulting_string += this._read_string_recursive(c);
  3127. }
  3128. if (this.has_char_escapes && this._options.unescape_strings) {
  3129. resulting_string = unescape_string(resulting_string);
  3130. }
  3131. if (this._input.peek() === c) {
  3132. resulting_string += this._input.next();
  3133. }
  3134. resulting_string = resulting_string.replace(acorn.allLineBreaks, '\n');
  3135. return this._create_token(TOKEN.STRING, resulting_string);
  3136. }
  3137. return null;
  3138. };
  3139. Tokenizer.prototype._allow_regexp_or_xml = function(previous_token) {
  3140. // regex and xml can only appear in specific locations during parsing
  3141. return (previous_token.type === TOKEN.RESERVED && in_array(previous_token.text, ['return', 'case', 'throw', 'else', 'do', 'typeof', 'yield'])) ||
  3142. (previous_token.type === TOKEN.END_EXPR && previous_token.text === ')' &&
  3143. previous_token.opened.previous.type === TOKEN.RESERVED && in_array(previous_token.opened.previous.text, ['if', 'while', 'for'])) ||
  3144. (in_array(previous_token.type, [TOKEN.COMMENT, TOKEN.START_EXPR, TOKEN.START_BLOCK, TOKEN.START,
  3145. TOKEN.END_BLOCK, TOKEN.OPERATOR, TOKEN.EQUALS, TOKEN.EOF, TOKEN.SEMICOLON, TOKEN.COMMA
  3146. ]));
  3147. };
  3148. Tokenizer.prototype._read_regexp = function(c, previous_token) {
  3149. if (c === '/' && this._allow_regexp_or_xml(previous_token)) {
  3150. // handle regexp
  3151. //
  3152. var resulting_string = this._input.next();
  3153. var esc = false;
  3154. var in_char_class = false;
  3155. while (this._input.hasNext() &&
  3156. ((esc || in_char_class || this._input.peek() !== c) &&
  3157. !this._input.testChar(acorn.newline))) {
  3158. resulting_string += this._input.peek();
  3159. if (!esc) {
  3160. esc = this._input.peek() === '\\';
  3161. if (this._input.peek() === '[') {
  3162. in_char_class = true;
  3163. } else if (this._input.peek() === ']') {
  3164. in_char_class = false;
  3165. }
  3166. } else {
  3167. esc = false;
  3168. }
  3169. this._input.next();
  3170. }
  3171. if (this._input.peek() === c) {
  3172. resulting_string += this._input.next();
  3173. // regexps may have modifiers /regexp/MOD , so fetch those, too
  3174. // Only [gim] are valid, but if the user puts in garbage, do what we can to take it.
  3175. resulting_string += this._input.read(acorn.identifier);
  3176. }
  3177. return this._create_token(TOKEN.STRING, resulting_string);
  3178. }
  3179. return null;
  3180. };
  3181. Tokenizer.prototype._read_xml = function(c, previous_token) {
  3182. if (this._options.e4x && c === "<" && this._allow_regexp_or_xml(previous_token)) {
  3183. var xmlStr = '';
  3184. var match = this.__patterns.xml.read_match();
  3185. // handle e4x xml literals
  3186. //
  3187. if (match) {
  3188. // Trim root tag to attempt to
  3189. var rootTag = match[2].replace(/^{\s+/, '{').replace(/\s+}$/, '}');
  3190. var isCurlyRoot = rootTag.indexOf('{') === 0;
  3191. var depth = 0;
  3192. while (match) {
  3193. var isEndTag = !!match[1];
  3194. var tagName = match[2];
  3195. var isSingletonTag = (!!match[match.length - 1]) || (tagName.slice(0, 8) === "![CDATA[");
  3196. if (!isSingletonTag &&
  3197. (tagName === rootTag || (isCurlyRoot && tagName.replace(/^{\s+/, '{').replace(/\s+}$/, '}')))) {
  3198. if (isEndTag) {
  3199. --depth;
  3200. } else {
  3201. ++depth;
  3202. }
  3203. }
  3204. xmlStr += match[0];
  3205. if (depth <= 0) {
  3206. break;
  3207. }
  3208. match = this.__patterns.xml.read_match();
  3209. }
  3210. // if we didn't close correctly, keep unformatted.
  3211. if (!match) {
  3212. xmlStr += this._input.match(/[\s\S]*/g)[0];
  3213. }
  3214. xmlStr = xmlStr.replace(acorn.allLineBreaks, '\n');
  3215. return this._create_token(TOKEN.STRING, xmlStr);
  3216. }
  3217. }
  3218. return null;
  3219. };
  3220. function unescape_string(s) {
  3221. // You think that a regex would work for this
  3222. // return s.replace(/\\x([0-9a-f]{2})/gi, function(match, val) {
  3223. // return String.fromCharCode(parseInt(val, 16));
  3224. // })
  3225. // However, dealing with '\xff', '\\xff', '\\\xff' makes this more fun.
  3226. var out = '',
  3227. escaped = 0;
  3228. var input_scan = new InputScanner(s);
  3229. var matched = null;
  3230. while (input_scan.hasNext()) {
  3231. // Keep any whitespace, non-slash characters
  3232. // also keep slash pairs.
  3233. matched = input_scan.match(/([\s]|[^\\]|\\\\)+/g);
  3234. if (matched) {
  3235. out += matched[0];
  3236. }
  3237. if (input_scan.peek() === '\\') {
  3238. input_scan.next();
  3239. if (input_scan.peek() === 'x') {
  3240. matched = input_scan.match(/x([0-9A-Fa-f]{2})/g);
  3241. } else if (input_scan.peek() === 'u') {
  3242. matched = input_scan.match(/u([0-9A-Fa-f]{4})/g);
  3243. } else {
  3244. out += '\\';
  3245. if (input_scan.hasNext()) {
  3246. out += input_scan.next();
  3247. }
  3248. continue;
  3249. }
  3250. // If there's some error decoding, return the original string
  3251. if (!matched) {
  3252. return s;
  3253. }
  3254. escaped = parseInt(matched[1], 16);
  3255. if (escaped > 0x7e && escaped <= 0xff && matched[0].indexOf('x') === 0) {
  3256. // we bail out on \x7f..\xff,
  3257. // leaving whole string escaped,
  3258. // as it's probably completely binary
  3259. return s;
  3260. } else if (escaped >= 0x00 && escaped < 0x20) {
  3261. // leave 0x00...0x1f escaped
  3262. out += '\\' + matched[0];
  3263. continue;
  3264. } else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
  3265. // single-quote, apostrophe, backslash - escape these
  3266. out += '\\' + String.fromCharCode(escaped);
  3267. } else {
  3268. out += String.fromCharCode(escaped);
  3269. }
  3270. }
  3271. }
  3272. return out;
  3273. }
  3274. // handle string
  3275. //
  3276. Tokenizer.prototype._read_string_recursive = function(delimiter, allow_unescaped_newlines, start_sub) {
  3277. var current_char;
  3278. var pattern;
  3279. if (delimiter === '\'') {
  3280. pattern = this.__patterns.single_quote;
  3281. } else if (delimiter === '"') {
  3282. pattern = this.__patterns.double_quote;
  3283. } else if (delimiter === '`') {
  3284. pattern = this.__patterns.template_text;
  3285. } else if (delimiter === '}') {
  3286. pattern = this.__patterns.template_expression;
  3287. }
  3288. var resulting_string = pattern.read();
  3289. var next = '';
  3290. while (this._input.hasNext()) {
  3291. next = this._input.next();
  3292. if (next === delimiter ||
  3293. (!allow_unescaped_newlines && acorn.newline.test(next))) {
  3294. this._input.back();
  3295. break;
  3296. } else if (next === '\\' && this._input.hasNext()) {
  3297. current_char = this._input.peek();
  3298. if (current_char === 'x' || current_char === 'u') {
  3299. this.has_char_escapes = true;
  3300. } else if (current_char === '\r' && this._input.peek(1) === '\n') {
  3301. this._input.next();
  3302. }
  3303. next += this._input.next();
  3304. } else if (start_sub) {
  3305. if (start_sub === '${' && next === '$' && this._input.peek() === '{') {
  3306. next += this._input.next();
  3307. }
  3308. if (start_sub === next) {
  3309. if (delimiter === '`') {
  3310. next += this._read_string_recursive('}', allow_unescaped_newlines, '`');
  3311. } else {
  3312. next += this._read_string_recursive('`', allow_unescaped_newlines, '${');
  3313. }
  3314. if (this._input.hasNext()) {
  3315. next += this._input.next();
  3316. }
  3317. }
  3318. }
  3319. next += pattern.read();
  3320. resulting_string += next;
  3321. }
  3322. return resulting_string;
  3323. };
  3324. tokenizer$2.Tokenizer = Tokenizer;
  3325. tokenizer$2.TOKEN = TOKEN;
  3326. tokenizer$2.positionable_operators = positionable_operators.slice();
  3327. tokenizer$2.line_starters = line_starters.slice();
  3328. return tokenizer$2;
  3329. }
  3330. /*jshint node:true */
  3331. var hasRequiredBeautifier$2;
  3332. function requireBeautifier$2 () {
  3333. if (hasRequiredBeautifier$2) return beautifier$2;
  3334. hasRequiredBeautifier$2 = 1;
  3335. var Output = requireOutput().Output;
  3336. var Token = requireToken().Token;
  3337. var acorn = requireAcorn();
  3338. var Options = requireOptions$2().Options;
  3339. var Tokenizer = requireTokenizer$1().Tokenizer;
  3340. var line_starters = requireTokenizer$1().line_starters;
  3341. var positionable_operators = requireTokenizer$1().positionable_operators;
  3342. var TOKEN = requireTokenizer$1().TOKEN;
  3343. function in_array(what, arr) {
  3344. return arr.indexOf(what) !== -1;
  3345. }
  3346. function ltrim(s) {
  3347. return s.replace(/^\s+/g, '');
  3348. }
  3349. function generateMapFromStrings(list) {
  3350. var result = {};
  3351. for (var x = 0; x < list.length; x++) {
  3352. // make the mapped names underscored instead of dash
  3353. result[list[x].replace(/-/g, '_')] = list[x];
  3354. }
  3355. return result;
  3356. }
  3357. function reserved_word(token, word) {
  3358. return token && token.type === TOKEN.RESERVED && token.text === word;
  3359. }
  3360. function reserved_array(token, words) {
  3361. return token && token.type === TOKEN.RESERVED && in_array(token.text, words);
  3362. }
  3363. // Unsure of what they mean, but they work. Worth cleaning up in future.
  3364. var special_words = ['case', 'return', 'do', 'if', 'throw', 'else', 'await', 'break', 'continue', 'async'];
  3365. var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
  3366. // Generate map from array
  3367. var OPERATOR_POSITION = generateMapFromStrings(validPositionValues);
  3368. var OPERATOR_POSITION_BEFORE_OR_PRESERVE = [OPERATOR_POSITION.before_newline, OPERATOR_POSITION.preserve_newline];
  3369. var MODE = {
  3370. BlockStatement: 'BlockStatement', // 'BLOCK'
  3371. Statement: 'Statement', // 'STATEMENT'
  3372. ObjectLiteral: 'ObjectLiteral', // 'OBJECT',
  3373. ArrayLiteral: 'ArrayLiteral', //'[EXPRESSION]',
  3374. ForInitializer: 'ForInitializer', //'(FOR-EXPRESSION)',
  3375. Conditional: 'Conditional', //'(COND-EXPRESSION)',
  3376. Expression: 'Expression' //'(EXPRESSION)'
  3377. };
  3378. function remove_redundant_indentation(output, frame) {
  3379. // This implementation is effective but has some issues:
  3380. // - can cause line wrap to happen too soon due to indent removal
  3381. // after wrap points are calculated
  3382. // These issues are minor compared to ugly indentation.
  3383. if (frame.multiline_frame ||
  3384. frame.mode === MODE.ForInitializer ||
  3385. frame.mode === MODE.Conditional) {
  3386. return;
  3387. }
  3388. // remove one indent from each line inside this section
  3389. output.remove_indent(frame.start_line_index);
  3390. }
  3391. // we could use just string.split, but
  3392. // IE doesn't like returning empty strings
  3393. function split_linebreaks(s) {
  3394. //return s.split(/\x0d\x0a|\x0a/);
  3395. s = s.replace(acorn.allLineBreaks, '\n');
  3396. var out = [],
  3397. idx = s.indexOf("\n");
  3398. while (idx !== -1) {
  3399. out.push(s.substring(0, idx));
  3400. s = s.substring(idx + 1);
  3401. idx = s.indexOf("\n");
  3402. }
  3403. if (s.length) {
  3404. out.push(s);
  3405. }
  3406. return out;
  3407. }
  3408. function is_array(mode) {
  3409. return mode === MODE.ArrayLiteral;
  3410. }
  3411. function is_expression(mode) {
  3412. return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
  3413. }
  3414. function all_lines_start_with(lines, c) {
  3415. for (var i = 0; i < lines.length; i++) {
  3416. var line = lines[i].trim();
  3417. if (line.charAt(0) !== c) {
  3418. return false;
  3419. }
  3420. }
  3421. return true;
  3422. }
  3423. function each_line_matches_indent(lines, indent) {
  3424. var i = 0,
  3425. len = lines.length,
  3426. line;
  3427. for (; i < len; i++) {
  3428. line = lines[i];
  3429. // allow empty lines to pass through
  3430. if (line && line.indexOf(indent) !== 0) {
  3431. return false;
  3432. }
  3433. }
  3434. return true;
  3435. }
  3436. function Beautifier(source_text, options) {
  3437. options = options || {};
  3438. this._source_text = source_text || '';
  3439. this._output = null;
  3440. this._tokens = null;
  3441. this._last_last_text = null;
  3442. this._flags = null;
  3443. this._previous_flags = null;
  3444. this._flag_store = null;
  3445. this._options = new Options(options);
  3446. }
  3447. Beautifier.prototype.create_flags = function(flags_base, mode) {
  3448. var next_indent_level = 0;
  3449. if (flags_base) {
  3450. next_indent_level = flags_base.indentation_level;
  3451. if (!this._output.just_added_newline() &&
  3452. flags_base.line_indent_level > next_indent_level) {
  3453. next_indent_level = flags_base.line_indent_level;
  3454. }
  3455. }
  3456. var next_flags = {
  3457. mode: mode,
  3458. parent: flags_base,
  3459. last_token: flags_base ? flags_base.last_token : new Token(TOKEN.START_BLOCK, ''), // last token text
  3460. last_word: flags_base ? flags_base.last_word : '', // last TOKEN.WORD passed
  3461. declaration_statement: false,
  3462. declaration_assignment: false,
  3463. multiline_frame: false,
  3464. inline_frame: false,
  3465. if_block: false,
  3466. else_block: false,
  3467. class_start_block: false, // class A { INSIDE HERE } or class B extends C { INSIDE HERE }
  3468. do_block: false,
  3469. do_while: false,
  3470. import_block: false,
  3471. in_case_statement: false, // switch(..){ INSIDE HERE }
  3472. in_case: false, // we're on the exact line with "case 0:"
  3473. case_body: false, // the indented case-action block
  3474. case_block: false, // the indented case-action block is wrapped with {}
  3475. indentation_level: next_indent_level,
  3476. alignment: 0,
  3477. line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
  3478. start_line_index: this._output.get_line_number(),
  3479. ternary_depth: 0
  3480. };
  3481. return next_flags;
  3482. };
  3483. Beautifier.prototype._reset = function(source_text) {
  3484. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  3485. this._last_last_text = ''; // pre-last token text
  3486. this._output = new Output(this._options, baseIndentString);
  3487. // If testing the ignore directive, start with output disable set to true
  3488. this._output.raw = this._options.test_output_raw;
  3489. // Stack of parsing/formatting states, including MODE.
  3490. // We tokenize, parse, and output in an almost purely a forward-only stream of token input
  3491. // and formatted output. This makes the beautifier less accurate than full parsers
  3492. // but also far more tolerant of syntax errors.
  3493. //
  3494. // For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type
  3495. // MODE.BlockStatement on the the stack, even though it could be object literal. If we later
  3496. // encounter a ":", we'll switch to to MODE.ObjectLiteral. If we then see a ";",
  3497. // most full parsers would die, but the beautifier gracefully falls back to
  3498. // MODE.BlockStatement and continues on.
  3499. this._flag_store = [];
  3500. this.set_mode(MODE.BlockStatement);
  3501. var tokenizer = new Tokenizer(source_text, this._options);
  3502. this._tokens = tokenizer.tokenize();
  3503. return source_text;
  3504. };
  3505. Beautifier.prototype.beautify = function() {
  3506. // if disabled, return the input unchanged.
  3507. if (this._options.disabled) {
  3508. return this._source_text;
  3509. }
  3510. var sweet_code;
  3511. var source_text = this._reset(this._source_text);
  3512. var eol = this._options.eol;
  3513. if (this._options.eol === 'auto') {
  3514. eol = '\n';
  3515. if (source_text && acorn.lineBreak.test(source_text || '')) {
  3516. eol = source_text.match(acorn.lineBreak)[0];
  3517. }
  3518. }
  3519. var current_token = this._tokens.next();
  3520. while (current_token) {
  3521. this.handle_token(current_token);
  3522. this._last_last_text = this._flags.last_token.text;
  3523. this._flags.last_token = current_token;
  3524. current_token = this._tokens.next();
  3525. }
  3526. sweet_code = this._output.get_code(eol);
  3527. return sweet_code;
  3528. };
  3529. Beautifier.prototype.handle_token = function(current_token, preserve_statement_flags) {
  3530. if (current_token.type === TOKEN.START_EXPR) {
  3531. this.handle_start_expr(current_token);
  3532. } else if (current_token.type === TOKEN.END_EXPR) {
  3533. this.handle_end_expr(current_token);
  3534. } else if (current_token.type === TOKEN.START_BLOCK) {
  3535. this.handle_start_block(current_token);
  3536. } else if (current_token.type === TOKEN.END_BLOCK) {
  3537. this.handle_end_block(current_token);
  3538. } else if (current_token.type === TOKEN.WORD) {
  3539. this.handle_word(current_token);
  3540. } else if (current_token.type === TOKEN.RESERVED) {
  3541. this.handle_word(current_token);
  3542. } else if (current_token.type === TOKEN.SEMICOLON) {
  3543. this.handle_semicolon(current_token);
  3544. } else if (current_token.type === TOKEN.STRING) {
  3545. this.handle_string(current_token);
  3546. } else if (current_token.type === TOKEN.EQUALS) {
  3547. this.handle_equals(current_token);
  3548. } else if (current_token.type === TOKEN.OPERATOR) {
  3549. this.handle_operator(current_token);
  3550. } else if (current_token.type === TOKEN.COMMA) {
  3551. this.handle_comma(current_token);
  3552. } else if (current_token.type === TOKEN.BLOCK_COMMENT) {
  3553. this.handle_block_comment(current_token, preserve_statement_flags);
  3554. } else if (current_token.type === TOKEN.COMMENT) {
  3555. this.handle_comment(current_token, preserve_statement_flags);
  3556. } else if (current_token.type === TOKEN.DOT) {
  3557. this.handle_dot(current_token);
  3558. } else if (current_token.type === TOKEN.EOF) {
  3559. this.handle_eof(current_token);
  3560. } else if (current_token.type === TOKEN.UNKNOWN) {
  3561. this.handle_unknown(current_token, preserve_statement_flags);
  3562. } else {
  3563. this.handle_unknown(current_token, preserve_statement_flags);
  3564. }
  3565. };
  3566. Beautifier.prototype.handle_whitespace_and_comments = function(current_token, preserve_statement_flags) {
  3567. var newlines = current_token.newlines;
  3568. var keep_whitespace = this._options.keep_array_indentation && is_array(this._flags.mode);
  3569. if (current_token.comments_before) {
  3570. var comment_token = current_token.comments_before.next();
  3571. while (comment_token) {
  3572. // The cleanest handling of inline comments is to treat them as though they aren't there.
  3573. // Just continue formatting and the behavior should be logical.
  3574. // Also ignore unknown tokens. Again, this should result in better behavior.
  3575. this.handle_whitespace_and_comments(comment_token, preserve_statement_flags);
  3576. this.handle_token(comment_token, preserve_statement_flags);
  3577. comment_token = current_token.comments_before.next();
  3578. }
  3579. }
  3580. if (keep_whitespace) {
  3581. for (var i = 0; i < newlines; i += 1) {
  3582. this.print_newline(i > 0, preserve_statement_flags);
  3583. }
  3584. } else {
  3585. if (this._options.max_preserve_newlines && newlines > this._options.max_preserve_newlines) {
  3586. newlines = this._options.max_preserve_newlines;
  3587. }
  3588. if (this._options.preserve_newlines) {
  3589. if (newlines > 1) {
  3590. this.print_newline(false, preserve_statement_flags);
  3591. for (var j = 1; j < newlines; j += 1) {
  3592. this.print_newline(true, preserve_statement_flags);
  3593. }
  3594. }
  3595. }
  3596. }
  3597. };
  3598. var newline_restricted_tokens = ['async', 'break', 'continue', 'return', 'throw', 'yield'];
  3599. Beautifier.prototype.allow_wrap_or_preserved_newline = function(current_token, force_linewrap) {
  3600. force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
  3601. // Never wrap the first token on a line
  3602. if (this._output.just_added_newline()) {
  3603. return;
  3604. }
  3605. var shouldPreserveOrForce = (this._options.preserve_newlines && current_token.newlines) || force_linewrap;
  3606. var operatorLogicApplies = in_array(this._flags.last_token.text, positionable_operators) ||
  3607. in_array(current_token.text, positionable_operators);
  3608. if (operatorLogicApplies) {
  3609. var shouldPrintOperatorNewline = (
  3610. in_array(this._flags.last_token.text, positionable_operators) &&
  3611. in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)
  3612. ) ||
  3613. in_array(current_token.text, positionable_operators);
  3614. shouldPreserveOrForce = shouldPreserveOrForce && shouldPrintOperatorNewline;
  3615. }
  3616. if (shouldPreserveOrForce) {
  3617. this.print_newline(false, true);
  3618. } else if (this._options.wrap_line_length) {
  3619. if (reserved_array(this._flags.last_token, newline_restricted_tokens)) {
  3620. // These tokens should never have a newline inserted
  3621. // between them and the following expression.
  3622. return;
  3623. }
  3624. this._output.set_wrap_point();
  3625. }
  3626. };
  3627. Beautifier.prototype.print_newline = function(force_newline, preserve_statement_flags) {
  3628. if (!preserve_statement_flags) {
  3629. 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 === '++')) {
  3630. var next_token = this._tokens.peek();
  3631. while (this._flags.mode === MODE.Statement &&
  3632. !(this._flags.if_block && reserved_word(next_token, 'else')) &&
  3633. !this._flags.do_block) {
  3634. this.restore_mode();
  3635. }
  3636. }
  3637. }
  3638. if (this._output.add_new_line(force_newline)) {
  3639. this._flags.multiline_frame = true;
  3640. }
  3641. };
  3642. Beautifier.prototype.print_token_line_indentation = function(current_token) {
  3643. if (this._output.just_added_newline()) {
  3644. if (this._options.keep_array_indentation &&
  3645. current_token.newlines &&
  3646. (current_token.text === '[' || is_array(this._flags.mode))) {
  3647. this._output.current_line.set_indent(-1);
  3648. this._output.current_line.push(current_token.whitespace_before);
  3649. this._output.space_before_token = false;
  3650. } else if (this._output.set_indent(this._flags.indentation_level, this._flags.alignment)) {
  3651. this._flags.line_indent_level = this._flags.indentation_level;
  3652. }
  3653. }
  3654. };
  3655. Beautifier.prototype.print_token = function(current_token) {
  3656. if (this._output.raw) {
  3657. this._output.add_raw_token(current_token);
  3658. return;
  3659. }
  3660. if (this._options.comma_first && current_token.previous && current_token.previous.type === TOKEN.COMMA &&
  3661. this._output.just_added_newline()) {
  3662. if (this._output.previous_line.last() === ',') {
  3663. var popped = this._output.previous_line.pop();
  3664. // if the comma was already at the start of the line,
  3665. // pull back onto that line and reprint the indentation
  3666. if (this._output.previous_line.is_empty()) {
  3667. this._output.previous_line.push(popped);
  3668. this._output.trim(true);
  3669. this._output.current_line.pop();
  3670. this._output.trim();
  3671. }
  3672. // add the comma in front of the next token
  3673. this.print_token_line_indentation(current_token);
  3674. this._output.add_token(',');
  3675. this._output.space_before_token = true;
  3676. }
  3677. }
  3678. this.print_token_line_indentation(current_token);
  3679. this._output.non_breaking_space = true;
  3680. this._output.add_token(current_token.text);
  3681. if (this._output.previous_token_wrapped) {
  3682. this._flags.multiline_frame = true;
  3683. }
  3684. };
  3685. Beautifier.prototype.indent = function() {
  3686. this._flags.indentation_level += 1;
  3687. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  3688. };
  3689. Beautifier.prototype.deindent = function() {
  3690. if (this._flags.indentation_level > 0 &&
  3691. ((!this._flags.parent) || this._flags.indentation_level > this._flags.parent.indentation_level)) {
  3692. this._flags.indentation_level -= 1;
  3693. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  3694. }
  3695. };
  3696. Beautifier.prototype.set_mode = function(mode) {
  3697. if (this._flags) {
  3698. this._flag_store.push(this._flags);
  3699. this._previous_flags = this._flags;
  3700. } else {
  3701. this._previous_flags = this.create_flags(null, mode);
  3702. }
  3703. this._flags = this.create_flags(this._previous_flags, mode);
  3704. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  3705. };
  3706. Beautifier.prototype.restore_mode = function() {
  3707. if (this._flag_store.length > 0) {
  3708. this._previous_flags = this._flags;
  3709. this._flags = this._flag_store.pop();
  3710. if (this._previous_flags.mode === MODE.Statement) {
  3711. remove_redundant_indentation(this._output, this._previous_flags);
  3712. }
  3713. this._output.set_indent(this._flags.indentation_level, this._flags.alignment);
  3714. }
  3715. };
  3716. Beautifier.prototype.start_of_object_property = function() {
  3717. return this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement && (
  3718. (this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || (reserved_array(this._flags.last_token, ['get', 'set'])));
  3719. };
  3720. Beautifier.prototype.start_of_statement = function(current_token) {
  3721. var start = false;
  3722. start = start || reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD;
  3723. start = start || reserved_word(this._flags.last_token, 'do');
  3724. 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;
  3725. start = start || reserved_word(this._flags.last_token, 'else') &&
  3726. !(reserved_word(current_token, 'if') && !current_token.comments_before);
  3727. start = start || (this._flags.last_token.type === TOKEN.END_EXPR && (this._previous_flags.mode === MODE.ForInitializer || this._previous_flags.mode === MODE.Conditional));
  3728. start = start || (this._flags.last_token.type === TOKEN.WORD && this._flags.mode === MODE.BlockStatement &&
  3729. !this._flags.in_case &&
  3730. !(current_token.text === '--' || current_token.text === '++') &&
  3731. this._last_last_text !== 'function' &&
  3732. current_token.type !== TOKEN.WORD && current_token.type !== TOKEN.RESERVED);
  3733. start = start || (this._flags.mode === MODE.ObjectLiteral && (
  3734. (this._flags.last_token.text === ':' && this._flags.ternary_depth === 0) || reserved_array(this._flags.last_token, ['get', 'set'])));
  3735. if (start) {
  3736. this.set_mode(MODE.Statement);
  3737. this.indent();
  3738. this.handle_whitespace_and_comments(current_token, true);
  3739. // Issue #276:
  3740. // If starting a new statement with [if, for, while, do], push to a new line.
  3741. // if (a) if (b) if(c) d(); else e(); else f();
  3742. if (!this.start_of_object_property()) {
  3743. this.allow_wrap_or_preserved_newline(current_token,
  3744. reserved_array(current_token, ['do', 'for', 'if', 'while']));
  3745. }
  3746. return true;
  3747. }
  3748. return false;
  3749. };
  3750. Beautifier.prototype.handle_start_expr = function(current_token) {
  3751. // The conditional starts the statement if appropriate.
  3752. if (!this.start_of_statement(current_token)) {
  3753. this.handle_whitespace_and_comments(current_token);
  3754. }
  3755. var next_mode = MODE.Expression;
  3756. if (current_token.text === '[') {
  3757. if (this._flags.last_token.type === TOKEN.WORD || this._flags.last_token.text === ')') {
  3758. // this is array index specifier, break immediately
  3759. // a[x], fn()[x]
  3760. if (reserved_array(this._flags.last_token, line_starters)) {
  3761. this._output.space_before_token = true;
  3762. }
  3763. this.print_token(current_token);
  3764. this.set_mode(next_mode);
  3765. this.indent();
  3766. if (this._options.space_in_paren) {
  3767. this._output.space_before_token = true;
  3768. }
  3769. return;
  3770. }
  3771. next_mode = MODE.ArrayLiteral;
  3772. if (is_array(this._flags.mode)) {
  3773. if (this._flags.last_token.text === '[' ||
  3774. (this._flags.last_token.text === ',' && (this._last_last_text === ']' || this._last_last_text === '}'))) {
  3775. // ], [ goes to new line
  3776. // }, [ goes to new line
  3777. if (!this._options.keep_array_indentation) {
  3778. this.print_newline();
  3779. }
  3780. }
  3781. }
  3782. if (!in_array(this._flags.last_token.type, [TOKEN.START_EXPR, TOKEN.END_EXPR, TOKEN.WORD, TOKEN.OPERATOR, TOKEN.DOT])) {
  3783. this._output.space_before_token = true;
  3784. }
  3785. } else {
  3786. if (this._flags.last_token.type === TOKEN.RESERVED) {
  3787. if (this._flags.last_token.text === 'for') {
  3788. this._output.space_before_token = this._options.space_before_conditional;
  3789. next_mode = MODE.ForInitializer;
  3790. } else if (in_array(this._flags.last_token.text, ['if', 'while', 'switch'])) {
  3791. this._output.space_before_token = this._options.space_before_conditional;
  3792. next_mode = MODE.Conditional;
  3793. } else if (in_array(this._flags.last_word, ['await', 'async'])) {
  3794. // Should be a space between await and an IIFE, or async and an arrow function
  3795. this._output.space_before_token = true;
  3796. } else if (this._flags.last_token.text === 'import' && current_token.whitespace_before === '') {
  3797. this._output.space_before_token = false;
  3798. } else if (in_array(this._flags.last_token.text, line_starters) || this._flags.last_token.text === 'catch') {
  3799. this._output.space_before_token = true;
  3800. }
  3801. } else if (this._flags.last_token.type === TOKEN.EQUALS || this._flags.last_token.type === TOKEN.OPERATOR) {
  3802. // Support of this kind of newline preservation.
  3803. // a = (b &&
  3804. // (c || d));
  3805. if (!this.start_of_object_property()) {
  3806. this.allow_wrap_or_preserved_newline(current_token);
  3807. }
  3808. } else if (this._flags.last_token.type === TOKEN.WORD) {
  3809. this._output.space_before_token = false;
  3810. // function name() vs function name ()
  3811. // function* name() vs function* name ()
  3812. // async name() vs async name ()
  3813. // In ES6, you can also define the method properties of an object
  3814. // var obj = {a: function() {}}
  3815. // It can be abbreviated
  3816. // var obj = {a() {}}
  3817. // var obj = { a() {}} vs var obj = { a () {}}
  3818. // var obj = { * a() {}} vs var obj = { * a () {}}
  3819. var peek_back_two = this._tokens.peek(-3);
  3820. if (this._options.space_after_named_function && peek_back_two) {
  3821. // peek starts at next character so -1 is current token
  3822. var peek_back_three = this._tokens.peek(-4);
  3823. if (reserved_array(peek_back_two, ['async', 'function']) ||
  3824. (peek_back_two.text === '*' && reserved_array(peek_back_three, ['async', 'function']))) {
  3825. this._output.space_before_token = true;
  3826. } else if (this._flags.mode === MODE.ObjectLiteral) {
  3827. if ((peek_back_two.text === '{' || peek_back_two.text === ',') ||
  3828. (peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
  3829. this._output.space_before_token = true;
  3830. }
  3831. } else if (this._flags.parent && this._flags.parent.class_start_block) {
  3832. this._output.space_before_token = true;
  3833. }
  3834. }
  3835. } else {
  3836. // Support preserving wrapped arrow function expressions
  3837. // a.b('c',
  3838. // () => d.e
  3839. // )
  3840. this.allow_wrap_or_preserved_newline(current_token);
  3841. }
  3842. // function() vs function ()
  3843. // yield*() vs yield* ()
  3844. // function*() vs function* ()
  3845. if ((this._flags.last_token.type === TOKEN.RESERVED && (this._flags.last_word === 'function' || this._flags.last_word === 'typeof')) ||
  3846. (this._flags.last_token.text === '*' &&
  3847. (in_array(this._last_last_text, ['function', 'yield']) ||
  3848. (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
  3849. this._output.space_before_token = this._options.space_after_anon_function;
  3850. }
  3851. }
  3852. if (this._flags.last_token.text === ';' || this._flags.last_token.type === TOKEN.START_BLOCK) {
  3853. this.print_newline();
  3854. } 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) {
  3855. // do nothing on (( and )( and ][ and ]( and .(
  3856. // TODO: Consider whether forcing this is required. Review failing tests when removed.
  3857. this.allow_wrap_or_preserved_newline(current_token, current_token.newlines);
  3858. }
  3859. this.print_token(current_token);
  3860. this.set_mode(next_mode);
  3861. if (this._options.space_in_paren) {
  3862. this._output.space_before_token = true;
  3863. }
  3864. // In all cases, if we newline while inside an expression it should be indented.
  3865. this.indent();
  3866. };
  3867. Beautifier.prototype.handle_end_expr = function(current_token) {
  3868. // statements inside expressions are not valid syntax, but...
  3869. // statements must all be closed when their container closes
  3870. while (this._flags.mode === MODE.Statement) {
  3871. this.restore_mode();
  3872. }
  3873. this.handle_whitespace_and_comments(current_token);
  3874. if (this._flags.multiline_frame) {
  3875. this.allow_wrap_or_preserved_newline(current_token,
  3876. current_token.text === ']' && is_array(this._flags.mode) && !this._options.keep_array_indentation);
  3877. }
  3878. if (this._options.space_in_paren) {
  3879. if (this._flags.last_token.type === TOKEN.START_EXPR && !this._options.space_in_empty_paren) {
  3880. // () [] no inner space in empty parens like these, ever, ref #320
  3881. this._output.trim();
  3882. this._output.space_before_token = false;
  3883. } else {
  3884. this._output.space_before_token = true;
  3885. }
  3886. }
  3887. this.deindent();
  3888. this.print_token(current_token);
  3889. this.restore_mode();
  3890. remove_redundant_indentation(this._output, this._previous_flags);
  3891. // do {} while () // no statement required after
  3892. if (this._flags.do_while && this._previous_flags.mode === MODE.Conditional) {
  3893. this._previous_flags.mode = MODE.Expression;
  3894. this._flags.do_block = false;
  3895. this._flags.do_while = false;
  3896. }
  3897. };
  3898. Beautifier.prototype.handle_start_block = function(current_token) {
  3899. this.handle_whitespace_and_comments(current_token);
  3900. // Check if this is should be treated as a ObjectLiteral
  3901. var next_token = this._tokens.peek();
  3902. var second_token = this._tokens.peek(1);
  3903. if (this._flags.last_word === 'switch' && this._flags.last_token.type === TOKEN.END_EXPR) {
  3904. this.set_mode(MODE.BlockStatement);
  3905. this._flags.in_case_statement = true;
  3906. } else if (this._flags.case_body) {
  3907. this.set_mode(MODE.BlockStatement);
  3908. } else if (second_token && (
  3909. (in_array(second_token.text, [':', ',']) && in_array(next_token.type, [TOKEN.STRING, TOKEN.WORD, TOKEN.RESERVED])) ||
  3910. (in_array(next_token.text, ['get', 'set', '...']) && in_array(second_token.type, [TOKEN.WORD, TOKEN.RESERVED]))
  3911. )) {
  3912. // We don't support TypeScript,but we didn't break it for a very long time.
  3913. // We'll try to keep not breaking it.
  3914. if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) {
  3915. this.set_mode(MODE.BlockStatement);
  3916. } else {
  3917. this.set_mode(MODE.ObjectLiteral);
  3918. }
  3919. } else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
  3920. // arrow function: (param1, paramN) => { statements }
  3921. this.set_mode(MODE.BlockStatement);
  3922. } else if (in_array(this._flags.last_token.type, [TOKEN.EQUALS, TOKEN.START_EXPR, TOKEN.COMMA, TOKEN.OPERATOR]) ||
  3923. reserved_array(this._flags.last_token, ['return', 'throw', 'import', 'default'])
  3924. ) {
  3925. // Detecting shorthand function syntax is difficult by scanning forward,
  3926. // so check the surrounding context.
  3927. // If the block is being returned, imported, export default, passed as arg,
  3928. // assigned with = or assigned in a nested object, treat as an ObjectLiteral.
  3929. this.set_mode(MODE.ObjectLiteral);
  3930. } else {
  3931. this.set_mode(MODE.BlockStatement);
  3932. }
  3933. if (this._flags.last_token) {
  3934. if (reserved_array(this._flags.last_token.previous, ['class', 'extends'])) {
  3935. this._flags.class_start_block = true;
  3936. }
  3937. }
  3938. var empty_braces = !next_token.comments_before && next_token.text === '}';
  3939. var empty_anonymous_function = empty_braces && this._flags.last_word === 'function' &&
  3940. this._flags.last_token.type === TOKEN.END_EXPR;
  3941. if (this._options.brace_preserve_inline) // check for inline, set inline_frame if so
  3942. {
  3943. // search forward for a newline wanted inside this block
  3944. var index = 0;
  3945. var check_token = null;
  3946. this._flags.inline_frame = true;
  3947. do {
  3948. index += 1;
  3949. check_token = this._tokens.peek(index - 1);
  3950. if (check_token.newlines) {
  3951. this._flags.inline_frame = false;
  3952. break;
  3953. }
  3954. } while (check_token.type !== TOKEN.EOF &&
  3955. !(check_token.type === TOKEN.END_BLOCK && check_token.opened === current_token));
  3956. }
  3957. if ((this._options.brace_style === "expand" ||
  3958. (this._options.brace_style === "none" && current_token.newlines)) &&
  3959. !this._flags.inline_frame) {
  3960. if (this._flags.last_token.type !== TOKEN.OPERATOR &&
  3961. (empty_anonymous_function ||
  3962. this._flags.last_token.type === TOKEN.EQUALS ||
  3963. (reserved_array(this._flags.last_token, special_words) && this._flags.last_token.text !== 'else'))) {
  3964. this._output.space_before_token = true;
  3965. } else {
  3966. this.print_newline(false, true);
  3967. }
  3968. } else { // collapse || inline_frame
  3969. if (is_array(this._previous_flags.mode) && (this._flags.last_token.type === TOKEN.START_EXPR || this._flags.last_token.type === TOKEN.COMMA)) {
  3970. if (this._flags.last_token.type === TOKEN.COMMA || this._options.space_in_paren) {
  3971. this._output.space_before_token = true;
  3972. }
  3973. if (this._flags.last_token.type === TOKEN.COMMA || (this._flags.last_token.type === TOKEN.START_EXPR && this._flags.inline_frame)) {
  3974. this.allow_wrap_or_preserved_newline(current_token);
  3975. this._previous_flags.multiline_frame = this._previous_flags.multiline_frame || this._flags.multiline_frame;
  3976. this._flags.multiline_frame = false;
  3977. }
  3978. }
  3979. if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
  3980. if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
  3981. this.print_newline();
  3982. } else {
  3983. this._output.space_before_token = true;
  3984. }
  3985. }
  3986. }
  3987. this.print_token(current_token);
  3988. this.indent();
  3989. // Except for specific cases, open braces are followed by a new line.
  3990. if (!empty_braces && !(this._options.brace_preserve_inline && this._flags.inline_frame)) {
  3991. this.print_newline();
  3992. }
  3993. };
  3994. Beautifier.prototype.handle_end_block = function(current_token) {
  3995. // statements must all be closed when their container closes
  3996. this.handle_whitespace_and_comments(current_token);
  3997. while (this._flags.mode === MODE.Statement) {
  3998. this.restore_mode();
  3999. }
  4000. var empty_braces = this._flags.last_token.type === TOKEN.START_BLOCK;
  4001. if (this._flags.inline_frame && !empty_braces) { // try inline_frame (only set if this._options.braces-preserve-inline) first
  4002. this._output.space_before_token = true;
  4003. } else if (this._options.brace_style === "expand") {
  4004. if (!empty_braces) {
  4005. this.print_newline();
  4006. }
  4007. } else {
  4008. // skip {}
  4009. if (!empty_braces) {
  4010. if (is_array(this._flags.mode) && this._options.keep_array_indentation) {
  4011. // we REALLY need a newline here, but newliner would skip that
  4012. this._options.keep_array_indentation = false;
  4013. this.print_newline();
  4014. this._options.keep_array_indentation = true;
  4015. } else {
  4016. this.print_newline();
  4017. }
  4018. }
  4019. }
  4020. this.restore_mode();
  4021. this.print_token(current_token);
  4022. };
  4023. Beautifier.prototype.handle_word = function(current_token) {
  4024. if (current_token.type === TOKEN.RESERVED) {
  4025. if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
  4026. current_token.type = TOKEN.WORD;
  4027. } else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) {
  4028. current_token.type = TOKEN.WORD;
  4029. } else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
  4030. current_token.type = TOKEN.WORD;
  4031. } else if (this._flags.mode === MODE.ObjectLiteral) {
  4032. var next_token = this._tokens.peek();
  4033. if (next_token.text === ':') {
  4034. current_token.type = TOKEN.WORD;
  4035. }
  4036. }
  4037. }
  4038. if (this.start_of_statement(current_token)) {
  4039. // The conditional starts the statement if appropriate.
  4040. if (reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD) {
  4041. this._flags.declaration_statement = true;
  4042. }
  4043. } else if (current_token.newlines && !is_expression(this._flags.mode) &&
  4044. (this._flags.last_token.type !== TOKEN.OPERATOR || (this._flags.last_token.text === '--' || this._flags.last_token.text === '++')) &&
  4045. this._flags.last_token.type !== TOKEN.EQUALS &&
  4046. (this._options.preserve_newlines || !reserved_array(this._flags.last_token, ['var', 'let', 'const', 'set', 'get']))) {
  4047. this.handle_whitespace_and_comments(current_token);
  4048. this.print_newline();
  4049. } else {
  4050. this.handle_whitespace_and_comments(current_token);
  4051. }
  4052. if (this._flags.do_block && !this._flags.do_while) {
  4053. if (reserved_word(current_token, 'while')) {
  4054. // do {} ## while ()
  4055. this._output.space_before_token = true;
  4056. this.print_token(current_token);
  4057. this._output.space_before_token = true;
  4058. this._flags.do_while = true;
  4059. return;
  4060. } else {
  4061. // do {} should always have while as the next word.
  4062. // if we don't see the expected while, recover
  4063. this.print_newline();
  4064. this._flags.do_block = false;
  4065. }
  4066. }
  4067. // if may be followed by else, or not
  4068. // Bare/inline ifs are tricky
  4069. // Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();
  4070. if (this._flags.if_block) {
  4071. if (!this._flags.else_block && reserved_word(current_token, 'else')) {
  4072. this._flags.else_block = true;
  4073. } else {
  4074. while (this._flags.mode === MODE.Statement) {
  4075. this.restore_mode();
  4076. }
  4077. this._flags.if_block = false;
  4078. this._flags.else_block = false;
  4079. }
  4080. }
  4081. if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) {
  4082. this.print_newline();
  4083. if (!this._flags.case_block && (this._flags.case_body || this._options.jslint_happy)) {
  4084. // switch cases following one another
  4085. this.deindent();
  4086. }
  4087. this._flags.case_body = false;
  4088. this.print_token(current_token);
  4089. this._flags.in_case = true;
  4090. return;
  4091. }
  4092. 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) {
  4093. if (!this.start_of_object_property()) {
  4094. this.allow_wrap_or_preserved_newline(current_token);
  4095. }
  4096. }
  4097. if (reserved_word(current_token, 'function')) {
  4098. if (in_array(this._flags.last_token.text, ['}', ';']) ||
  4099. (this._output.just_added_newline() && !(in_array(this._flags.last_token.text, ['(', '[', '{', ':', '=', ',']) || this._flags.last_token.type === TOKEN.OPERATOR))) {
  4100. // make sure there is a nice clean space of at least one blank line
  4101. // before a new function definition
  4102. if (!this._output.just_added_blankline() && !current_token.comments_before) {
  4103. this.print_newline();
  4104. this.print_newline(true);
  4105. }
  4106. }
  4107. if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD) {
  4108. if (reserved_array(this._flags.last_token, ['get', 'set', 'new', 'export']) ||
  4109. reserved_array(this._flags.last_token, newline_restricted_tokens)) {
  4110. this._output.space_before_token = true;
  4111. } else if (reserved_word(this._flags.last_token, 'default') && this._last_last_text === 'export') {
  4112. this._output.space_before_token = true;
  4113. } else if (this._flags.last_token.text === 'declare') {
  4114. // accomodates Typescript declare function formatting
  4115. this._output.space_before_token = true;
  4116. } else {
  4117. this.print_newline();
  4118. }
  4119. } else if (this._flags.last_token.type === TOKEN.OPERATOR || this._flags.last_token.text === '=') {
  4120. // foo = function
  4121. this._output.space_before_token = true;
  4122. } else if (!this._flags.multiline_frame && (is_expression(this._flags.mode) || is_array(this._flags.mode))) ; else {
  4123. this.print_newline();
  4124. }
  4125. this.print_token(current_token);
  4126. this._flags.last_word = current_token.text;
  4127. return;
  4128. }
  4129. var prefix = 'NONE';
  4130. if (this._flags.last_token.type === TOKEN.END_BLOCK) {
  4131. if (this._previous_flags.inline_frame) {
  4132. prefix = 'SPACE';
  4133. } else if (!reserved_array(current_token, ['else', 'catch', 'finally', 'from'])) {
  4134. prefix = 'NEWLINE';
  4135. } else {
  4136. if (this._options.brace_style === "expand" ||
  4137. this._options.brace_style === "end-expand" ||
  4138. (this._options.brace_style === "none" && current_token.newlines)) {
  4139. prefix = 'NEWLINE';
  4140. } else {
  4141. prefix = 'SPACE';
  4142. this._output.space_before_token = true;
  4143. }
  4144. }
  4145. } else if (this._flags.last_token.type === TOKEN.SEMICOLON && this._flags.mode === MODE.BlockStatement) {
  4146. // TODO: Should this be for STATEMENT as well?
  4147. prefix = 'NEWLINE';
  4148. } else if (this._flags.last_token.type === TOKEN.SEMICOLON && is_expression(this._flags.mode)) {
  4149. prefix = 'SPACE';
  4150. } else if (this._flags.last_token.type === TOKEN.STRING) {
  4151. prefix = 'NEWLINE';
  4152. } else if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD ||
  4153. (this._flags.last_token.text === '*' &&
  4154. (in_array(this._last_last_text, ['function', 'yield']) ||
  4155. (this._flags.mode === MODE.ObjectLiteral && in_array(this._last_last_text, ['{', ',']))))) {
  4156. prefix = 'SPACE';
  4157. } else if (this._flags.last_token.type === TOKEN.START_BLOCK) {
  4158. if (this._flags.inline_frame) {
  4159. prefix = 'SPACE';
  4160. } else {
  4161. prefix = 'NEWLINE';
  4162. }
  4163. } else if (this._flags.last_token.type === TOKEN.END_EXPR) {
  4164. this._output.space_before_token = true;
  4165. prefix = 'NEWLINE';
  4166. }
  4167. if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
  4168. if (this._flags.inline_frame || this._flags.last_token.text === 'else' || this._flags.last_token.text === 'export') {
  4169. prefix = 'SPACE';
  4170. } else {
  4171. prefix = 'NEWLINE';
  4172. }
  4173. }
  4174. if (reserved_array(current_token, ['else', 'catch', 'finally'])) {
  4175. if ((!(this._flags.last_token.type === TOKEN.END_BLOCK && this._previous_flags.mode === MODE.BlockStatement) ||
  4176. this._options.brace_style === "expand" ||
  4177. this._options.brace_style === "end-expand" ||
  4178. (this._options.brace_style === "none" && current_token.newlines)) &&
  4179. !this._flags.inline_frame) {
  4180. this.print_newline();
  4181. } else {
  4182. this._output.trim(true);
  4183. var line = this._output.current_line;
  4184. // If we trimmed and there's something other than a close block before us
  4185. // put a newline back in. Handles '} // comment' scenario.
  4186. if (line.last() !== '}') {
  4187. this.print_newline();
  4188. }
  4189. this._output.space_before_token = true;
  4190. }
  4191. } else if (prefix === 'NEWLINE') {
  4192. if (reserved_array(this._flags.last_token, special_words)) {
  4193. // no newline between 'return nnn'
  4194. this._output.space_before_token = true;
  4195. } else if (this._flags.last_token.text === 'declare' && reserved_array(current_token, ['var', 'let', 'const'])) {
  4196. // accomodates Typescript declare formatting
  4197. this._output.space_before_token = true;
  4198. } else if (this._flags.last_token.type !== TOKEN.END_EXPR) {
  4199. if ((this._flags.last_token.type !== TOKEN.START_EXPR || !reserved_array(current_token, ['var', 'let', 'const'])) && this._flags.last_token.text !== ':') {
  4200. // no need to force newline on 'var': for (var x = 0...)
  4201. if (reserved_word(current_token, 'if') && reserved_word(current_token.previous, 'else')) {
  4202. // no newline for } else if {
  4203. this._output.space_before_token = true;
  4204. } else {
  4205. this.print_newline();
  4206. }
  4207. }
  4208. } else if (reserved_array(current_token, line_starters) && this._flags.last_token.text !== ')') {
  4209. this.print_newline();
  4210. }
  4211. } else if (this._flags.multiline_frame && is_array(this._flags.mode) && this._flags.last_token.text === ',' && this._last_last_text === '}') {
  4212. this.print_newline(); // }, in lists get a newline treatment
  4213. } else if (prefix === 'SPACE') {
  4214. this._output.space_before_token = true;
  4215. }
  4216. if (current_token.previous && (current_token.previous.type === TOKEN.WORD || current_token.previous.type === TOKEN.RESERVED)) {
  4217. this._output.space_before_token = true;
  4218. }
  4219. this.print_token(current_token);
  4220. this._flags.last_word = current_token.text;
  4221. if (current_token.type === TOKEN.RESERVED) {
  4222. if (current_token.text === 'do') {
  4223. this._flags.do_block = true;
  4224. } else if (current_token.text === 'if') {
  4225. this._flags.if_block = true;
  4226. } else if (current_token.text === 'import') {
  4227. this._flags.import_block = true;
  4228. } else if (this._flags.import_block && reserved_word(current_token, 'from')) {
  4229. this._flags.import_block = false;
  4230. }
  4231. }
  4232. };
  4233. Beautifier.prototype.handle_semicolon = function(current_token) {
  4234. if (this.start_of_statement(current_token)) {
  4235. // The conditional starts the statement if appropriate.
  4236. // Semicolon can be the start (and end) of a statement
  4237. this._output.space_before_token = false;
  4238. } else {
  4239. this.handle_whitespace_and_comments(current_token);
  4240. }
  4241. var next_token = this._tokens.peek();
  4242. while (this._flags.mode === MODE.Statement &&
  4243. !(this._flags.if_block && reserved_word(next_token, 'else')) &&
  4244. !this._flags.do_block) {
  4245. this.restore_mode();
  4246. }
  4247. // hacky but effective for the moment
  4248. if (this._flags.import_block) {
  4249. this._flags.import_block = false;
  4250. }
  4251. this.print_token(current_token);
  4252. };
  4253. Beautifier.prototype.handle_string = function(current_token) {
  4254. 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)) {
  4255. // The conditional starts the statement if appropriate.
  4256. // One difference - strings want at least a space before
  4257. this._output.space_before_token = true;
  4258. } else {
  4259. this.handle_whitespace_and_comments(current_token);
  4260. if (this._flags.last_token.type === TOKEN.RESERVED || this._flags.last_token.type === TOKEN.WORD || this._flags.inline_frame) {
  4261. this._output.space_before_token = true;
  4262. } 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) {
  4263. if (!this.start_of_object_property()) {
  4264. this.allow_wrap_or_preserved_newline(current_token);
  4265. }
  4266. } 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)) {
  4267. this._output.space_before_token = true;
  4268. } else {
  4269. this.print_newline();
  4270. }
  4271. }
  4272. this.print_token(current_token);
  4273. };
  4274. Beautifier.prototype.handle_equals = function(current_token) {
  4275. if (this.start_of_statement(current_token)) ; else {
  4276. this.handle_whitespace_and_comments(current_token);
  4277. }
  4278. if (this._flags.declaration_statement) {
  4279. // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
  4280. this._flags.declaration_assignment = true;
  4281. }
  4282. this._output.space_before_token = true;
  4283. this.print_token(current_token);
  4284. this._output.space_before_token = true;
  4285. };
  4286. Beautifier.prototype.handle_comma = function(current_token) {
  4287. this.handle_whitespace_and_comments(current_token, true);
  4288. this.print_token(current_token);
  4289. this._output.space_before_token = true;
  4290. if (this._flags.declaration_statement) {
  4291. if (is_expression(this._flags.parent.mode)) {
  4292. // do not break on comma, for(var a = 1, b = 2)
  4293. this._flags.declaration_assignment = false;
  4294. }
  4295. if (this._flags.declaration_assignment) {
  4296. this._flags.declaration_assignment = false;
  4297. this.print_newline(false, true);
  4298. } else if (this._options.comma_first) {
  4299. // for comma-first, we want to allow a newline before the comma
  4300. // to turn into a newline after the comma, which we will fixup later
  4301. this.allow_wrap_or_preserved_newline(current_token);
  4302. }
  4303. } else if (this._flags.mode === MODE.ObjectLiteral ||
  4304. (this._flags.mode === MODE.Statement && this._flags.parent.mode === MODE.ObjectLiteral)) {
  4305. if (this._flags.mode === MODE.Statement) {
  4306. this.restore_mode();
  4307. }
  4308. if (!this._flags.inline_frame) {
  4309. this.print_newline();
  4310. }
  4311. } else if (this._options.comma_first) {
  4312. // EXPR or DO_BLOCK
  4313. // for comma-first, we want to allow a newline before the comma
  4314. // to turn into a newline after the comma, which we will fixup later
  4315. this.allow_wrap_or_preserved_newline(current_token);
  4316. }
  4317. };
  4318. Beautifier.prototype.handle_operator = function(current_token) {
  4319. var isGeneratorAsterisk = current_token.text === '*' &&
  4320. (reserved_array(this._flags.last_token, ['function', 'yield']) ||
  4321. (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.COMMA, TOKEN.END_BLOCK, TOKEN.SEMICOLON]))
  4322. );
  4323. var isUnary = in_array(current_token.text, ['-', '+']) && (
  4324. in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.START_EXPR, TOKEN.EQUALS, TOKEN.OPERATOR]) ||
  4325. in_array(this._flags.last_token.text, line_starters) ||
  4326. this._flags.last_token.text === ','
  4327. );
  4328. if (this.start_of_statement(current_token)) ; else {
  4329. var preserve_statement_flags = !isGeneratorAsterisk;
  4330. this.handle_whitespace_and_comments(current_token, preserve_statement_flags);
  4331. }
  4332. // hack for actionscript's import .*;
  4333. if (current_token.text === '*' && this._flags.last_token.type === TOKEN.DOT) {
  4334. this.print_token(current_token);
  4335. return;
  4336. }
  4337. if (current_token.text === '::') {
  4338. // no spaces around exotic namespacing syntax operator
  4339. this.print_token(current_token);
  4340. return;
  4341. }
  4342. // Allow line wrapping between operators when operator_position is
  4343. // set to before or preserve
  4344. if (this._flags.last_token.type === TOKEN.OPERATOR && in_array(this._options.operator_position, OPERATOR_POSITION_BEFORE_OR_PRESERVE)) {
  4345. this.allow_wrap_or_preserved_newline(current_token);
  4346. }
  4347. if (current_token.text === ':' && this._flags.in_case) {
  4348. this.print_token(current_token);
  4349. this._flags.in_case = false;
  4350. this._flags.case_body = true;
  4351. if (this._tokens.peek().type !== TOKEN.START_BLOCK) {
  4352. this.indent();
  4353. this.print_newline();
  4354. this._flags.case_block = false;
  4355. } else {
  4356. this._flags.case_block = true;
  4357. this._output.space_before_token = true;
  4358. }
  4359. return;
  4360. }
  4361. var space_before = true;
  4362. var space_after = true;
  4363. var in_ternary = false;
  4364. if (current_token.text === ':') {
  4365. if (this._flags.ternary_depth === 0) {
  4366. // Colon is invalid javascript outside of ternary and object, but do our best to guess what was meant.
  4367. space_before = false;
  4368. } else {
  4369. this._flags.ternary_depth -= 1;
  4370. in_ternary = true;
  4371. }
  4372. } else if (current_token.text === '?') {
  4373. this._flags.ternary_depth += 1;
  4374. }
  4375. // let's handle the operator_position option prior to any conflicting logic
  4376. if (!isUnary && !isGeneratorAsterisk && this._options.preserve_newlines && in_array(current_token.text, positionable_operators)) {
  4377. var isColon = current_token.text === ':';
  4378. var isTernaryColon = (isColon && in_ternary);
  4379. var isOtherColon = (isColon && !in_ternary);
  4380. switch (this._options.operator_position) {
  4381. case OPERATOR_POSITION.before_newline:
  4382. // if the current token is : and it's not a ternary statement then we set space_before to false
  4383. this._output.space_before_token = !isOtherColon;
  4384. this.print_token(current_token);
  4385. if (!isColon || isTernaryColon) {
  4386. this.allow_wrap_or_preserved_newline(current_token);
  4387. }
  4388. this._output.space_before_token = true;
  4389. return;
  4390. case OPERATOR_POSITION.after_newline:
  4391. // if the current token is anything but colon, or (via deduction) it's a colon and in a ternary statement,
  4392. // then print a newline.
  4393. this._output.space_before_token = true;
  4394. if (!isColon || isTernaryColon) {
  4395. if (this._tokens.peek().newlines) {
  4396. this.print_newline(false, true);
  4397. } else {
  4398. this.allow_wrap_or_preserved_newline(current_token);
  4399. }
  4400. } else {
  4401. this._output.space_before_token = false;
  4402. }
  4403. this.print_token(current_token);
  4404. this._output.space_before_token = true;
  4405. return;
  4406. case OPERATOR_POSITION.preserve_newline:
  4407. if (!isOtherColon) {
  4408. this.allow_wrap_or_preserved_newline(current_token);
  4409. }
  4410. // if we just added a newline, or the current token is : and it's not a ternary statement,
  4411. // then we set space_before to false
  4412. space_before = !(this._output.just_added_newline() || isOtherColon);
  4413. this._output.space_before_token = space_before;
  4414. this.print_token(current_token);
  4415. this._output.space_before_token = true;
  4416. return;
  4417. }
  4418. }
  4419. if (isGeneratorAsterisk) {
  4420. this.allow_wrap_or_preserved_newline(current_token);
  4421. space_before = false;
  4422. var next_token = this._tokens.peek();
  4423. space_after = next_token && in_array(next_token.type, [TOKEN.WORD, TOKEN.RESERVED]);
  4424. } else if (current_token.text === '...') {
  4425. this.allow_wrap_or_preserved_newline(current_token);
  4426. space_before = this._flags.last_token.type === TOKEN.START_BLOCK;
  4427. space_after = false;
  4428. } else if (in_array(current_token.text, ['--', '++', '!', '~']) || isUnary) {
  4429. // unary operators (and binary +/- pretending to be unary) special cases
  4430. if (this._flags.last_token.type === TOKEN.COMMA || this._flags.last_token.type === TOKEN.START_EXPR) {
  4431. this.allow_wrap_or_preserved_newline(current_token);
  4432. }
  4433. space_before = false;
  4434. space_after = false;
  4435. // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
  4436. // if there is a newline between -- or ++ and anything else we should preserve it.
  4437. if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) {
  4438. var new_line_needed = reserved_array(this._flags.last_token, special_words) && current_token.newlines;
  4439. if (new_line_needed && (this._previous_flags.if_block || this._previous_flags.else_block)) {
  4440. this.restore_mode();
  4441. }
  4442. this.print_newline(new_line_needed, true);
  4443. }
  4444. if (this._flags.last_token.text === ';' && is_expression(this._flags.mode)) {
  4445. // for (;; ++i)
  4446. // ^^^
  4447. space_before = true;
  4448. }
  4449. if (this._flags.last_token.type === TOKEN.RESERVED) {
  4450. space_before = true;
  4451. } else if (this._flags.last_token.type === TOKEN.END_EXPR) {
  4452. space_before = !(this._flags.last_token.text === ']' && (current_token.text === '--' || current_token.text === '++'));
  4453. } else if (this._flags.last_token.type === TOKEN.OPERATOR) {
  4454. // a++ + ++b;
  4455. // a - -b
  4456. space_before = in_array(current_token.text, ['--', '-', '++', '+']) && in_array(this._flags.last_token.text, ['--', '-', '++', '+']);
  4457. // + and - are not unary when preceeded by -- or ++ operator
  4458. // a-- + b
  4459. // a * +b
  4460. // a - -b
  4461. if (in_array(current_token.text, ['+', '-']) && in_array(this._flags.last_token.text, ['--', '++'])) {
  4462. space_after = true;
  4463. }
  4464. }
  4465. if (((this._flags.mode === MODE.BlockStatement && !this._flags.inline_frame) || this._flags.mode === MODE.Statement) &&
  4466. (this._flags.last_token.text === '{' || this._flags.last_token.text === ';')) {
  4467. // { foo; --i }
  4468. // foo(); --bar;
  4469. this.print_newline();
  4470. }
  4471. }
  4472. this._output.space_before_token = this._output.space_before_token || space_before;
  4473. this.print_token(current_token);
  4474. this._output.space_before_token = space_after;
  4475. };
  4476. Beautifier.prototype.handle_block_comment = function(current_token, preserve_statement_flags) {
  4477. if (this._output.raw) {
  4478. this._output.add_raw_token(current_token);
  4479. if (current_token.directives && current_token.directives.preserve === 'end') {
  4480. // If we're testing the raw output behavior, do not allow a directive to turn it off.
  4481. this._output.raw = this._options.test_output_raw;
  4482. }
  4483. return;
  4484. }
  4485. if (current_token.directives) {
  4486. this.print_newline(false, preserve_statement_flags);
  4487. this.print_token(current_token);
  4488. if (current_token.directives.preserve === 'start') {
  4489. this._output.raw = true;
  4490. }
  4491. this.print_newline(false, true);
  4492. return;
  4493. }
  4494. // inline block
  4495. if (!acorn.newline.test(current_token.text) && !current_token.newlines) {
  4496. this._output.space_before_token = true;
  4497. this.print_token(current_token);
  4498. this._output.space_before_token = true;
  4499. return;
  4500. } else {
  4501. this.print_block_commment(current_token, preserve_statement_flags);
  4502. }
  4503. };
  4504. Beautifier.prototype.print_block_commment = function(current_token, preserve_statement_flags) {
  4505. var lines = split_linebreaks(current_token.text);
  4506. var j; // iterator for this case
  4507. var javadoc = false;
  4508. var starless = false;
  4509. var lastIndent = current_token.whitespace_before;
  4510. var lastIndentLength = lastIndent.length;
  4511. // block comment starts with a new line
  4512. this.print_newline(false, preserve_statement_flags);
  4513. // first line always indented
  4514. this.print_token_line_indentation(current_token);
  4515. this._output.add_token(lines[0]);
  4516. this.print_newline(false, preserve_statement_flags);
  4517. if (lines.length > 1) {
  4518. lines = lines.slice(1);
  4519. javadoc = all_lines_start_with(lines, '*');
  4520. starless = each_line_matches_indent(lines, lastIndent);
  4521. if (javadoc) {
  4522. this._flags.alignment = 1;
  4523. }
  4524. for (j = 0; j < lines.length; j++) {
  4525. if (javadoc) {
  4526. // javadoc: reformat and re-indent
  4527. this.print_token_line_indentation(current_token);
  4528. this._output.add_token(ltrim(lines[j]));
  4529. } else if (starless && lines[j]) {
  4530. // starless: re-indent non-empty content, avoiding trim
  4531. this.print_token_line_indentation(current_token);
  4532. this._output.add_token(lines[j].substring(lastIndentLength));
  4533. } else {
  4534. // normal comments output raw
  4535. this._output.current_line.set_indent(-1);
  4536. this._output.add_token(lines[j]);
  4537. }
  4538. // for comments on their own line or more than one line, make sure there's a new line after
  4539. this.print_newline(false, preserve_statement_flags);
  4540. }
  4541. this._flags.alignment = 0;
  4542. }
  4543. };
  4544. Beautifier.prototype.handle_comment = function(current_token, preserve_statement_flags) {
  4545. if (current_token.newlines) {
  4546. this.print_newline(false, preserve_statement_flags);
  4547. } else {
  4548. this._output.trim(true);
  4549. }
  4550. this._output.space_before_token = true;
  4551. this.print_token(current_token);
  4552. this.print_newline(false, preserve_statement_flags);
  4553. };
  4554. Beautifier.prototype.handle_dot = function(current_token) {
  4555. if (this.start_of_statement(current_token)) ; else {
  4556. this.handle_whitespace_and_comments(current_token, true);
  4557. }
  4558. if (this._flags.last_token.text.match('^[0-9]+$')) {
  4559. this._output.space_before_token = true;
  4560. }
  4561. if (reserved_array(this._flags.last_token, special_words)) {
  4562. this._output.space_before_token = false;
  4563. } else {
  4564. // allow preserved newlines before dots in general
  4565. // force newlines on dots after close paren when break_chained - for bar().baz()
  4566. this.allow_wrap_or_preserved_newline(current_token,
  4567. this._flags.last_token.text === ')' && this._options.break_chained_methods);
  4568. }
  4569. // Only unindent chained method dot if this dot starts a new line.
  4570. // Otherwise the automatic extra indentation removal will handle the over indent
  4571. if (this._options.unindent_chained_methods && this._output.just_added_newline()) {
  4572. this.deindent();
  4573. }
  4574. this.print_token(current_token);
  4575. };
  4576. Beautifier.prototype.handle_unknown = function(current_token, preserve_statement_flags) {
  4577. this.print_token(current_token);
  4578. if (current_token.text[current_token.text.length - 1] === '\n') {
  4579. this.print_newline(false, preserve_statement_flags);
  4580. }
  4581. };
  4582. Beautifier.prototype.handle_eof = function(current_token) {
  4583. // Unwind any open statements
  4584. while (this._flags.mode === MODE.Statement) {
  4585. this.restore_mode();
  4586. }
  4587. this.handle_whitespace_and_comments(current_token);
  4588. };
  4589. beautifier$2.Beautifier = Beautifier;
  4590. return beautifier$2;
  4591. }
  4592. /*jshint node:true */
  4593. var hasRequiredJavascript;
  4594. function requireJavascript () {
  4595. if (hasRequiredJavascript) return javascript.exports;
  4596. hasRequiredJavascript = 1;
  4597. var Beautifier = requireBeautifier$2().Beautifier,
  4598. Options = requireOptions$2().Options;
  4599. function js_beautify(js_source_text, options) {
  4600. var beautifier = new Beautifier(js_source_text, options);
  4601. return beautifier.beautify();
  4602. }
  4603. javascript.exports = js_beautify;
  4604. javascript.exports.defaultOptions = function() {
  4605. return new Options();
  4606. };
  4607. return javascript.exports;
  4608. }
  4609. var css = {exports: {}};
  4610. var beautifier$1 = {};
  4611. var options$1 = {};
  4612. /*jshint node:true */
  4613. var hasRequiredOptions$1;
  4614. function requireOptions$1 () {
  4615. if (hasRequiredOptions$1) return options$1;
  4616. hasRequiredOptions$1 = 1;
  4617. var BaseOptions = requireOptions$3().Options;
  4618. function Options(options) {
  4619. BaseOptions.call(this, options, 'css');
  4620. this.selector_separator_newline = this._get_boolean('selector_separator_newline', true);
  4621. this.newline_between_rules = this._get_boolean('newline_between_rules', true);
  4622. var space_around_selector_separator = this._get_boolean('space_around_selector_separator');
  4623. this.space_around_combinator = this._get_boolean('space_around_combinator') || space_around_selector_separator;
  4624. var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
  4625. this.brace_style = 'collapse';
  4626. for (var bs = 0; bs < brace_style_split.length; bs++) {
  4627. if (brace_style_split[bs] !== 'expand') {
  4628. // default to collapse, as only collapse|expand is implemented for now
  4629. this.brace_style = 'collapse';
  4630. } else {
  4631. this.brace_style = brace_style_split[bs];
  4632. }
  4633. }
  4634. }
  4635. Options.prototype = new BaseOptions();
  4636. options$1.Options = Options;
  4637. return options$1;
  4638. }
  4639. /*jshint node:true */
  4640. var hasRequiredBeautifier$1;
  4641. function requireBeautifier$1 () {
  4642. if (hasRequiredBeautifier$1) return beautifier$1;
  4643. hasRequiredBeautifier$1 = 1;
  4644. var Options = requireOptions$1().Options;
  4645. var Output = requireOutput().Output;
  4646. var InputScanner = requireInputscanner().InputScanner;
  4647. var Directives = requireDirectives().Directives;
  4648. var directives_core = new Directives(/\/\*/, /\*\//);
  4649. var lineBreak = /\r\n|[\r\n]/;
  4650. var allLineBreaks = /\r\n|[\r\n]/g;
  4651. // tokenizer
  4652. var whitespaceChar = /\s/;
  4653. var whitespacePattern = /(?:\s|\n)+/g;
  4654. var block_comment_pattern = /\/\*(?:[\s\S]*?)((?:\*\/)|$)/g;
  4655. var comment_pattern = /\/\/(?:[^\n\r\u2028\u2029]*)/g;
  4656. function Beautifier(source_text, options) {
  4657. this._source_text = source_text || '';
  4658. // Allow the setting of language/file-type specific options
  4659. // with inheritance of overall settings
  4660. this._options = new Options(options);
  4661. this._ch = null;
  4662. this._input = null;
  4663. // https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule
  4664. this.NESTED_AT_RULE = {
  4665. "page": true,
  4666. "font-face": true,
  4667. "keyframes": true,
  4668. // also in CONDITIONAL_GROUP_RULE below
  4669. "media": true,
  4670. "supports": true,
  4671. "document": true
  4672. };
  4673. this.CONDITIONAL_GROUP_RULE = {
  4674. "media": true,
  4675. "supports": true,
  4676. "document": true
  4677. };
  4678. this.NON_SEMICOLON_NEWLINE_PROPERTY = [
  4679. "grid-template-areas",
  4680. "grid-template"
  4681. ];
  4682. }
  4683. Beautifier.prototype.eatString = function(endChars) {
  4684. var result = '';
  4685. this._ch = this._input.next();
  4686. while (this._ch) {
  4687. result += this._ch;
  4688. if (this._ch === "\\") {
  4689. result += this._input.next();
  4690. } else if (endChars.indexOf(this._ch) !== -1 || this._ch === "\n") {
  4691. break;
  4692. }
  4693. this._ch = this._input.next();
  4694. }
  4695. return result;
  4696. };
  4697. // Skips any white space in the source text from the current position.
  4698. // When allowAtLeastOneNewLine is true, will output new lines for each
  4699. // newline character found; if the user has preserve_newlines off, only
  4700. // the first newline will be output
  4701. Beautifier.prototype.eatWhitespace = function(allowAtLeastOneNewLine) {
  4702. var result = whitespaceChar.test(this._input.peek());
  4703. var newline_count = 0;
  4704. while (whitespaceChar.test(this._input.peek())) {
  4705. this._ch = this._input.next();
  4706. if (allowAtLeastOneNewLine && this._ch === '\n') {
  4707. if (newline_count === 0 || newline_count < this._options.max_preserve_newlines) {
  4708. newline_count++;
  4709. this._output.add_new_line(true);
  4710. }
  4711. }
  4712. }
  4713. return result;
  4714. };
  4715. // Nested pseudo-class if we are insideRule
  4716. // and the next special character found opens
  4717. // a new block
  4718. Beautifier.prototype.foundNestedPseudoClass = function() {
  4719. var openParen = 0;
  4720. var i = 1;
  4721. var ch = this._input.peek(i);
  4722. while (ch) {
  4723. if (ch === "{") {
  4724. return true;
  4725. } else if (ch === '(') {
  4726. // pseudoclasses can contain ()
  4727. openParen += 1;
  4728. } else if (ch === ')') {
  4729. if (openParen === 0) {
  4730. return false;
  4731. }
  4732. openParen -= 1;
  4733. } else if (ch === ";" || ch === "}") {
  4734. return false;
  4735. }
  4736. i++;
  4737. ch = this._input.peek(i);
  4738. }
  4739. return false;
  4740. };
  4741. Beautifier.prototype.print_string = function(output_string) {
  4742. this._output.set_indent(this._indentLevel);
  4743. this._output.non_breaking_space = true;
  4744. this._output.add_token(output_string);
  4745. };
  4746. Beautifier.prototype.preserveSingleSpace = function(isAfterSpace) {
  4747. if (isAfterSpace) {
  4748. this._output.space_before_token = true;
  4749. }
  4750. };
  4751. Beautifier.prototype.indent = function() {
  4752. this._indentLevel++;
  4753. };
  4754. Beautifier.prototype.outdent = function() {
  4755. if (this._indentLevel > 0) {
  4756. this._indentLevel--;
  4757. }
  4758. };
  4759. /*_____________________--------------------_____________________*/
  4760. Beautifier.prototype.beautify = function() {
  4761. if (this._options.disabled) {
  4762. return this._source_text;
  4763. }
  4764. var source_text = this._source_text;
  4765. var eol = this._options.eol;
  4766. if (eol === 'auto') {
  4767. eol = '\n';
  4768. if (source_text && lineBreak.test(source_text || '')) {
  4769. eol = source_text.match(lineBreak)[0];
  4770. }
  4771. }
  4772. // HACK: newline parsing inconsistent. This brute force normalizes the this._input.
  4773. source_text = source_text.replace(allLineBreaks, '\n');
  4774. // reset
  4775. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  4776. this._output = new Output(this._options, baseIndentString);
  4777. this._input = new InputScanner(source_text);
  4778. this._indentLevel = 0;
  4779. this._nestedLevel = 0;
  4780. this._ch = null;
  4781. var parenLevel = 0;
  4782. var insideRule = false;
  4783. // This is the value side of a property value pair (blue in the following ex)
  4784. // label { content: blue }
  4785. var insidePropertyValue = false;
  4786. var enteringConditionalGroup = false;
  4787. var insideNonNestedAtRule = false;
  4788. var insideScssMap = false;
  4789. var topCharacter = this._ch;
  4790. var insideNonSemiColonValues = false;
  4791. var whitespace;
  4792. var isAfterSpace;
  4793. var previous_ch;
  4794. while (true) {
  4795. whitespace = this._input.read(whitespacePattern);
  4796. isAfterSpace = whitespace !== '';
  4797. previous_ch = topCharacter;
  4798. this._ch = this._input.next();
  4799. if (this._ch === '\\' && this._input.hasNext()) {
  4800. this._ch += this._input.next();
  4801. }
  4802. topCharacter = this._ch;
  4803. if (!this._ch) {
  4804. break;
  4805. } else if (this._ch === '/' && this._input.peek() === '*') {
  4806. // /* css comment */
  4807. // Always start block comments on a new line.
  4808. // This handles scenarios where a block comment immediately
  4809. // follows a property definition on the same line or where
  4810. // minified code is being beautified.
  4811. this._output.add_new_line();
  4812. this._input.back();
  4813. var comment = this._input.read(block_comment_pattern);
  4814. // Handle ignore directive
  4815. var directives = directives_core.get_directives(comment);
  4816. if (directives && directives.ignore === 'start') {
  4817. comment += directives_core.readIgnored(this._input);
  4818. }
  4819. this.print_string(comment);
  4820. // Ensures any new lines following the comment are preserved
  4821. this.eatWhitespace(true);
  4822. // Block comments are followed by a new line so they don't
  4823. // share a line with other properties
  4824. this._output.add_new_line();
  4825. } else if (this._ch === '/' && this._input.peek() === '/') {
  4826. // // single line comment
  4827. // Preserves the space before a comment
  4828. // on the same line as a rule
  4829. this._output.space_before_token = true;
  4830. this._input.back();
  4831. this.print_string(this._input.read(comment_pattern));
  4832. // Ensures any new lines following the comment are preserved
  4833. this.eatWhitespace(true);
  4834. } else if (this._ch === '$') {
  4835. this.preserveSingleSpace(isAfterSpace);
  4836. this.print_string(this._ch);
  4837. // strip trailing space, if present, for hash property checks
  4838. var variable = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
  4839. if (variable.match(/[ :]$/)) {
  4840. // we have a variable or pseudo-class, add it and insert one space before continuing
  4841. variable = this.eatString(": ").replace(/\s$/, '');
  4842. this.print_string(variable);
  4843. this._output.space_before_token = true;
  4844. }
  4845. variable = variable.replace(/\s$/, '');
  4846. // might be sass variable
  4847. if (parenLevel === 0 && variable.indexOf(':') !== -1) {
  4848. insidePropertyValue = true;
  4849. this.indent();
  4850. }
  4851. } else if (this._ch === '@') {
  4852. this.preserveSingleSpace(isAfterSpace);
  4853. // deal with less property mixins @{...}
  4854. if (this._input.peek() === '{') {
  4855. this.print_string(this._ch + this.eatString('}'));
  4856. } else {
  4857. this.print_string(this._ch);
  4858. // strip trailing space, if present, for hash property checks
  4859. var variableOrRule = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
  4860. if (variableOrRule.match(/[ :]$/)) {
  4861. // we have a variable or pseudo-class, add it and insert one space before continuing
  4862. variableOrRule = this.eatString(": ").replace(/\s$/, '');
  4863. this.print_string(variableOrRule);
  4864. this._output.space_before_token = true;
  4865. }
  4866. variableOrRule = variableOrRule.replace(/\s$/, '');
  4867. // might be less variable
  4868. if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
  4869. insidePropertyValue = true;
  4870. this.indent();
  4871. // might be a nesting at-rule
  4872. } else if (variableOrRule in this.NESTED_AT_RULE) {
  4873. this._nestedLevel += 1;
  4874. if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
  4875. enteringConditionalGroup = true;
  4876. }
  4877. // might be a non-nested at-rule
  4878. } else if (parenLevel === 0 && !insidePropertyValue) {
  4879. insideNonNestedAtRule = true;
  4880. }
  4881. }
  4882. } else if (this._ch === '#' && this._input.peek() === '{') {
  4883. this.preserveSingleSpace(isAfterSpace);
  4884. this.print_string(this._ch + this.eatString('}'));
  4885. } else if (this._ch === '{') {
  4886. if (insidePropertyValue) {
  4887. insidePropertyValue = false;
  4888. this.outdent();
  4889. }
  4890. // non nested at rule becomes nested
  4891. insideNonNestedAtRule = false;
  4892. // when entering conditional groups, only rulesets are allowed
  4893. if (enteringConditionalGroup) {
  4894. enteringConditionalGroup = false;
  4895. insideRule = (this._indentLevel >= this._nestedLevel);
  4896. } else {
  4897. // otherwise, declarations are also allowed
  4898. insideRule = (this._indentLevel >= this._nestedLevel - 1);
  4899. }
  4900. if (this._options.newline_between_rules && insideRule) {
  4901. if (this._output.previous_line && this._output.previous_line.item(-1) !== '{') {
  4902. this._output.ensure_empty_line_above('/', ',');
  4903. }
  4904. }
  4905. this._output.space_before_token = true;
  4906. // The difference in print_string and indent order is necessary to indent the '{' correctly
  4907. if (this._options.brace_style === 'expand') {
  4908. this._output.add_new_line();
  4909. this.print_string(this._ch);
  4910. this.indent();
  4911. this._output.set_indent(this._indentLevel);
  4912. } else {
  4913. // inside mixin and first param is object
  4914. if (previous_ch === '(') {
  4915. this._output.space_before_token = false;
  4916. } else if (previous_ch !== ',') {
  4917. this.indent();
  4918. }
  4919. this.print_string(this._ch);
  4920. }
  4921. this.eatWhitespace(true);
  4922. this._output.add_new_line();
  4923. } else if (this._ch === '}') {
  4924. this.outdent();
  4925. this._output.add_new_line();
  4926. if (previous_ch === '{') {
  4927. this._output.trim(true);
  4928. }
  4929. if (insidePropertyValue) {
  4930. this.outdent();
  4931. insidePropertyValue = false;
  4932. }
  4933. this.print_string(this._ch);
  4934. insideRule = false;
  4935. if (this._nestedLevel) {
  4936. this._nestedLevel--;
  4937. }
  4938. this.eatWhitespace(true);
  4939. this._output.add_new_line();
  4940. if (this._options.newline_between_rules && !this._output.just_added_blankline()) {
  4941. if (this._input.peek() !== '}') {
  4942. this._output.add_new_line(true);
  4943. }
  4944. }
  4945. if (this._input.peek() === ')') {
  4946. this._output.trim(true);
  4947. if (this._options.brace_style === "expand") {
  4948. this._output.add_new_line(true);
  4949. }
  4950. }
  4951. } else if (this._ch === ":") {
  4952. for (var i = 0; i < this.NON_SEMICOLON_NEWLINE_PROPERTY.length; i++) {
  4953. if (this._input.lookBack(this.NON_SEMICOLON_NEWLINE_PROPERTY[i])) {
  4954. insideNonSemiColonValues = true;
  4955. break;
  4956. }
  4957. }
  4958. if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideNonNestedAtRule && parenLevel === 0) {
  4959. // 'property: value' delimiter
  4960. // which could be in a conditional group query
  4961. this.print_string(':');
  4962. if (!insidePropertyValue) {
  4963. insidePropertyValue = true;
  4964. this._output.space_before_token = true;
  4965. this.eatWhitespace(true);
  4966. this.indent();
  4967. }
  4968. } else {
  4969. // sass/less parent reference don't use a space
  4970. // sass nested pseudo-class don't use a space
  4971. // preserve space before pseudoclasses/pseudoelements, as it means "in any child"
  4972. if (this._input.lookBack(" ")) {
  4973. this._output.space_before_token = true;
  4974. }
  4975. if (this._input.peek() === ":") {
  4976. // pseudo-element
  4977. this._ch = this._input.next();
  4978. this.print_string("::");
  4979. } else {
  4980. // pseudo-class
  4981. this.print_string(':');
  4982. }
  4983. }
  4984. } else if (this._ch === '"' || this._ch === '\'') {
  4985. var preserveQuoteSpace = previous_ch === '"' || previous_ch === '\'';
  4986. this.preserveSingleSpace(preserveQuoteSpace || isAfterSpace);
  4987. this.print_string(this._ch + this.eatString(this._ch));
  4988. this.eatWhitespace(true);
  4989. } else if (this._ch === ';') {
  4990. insideNonSemiColonValues = false;
  4991. if (parenLevel === 0) {
  4992. if (insidePropertyValue) {
  4993. this.outdent();
  4994. insidePropertyValue = false;
  4995. }
  4996. insideNonNestedAtRule = false;
  4997. this.print_string(this._ch);
  4998. this.eatWhitespace(true);
  4999. // This maintains single line comments on the same
  5000. // line. Block comments are also affected, but
  5001. // a new line is always output before one inside
  5002. // that section
  5003. if (this._input.peek() !== '/') {
  5004. this._output.add_new_line();
  5005. }
  5006. } else {
  5007. this.print_string(this._ch);
  5008. this.eatWhitespace(true);
  5009. this._output.space_before_token = true;
  5010. }
  5011. } else if (this._ch === '(') { // may be a url
  5012. if (this._input.lookBack("url")) {
  5013. this.print_string(this._ch);
  5014. this.eatWhitespace();
  5015. parenLevel++;
  5016. this.indent();
  5017. this._ch = this._input.next();
  5018. if (this._ch === ')' || this._ch === '"' || this._ch === '\'') {
  5019. this._input.back();
  5020. } else if (this._ch) {
  5021. this.print_string(this._ch + this.eatString(')'));
  5022. if (parenLevel) {
  5023. parenLevel--;
  5024. this.outdent();
  5025. }
  5026. }
  5027. } else {
  5028. var space_needed = false;
  5029. if (this._input.lookBack("with")) {
  5030. // look back is not an accurate solution, we need tokens to confirm without whitespaces
  5031. space_needed = true;
  5032. }
  5033. this.preserveSingleSpace(isAfterSpace || space_needed);
  5034. this.print_string(this._ch);
  5035. // handle scss/sass map
  5036. if (insidePropertyValue && previous_ch === "$" && this._options.selector_separator_newline) {
  5037. this._output.add_new_line();
  5038. insideScssMap = true;
  5039. } else {
  5040. this.eatWhitespace();
  5041. parenLevel++;
  5042. this.indent();
  5043. }
  5044. }
  5045. } else if (this._ch === ')') {
  5046. if (parenLevel) {
  5047. parenLevel--;
  5048. this.outdent();
  5049. }
  5050. if (insideScssMap && this._input.peek() === ";" && this._options.selector_separator_newline) {
  5051. insideScssMap = false;
  5052. this.outdent();
  5053. this._output.add_new_line();
  5054. }
  5055. this.print_string(this._ch);
  5056. } else if (this._ch === ',') {
  5057. this.print_string(this._ch);
  5058. this.eatWhitespace(true);
  5059. if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) {
  5060. this._output.add_new_line();
  5061. } else {
  5062. this._output.space_before_token = true;
  5063. }
  5064. } else if ((this._ch === '>' || this._ch === '+' || this._ch === '~') && !insidePropertyValue && parenLevel === 0) {
  5065. //handle combinator spacing
  5066. if (this._options.space_around_combinator) {
  5067. this._output.space_before_token = true;
  5068. this.print_string(this._ch);
  5069. this._output.space_before_token = true;
  5070. } else {
  5071. this.print_string(this._ch);
  5072. this.eatWhitespace();
  5073. // squash extra whitespace
  5074. if (this._ch && whitespaceChar.test(this._ch)) {
  5075. this._ch = '';
  5076. }
  5077. }
  5078. } else if (this._ch === ']') {
  5079. this.print_string(this._ch);
  5080. } else if (this._ch === '[') {
  5081. this.preserveSingleSpace(isAfterSpace);
  5082. this.print_string(this._ch);
  5083. } else if (this._ch === '=') { // no whitespace before or after
  5084. this.eatWhitespace();
  5085. this.print_string('=');
  5086. if (whitespaceChar.test(this._ch)) {
  5087. this._ch = '';
  5088. }
  5089. } else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
  5090. this._output.space_before_token = true;
  5091. this.print_string(this._ch);
  5092. } else {
  5093. var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
  5094. this.preserveSingleSpace(preserveAfterSpace || isAfterSpace);
  5095. this.print_string(this._ch);
  5096. if (!this._output.just_added_newline() && this._input.peek() === '\n' && insideNonSemiColonValues) {
  5097. this._output.add_new_line();
  5098. }
  5099. }
  5100. }
  5101. var sweetCode = this._output.get_code(eol);
  5102. return sweetCode;
  5103. };
  5104. beautifier$1.Beautifier = Beautifier;
  5105. return beautifier$1;
  5106. }
  5107. /*jshint node:true */
  5108. var hasRequiredCss;
  5109. function requireCss () {
  5110. if (hasRequiredCss) return css.exports;
  5111. hasRequiredCss = 1;
  5112. var Beautifier = requireBeautifier$1().Beautifier,
  5113. Options = requireOptions$1().Options;
  5114. function css_beautify(source_text, options) {
  5115. var beautifier = new Beautifier(source_text, options);
  5116. return beautifier.beautify();
  5117. }
  5118. css.exports = css_beautify;
  5119. css.exports.defaultOptions = function() {
  5120. return new Options();
  5121. };
  5122. return css.exports;
  5123. }
  5124. var html = {exports: {}};
  5125. var beautifier = {};
  5126. var options = {};
  5127. /*jshint node:true */
  5128. var hasRequiredOptions;
  5129. function requireOptions () {
  5130. if (hasRequiredOptions) return options;
  5131. hasRequiredOptions = 1;
  5132. var BaseOptions = requireOptions$3().Options;
  5133. function Options(options) {
  5134. BaseOptions.call(this, options, 'html');
  5135. if (this.templating.length === 1 && this.templating[0] === 'auto') {
  5136. this.templating = ['django', 'erb', 'handlebars', 'php'];
  5137. }
  5138. this.indent_inner_html = this._get_boolean('indent_inner_html');
  5139. this.indent_body_inner_html = this._get_boolean('indent_body_inner_html', true);
  5140. this.indent_head_inner_html = this._get_boolean('indent_head_inner_html', true);
  5141. this.indent_handlebars = this._get_boolean('indent_handlebars', true);
  5142. this.wrap_attributes = this._get_selection('wrap_attributes',
  5143. ['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
  5144. this.wrap_attributes_min_attrs = this._get_number('wrap_attributes_min_attrs', 2);
  5145. this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);
  5146. this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);
  5147. // Block vs inline elements
  5148. // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
  5149. // https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
  5150. // https://www.w3.org/TR/html5/dom.html#phrasing-content
  5151. this.inline = this._get_array('inline', [
  5152. 'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite',
  5153. 'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img',
  5154. 'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'meter', 'noscript',
  5155. 'object', 'output', 'progress', 'q', 'ruby', 's', 'samp', /* 'script', */ 'select', 'small',
  5156. 'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
  5157. 'video', 'wbr', 'text',
  5158. // obsolete inline tags
  5159. 'acronym', 'big', 'strike', 'tt'
  5160. ]);
  5161. this.inline_custom_elements = this._get_boolean('inline_custom_elements', true);
  5162. this.void_elements = this._get_array('void_elements', [
  5163. // HTLM void elements - aka self-closing tags - aka singletons
  5164. // https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
  5165. 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
  5166. 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
  5167. // NOTE: Optional tags are too complex for a simple list
  5168. // they are hard coded in _do_optional_end_element
  5169. // Doctype and xml elements
  5170. '!doctype', '?xml',
  5171. // obsolete tags
  5172. // basefont: https://www.computerhope.com/jargon/h/html-basefont-tag.htm
  5173. // isndex: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/isindex
  5174. 'basefont', 'isindex'
  5175. ]);
  5176. this.unformatted = this._get_array('unformatted', []);
  5177. this.content_unformatted = this._get_array('content_unformatted', [
  5178. 'pre', 'textarea'
  5179. ]);
  5180. this.unformatted_content_delimiter = this._get_characters('unformatted_content_delimiter');
  5181. this.indent_scripts = this._get_selection('indent_scripts', ['normal', 'keep', 'separate']);
  5182. }
  5183. Options.prototype = new BaseOptions();
  5184. options.Options = Options;
  5185. return options;
  5186. }
  5187. var tokenizer = {};
  5188. /*jshint node:true */
  5189. var hasRequiredTokenizer;
  5190. function requireTokenizer () {
  5191. if (hasRequiredTokenizer) return tokenizer;
  5192. hasRequiredTokenizer = 1;
  5193. var BaseTokenizer = requireTokenizer$2().Tokenizer;
  5194. var BASETOKEN = requireTokenizer$2().TOKEN;
  5195. var Directives = requireDirectives().Directives;
  5196. var TemplatablePattern = requireTemplatablepattern().TemplatablePattern;
  5197. var Pattern = requirePattern().Pattern;
  5198. var TOKEN = {
  5199. TAG_OPEN: 'TK_TAG_OPEN',
  5200. TAG_CLOSE: 'TK_TAG_CLOSE',
  5201. ATTRIBUTE: 'TK_ATTRIBUTE',
  5202. EQUALS: 'TK_EQUALS',
  5203. VALUE: 'TK_VALUE',
  5204. COMMENT: 'TK_COMMENT',
  5205. TEXT: 'TK_TEXT',
  5206. UNKNOWN: 'TK_UNKNOWN',
  5207. START: BASETOKEN.START,
  5208. RAW: BASETOKEN.RAW,
  5209. EOF: BASETOKEN.EOF
  5210. };
  5211. var directives_core = new Directives(/<\!--/, /-->/);
  5212. var Tokenizer = function(input_string, options) {
  5213. BaseTokenizer.call(this, input_string, options);
  5214. this._current_tag_name = '';
  5215. // Words end at whitespace or when a tag starts
  5216. // if we are indenting handlebars, they are considered tags
  5217. var templatable_reader = new TemplatablePattern(this._input).read_options(this._options);
  5218. var pattern_reader = new Pattern(this._input);
  5219. this.__patterns = {
  5220. word: templatable_reader.until(/[\n\r\t <]/),
  5221. single_quote: templatable_reader.until_after(/'/),
  5222. double_quote: templatable_reader.until_after(/"/),
  5223. attribute: templatable_reader.until(/[\n\r\t =>]|\/>/),
  5224. element_name: templatable_reader.until(/[\n\r\t >\/]/),
  5225. handlebars_comment: pattern_reader.starting_with(/{{!--/).until_after(/--}}/),
  5226. handlebars: pattern_reader.starting_with(/{{/).until_after(/}}/),
  5227. handlebars_open: pattern_reader.until(/[\n\r\t }]/),
  5228. handlebars_raw_close: pattern_reader.until(/}}/),
  5229. comment: pattern_reader.starting_with(/<!--/).until_after(/-->/),
  5230. cdata: pattern_reader.starting_with(/<!\[CDATA\[/).until_after(/]]>/),
  5231. // https://en.wikipedia.org/wiki/Conditional_comment
  5232. conditional_comment: pattern_reader.starting_with(/<!\[/).until_after(/]>/),
  5233. processing: pattern_reader.starting_with(/<\?/).until_after(/\?>/)
  5234. };
  5235. if (this._options.indent_handlebars) {
  5236. this.__patterns.word = this.__patterns.word.exclude('handlebars');
  5237. }
  5238. this._unformatted_content_delimiter = null;
  5239. if (this._options.unformatted_content_delimiter) {
  5240. var literal_regexp = this._input.get_literal_regexp(this._options.unformatted_content_delimiter);
  5241. this.__patterns.unformatted_content_delimiter =
  5242. pattern_reader.matching(literal_regexp)
  5243. .until_after(literal_regexp);
  5244. }
  5245. };
  5246. Tokenizer.prototype = new BaseTokenizer();
  5247. Tokenizer.prototype._is_comment = function(current_token) { // jshint unused:false
  5248. return false; //current_token.type === TOKEN.COMMENT || current_token.type === TOKEN.UNKNOWN;
  5249. };
  5250. Tokenizer.prototype._is_opening = function(current_token) {
  5251. return current_token.type === TOKEN.TAG_OPEN;
  5252. };
  5253. Tokenizer.prototype._is_closing = function(current_token, open_token) {
  5254. return current_token.type === TOKEN.TAG_CLOSE &&
  5255. (open_token && (
  5256. ((current_token.text === '>' || current_token.text === '/>') && open_token.text[0] === '<') ||
  5257. (current_token.text === '}}' && open_token.text[0] === '{' && open_token.text[1] === '{')));
  5258. };
  5259. Tokenizer.prototype._reset = function() {
  5260. this._current_tag_name = '';
  5261. };
  5262. Tokenizer.prototype._get_next_token = function(previous_token, open_token) { // jshint unused:false
  5263. var token = null;
  5264. this._readWhitespace();
  5265. var c = this._input.peek();
  5266. if (c === null) {
  5267. return this._create_token(TOKEN.EOF, '');
  5268. }
  5269. token = token || this._read_open_handlebars(c, open_token);
  5270. token = token || this._read_attribute(c, previous_token, open_token);
  5271. token = token || this._read_close(c, open_token);
  5272. token = token || this._read_raw_content(c, previous_token, open_token);
  5273. token = token || this._read_content_word(c);
  5274. token = token || this._read_comment_or_cdata(c);
  5275. token = token || this._read_processing(c);
  5276. token = token || this._read_open(c, open_token);
  5277. token = token || this._create_token(TOKEN.UNKNOWN, this._input.next());
  5278. return token;
  5279. };
  5280. Tokenizer.prototype._read_comment_or_cdata = function(c) { // jshint unused:false
  5281. var token = null;
  5282. var resulting_string = null;
  5283. var directives = null;
  5284. if (c === '<') {
  5285. var peek1 = this._input.peek(1);
  5286. // We treat all comments as literals, even more than preformatted tags
  5287. // we only look for the appropriate closing marker
  5288. if (peek1 === '!') {
  5289. resulting_string = this.__patterns.comment.read();
  5290. // only process directive on html comments
  5291. if (resulting_string) {
  5292. directives = directives_core.get_directives(resulting_string);
  5293. if (directives && directives.ignore === 'start') {
  5294. resulting_string += directives_core.readIgnored(this._input);
  5295. }
  5296. } else {
  5297. resulting_string = this.__patterns.cdata.read();
  5298. }
  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_processing = function(c) { // jshint unused:false
  5308. var token = null;
  5309. var resulting_string = null;
  5310. var directives = null;
  5311. if (c === '<') {
  5312. var peek1 = this._input.peek(1);
  5313. if (peek1 === '!' || peek1 === '?') {
  5314. resulting_string = this.__patterns.conditional_comment.read();
  5315. resulting_string = resulting_string || this.__patterns.processing.read();
  5316. }
  5317. if (resulting_string) {
  5318. token = this._create_token(TOKEN.COMMENT, resulting_string);
  5319. token.directives = directives;
  5320. }
  5321. }
  5322. return token;
  5323. };
  5324. Tokenizer.prototype._read_open = function(c, open_token) {
  5325. var resulting_string = null;
  5326. var token = null;
  5327. if (!open_token) {
  5328. if (c === '<') {
  5329. resulting_string = this._input.next();
  5330. if (this._input.peek() === '/') {
  5331. resulting_string += this._input.next();
  5332. }
  5333. resulting_string += this.__patterns.element_name.read();
  5334. token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
  5335. }
  5336. }
  5337. return token;
  5338. };
  5339. Tokenizer.prototype._read_open_handlebars = function(c, open_token) {
  5340. var resulting_string = null;
  5341. var token = null;
  5342. if (!open_token) {
  5343. if (this._options.indent_handlebars && c === '{' && this._input.peek(1) === '{') {
  5344. if (this._input.peek(2) === '!') {
  5345. resulting_string = this.__patterns.handlebars_comment.read();
  5346. resulting_string = resulting_string || this.__patterns.handlebars.read();
  5347. token = this._create_token(TOKEN.COMMENT, resulting_string);
  5348. } else {
  5349. resulting_string = this.__patterns.handlebars_open.read();
  5350. token = this._create_token(TOKEN.TAG_OPEN, resulting_string);
  5351. }
  5352. }
  5353. }
  5354. return token;
  5355. };
  5356. Tokenizer.prototype._read_close = function(c, open_token) {
  5357. var resulting_string = null;
  5358. var token = null;
  5359. if (open_token) {
  5360. if (open_token.text[0] === '<' && (c === '>' || (c === '/' && this._input.peek(1) === '>'))) {
  5361. resulting_string = this._input.next();
  5362. if (c === '/') { // for close tag "/>"
  5363. resulting_string += this._input.next();
  5364. }
  5365. token = this._create_token(TOKEN.TAG_CLOSE, resulting_string);
  5366. } else if (open_token.text[0] === '{' && c === '}' && this._input.peek(1) === '}') {
  5367. this._input.next();
  5368. this._input.next();
  5369. token = this._create_token(TOKEN.TAG_CLOSE, '}}');
  5370. }
  5371. }
  5372. return token;
  5373. };
  5374. Tokenizer.prototype._read_attribute = function(c, previous_token, open_token) {
  5375. var token = null;
  5376. var resulting_string = '';
  5377. if (open_token && open_token.text[0] === '<') {
  5378. if (c === '=') {
  5379. token = this._create_token(TOKEN.EQUALS, this._input.next());
  5380. } else if (c === '"' || c === "'") {
  5381. var content = this._input.next();
  5382. if (c === '"') {
  5383. content += this.__patterns.double_quote.read();
  5384. } else {
  5385. content += this.__patterns.single_quote.read();
  5386. }
  5387. token = this._create_token(TOKEN.VALUE, content);
  5388. } else {
  5389. resulting_string = this.__patterns.attribute.read();
  5390. if (resulting_string) {
  5391. if (previous_token.type === TOKEN.EQUALS) {
  5392. token = this._create_token(TOKEN.VALUE, resulting_string);
  5393. } else {
  5394. token = this._create_token(TOKEN.ATTRIBUTE, resulting_string);
  5395. }
  5396. }
  5397. }
  5398. }
  5399. return token;
  5400. };
  5401. Tokenizer.prototype._is_content_unformatted = function(tag_name) {
  5402. // void_elements have no content and so cannot have unformatted content
  5403. // script and style tags should always be read as unformatted content
  5404. // finally content_unformatted and unformatted element contents are unformatted
  5405. return this._options.void_elements.indexOf(tag_name) === -1 &&
  5406. (this._options.content_unformatted.indexOf(tag_name) !== -1 ||
  5407. this._options.unformatted.indexOf(tag_name) !== -1);
  5408. };
  5409. Tokenizer.prototype._read_raw_content = function(c, previous_token, open_token) { // jshint unused:false
  5410. var resulting_string = '';
  5411. if (open_token && open_token.text[0] === '{') {
  5412. resulting_string = this.__patterns.handlebars_raw_close.read();
  5413. } else if (previous_token.type === TOKEN.TAG_CLOSE &&
  5414. previous_token.opened.text[0] === '<' && previous_token.text[0] !== '/') {
  5415. // ^^ empty tag has no content
  5416. var tag_name = previous_token.opened.text.substr(1).toLowerCase();
  5417. if (tag_name === 'script' || tag_name === 'style') {
  5418. // Script and style tags are allowed to have comments wrapping their content
  5419. // or just have regular content.
  5420. var token = this._read_comment_or_cdata(c);
  5421. if (token) {
  5422. token.type = TOKEN.TEXT;
  5423. return token;
  5424. }
  5425. resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
  5426. } else if (this._is_content_unformatted(tag_name)) {
  5427. resulting_string = this._input.readUntil(new RegExp('</' + tag_name + '[\\n\\r\\t ]*?>', 'ig'));
  5428. }
  5429. }
  5430. if (resulting_string) {
  5431. return this._create_token(TOKEN.TEXT, resulting_string);
  5432. }
  5433. return null;
  5434. };
  5435. Tokenizer.prototype._read_content_word = function(c) {
  5436. var resulting_string = '';
  5437. if (this._options.unformatted_content_delimiter) {
  5438. if (c === this._options.unformatted_content_delimiter[0]) {
  5439. resulting_string = this.__patterns.unformatted_content_delimiter.read();
  5440. }
  5441. }
  5442. if (!resulting_string) {
  5443. resulting_string = this.__patterns.word.read();
  5444. }
  5445. if (resulting_string) {
  5446. return this._create_token(TOKEN.TEXT, resulting_string);
  5447. }
  5448. };
  5449. tokenizer.Tokenizer = Tokenizer;
  5450. tokenizer.TOKEN = TOKEN;
  5451. return tokenizer;
  5452. }
  5453. /*jshint node:true */
  5454. var hasRequiredBeautifier;
  5455. function requireBeautifier () {
  5456. if (hasRequiredBeautifier) return beautifier;
  5457. hasRequiredBeautifier = 1;
  5458. var Options = requireOptions().Options;
  5459. var Output = requireOutput().Output;
  5460. var Tokenizer = requireTokenizer().Tokenizer;
  5461. var TOKEN = requireTokenizer().TOKEN;
  5462. var lineBreak = /\r\n|[\r\n]/;
  5463. var allLineBreaks = /\r\n|[\r\n]/g;
  5464. var Printer = function(options, base_indent_string) { //handles input/output and some other printing functions
  5465. this.indent_level = 0;
  5466. this.alignment_size = 0;
  5467. this.max_preserve_newlines = options.max_preserve_newlines;
  5468. this.preserve_newlines = options.preserve_newlines;
  5469. this._output = new Output(options, base_indent_string);
  5470. };
  5471. Printer.prototype.current_line_has_match = function(pattern) {
  5472. return this._output.current_line.has_match(pattern);
  5473. };
  5474. Printer.prototype.set_space_before_token = function(value, non_breaking) {
  5475. this._output.space_before_token = value;
  5476. this._output.non_breaking_space = non_breaking;
  5477. };
  5478. Printer.prototype.set_wrap_point = function() {
  5479. this._output.set_indent(this.indent_level, this.alignment_size);
  5480. this._output.set_wrap_point();
  5481. };
  5482. Printer.prototype.add_raw_token = function(token) {
  5483. this._output.add_raw_token(token);
  5484. };
  5485. Printer.prototype.print_preserved_newlines = function(raw_token) {
  5486. var newlines = 0;
  5487. if (raw_token.type !== TOKEN.TEXT && raw_token.previous.type !== TOKEN.TEXT) {
  5488. newlines = raw_token.newlines ? 1 : 0;
  5489. }
  5490. if (this.preserve_newlines) {
  5491. newlines = raw_token.newlines < this.max_preserve_newlines + 1 ? raw_token.newlines : this.max_preserve_newlines + 1;
  5492. }
  5493. for (var n = 0; n < newlines; n++) {
  5494. this.print_newline(n > 0);
  5495. }
  5496. return newlines !== 0;
  5497. };
  5498. Printer.prototype.traverse_whitespace = function(raw_token) {
  5499. if (raw_token.whitespace_before || raw_token.newlines) {
  5500. if (!this.print_preserved_newlines(raw_token)) {
  5501. this._output.space_before_token = true;
  5502. }
  5503. return true;
  5504. }
  5505. return false;
  5506. };
  5507. Printer.prototype.previous_token_wrapped = function() {
  5508. return this._output.previous_token_wrapped;
  5509. };
  5510. Printer.prototype.print_newline = function(force) {
  5511. this._output.add_new_line(force);
  5512. };
  5513. Printer.prototype.print_token = function(token) {
  5514. if (token.text) {
  5515. this._output.set_indent(this.indent_level, this.alignment_size);
  5516. this._output.add_token(token.text);
  5517. }
  5518. };
  5519. Printer.prototype.indent = function() {
  5520. this.indent_level++;
  5521. };
  5522. Printer.prototype.get_full_indent = function(level) {
  5523. level = this.indent_level + (level || 0);
  5524. if (level < 1) {
  5525. return '';
  5526. }
  5527. return this._output.get_indent_string(level);
  5528. };
  5529. var get_type_attribute = function(start_token) {
  5530. var result = null;
  5531. var raw_token = start_token.next;
  5532. // Search attributes for a type attribute
  5533. while (raw_token.type !== TOKEN.EOF && start_token.closed !== raw_token) {
  5534. if (raw_token.type === TOKEN.ATTRIBUTE && raw_token.text === 'type') {
  5535. if (raw_token.next && raw_token.next.type === TOKEN.EQUALS &&
  5536. raw_token.next.next && raw_token.next.next.type === TOKEN.VALUE) {
  5537. result = raw_token.next.next.text;
  5538. }
  5539. break;
  5540. }
  5541. raw_token = raw_token.next;
  5542. }
  5543. return result;
  5544. };
  5545. var get_custom_beautifier_name = function(tag_check, raw_token) {
  5546. var typeAttribute = null;
  5547. var result = null;
  5548. if (!raw_token.closed) {
  5549. return null;
  5550. }
  5551. if (tag_check === 'script') {
  5552. typeAttribute = 'text/javascript';
  5553. } else if (tag_check === 'style') {
  5554. typeAttribute = 'text/css';
  5555. }
  5556. typeAttribute = get_type_attribute(raw_token) || typeAttribute;
  5557. // For script and style tags that have a type attribute, only enable custom beautifiers for matching values
  5558. // For those without a type attribute use default;
  5559. if (typeAttribute.search('text/css') > -1) {
  5560. result = 'css';
  5561. } else if (typeAttribute.search(/module|((text|application|dojo)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json|method|aspect))/) > -1) {
  5562. result = 'javascript';
  5563. } else if (typeAttribute.search(/(text|application|dojo)\/(x-)?(html)/) > -1) {
  5564. result = 'html';
  5565. } else if (typeAttribute.search(/test\/null/) > -1) {
  5566. // Test only mime-type for testing the beautifier when null is passed as beautifing function
  5567. result = 'null';
  5568. }
  5569. return result;
  5570. };
  5571. function in_array(what, arr) {
  5572. return arr.indexOf(what) !== -1;
  5573. }
  5574. function TagFrame(parent, parser_token, indent_level) {
  5575. this.parent = parent || null;
  5576. this.tag = parser_token ? parser_token.tag_name : '';
  5577. this.indent_level = indent_level || 0;
  5578. this.parser_token = parser_token || null;
  5579. }
  5580. function TagStack(printer) {
  5581. this._printer = printer;
  5582. this._current_frame = null;
  5583. }
  5584. TagStack.prototype.get_parser_token = function() {
  5585. return this._current_frame ? this._current_frame.parser_token : null;
  5586. };
  5587. TagStack.prototype.record_tag = function(parser_token) { //function to record a tag and its parent in this.tags Object
  5588. var new_frame = new TagFrame(this._current_frame, parser_token, this._printer.indent_level);
  5589. this._current_frame = new_frame;
  5590. };
  5591. TagStack.prototype._try_pop_frame = function(frame) { //function to retrieve the opening tag to the corresponding closer
  5592. var parser_token = null;
  5593. if (frame) {
  5594. parser_token = frame.parser_token;
  5595. this._printer.indent_level = frame.indent_level;
  5596. this._current_frame = frame.parent;
  5597. }
  5598. return parser_token;
  5599. };
  5600. TagStack.prototype._get_frame = function(tag_list, stop_list) { //function to retrieve the opening tag to the corresponding closer
  5601. var frame = this._current_frame;
  5602. while (frame) { //till we reach '' (the initial value);
  5603. if (tag_list.indexOf(frame.tag) !== -1) { //if this is it use it
  5604. break;
  5605. } else if (stop_list && stop_list.indexOf(frame.tag) !== -1) {
  5606. frame = null;
  5607. break;
  5608. }
  5609. frame = frame.parent;
  5610. }
  5611. return frame;
  5612. };
  5613. TagStack.prototype.try_pop = function(tag, stop_list) { //function to retrieve the opening tag to the corresponding closer
  5614. var frame = this._get_frame([tag], stop_list);
  5615. return this._try_pop_frame(frame);
  5616. };
  5617. TagStack.prototype.indent_to_tag = function(tag_list) {
  5618. var frame = this._get_frame(tag_list);
  5619. if (frame) {
  5620. this._printer.indent_level = frame.indent_level;
  5621. }
  5622. };
  5623. function Beautifier(source_text, options, js_beautify, css_beautify) {
  5624. //Wrapper function to invoke all the necessary constructors and deal with the output.
  5625. this._source_text = source_text || '';
  5626. options = options || {};
  5627. this._js_beautify = js_beautify;
  5628. this._css_beautify = css_beautify;
  5629. this._tag_stack = null;
  5630. // Allow the setting of language/file-type specific options
  5631. // with inheritance of overall settings
  5632. var optionHtml = new Options(options, 'html');
  5633. this._options = optionHtml;
  5634. this._is_wrap_attributes_force = this._options.wrap_attributes.substr(0, 'force'.length) === 'force';
  5635. this._is_wrap_attributes_force_expand_multiline = (this._options.wrap_attributes === 'force-expand-multiline');
  5636. this._is_wrap_attributes_force_aligned = (this._options.wrap_attributes === 'force-aligned');
  5637. this._is_wrap_attributes_aligned_multiple = (this._options.wrap_attributes === 'aligned-multiple');
  5638. this._is_wrap_attributes_preserve = this._options.wrap_attributes.substr(0, 'preserve'.length) === 'preserve';
  5639. this._is_wrap_attributes_preserve_aligned = (this._options.wrap_attributes === 'preserve-aligned');
  5640. }
  5641. Beautifier.prototype.beautify = function() {
  5642. // if disabled, return the input unchanged.
  5643. if (this._options.disabled) {
  5644. return this._source_text;
  5645. }
  5646. var source_text = this._source_text;
  5647. var eol = this._options.eol;
  5648. if (this._options.eol === 'auto') {
  5649. eol = '\n';
  5650. if (source_text && lineBreak.test(source_text)) {
  5651. eol = source_text.match(lineBreak)[0];
  5652. }
  5653. }
  5654. // HACK: newline parsing inconsistent. This brute force normalizes the input.
  5655. source_text = source_text.replace(allLineBreaks, '\n');
  5656. var baseIndentString = source_text.match(/^[\t ]*/)[0];
  5657. var last_token = {
  5658. text: '',
  5659. type: ''
  5660. };
  5661. var last_tag_token = new TagOpenParserToken();
  5662. var printer = new Printer(this._options, baseIndentString);
  5663. var tokens = new Tokenizer(source_text, this._options).tokenize();
  5664. this._tag_stack = new TagStack(printer);
  5665. var parser_token = null;
  5666. var raw_token = tokens.next();
  5667. while (raw_token.type !== TOKEN.EOF) {
  5668. if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
  5669. parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token, tokens);
  5670. last_tag_token = parser_token;
  5671. } else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
  5672. (raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
  5673. parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, last_token);
  5674. } else if (raw_token.type === TOKEN.TAG_CLOSE) {
  5675. parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);
  5676. } else if (raw_token.type === TOKEN.TEXT) {
  5677. parser_token = this._handle_text(printer, raw_token, last_tag_token);
  5678. } else {
  5679. // This should never happen, but if it does. Print the raw token
  5680. printer.add_raw_token(raw_token);
  5681. }
  5682. last_token = parser_token;
  5683. raw_token = tokens.next();
  5684. }
  5685. var sweet_code = printer._output.get_code(eol);
  5686. return sweet_code;
  5687. };
  5688. Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_token) {
  5689. var parser_token = {
  5690. text: raw_token.text,
  5691. type: raw_token.type
  5692. };
  5693. printer.alignment_size = 0;
  5694. last_tag_token.tag_complete = true;
  5695. printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
  5696. if (last_tag_token.is_unformatted) {
  5697. printer.add_raw_token(raw_token);
  5698. } else {
  5699. if (last_tag_token.tag_start_char === '<') {
  5700. printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before >
  5701. if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
  5702. printer.print_newline(false);
  5703. }
  5704. }
  5705. printer.print_token(raw_token);
  5706. }
  5707. if (last_tag_token.indent_content &&
  5708. !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
  5709. printer.indent();
  5710. // only indent once per opened tag
  5711. last_tag_token.indent_content = false;
  5712. }
  5713. if (!last_tag_token.is_inline_element &&
  5714. !(last_tag_token.is_unformatted || last_tag_token.is_content_unformatted)) {
  5715. printer.set_wrap_point();
  5716. }
  5717. return parser_token;
  5718. };
  5719. Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, last_token) {
  5720. var wrapped = last_tag_token.has_wrapped_attrs;
  5721. var parser_token = {
  5722. text: raw_token.text,
  5723. type: raw_token.type
  5724. };
  5725. printer.set_space_before_token(raw_token.newlines || raw_token.whitespace_before !== '', true);
  5726. if (last_tag_token.is_unformatted) {
  5727. printer.add_raw_token(raw_token);
  5728. } else if (last_tag_token.tag_start_char === '{' && raw_token.type === TOKEN.TEXT) {
  5729. // For the insides of handlebars allow newlines or a single space between open and contents
  5730. if (printer.print_preserved_newlines(raw_token)) {
  5731. raw_token.newlines = 0;
  5732. printer.add_raw_token(raw_token);
  5733. } else {
  5734. printer.print_token(raw_token);
  5735. }
  5736. } else {
  5737. if (raw_token.type === TOKEN.ATTRIBUTE) {
  5738. printer.set_space_before_token(true);
  5739. } else if (raw_token.type === TOKEN.EQUALS) { //no space before =
  5740. printer.set_space_before_token(false);
  5741. } else if (raw_token.type === TOKEN.VALUE && raw_token.previous.type === TOKEN.EQUALS) { //no space before value
  5742. printer.set_space_before_token(false);
  5743. }
  5744. if (raw_token.type === TOKEN.ATTRIBUTE && last_tag_token.tag_start_char === '<') {
  5745. if (this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) {
  5746. printer.traverse_whitespace(raw_token);
  5747. wrapped = wrapped || raw_token.newlines !== 0;
  5748. }
  5749. // Wrap for 'force' options, and if the number of attributes is at least that specified in 'wrap_attributes_min_attrs':
  5750. // 1. always wrap the second and beyond attributes
  5751. // 2. wrap the first attribute only if 'force-expand-multiline' is specified
  5752. if (this._is_wrap_attributes_force &&
  5753. last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
  5754. (last_token.type !== TOKEN.TAG_OPEN || // ie. second attribute and beyond
  5755. this._is_wrap_attributes_force_expand_multiline)) {
  5756. printer.print_newline(false);
  5757. wrapped = true;
  5758. }
  5759. }
  5760. printer.print_token(raw_token);
  5761. wrapped = wrapped || printer.previous_token_wrapped();
  5762. last_tag_token.has_wrapped_attrs = wrapped;
  5763. }
  5764. return parser_token;
  5765. };
  5766. Beautifier.prototype._handle_text = function(printer, raw_token, last_tag_token) {
  5767. var parser_token = {
  5768. text: raw_token.text,
  5769. type: 'TK_CONTENT'
  5770. };
  5771. if (last_tag_token.custom_beautifier_name) { //check if we need to format javascript
  5772. this._print_custom_beatifier_text(printer, raw_token, last_tag_token);
  5773. } else if (last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) {
  5774. printer.add_raw_token(raw_token);
  5775. } else {
  5776. printer.traverse_whitespace(raw_token);
  5777. printer.print_token(raw_token);
  5778. }
  5779. return parser_token;
  5780. };
  5781. Beautifier.prototype._print_custom_beatifier_text = function(printer, raw_token, last_tag_token) {
  5782. var local = this;
  5783. if (raw_token.text !== '') {
  5784. var text = raw_token.text,
  5785. _beautifier,
  5786. script_indent_level = 1,
  5787. pre = '',
  5788. post = '';
  5789. if (last_tag_token.custom_beautifier_name === 'javascript' && typeof this._js_beautify === 'function') {
  5790. _beautifier = this._js_beautify;
  5791. } else if (last_tag_token.custom_beautifier_name === 'css' && typeof this._css_beautify === 'function') {
  5792. _beautifier = this._css_beautify;
  5793. } else if (last_tag_token.custom_beautifier_name === 'html') {
  5794. _beautifier = function(html_source, options) {
  5795. var beautifier = new Beautifier(html_source, options, local._js_beautify, local._css_beautify);
  5796. return beautifier.beautify();
  5797. };
  5798. }
  5799. if (this._options.indent_scripts === "keep") {
  5800. script_indent_level = 0;
  5801. } else if (this._options.indent_scripts === "separate") {
  5802. script_indent_level = -printer.indent_level;
  5803. }
  5804. var indentation = printer.get_full_indent(script_indent_level);
  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. // Handle the case where content is wrapped in a comment or cdata.
  5809. if (last_tag_token.custom_beautifier_name !== 'html' &&
  5810. text[0] === '<' && text.match(/^(<!--|<!\[CDATA\[)/)) {
  5811. var matched = /^(<!--[^\n]*|<!\[CDATA\[)(\n?)([ \t\n]*)([\s\S]*)(-->|]]>)$/.exec(text);
  5812. // if we start to wrap but don't finish, print raw
  5813. if (!matched) {
  5814. printer.add_raw_token(raw_token);
  5815. return;
  5816. }
  5817. pre = indentation + matched[1] + '\n';
  5818. text = matched[4];
  5819. if (matched[5]) {
  5820. post = indentation + matched[5];
  5821. }
  5822. // if there is at least one empty line at the end of this text, strip it
  5823. // we'll be adding one back after the text but before the containing tag.
  5824. text = text.replace(/\n[ \t]*$/, '');
  5825. if (matched[2] || matched[3].indexOf('\n') !== -1) {
  5826. // if the first line of the non-comment text has spaces
  5827. // use that as the basis for indenting in null case.
  5828. matched = matched[3].match(/[ \t]+$/);
  5829. if (matched) {
  5830. raw_token.whitespace_before = matched[0];
  5831. }
  5832. }
  5833. }
  5834. if (text) {
  5835. if (_beautifier) {
  5836. // call the Beautifier if avaliable
  5837. var Child_options = function() {
  5838. this.eol = '\n';
  5839. };
  5840. Child_options.prototype = this._options.raw_options;
  5841. var child_options = new Child_options();
  5842. text = _beautifier(indentation + text, child_options);
  5843. } else {
  5844. // simply indent the string otherwise
  5845. var white = raw_token.whitespace_before;
  5846. if (white) {
  5847. text = text.replace(new RegExp('\n(' + white + ')?', 'g'), '\n');
  5848. }
  5849. text = indentation + text.replace(/\n/g, '\n' + indentation);
  5850. }
  5851. }
  5852. if (pre) {
  5853. if (!text) {
  5854. text = pre + post;
  5855. } else {
  5856. text = pre + text + '\n' + post;
  5857. }
  5858. }
  5859. printer.print_newline(false);
  5860. if (text) {
  5861. raw_token.text = text;
  5862. raw_token.whitespace_before = '';
  5863. raw_token.newlines = 0;
  5864. printer.add_raw_token(raw_token);
  5865. printer.print_newline(true);
  5866. }
  5867. }
  5868. };
  5869. Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token, tokens) {
  5870. var parser_token = this._get_tag_open_token(raw_token);
  5871. if ((last_tag_token.is_unformatted || last_tag_token.is_content_unformatted) &&
  5872. !last_tag_token.is_empty_element &&
  5873. raw_token.type === TOKEN.TAG_OPEN && !parser_token.is_start_tag) {
  5874. // End element tags for unformatted or content_unformatted elements
  5875. // are printed raw to keep any newlines inside them exactly the same.
  5876. printer.add_raw_token(raw_token);
  5877. parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name);
  5878. } else {
  5879. printer.traverse_whitespace(raw_token);
  5880. this._set_tag_position(printer, raw_token, parser_token, last_tag_token, last_token);
  5881. if (!parser_token.is_inline_element) {
  5882. printer.set_wrap_point();
  5883. }
  5884. printer.print_token(raw_token);
  5885. }
  5886. // count the number of attributes
  5887. if (parser_token.is_start_tag && this._is_wrap_attributes_force) {
  5888. var peek_index = 0;
  5889. var peek_token;
  5890. do {
  5891. peek_token = tokens.peek(peek_index);
  5892. if (peek_token.type === TOKEN.ATTRIBUTE) {
  5893. parser_token.attr_count += 1;
  5894. }
  5895. peek_index += 1;
  5896. } while (peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
  5897. }
  5898. //indent attributes an auto, forced, aligned or forced-align line-wrap
  5899. if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {
  5900. parser_token.alignment_size = raw_token.text.length + 1;
  5901. }
  5902. if (!parser_token.tag_complete && !parser_token.is_unformatted) {
  5903. printer.alignment_size = parser_token.alignment_size;
  5904. }
  5905. return parser_token;
  5906. };
  5907. var TagOpenParserToken = function(parent, raw_token) {
  5908. this.parent = parent || null;
  5909. this.text = '';
  5910. this.type = 'TK_TAG_OPEN';
  5911. this.tag_name = '';
  5912. this.is_inline_element = false;
  5913. this.is_unformatted = false;
  5914. this.is_content_unformatted = false;
  5915. this.is_empty_element = false;
  5916. this.is_start_tag = false;
  5917. this.is_end_tag = false;
  5918. this.indent_content = false;
  5919. this.multiline_content = false;
  5920. this.custom_beautifier_name = null;
  5921. this.start_tag_token = null;
  5922. this.attr_count = 0;
  5923. this.has_wrapped_attrs = false;
  5924. this.alignment_size = 0;
  5925. this.tag_complete = false;
  5926. this.tag_start_char = '';
  5927. this.tag_check = '';
  5928. if (!raw_token) {
  5929. this.tag_complete = true;
  5930. } else {
  5931. var tag_check_match;
  5932. this.tag_start_char = raw_token.text[0];
  5933. this.text = raw_token.text;
  5934. if (this.tag_start_char === '<') {
  5935. tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
  5936. this.tag_check = tag_check_match ? tag_check_match[1] : '';
  5937. } else {
  5938. tag_check_match = raw_token.text.match(/^{{~?(?:[\^]|#\*?)?([^\s}]+)/);
  5939. this.tag_check = tag_check_match ? tag_check_match[1] : '';
  5940. // handle "{{#> myPartial}}" or "{{~#> myPartial}}"
  5941. if ((raw_token.text.startsWith('{{#>') || raw_token.text.startsWith('{{~#>')) && this.tag_check[0] === '>') {
  5942. if (this.tag_check === '>' && raw_token.next !== null) {
  5943. this.tag_check = raw_token.next.text.split(' ')[0];
  5944. } else {
  5945. this.tag_check = raw_token.text.split('>')[1];
  5946. }
  5947. }
  5948. }
  5949. this.tag_check = this.tag_check.toLowerCase();
  5950. if (raw_token.type === TOKEN.COMMENT) {
  5951. this.tag_complete = true;
  5952. }
  5953. this.is_start_tag = this.tag_check.charAt(0) !== '/';
  5954. this.tag_name = !this.is_start_tag ? this.tag_check.substr(1) : this.tag_check;
  5955. this.is_end_tag = !this.is_start_tag ||
  5956. (raw_token.closed && raw_token.closed.text === '/>');
  5957. // if whitespace handler ~ included (i.e. {{~#if true}}), handlebars tags start at pos 3 not pos 2
  5958. var handlebar_starts = 2;
  5959. if (this.tag_start_char === '{' && this.text.length >= 3) {
  5960. if (this.text.charAt(2) === '~') {
  5961. handlebar_starts = 3;
  5962. }
  5963. }
  5964. // handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
  5965. this.is_end_tag = this.is_end_tag ||
  5966. (this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
  5967. }
  5968. };
  5969. Beautifier.prototype._get_tag_open_token = function(raw_token) { //function to get a full tag and parse its type
  5970. var parser_token = new TagOpenParserToken(this._tag_stack.get_parser_token(), raw_token);
  5971. parser_token.alignment_size = this._options.wrap_attributes_indent_size;
  5972. parser_token.is_end_tag = parser_token.is_end_tag ||
  5973. in_array(parser_token.tag_check, this._options.void_elements);
  5974. parser_token.is_empty_element = parser_token.tag_complete ||
  5975. (parser_token.is_start_tag && parser_token.is_end_tag);
  5976. parser_token.is_unformatted = !parser_token.tag_complete && in_array(parser_token.tag_check, this._options.unformatted);
  5977. parser_token.is_content_unformatted = !parser_token.is_empty_element && in_array(parser_token.tag_check, this._options.content_unformatted);
  5978. 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 === '{';
  5979. return parser_token;
  5980. };
  5981. Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_token, last_tag_token, last_token) {
  5982. if (!parser_token.is_empty_element) {
  5983. if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
  5984. parser_token.start_tag_token = this._tag_stack.try_pop(parser_token.tag_name); //remove it and all ancestors
  5985. } else { // it's a start-tag
  5986. // check if this tag is starting an element that has optional end element
  5987. // and do an ending needed
  5988. if (this._do_optional_end_element(parser_token)) {
  5989. if (!parser_token.is_inline_element) {
  5990. printer.print_newline(false);
  5991. }
  5992. }
  5993. this._tag_stack.record_tag(parser_token); //push it on the tag stack
  5994. if ((parser_token.tag_name === 'script' || parser_token.tag_name === 'style') &&
  5995. !(parser_token.is_unformatted || parser_token.is_content_unformatted)) {
  5996. parser_token.custom_beautifier_name = get_custom_beautifier_name(parser_token.tag_check, raw_token);
  5997. }
  5998. }
  5999. }
  6000. if (in_array(parser_token.tag_check, this._options.extra_liners)) { //check if this double needs an extra line
  6001. printer.print_newline(false);
  6002. if (!printer._output.just_added_blankline()) {
  6003. printer.print_newline(true);
  6004. }
  6005. }
  6006. if (parser_token.is_empty_element) { //if this tag name is a single tag type (either in the list or has a closing /)
  6007. // if you hit an else case, reset the indent level if you are inside an:
  6008. // 'if', 'unless', or 'each' block.
  6009. if (parser_token.tag_start_char === '{' && parser_token.tag_check === 'else') {
  6010. this._tag_stack.indent_to_tag(['if', 'unless', 'each']);
  6011. parser_token.indent_content = true;
  6012. // Don't add a newline if opening {{#if}} tag is on the current line
  6013. var foundIfOnCurrentLine = printer.current_line_has_match(/{{#if/);
  6014. if (!foundIfOnCurrentLine) {
  6015. printer.print_newline(false);
  6016. }
  6017. }
  6018. // Don't add a newline before elements that should remain where they are.
  6019. if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE &&
  6020. last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) ; else {
  6021. if (!(parser_token.is_inline_element || parser_token.is_unformatted)) {
  6022. printer.print_newline(false);
  6023. }
  6024. this._calcluate_parent_multiline(printer, parser_token);
  6025. }
  6026. } else if (parser_token.is_end_tag) { //this tag is a double tag so check for tag-ending
  6027. var do_end_expand = false;
  6028. // deciding whether a block is multiline should not be this hard
  6029. do_end_expand = parser_token.start_tag_token && parser_token.start_tag_token.multiline_content;
  6030. do_end_expand = do_end_expand || (!parser_token.is_inline_element &&
  6031. !(last_tag_token.is_inline_element || last_tag_token.is_unformatted) &&
  6032. !(last_token.type === TOKEN.TAG_CLOSE && parser_token.start_tag_token === last_tag_token) &&
  6033. last_token.type !== 'TK_CONTENT'
  6034. );
  6035. if (parser_token.is_content_unformatted || parser_token.is_unformatted) {
  6036. do_end_expand = false;
  6037. }
  6038. if (do_end_expand) {
  6039. printer.print_newline(false);
  6040. }
  6041. } else { // it's a start-tag
  6042. parser_token.indent_content = !parser_token.custom_beautifier_name;
  6043. if (parser_token.tag_start_char === '<') {
  6044. if (parser_token.tag_name === 'html') {
  6045. parser_token.indent_content = this._options.indent_inner_html;
  6046. } else if (parser_token.tag_name === 'head') {
  6047. parser_token.indent_content = this._options.indent_head_inner_html;
  6048. } else if (parser_token.tag_name === 'body') {
  6049. parser_token.indent_content = this._options.indent_body_inner_html;
  6050. }
  6051. }
  6052. if (!(parser_token.is_inline_element || parser_token.is_unformatted) &&
  6053. (last_token.type !== 'TK_CONTENT' || parser_token.is_content_unformatted)) {
  6054. printer.print_newline(false);
  6055. }
  6056. this._calcluate_parent_multiline(printer, parser_token);
  6057. }
  6058. };
  6059. Beautifier.prototype._calcluate_parent_multiline = function(printer, parser_token) {
  6060. if (parser_token.parent && printer._output.just_added_newline() &&
  6061. !((parser_token.is_inline_element || parser_token.is_unformatted) && parser_token.parent.is_inline_element)) {
  6062. parser_token.parent.multiline_content = true;
  6063. }
  6064. };
  6065. //To be used for <p> tag special case:
  6066. 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'];
  6067. var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
  6068. Beautifier.prototype._do_optional_end_element = function(parser_token) {
  6069. var result = null;
  6070. // NOTE: cases of "if there is no more content in the parent element"
  6071. // are handled automatically by the beautifier.
  6072. // It assumes parent or ancestor close tag closes all children.
  6073. // https://www.w3.org/TR/html5/syntax.html#optional-tags
  6074. if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
  6075. return;
  6076. }
  6077. if (parser_token.tag_name === 'body') {
  6078. // A head element’s end tag may be omitted if the head element is not immediately followed by a space character or a comment.
  6079. result = result || this._tag_stack.try_pop('head');
  6080. //} else if (parser_token.tag_name === 'body') {
  6081. // DONE: A body element’s end tag may be omitted if the body element is not immediately followed by a comment.
  6082. } else if (parser_token.tag_name === 'li') {
  6083. // 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.
  6084. result = result || this._tag_stack.try_pop('li', ['ol', 'ul', 'menu']);
  6085. } else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {
  6086. // 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.
  6087. // A dt element’s end tag may be omitted if the dt element is immediately followed by another dt element or a dd element.
  6088. result = result || this._tag_stack.try_pop('dt', ['dl']);
  6089. result = result || this._tag_stack.try_pop('dd', ['dl']);
  6090. } else if (parser_token.parent.tag_name === 'p' && p_closers.indexOf(parser_token.tag_name) !== -1) {
  6091. // IMPORTANT: this else-if works because p_closers has no overlap with any other element we look for in this method
  6092. // 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.
  6093. // To do this right, this needs to be coded as an inclusion of the inverse of the exclusion above.
  6094. // But to start with (if we ignore "autonomous custom elements") the exclusion would be fine.
  6095. var p_parent = parser_token.parent.parent;
  6096. if (!p_parent || p_parent_excludes.indexOf(p_parent.tag_name) === -1) {
  6097. result = result || this._tag_stack.try_pop('p');
  6098. }
  6099. } else if (parser_token.tag_name === 'rp' || parser_token.tag_name === 'rt') {
  6100. // 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.
  6101. // 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.
  6102. result = result || this._tag_stack.try_pop('rt', ['ruby', 'rtc']);
  6103. result = result || this._tag_stack.try_pop('rp', ['ruby', 'rtc']);
  6104. } else if (parser_token.tag_name === 'optgroup') {
  6105. // 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.
  6106. // 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.
  6107. result = result || this._tag_stack.try_pop('optgroup', ['select']);
  6108. //result = result || this._tag_stack.try_pop('option', ['select']);
  6109. } else if (parser_token.tag_name === 'option') {
  6110. // 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.
  6111. result = result || this._tag_stack.try_pop('option', ['select', 'datalist', 'optgroup']);
  6112. } else if (parser_token.tag_name === 'colgroup') {
  6113. // 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.
  6114. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  6115. result = result || this._tag_stack.try_pop('caption', ['table']);
  6116. } else if (parser_token.tag_name === 'thead') {
  6117. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  6118. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  6119. result = result || this._tag_stack.try_pop('caption', ['table']);
  6120. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  6121. //} else if (parser_token.tag_name === 'caption') {
  6122. // 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.
  6123. } else if (parser_token.tag_name === 'tbody' || parser_token.tag_name === 'tfoot') {
  6124. // A thead element’s end tag may be omitted if the thead element is immediately followed by a tbody or tfoot element.
  6125. // 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.
  6126. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  6127. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  6128. result = result || this._tag_stack.try_pop('caption', ['table']);
  6129. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  6130. result = result || this._tag_stack.try_pop('thead', ['table']);
  6131. result = result || this._tag_stack.try_pop('tbody', ['table']);
  6132. //} else if (parser_token.tag_name === 'tfoot') {
  6133. // DONE: A tfoot element’s end tag may be omitted if there is no more content in the parent element.
  6134. } else if (parser_token.tag_name === 'tr') {
  6135. // 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.
  6136. // A colgroup element's end tag may be ommitted if a thead, tfoot, tbody, or tr element is started.
  6137. // A caption element's end tag may be ommitted if a colgroup, thead, tfoot, tbody, or tr element is started.
  6138. result = result || this._tag_stack.try_pop('caption', ['table']);
  6139. result = result || this._tag_stack.try_pop('colgroup', ['table']);
  6140. result = result || this._tag_stack.try_pop('tr', ['table', 'thead', 'tbody', 'tfoot']);
  6141. } else if (parser_token.tag_name === 'th' || parser_token.tag_name === 'td') {
  6142. // 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.
  6143. // 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.
  6144. result = result || this._tag_stack.try_pop('td', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
  6145. result = result || this._tag_stack.try_pop('th', ['table', 'thead', 'tbody', 'tfoot', 'tr']);
  6146. }
  6147. // Start element omission not handled currently
  6148. // 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.
  6149. // 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.)
  6150. // 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.)
  6151. // Fix up the parent of the parser token
  6152. parser_token.parent = this._tag_stack.get_parser_token();
  6153. return result;
  6154. };
  6155. beautifier.Beautifier = Beautifier;
  6156. return beautifier;
  6157. }
  6158. /*jshint node:true */
  6159. var hasRequiredHtml;
  6160. function requireHtml () {
  6161. if (hasRequiredHtml) return html.exports;
  6162. hasRequiredHtml = 1;
  6163. var Beautifier = requireBeautifier().Beautifier,
  6164. Options = requireOptions().Options;
  6165. function style_html(html_source, options, js_beautify, css_beautify) {
  6166. var beautifier = new Beautifier(html_source, options, js_beautify, css_beautify);
  6167. return beautifier.beautify();
  6168. }
  6169. html.exports = style_html;
  6170. html.exports.defaultOptions = function() {
  6171. return new Options();
  6172. };
  6173. return html.exports;
  6174. }
  6175. /*jshint node:true */
  6176. var hasRequiredSrc;
  6177. function requireSrc () {
  6178. if (hasRequiredSrc) return src;
  6179. hasRequiredSrc = 1;
  6180. var js_beautify = requireJavascript();
  6181. var css_beautify = requireCss();
  6182. var html_beautify = requireHtml();
  6183. function style_html(html_source, options, js, css) {
  6184. js = js || js_beautify;
  6185. css = css || css_beautify;
  6186. return html_beautify(html_source, options, js, css);
  6187. }
  6188. style_html.defaultOptions = html_beautify.defaultOptions;
  6189. src.js = js_beautify;
  6190. src.css = css_beautify;
  6191. src.html = style_html;
  6192. return src;
  6193. }
  6194. /*jshint node:true */
  6195. (function (module) {
  6196. /**
  6197. The following batches are equivalent:
  6198. var beautify_js = require('js-beautify');
  6199. var beautify_js = require('js-beautify').js;
  6200. var beautify_js = require('js-beautify').js_beautify;
  6201. var beautify_css = require('js-beautify').css;
  6202. var beautify_css = require('js-beautify').css_beautify;
  6203. var beautify_html = require('js-beautify').html;
  6204. var beautify_html = require('js-beautify').html_beautify;
  6205. All methods returned accept two arguments, the source string and an options object.
  6206. **/
  6207. function get_beautify(js_beautify, css_beautify, html_beautify) {
  6208. // the default is js
  6209. var beautify = function(src, config) {
  6210. return js_beautify.js_beautify(src, config);
  6211. };
  6212. // short aliases
  6213. beautify.js = js_beautify.js_beautify;
  6214. beautify.css = css_beautify.css_beautify;
  6215. beautify.html = html_beautify.html_beautify;
  6216. // legacy aliases
  6217. beautify.js_beautify = js_beautify.js_beautify;
  6218. beautify.css_beautify = css_beautify.css_beautify;
  6219. beautify.html_beautify = html_beautify.html_beautify;
  6220. return beautify;
  6221. }
  6222. {
  6223. (function(mod) {
  6224. var beautifier = requireSrc();
  6225. beautifier.js_beautify = beautifier.js;
  6226. beautifier.css_beautify = beautifier.css;
  6227. beautifier.html_beautify = beautifier.html;
  6228. mod.exports = get_beautify(beautifier, beautifier, beautifier);
  6229. })(module);
  6230. }
  6231. } (js));
  6232. var jsExports = js.exports;
  6233. var beautify = /*@__PURE__*/getDefaultExportFromCjs(jsExports);
  6234. var BaseWrapper = /** @class */ (function () {
  6235. function BaseWrapper(element) {
  6236. var _this = this;
  6237. this.isDisabled = function () {
  6238. var validTagsToBeDisabled = [
  6239. 'BUTTON',
  6240. 'COMMAND',
  6241. 'FIELDSET',
  6242. 'KEYGEN',
  6243. 'OPTGROUP',
  6244. 'OPTION',
  6245. 'SELECT',
  6246. 'TEXTAREA',
  6247. 'INPUT'
  6248. ];
  6249. var hasDisabledAttribute = _this.attributes().disabled !== undefined;
  6250. var elementCanBeDisabled = isElement(_this.element) &&
  6251. validTagsToBeDisabled.includes(_this.element.tagName);
  6252. return hasDisabledAttribute && elementCanBeDisabled;
  6253. };
  6254. this.wrapperElement = element;
  6255. }
  6256. Object.defineProperty(BaseWrapper.prototype, "element", {
  6257. get: function () {
  6258. return this.wrapperElement;
  6259. },
  6260. enumerable: false,
  6261. configurable: true
  6262. });
  6263. BaseWrapper.prototype.findAllDOMElements = function (selector) {
  6264. var elementRootNodes = this.getRootNodes().filter(isElement);
  6265. if (elementRootNodes.length === 0)
  6266. return [];
  6267. var result = __spreadArray([], elementRootNodes.filter(function (node) { return node.matches(selector); }), true);
  6268. elementRootNodes.forEach(function (rootNode) {
  6269. result.push.apply(result, Array.from(rootNode.querySelectorAll(selector)));
  6270. });
  6271. return result;
  6272. };
  6273. BaseWrapper.prototype.find = function (selector) {
  6274. if (typeof selector === 'object' && 'ref' in selector) {
  6275. var currentComponent = this.getCurrentComponent();
  6276. if (!currentComponent) {
  6277. return createWrapperError('DOMWrapper');
  6278. }
  6279. var result = currentComponent.refs[selector.ref];
  6280. // When using ref inside v-for, then refs contains array of component instances and nodes
  6281. if (Array.isArray(result)) {
  6282. result = result.length ? result[0] : undefined;
  6283. }
  6284. if (result instanceof Node) {
  6285. return createDOMWrapper(result);
  6286. }
  6287. else {
  6288. return createWrapperError('DOMWrapper');
  6289. }
  6290. }
  6291. var elements = this.findAll(selector);
  6292. if (elements.length > 0) {
  6293. return elements[0];
  6294. }
  6295. return createWrapperError('DOMWrapper');
  6296. };
  6297. BaseWrapper.prototype.findComponent = function (selector) {
  6298. var currentComponent = this.getCurrentComponent();
  6299. if (!currentComponent) {
  6300. return createWrapperError('VueWrapper');
  6301. }
  6302. if (typeof selector === 'object' && 'ref' in selector) {
  6303. var result_1 = currentComponent.refs[selector.ref];
  6304. // When using ref inside v-for, then refs contains array of component instances
  6305. if (Array.isArray(result_1)) {
  6306. result_1 = result_1.length ? result_1[0] : undefined;
  6307. }
  6308. if (result_1 && !(result_1 instanceof HTMLElement)) {
  6309. return createVueWrapper(null, result_1);
  6310. }
  6311. else {
  6312. return createWrapperError('VueWrapper');
  6313. }
  6314. }
  6315. if (matches(currentComponent.vnode, selector) &&
  6316. this.element.contains(currentComponent.vnode.el)) {
  6317. return createVueWrapper(null, currentComponent.subTree.component
  6318. ? currentComponent.subTree.component.proxy
  6319. : currentComponent.proxy);
  6320. }
  6321. var result = this.findAllComponents(selector)[0];
  6322. return result !== null && result !== void 0 ? result : createWrapperError('VueWrapper');
  6323. };
  6324. BaseWrapper.prototype.findAllComponents = function (selector) {
  6325. var currentComponent = this.getCurrentComponent();
  6326. if (!currentComponent) {
  6327. return [];
  6328. }
  6329. var results = find(currentComponent.subTree, selector);
  6330. return results.map(function (c) {
  6331. return c.proxy
  6332. ? createVueWrapper(null, c.proxy)
  6333. : createDOMWrapper(c.vnode.el);
  6334. });
  6335. };
  6336. BaseWrapper.prototype.html = function (options) {
  6337. var stringNodes = this.getRootNodes().map(function (node) { return stringifyNode(node); });
  6338. if (options === null || options === void 0 ? void 0 : options.raw)
  6339. return stringNodes.join('');
  6340. return stringNodes
  6341. .map(function (node) {
  6342. return beautify.html(node, {
  6343. unformatted: ['code', 'pre', 'em', 'strong', 'span'],
  6344. indent_inner_html: true,
  6345. indent_size: 2,
  6346. inline_custom_elements: false
  6347. // TODO the cast can be removed when @types/js-beautify will be up-to-date
  6348. });
  6349. })
  6350. .join('\n');
  6351. };
  6352. BaseWrapper.prototype.classes = function (className) {
  6353. var classes = isElement(this.element)
  6354. ? Array.from(this.element.classList)
  6355. : [];
  6356. if (className)
  6357. return classes.includes(className);
  6358. return classes;
  6359. };
  6360. BaseWrapper.prototype.attributes = function (key) {
  6361. var attributeMap = {};
  6362. if (isElement(this.element)) {
  6363. var attributes = Array.from(this.element.attributes);
  6364. for (var _i = 0, attributes_1 = attributes; _i < attributes_1.length; _i++) {
  6365. var attribute = attributes_1[_i];
  6366. attributeMap[attribute.localName] = attribute.value;
  6367. }
  6368. }
  6369. return key ? attributeMap[key] : attributeMap;
  6370. };
  6371. BaseWrapper.prototype.text = function () {
  6372. return this.getRootNodes().map(textContent).join('');
  6373. };
  6374. BaseWrapper.prototype.exists = function () {
  6375. return true;
  6376. };
  6377. BaseWrapper.prototype.get = function (selector) {
  6378. var result = this.find(selector);
  6379. if (result.exists()) {
  6380. return result;
  6381. }
  6382. throw new Error("Unable to get ".concat(selector, " within: ").concat(this.html()));
  6383. };
  6384. BaseWrapper.prototype.getComponent = function (selector) {
  6385. var result = this.findComponent(selector);
  6386. if (result.exists()) {
  6387. return result;
  6388. }
  6389. var message = 'Unable to get ';
  6390. if (typeof selector === 'string') {
  6391. message += "component with selector ".concat(selector);
  6392. }
  6393. else if ('name' in selector) {
  6394. message += "component with name ".concat(selector.name);
  6395. }
  6396. else if ('ref' in selector) {
  6397. message += "component with ref ".concat(selector.ref);
  6398. }
  6399. else {
  6400. message += 'specified component';
  6401. }
  6402. message += " within: ".concat(this.html());
  6403. throw new Error(message);
  6404. };
  6405. BaseWrapper.prototype.isVisible = function () {
  6406. return isElement(this.element) && isElementVisible(this.element);
  6407. };
  6408. BaseWrapper.prototype.trigger = function (eventString, options) {
  6409. return __awaiter(this, void 0, void 0, function () {
  6410. var event_1;
  6411. return __generator(this, function (_a) {
  6412. if (options && options['target']) {
  6413. throw Error("[vue-test-utils]: you cannot set the target value of an event. See the notes section " +
  6414. "of the docs for more details\u2014" +
  6415. "https://vue-test-utils.vuejs.org/api/wrapper/trigger.html");
  6416. }
  6417. if (this.element && !this.isDisabled()) {
  6418. event_1 = createDOMEvent(eventString, options);
  6419. // see https://github.com/vuejs/test-utils/issues/1854
  6420. // fakeTimers provoke an issue as Date.now() always return the same value
  6421. // and Vue relies on it to determine if the handler should be invoked
  6422. // see https://github.com/vuejs/core/blob/5ee40532a63e0b792e0c1eccf3cf68546a4e23e9/packages/runtime-dom/src/modules/events.ts#L100-L104
  6423. // we workaround this issue by manually setting _vts to Date.now() + 1
  6424. // thus making sure the event handler is invoked
  6425. event_1._vts = Date.now() + 1;
  6426. this.element.dispatchEvent(event_1);
  6427. }
  6428. return [2 /*return*/, Vue.nextTick()];
  6429. });
  6430. });
  6431. };
  6432. return BaseWrapper;
  6433. }());
  6434. var DOMWrapper = /** @class */ (function (_super) {
  6435. __extends(DOMWrapper, _super);
  6436. function DOMWrapper(element) {
  6437. var _this = this;
  6438. if (!element) {
  6439. return createWrapperError('DOMWrapper');
  6440. }
  6441. _this = _super.call(this, element) || this;
  6442. // plugins hook
  6443. config.plugins.DOMWrapper.extend(_this);
  6444. return _this;
  6445. }
  6446. DOMWrapper.prototype.getRootNodes = function () {
  6447. return [this.wrapperElement];
  6448. };
  6449. DOMWrapper.prototype.getCurrentComponent = function () {
  6450. var _a;
  6451. var component = this.element.__vueParentComponent;
  6452. while (((_a = component === null || component === void 0 ? void 0 : component.parent) === null || _a === void 0 ? void 0 : _a.vnode.el) === this.element) {
  6453. component = component.parent;
  6454. }
  6455. return component;
  6456. };
  6457. DOMWrapper.prototype.find = function (selector) {
  6458. var result = _super.prototype.find.call(this, selector);
  6459. if (result.exists() && isRefSelector(selector)) {
  6460. return this.element.contains(result.element)
  6461. ? result
  6462. : createWrapperError('DOMWrapper');
  6463. }
  6464. return result;
  6465. };
  6466. DOMWrapper.prototype.findAll = function (selector) {
  6467. if (!(this.wrapperElement instanceof Element)) {
  6468. return [];
  6469. }
  6470. return Array.from(this.wrapperElement.querySelectorAll(selector), createDOMWrapper);
  6471. };
  6472. DOMWrapper.prototype.findAllComponents = function (selector) {
  6473. var _this = this;
  6474. var results = _super.prototype.findAllComponents.call(this, selector);
  6475. return results.filter(function (r) { return _this.element.contains(r.element); });
  6476. };
  6477. DOMWrapper.prototype.setChecked = function () {
  6478. return __awaiter(this, arguments, void 0, function (checked) {
  6479. var element, type;
  6480. if (checked === void 0) { checked = true; }
  6481. return __generator(this, function (_a) {
  6482. element = this.element;
  6483. type = this.attributes().type;
  6484. if (type === 'radio' && !checked) {
  6485. throw Error("wrapper.setChecked() cannot be called with parameter false on a '<input type=\"radio\" /> element.");
  6486. }
  6487. // we do not want to trigger an event if the user
  6488. // attempting set the same value twice
  6489. // this is because in a browser setting checked = true when it is
  6490. // already true is a no-op; no change event is triggered
  6491. if (checked === element.checked) {
  6492. return [2 /*return*/];
  6493. }
  6494. element.checked = checked;
  6495. this.trigger('input');
  6496. return [2 /*return*/, this.trigger('change')];
  6497. });
  6498. });
  6499. };
  6500. DOMWrapper.prototype.setValue = function (value) {
  6501. var element = this.element;
  6502. var tagName = element.tagName;
  6503. var type = this.attributes().type;
  6504. if (tagName === 'OPTION') {
  6505. this.setSelected();
  6506. return Promise.resolve();
  6507. }
  6508. else if (tagName === 'INPUT' && type === 'checkbox') {
  6509. return this.setChecked(value);
  6510. }
  6511. else if (tagName === 'INPUT' && type === 'radio') {
  6512. return this.setChecked(value);
  6513. }
  6514. else if (tagName === 'SELECT') {
  6515. if (Array.isArray(value)) {
  6516. var selectElement = element;
  6517. for (var i = 0; i < selectElement.options.length; i++) {
  6518. var option = selectElement.options[i];
  6519. option.selected = value.includes(option.value);
  6520. }
  6521. }
  6522. else {
  6523. element.value = value;
  6524. }
  6525. this.trigger('input');
  6526. return this.trigger('change');
  6527. }
  6528. else if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
  6529. element.value = value;
  6530. this.trigger('input');
  6531. // trigger `change` for `v-model.lazy`
  6532. return this.trigger('change');
  6533. }
  6534. else {
  6535. throw Error("wrapper.setValue() cannot be called on ".concat(tagName));
  6536. }
  6537. };
  6538. DOMWrapper.prototype.setSelected = function () {
  6539. var element = this.element;
  6540. if (element.selected) {
  6541. return;
  6542. }
  6543. // todo - review all non-null assertion operators in project
  6544. // search globally for `!.` and with regex `!$`
  6545. element.selected = true;
  6546. var parentElement = element.parentElement;
  6547. if (parentElement.tagName === 'OPTGROUP') {
  6548. parentElement = parentElement.parentElement;
  6549. }
  6550. var parentWrapper = new DOMWrapper(parentElement);
  6551. parentWrapper.trigger('input');
  6552. return parentWrapper.trigger('change');
  6553. };
  6554. return DOMWrapper;
  6555. }(BaseWrapper));
  6556. registerFactory(WrapperType.DOMWrapper, function (element) { return new DOMWrapper(element); });
  6557. function getRootNodes(vnode) {
  6558. if (vnode.shapeFlag & 1 /* ShapeFlags.ELEMENT */) {
  6559. return [vnode.el];
  6560. }
  6561. else if (vnode.shapeFlag & 6 /* ShapeFlags.COMPONENT */) {
  6562. var subTree = vnode.component.subTree;
  6563. return getRootNodes(subTree);
  6564. }
  6565. else if (vnode.shapeFlag & 128 /* ShapeFlags.SUSPENSE */) {
  6566. return getRootNodes(vnode.suspense.activeBranch);
  6567. }
  6568. else if (vnode.shapeFlag &
  6569. (8 /* ShapeFlags.TEXT_CHILDREN */ | 64 /* ShapeFlags.TELEPORT */)) {
  6570. // static node optimization, subTree.children will be static string and will not help us
  6571. var result = [vnode.el];
  6572. if (vnode.anchor) {
  6573. var currentNode = result[0].nextSibling;
  6574. while (currentNode && currentNode.previousSibling !== vnode.anchor) {
  6575. result.push(currentNode);
  6576. currentNode = currentNode.nextSibling;
  6577. }
  6578. }
  6579. return result;
  6580. }
  6581. else if (vnode.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6582. var children = vnode.children.flat();
  6583. return children
  6584. .flatMap(function (vnode) { return getRootNodes(vnode); })
  6585. .filter(isNotNullOrUndefined);
  6586. }
  6587. // Missing cases which do not need special handling:
  6588. // ShapeFlags.SLOTS_CHILDREN comes with ShapeFlags.ELEMENT
  6589. // Will hit this default when ShapeFlags is 0
  6590. // This is the case for example for unresolved async component without loader
  6591. return [];
  6592. }
  6593. var events = {};
  6594. function emitted(vm, eventName) {
  6595. var cid = vm.$.uid;
  6596. var vmEvents = events[cid] || {};
  6597. if (eventName) {
  6598. return vmEvents ? vmEvents[eventName] : undefined;
  6599. }
  6600. return vmEvents;
  6601. }
  6602. var attachEmitListener = function () {
  6603. var target = getGlobalThis();
  6604. // override emit to capture events when devtools is defined
  6605. if (target.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
  6606. var _emit_1 = target.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit;
  6607. target.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit = function (eventType) {
  6608. var payload = [];
  6609. for (var _i = 1; _i < arguments.length; _i++) {
  6610. payload[_i - 1] = arguments[_i];
  6611. }
  6612. _emit_1.call.apply(_emit_1, __spreadArray([target.__VUE_DEVTOOLS_GLOBAL_HOOK__, eventType], payload, false));
  6613. captureDevtoolsVueComponentEmitEvent(eventType, payload);
  6614. };
  6615. }
  6616. else {
  6617. // use devtools to capture this "emit"
  6618. Vue.setDevtoolsHook(createDevTools(), {});
  6619. }
  6620. };
  6621. function captureDevtoolsVueComponentEmitEvent(eventType, payload) {
  6622. if (eventType === "component:emit" /* DevtoolsHooks.COMPONENT_EMIT */) {
  6623. payload[0]; var componentVM = payload[1], event_1 = payload[2], eventArgs = payload[3];
  6624. recordEvent(componentVM, event_1, eventArgs);
  6625. }
  6626. }
  6627. // devtools hook only catches Vue component custom events
  6628. function createDevTools() {
  6629. return {
  6630. emit: function (eventType) {
  6631. var payload = [];
  6632. for (var _i = 1; _i < arguments.length; _i++) {
  6633. payload[_i - 1] = arguments[_i];
  6634. }
  6635. captureDevtoolsVueComponentEmitEvent(eventType, payload);
  6636. }
  6637. };
  6638. }
  6639. var recordEvent = function (vm, event, args) {
  6640. // Functional component wrapper creates a parent component
  6641. var wrapperVm = vm;
  6642. while (typeof (wrapperVm === null || wrapperVm === void 0 ? void 0 : wrapperVm.type) === 'function')
  6643. wrapperVm = wrapperVm.parent;
  6644. var cid = wrapperVm.uid;
  6645. if (!(cid in events)) {
  6646. events[cid] = {};
  6647. }
  6648. if (!(event in events[cid])) {
  6649. events[cid][event] = [];
  6650. }
  6651. // Record the event message sent by the emit
  6652. events[cid][event].push(args);
  6653. };
  6654. var removeEventHistory = function (vm) {
  6655. var cid = vm.$.uid;
  6656. delete events[cid];
  6657. };
  6658. /**
  6659. * Creates a proxy around the VM instance.
  6660. * This proxy returns the value from the setupState if there is one, or the one from the VM if not.
  6661. * See https://github.com/vuejs/core/issues/7103
  6662. */
  6663. function createVMProxy(vm, setupState) {
  6664. return new Proxy(vm, {
  6665. get: function (vm, key, receiver) {
  6666. if (vm.$.exposed && vm.$.exposeProxy && key in vm.$.exposeProxy) {
  6667. // first if the key is exposed
  6668. return Reflect.get(vm.$.exposeProxy, key, receiver);
  6669. }
  6670. else if (key in setupState) {
  6671. // second if the key is acccessible from the setupState
  6672. return Reflect.get(setupState, key, receiver);
  6673. }
  6674. else {
  6675. // vm.$.ctx is the internal context of the vm
  6676. // with all variables, methods and props
  6677. return vm.$.ctx[key];
  6678. }
  6679. },
  6680. set: function (vm, key, value, receiver) {
  6681. if (key in setupState) {
  6682. return Reflect.set(setupState, key, value, receiver);
  6683. }
  6684. else {
  6685. return Reflect.set(vm, key, value, receiver);
  6686. }
  6687. },
  6688. has: function (vm, property) {
  6689. return Reflect.has(setupState, property) || Reflect.has(vm, property);
  6690. },
  6691. defineProperty: function (vm, key, attributes) {
  6692. if (key in setupState) {
  6693. return Reflect.defineProperty(setupState, key, attributes);
  6694. }
  6695. else {
  6696. return Reflect.defineProperty(vm, key, attributes);
  6697. }
  6698. },
  6699. getOwnPropertyDescriptor: function (vm, property) {
  6700. if (property in setupState) {
  6701. return Reflect.getOwnPropertyDescriptor(setupState, property);
  6702. }
  6703. else {
  6704. return Reflect.getOwnPropertyDescriptor(vm, property);
  6705. }
  6706. },
  6707. deleteProperty: function (vm, property) {
  6708. if (property in setupState) {
  6709. return Reflect.deleteProperty(setupState, property);
  6710. }
  6711. else {
  6712. return Reflect.deleteProperty(vm, property);
  6713. }
  6714. }
  6715. });
  6716. }
  6717. var VueWrapper = /** @class */ (function (_super) {
  6718. __extends(VueWrapper, _super);
  6719. function VueWrapper(app, vm, setProps) {
  6720. var _this = _super.call(this, vm === null || vm === void 0 ? void 0 : vm.$el) || this;
  6721. _this.cleanUpCallbacks = [];
  6722. _this.__app = app;
  6723. // root is null on functional components
  6724. _this.rootVM = vm === null || vm === void 0 ? void 0 : vm.$root;
  6725. // `vm.$.setupState` is what the template has access to
  6726. // so even if the component is closed (as they are by default for `script setup`)
  6727. // a test will still be able to do something like
  6728. // `expect(wrapper.vm.count).toBe(1)`
  6729. // if we return it as `vm`
  6730. // This does not work for functional components though (as they have no vm)
  6731. // or for components with a setup that returns a render function (as they have an empty proxy)
  6732. // in both cases, we return `vm` directly instead
  6733. if (hasSetupState(vm)) {
  6734. _this.componentVM = createVMProxy(vm, vm.$.setupState);
  6735. }
  6736. else {
  6737. _this.componentVM = vm;
  6738. }
  6739. _this.__setProps = setProps;
  6740. _this.attachNativeEventListener();
  6741. config.plugins.VueWrapper.extend(_this);
  6742. return _this;
  6743. }
  6744. Object.defineProperty(VueWrapper.prototype, "hasMultipleRoots", {
  6745. get: function () {
  6746. // Recursive check subtree for nested root elements
  6747. // <template>
  6748. // <WithMultipleRoots />
  6749. // </template>
  6750. var checkTree = function (subTree) {
  6751. var _a;
  6752. // if the subtree is an array of children, we have multiple root nodes
  6753. if (subTree.shapeFlag === 16 /* ShapeFlags.ARRAY_CHILDREN */)
  6754. return true;
  6755. if (subTree.shapeFlag & 4 /* ShapeFlags.STATEFUL_COMPONENT */ ||
  6756. subTree.shapeFlag & 2 /* ShapeFlags.FUNCTIONAL_COMPONENT */) {
  6757. // We are rendering other component, check it's tree instead
  6758. if ((_a = subTree.component) === null || _a === void 0 ? void 0 : _a.subTree) {
  6759. return checkTree(subTree.component.subTree);
  6760. }
  6761. // Component has multiple children
  6762. if (subTree.shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
  6763. return true;
  6764. }
  6765. }
  6766. return false;
  6767. };
  6768. return checkTree(this.vm.$.subTree);
  6769. },
  6770. enumerable: false,
  6771. configurable: true
  6772. });
  6773. VueWrapper.prototype.getRootNodes = function () {
  6774. return getRootNodes(this.vm.$.vnode);
  6775. };
  6776. Object.defineProperty(VueWrapper.prototype, "parentElement", {
  6777. get: function () {
  6778. return this.vm.$el.parentElement;
  6779. },
  6780. enumerable: false,
  6781. configurable: true
  6782. });
  6783. VueWrapper.prototype.getCurrentComponent = function () {
  6784. return this.vm.$;
  6785. };
  6786. VueWrapper.prototype.exists = function () {
  6787. return !this.getCurrentComponent().isUnmounted;
  6788. };
  6789. VueWrapper.prototype.findAll = function (selector) {
  6790. return this.findAllDOMElements(selector).map(createDOMWrapper);
  6791. };
  6792. VueWrapper.prototype.attachNativeEventListener = function () {
  6793. var vm = this.vm;
  6794. if (!vm)
  6795. return;
  6796. var emits = vm.$options.emits
  6797. ? // if emits is declared as an array
  6798. Array.isArray(vm.$options.emits)
  6799. ? // use it
  6800. vm.$options.emits
  6801. : // otherwise it's declared as an object
  6802. // and we only need the keys
  6803. Object.keys(vm.$options.emits)
  6804. : [];
  6805. var elementRoots = this.getRootNodes().filter(function (node) { return node instanceof Element; });
  6806. if (elementRoots.length !== 1) {
  6807. return;
  6808. }
  6809. var element = elementRoots[0];
  6810. var _loop_1 = function (eventName) {
  6811. // if a component includes events in 'emits' with the same name as native
  6812. // events, the native events with that name should be ignored
  6813. // @see https://github.com/vuejs/rfcs/blob/master/active-rfcs/0030-emits-option.md#fallthrough-control
  6814. if (emits.includes(eventName))
  6815. return "continue";
  6816. var eventListener = function () {
  6817. var args = [];
  6818. for (var _i = 0; _i < arguments.length; _i++) {
  6819. args[_i] = arguments[_i];
  6820. }
  6821. recordEvent(vm.$, eventName, args);
  6822. };
  6823. element.addEventListener(eventName, eventListener);
  6824. this_1.cleanUpCallbacks.push(function () {
  6825. element.removeEventListener(eventName, eventListener);
  6826. });
  6827. };
  6828. var this_1 = this;
  6829. for (var _i = 0, _a = Object.keys(domEvents); _i < _a.length; _i++) {
  6830. var eventName = _a[_i];
  6831. _loop_1(eventName);
  6832. }
  6833. };
  6834. Object.defineProperty(VueWrapper.prototype, "element", {
  6835. get: function () {
  6836. // if the component has multiple root elements, we use the parent's element
  6837. return this.hasMultipleRoots ? this.parentElement : this.vm.$el;
  6838. },
  6839. enumerable: false,
  6840. configurable: true
  6841. });
  6842. Object.defineProperty(VueWrapper.prototype, "vm", {
  6843. get: function () {
  6844. return this.componentVM;
  6845. },
  6846. enumerable: false,
  6847. configurable: true
  6848. });
  6849. VueWrapper.prototype.props = function (selector) {
  6850. var props = this.componentVM.$props;
  6851. return selector ? props[selector] : props;
  6852. };
  6853. VueWrapper.prototype.emitted = function (eventName) {
  6854. return emitted(this.vm, eventName);
  6855. };
  6856. VueWrapper.prototype.isVisible = function () {
  6857. var domWrapper = createDOMWrapper(this.element);
  6858. return domWrapper.isVisible();
  6859. };
  6860. VueWrapper.prototype.setData = function (data) {
  6861. mergeDeep(this.componentVM.$data, data);
  6862. return Vue.nextTick();
  6863. };
  6864. VueWrapper.prototype.setProps = function (props) {
  6865. // if this VM's parent is not the root or if setProps does not exist, error out
  6866. if (this.vm.$parent !== this.rootVM || !this.__setProps) {
  6867. throw Error('You can only use setProps on your mounted component');
  6868. }
  6869. this.__setProps(props);
  6870. return Vue.nextTick();
  6871. };
  6872. VueWrapper.prototype.setValue = function (value, prop) {
  6873. var propEvent = prop || 'modelValue';
  6874. this.vm.$emit("update:".concat(propEvent), value);
  6875. return this.vm.$nextTick();
  6876. };
  6877. VueWrapper.prototype.unmount = function () {
  6878. // preventing dispose of child component
  6879. if (!this.__app) {
  6880. throw new Error("wrapper.unmount() can only be called by the root wrapper");
  6881. }
  6882. // Clear emitted events cache for this component instance
  6883. removeEventHistory(this.vm);
  6884. this.cleanUpCallbacks.forEach(function (cb) { return cb(); });
  6885. this.cleanUpCallbacks = [];
  6886. this.__app.unmount();
  6887. };
  6888. return VueWrapper;
  6889. }(BaseWrapper));
  6890. registerFactory(WrapperType.VueWrapper, function (app, vm, setProps) { return new VueWrapper(app, vm, setProps); });
  6891. function processSlot(source, Vue) {
  6892. if (source === void 0) { source = ''; }
  6893. if (Vue === void 0) { Vue = Vue__namespace; }
  6894. var template = source.trim();
  6895. var hasWrappingTemplate = template && template.startsWith('<template');
  6896. // allow content without `template` tag, for easier testing
  6897. if (!hasWrappingTemplate) {
  6898. template = "<template #default=\"params\">".concat(template, "</template>");
  6899. }
  6900. // Vue does not provide an easy way to compile template in "slot" mode
  6901. // Since we do not want to rely on compiler internals and specify
  6902. // transforms manually we create fake component invocation with the slot we
  6903. // need and pick slots param from render function later. Fake component will
  6904. // never be instantiated but it requires to be a component so compile
  6905. // properly generate invocation. Since we do not want to monkey-patch
  6906. // `resolveComponent` function we are just using one of built-in components:
  6907. // transition
  6908. var code = compilerDom.compile("<transition>".concat(template, "</transition>"), {
  6909. mode: 'function',
  6910. prefixIdentifiers: false
  6911. }).code;
  6912. var createRenderFunction = new Function('Vue', code);
  6913. var renderFn = createRenderFunction(Vue);
  6914. return function (ctx) {
  6915. if (ctx === void 0) { ctx = {}; }
  6916. var result = renderFn(ctx);
  6917. var slotName = Object.keys(result.children)[0];
  6918. return result.children[slotName](ctx);
  6919. };
  6920. }
  6921. var isTeleport = function (type) { return type.__isTeleport; };
  6922. var isKeepAlive = function (type) { return type.__isKeepAlive; };
  6923. var isRootComponent = function (rootComponents, type, instance) {
  6924. return !!(!instance ||
  6925. // Don't stub mounted component on root level
  6926. (rootComponents.component === type && !(instance === null || instance === void 0 ? void 0 : instance.parent)) ||
  6927. // Don't stub component with compat wrapper
  6928. (rootComponents.functional && rootComponents.functional === type));
  6929. };
  6930. var createVNodeTransformer = function (_a) {
  6931. var rootComponents = _a.rootComponents, transformers = _a.transformers;
  6932. var transformationCache = new WeakMap();
  6933. return function (args, instance) {
  6934. var originalType = args[0], props = args[1], children = args[2], restVNodeArgs = args.slice(3);
  6935. if (!isComponent(originalType)) {
  6936. return __spreadArray([originalType, props, children], restVNodeArgs, true);
  6937. }
  6938. var componentType = originalType;
  6939. var cachedTransformation = transformationCache.get(originalType);
  6940. if (cachedTransformation &&
  6941. // Don't use cache for root component, as it could use stubbed recursive component
  6942. !isRootComponent(rootComponents, componentType, instance) &&
  6943. !isTeleport(originalType) &&
  6944. !isKeepAlive(originalType)) {
  6945. return __spreadArray([cachedTransformation, props, children], restVNodeArgs, true);
  6946. }
  6947. var transformedType = transformers.reduce(function (type, transformer) { return transformer(type, instance); }, componentType);
  6948. if (originalType !== transformedType) {
  6949. transformationCache.set(originalType, transformedType);
  6950. registerStub({ source: originalType, stub: transformedType });
  6951. // https://github.com/vuejs/test-utils/issues/1829 & https://github.com/vuejs/test-utils/issues/1888
  6952. // Teleport/KeepAlive should return child nodes as a function
  6953. if (isTeleport(originalType) || isKeepAlive(originalType)) {
  6954. return __spreadArray([transformedType, props, function () { return children; }], restVNodeArgs, true);
  6955. }
  6956. }
  6957. return __spreadArray([transformedType, props, children], restVNodeArgs, true);
  6958. };
  6959. };
  6960. var normalizeStubProps = function (props) {
  6961. // props are always normalized to object syntax
  6962. var $props = props;
  6963. return Object.keys($props).reduce(function (acc, key) {
  6964. var _a, _b, _c;
  6965. var _d;
  6966. if (typeof $props[key] === 'symbol') {
  6967. return __assign(__assign({}, acc), (_a = {}, _a[key] = (_d = $props[key]) === null || _d === void 0 ? void 0 : _d.toString(), _a));
  6968. }
  6969. if (typeof $props[key] === 'function') {
  6970. return __assign(__assign({}, acc), (_b = {}, _b[key] = '[Function]', _b));
  6971. }
  6972. return __assign(__assign({}, acc), (_c = {}, _c[key] = $props[key], _c));
  6973. }, {});
  6974. };
  6975. var clearAndUpper = function (text) { return text.replace(/-/, '').toUpperCase(); };
  6976. var kebabToPascalCase = function (tag) {
  6977. return tag.replace(/(^\w|-\w)/g, clearAndUpper);
  6978. };
  6979. var DEFAULT_STUBS = {
  6980. teleport: isTeleport,
  6981. 'keep-alive': isKeepAlive,
  6982. transition: function (type) { return type === Vue.Transition || type === Vue.BaseTransition; },
  6983. 'transition-group': function (type) { return type === Vue.TransitionGroup; }
  6984. };
  6985. var createDefaultStub = function (kebabTag, predicate, type, stubs) {
  6986. var pascalTag = kebabToPascalCase(kebabTag);
  6987. if (predicate(type) && (pascalTag in stubs || kebabTag in stubs)) {
  6988. if (kebabTag in stubs && stubs[kebabTag] === false)
  6989. return type;
  6990. if (pascalTag in stubs && stubs[pascalTag] === false)
  6991. return type;
  6992. if (stubs[kebabTag] === true || stubs[pascalTag] === true) {
  6993. return createStub({
  6994. name: kebabTag,
  6995. type: type,
  6996. renderStubDefaultSlot: true
  6997. });
  6998. }
  6999. }
  7000. };
  7001. var createStub = function (_a) {
  7002. var name = _a.name, type = _a.type, renderStubDefaultSlot = _a.renderStubDefaultSlot;
  7003. var anonName = 'anonymous-stub';
  7004. var tag = name ? "".concat(hyphenate(name), "-stub") : anonName;
  7005. var componentOptions = type
  7006. ? unwrapLegacyVueExtendComponent(type) || {}
  7007. : {};
  7008. var stub = Vue.defineComponent({
  7009. name: name || anonName,
  7010. props: componentOptions.props || {},
  7011. // fix #1550 - respect old-style v-model for shallow mounted components with @vue/compat
  7012. // @ts-expect-error
  7013. model: componentOptions.model,
  7014. setup: function (props, _a) {
  7015. var slots = _a.slots;
  7016. return function () {
  7017. // https://github.com/vuejs/test-utils/issues/1076
  7018. // Passing a symbol as a static prop is not legal, since Vue will try to do
  7019. // something like `el.setAttribute('val', Symbol())` which is not valid and
  7020. // causes an error.
  7021. // Only a problem when shallow mounting. For this reason we iterate of the
  7022. // props that will be passed and stringify any that are symbols.
  7023. // Also having function text as attribute is useless and annoying so
  7024. // we replace it with "[Function]""
  7025. var stubProps = normalizeStubProps(props);
  7026. return Vue.h(tag, stubProps, renderStubDefaultSlot ? slots : undefined);
  7027. };
  7028. }
  7029. });
  7030. var asyncLoader = type.__asyncLoader;
  7031. if (asyncLoader) {
  7032. asyncLoader().then(function () {
  7033. registerStub({
  7034. source: type.__asyncResolved,
  7035. stub: stub
  7036. });
  7037. });
  7038. }
  7039. return stub;
  7040. };
  7041. var resolveComponentStubByName = function (componentName, stubs) {
  7042. for (var _i = 0, _a = Object.entries(stubs); _i < _a.length; _i++) {
  7043. var _b = _a[_i], stubKey = _b[0], value = _b[1];
  7044. if (matchName(componentName, stubKey)) {
  7045. return value;
  7046. }
  7047. }
  7048. };
  7049. function createStubComponentsTransformer(_a) {
  7050. 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;
  7051. return function componentsTransformer(type, instance) {
  7052. var _a, _b, _c;
  7053. for (var tag in DEFAULT_STUBS) {
  7054. var predicate = DEFAULT_STUBS[tag];
  7055. var defaultStub = createDefaultStub(tag, predicate, type, stubs);
  7056. if (defaultStub)
  7057. return defaultStub;
  7058. }
  7059. // Don't stub root components
  7060. if (isRootComponent(rootComponents, type, instance)) {
  7061. return type;
  7062. }
  7063. var registeredName = getComponentRegisteredName(instance, type);
  7064. var componentName = getComponentName(instance, type);
  7065. var stub = null;
  7066. var name = null;
  7067. // Prio 1 using the key in locally registered components in the parent
  7068. if (registeredName) {
  7069. stub = resolveComponentStubByName(registeredName, stubs);
  7070. if (stub) {
  7071. name = registeredName;
  7072. }
  7073. }
  7074. // Prio 2 using the name attribute in the component
  7075. if (!stub && componentName) {
  7076. stub = resolveComponentStubByName(componentName, stubs);
  7077. if (stub) {
  7078. name = componentName;
  7079. }
  7080. }
  7081. // case 2: custom implementation
  7082. if (isComponent(stub)) {
  7083. var unwrappedStub = unwrapLegacyVueExtendComponent(stub);
  7084. var stubFn_1 = isFunctionalComponent(unwrappedStub) ? unwrappedStub : null;
  7085. // Edge case: stub is component, we will not render stub but instead will create
  7086. // a new "copy" of stub component definition, but we want user still to be able
  7087. // to find our component by stub definition, so we register it manually
  7088. registerStub({ source: type, stub: stub });
  7089. var specializedStubComponent = stubFn_1
  7090. ? function () {
  7091. var args = [];
  7092. for (var _i = 0; _i < arguments.length; _i++) {
  7093. args[_i] = arguments[_i];
  7094. }
  7095. return stubFn_1.apply(void 0, args);
  7096. }
  7097. : __assign({}, unwrappedStub);
  7098. specializedStubComponent.props = unwrappedStub.props;
  7099. return specializedStubComponent;
  7100. }
  7101. if (stub === false) {
  7102. // we explicitly opt out of stubbing this component
  7103. return type;
  7104. }
  7105. // we return a stub by matching Vue's `h` function
  7106. // where the signature is h(Component, props, slots)
  7107. // case 1: default stub
  7108. if (stub === true || shallow) {
  7109. // Set name when using shallow without stub
  7110. var stubName = name || registeredName || componentName;
  7111. return ((_c = (_b = (_a = config.plugins).createStubs) === null || _b === void 0 ? void 0 : _b.call(_a, {
  7112. name: stubName,
  7113. component: type,
  7114. registerStub: registerStub
  7115. })) !== null && _c !== void 0 ? _c : createStub({
  7116. name: stubName,
  7117. type: type,
  7118. renderStubDefaultSlot: renderStubDefaultSlot
  7119. }));
  7120. }
  7121. return type;
  7122. };
  7123. }
  7124. var noop = function () { };
  7125. function createStubDirectivesTransformer(_a) {
  7126. var _b = _a.directives, directives = _b === void 0 ? {} : _b;
  7127. if (Object.keys(directives).length === 0) {
  7128. return function (type) { return type; };
  7129. }
  7130. return function directivesTransformer(type) {
  7131. if (isObjectComponent(type) && type.directives) {
  7132. // We want to change component types as rarely as possible
  7133. // So first we check if there are any directives we should stub
  7134. var directivesToPatch = Object.keys(type.directives).filter(function (key) { return key in directives; });
  7135. if (!directivesToPatch.length) {
  7136. return type;
  7137. }
  7138. var replacementDirectives = Object.fromEntries(directivesToPatch.map(function (name) {
  7139. var directive = directives[name];
  7140. return [name, typeof directive === 'boolean' ? noop : directive];
  7141. }));
  7142. return __assign(__assign({}, type), { directives: __assign(__assign({}, type.directives), replacementDirectives) });
  7143. }
  7144. return type;
  7145. };
  7146. }
  7147. var MOUNT_OPTIONS = [
  7148. 'attachTo',
  7149. 'attrs',
  7150. 'data',
  7151. 'props',
  7152. 'slots',
  7153. 'global',
  7154. 'shallow'
  7155. ];
  7156. function getInstanceOptions(options) {
  7157. if (options.methods) {
  7158. 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");
  7159. delete options.methods;
  7160. }
  7161. var resultOptions = __assign({}, options);
  7162. for (var _i = 0, _a = Object.keys(options); _i < _a.length; _i++) {
  7163. var key = _a[_i];
  7164. if (MOUNT_OPTIONS.includes(key)) {
  7165. delete resultOptions[key];
  7166. }
  7167. }
  7168. return resultOptions;
  7169. }
  7170. // implementation
  7171. function createInstance(inputComponent, options) {
  7172. // normalize the incoming component
  7173. var originalComponent = unwrapLegacyVueExtendComponent(inputComponent);
  7174. var component;
  7175. var instanceOptions = getInstanceOptions(options !== null && options !== void 0 ? options : {});
  7176. var rootComponents = {};
  7177. if (isFunctionalComponent(originalComponent) ||
  7178. isLegacyFunctionalComponent(originalComponent)) {
  7179. component = Vue.defineComponent(__assign({ compatConfig: {
  7180. MODE: 3,
  7181. INSTANCE_LISTENERS: false,
  7182. INSTANCE_ATTRS_CLASS_STYLE: false,
  7183. COMPONENT_FUNCTIONAL: isLegacyFunctionalComponent(originalComponent)
  7184. ? 'suppress-warning'
  7185. : false
  7186. }, props: originalComponent.props || {}, setup: function (props, _a) {
  7187. var attrs = _a.attrs, slots = _a.slots;
  7188. return function () {
  7189. return Vue.h(originalComponent, __assign(__assign({}, props), attrs), slots);
  7190. };
  7191. } }, instanceOptions));
  7192. rootComponents.functional = originalComponent;
  7193. }
  7194. else if (isObjectComponent(originalComponent)) {
  7195. component = __assign(__assign({}, originalComponent), instanceOptions);
  7196. }
  7197. else {
  7198. component = originalComponent;
  7199. }
  7200. rootComponents.component = component;
  7201. // We've just replaced our component with its copy
  7202. // Let's register it as a stub so user can find it
  7203. registerStub({ source: originalComponent, stub: component });
  7204. function slotToFunction(slot) {
  7205. switch (typeof slot) {
  7206. case 'function':
  7207. return slot;
  7208. case 'object':
  7209. return function () { return Vue.h(slot); };
  7210. case 'string':
  7211. return processSlot(slot);
  7212. default:
  7213. throw Error("Invalid slot received.");
  7214. }
  7215. }
  7216. // handle any slots passed via mounting options
  7217. var slots = (options === null || options === void 0 ? void 0 : options.slots) &&
  7218. Object.entries(options.slots).reduce(function (acc, _a) {
  7219. var name = _a[0], slot = _a[1];
  7220. if (Array.isArray(slot)) {
  7221. var normalized_1 = slot.map(slotToFunction);
  7222. acc[name] = function (args) { return normalized_1.map(function (f) { return f(args); }); };
  7223. return acc;
  7224. }
  7225. acc[name] = slotToFunction(slot);
  7226. return acc;
  7227. }, {});
  7228. // override component data with mounting options data
  7229. if (options === null || options === void 0 ? void 0 : options.data) {
  7230. var providedData_1 = options.data();
  7231. if (isObjectComponent(originalComponent)) {
  7232. // component is guaranteed to be the same type as originalComponent
  7233. var objectComponent = component;
  7234. var originalDataFn_1 = originalComponent.data || (function () { return ({}); });
  7235. objectComponent.data = function (vm) { return (__assign(__assign({}, originalDataFn_1.call(vm, vm)), providedData_1)); };
  7236. }
  7237. else {
  7238. throw new Error('data() option is not supported on functional and class components');
  7239. }
  7240. }
  7241. var MOUNT_COMPONENT_REF = 'VTU_COMPONENT';
  7242. // we define props as reactive so that way when we update them with `setProps`
  7243. // Vue's reactivity system will cause a rerender.
  7244. var refs = Vue.shallowReactive({});
  7245. var props = Vue.reactive({});
  7246. 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) {
  7247. var k = _a[0], v = _a[1];
  7248. if (isDeepRef(v)) {
  7249. refs[k] = v;
  7250. }
  7251. else {
  7252. props[k] = v;
  7253. }
  7254. });
  7255. var global = mergeGlobalProperties(options === null || options === void 0 ? void 0 : options.global);
  7256. if (isObjectComponent(component)) {
  7257. component.components = __assign(__assign({}, component.components), global.components);
  7258. }
  7259. var componentRef = Vue.ref(null);
  7260. // create the wrapper component
  7261. var Parent = Vue.defineComponent({
  7262. name: 'VTU_ROOT',
  7263. setup: function () {
  7264. var _a;
  7265. return _a = {},
  7266. _a[MOUNT_COMPONENT_REF] = componentRef,
  7267. _a;
  7268. },
  7269. render: function () {
  7270. return Vue.h(component, __assign(__assign({}, props), refs), slots);
  7271. }
  7272. });
  7273. // create the app
  7274. var app = Vue.createApp(Parent);
  7275. // add tracking for emitted events
  7276. // this must be done after `createApp`: https://github.com/vuejs/test-utils/issues/436
  7277. attachEmitListener();
  7278. // global mocks mixin
  7279. if (global === null || global === void 0 ? void 0 : global.mocks) {
  7280. var mixin = {
  7281. beforeCreate: function () {
  7282. // we need to differentiate components that are or not not `script setup`
  7283. // otherwise we run into a proxy set error
  7284. // due to https://github.com/vuejs/core/commit/f73925d76a76ee259749b8b48cb68895f539a00f#diff-ea4d1ddabb7e22e17e80ada458eef70679af4005df2a1a6b73418fec897603ceR404
  7285. // introduced in Vue v3.2.45
  7286. // Also ensures not to include option API components in this block
  7287. // since they can also have setup state but need to be patched using
  7288. // the regular method.
  7289. if (isScriptSetup(this)) {
  7290. // add the mocks to setupState
  7291. for (var _i = 0, _a = Object.entries(global.mocks); _i < _a.length; _i++) {
  7292. var _b = _a[_i], k = _b[0], v = _b[1];
  7293. // we do this in a try/catch, as some properties might be read-only
  7294. try {
  7295. this.$.setupState[k] = v;
  7296. // eslint-disable-next-line no-empty
  7297. }
  7298. catch (e) { }
  7299. }
  7300. this.$.proxy = new Proxy(this.$.proxy, {
  7301. get: function (target, key) {
  7302. if (key in global.mocks) {
  7303. return global.mocks[key];
  7304. }
  7305. return target[key];
  7306. }
  7307. });
  7308. }
  7309. else {
  7310. for (var _c = 0, _d = Object.entries(global.mocks); _c < _d.length; _c++) {
  7311. var _e = _d[_c], k = _e[0], v = _e[1];
  7312. this[k] = v;
  7313. }
  7314. }
  7315. }
  7316. };
  7317. app.mixin(mixin);
  7318. }
  7319. // AppConfig
  7320. if (global.config) {
  7321. for (var _i = 0, _a = Object.entries(global.config); _i < _a.length; _i++) {
  7322. var _b = _a[_i], k = _b[0], v = _b[1];
  7323. app.config[k] = isObject(app.config[k])
  7324. ? Object.assign(app.config[k], v)
  7325. : v;
  7326. }
  7327. }
  7328. // use and plugins from mounting options
  7329. if (global.plugins) {
  7330. for (var _c = 0, _d = global.plugins; _c < _d.length; _c++) {
  7331. var plugin = _d[_c];
  7332. if (Array.isArray(plugin)) {
  7333. app.use.apply(app, __spreadArray([plugin[0]], plugin.slice(1), false));
  7334. continue;
  7335. }
  7336. app.use(plugin);
  7337. }
  7338. }
  7339. // use any mixins from mounting options
  7340. if (global.mixins) {
  7341. for (var _e = 0, _f = global.mixins; _e < _f.length; _e++) {
  7342. var mixin = _f[_e];
  7343. app.mixin(mixin);
  7344. }
  7345. }
  7346. if (global.components) {
  7347. for (var _g = 0, _h = Object.keys(global.components); _g < _h.length; _g++) {
  7348. var key = _h[_g];
  7349. // avoid registering components that are stubbed twice
  7350. if (!(key in global.stubs)) {
  7351. app.component(key, global.components[key]);
  7352. }
  7353. }
  7354. }
  7355. if (global.directives) {
  7356. for (var _j = 0, _k = Object.keys(global.directives); _j < _k.length; _j++) {
  7357. var key = _k[_j];
  7358. app.directive(key, global.directives[key]);
  7359. }
  7360. }
  7361. // provide any values passed via provides mounting option
  7362. if (global.provide) {
  7363. for (var _l = 0, _m = Reflect.ownKeys(global.provide); _l < _m.length; _l++) {
  7364. var key = _m[_l];
  7365. // @ts-ignore: https://github.com/microsoft/TypeScript/issues/1863
  7366. app.provide(key, global.provide[key]);
  7367. }
  7368. }
  7369. // stubs
  7370. // even if we are using `mount`, we will still
  7371. // stub out Transition and Transition Group by default.
  7372. Vue.transformVNodeArgs(createVNodeTransformer({
  7373. rootComponents: rootComponents,
  7374. transformers: [
  7375. createStubComponentsTransformer({
  7376. rootComponents: rootComponents,
  7377. stubs: getComponentsFromStubs(global.stubs),
  7378. shallow: options === null || options === void 0 ? void 0 : options.shallow,
  7379. renderStubDefaultSlot: global.renderStubDefaultSlot
  7380. }),
  7381. createStubDirectivesTransformer({
  7382. directives: getDirectivesFromStubs(global.stubs)
  7383. })
  7384. ]
  7385. }));
  7386. // users expect stubs to work with globally registered
  7387. // components so we register stubs as global components to avoid
  7388. // warning about not being able to resolve component
  7389. //
  7390. // component implementation provided here will never be called
  7391. // but we need name to make sure that stubComponents will
  7392. // properly stub this later by matching stub name
  7393. //
  7394. // ref: https://github.com/vuejs/test-utils/issues/249
  7395. // ref: https://github.com/vuejs/test-utils/issues/425
  7396. if (global === null || global === void 0 ? void 0 : global.stubs) {
  7397. for (var _o = 0, _p = Object.keys(getComponentsFromStubs(global.stubs)); _o < _p.length; _o++) {
  7398. var name_1 = _p[_o];
  7399. if (!app.component(name_1)) {
  7400. app.component(name_1, { name: name_1 });
  7401. }
  7402. }
  7403. }
  7404. return {
  7405. app: app,
  7406. props: props,
  7407. componentRef: componentRef
  7408. };
  7409. }
  7410. var isEnabled = false;
  7411. var wrapperInstances = [];
  7412. function disableAutoUnmount() {
  7413. isEnabled = false;
  7414. wrapperInstances.length = 0;
  7415. }
  7416. function enableAutoUnmount(hook) {
  7417. if (isEnabled) {
  7418. throw new Error('enableAutoUnmount cannot be called more than once');
  7419. }
  7420. isEnabled = true;
  7421. hook(function () {
  7422. wrapperInstances.forEach(function (wrapper) {
  7423. wrapper.unmount();
  7424. });
  7425. wrapperInstances.length = 0;
  7426. });
  7427. }
  7428. function trackInstance(wrapper) {
  7429. if (!isEnabled)
  7430. return;
  7431. wrapperInstances.push(wrapper);
  7432. }
  7433. // implementation
  7434. function mount(inputComponent, options) {
  7435. var _a = createInstance(inputComponent, options), app = _a.app, props = _a.props, componentRef = _a.componentRef;
  7436. var setProps = function (newProps) {
  7437. for (var _i = 0, _a = Object.entries(newProps); _i < _a.length; _i++) {
  7438. var _b = _a[_i], k = _b[0], v = _b[1];
  7439. props[k] = v;
  7440. }
  7441. return vm.$nextTick();
  7442. };
  7443. // Workaround for https://github.com/vuejs/core/issues/7020
  7444. var originalErrorHandler = app.config.errorHandler;
  7445. var errorOnMount = null;
  7446. app.config.errorHandler = function (err, instance, info) {
  7447. errorOnMount = err;
  7448. return originalErrorHandler === null || originalErrorHandler === void 0 ? void 0 : originalErrorHandler(err, instance, info);
  7449. };
  7450. // mount the app!
  7451. var el = document.createElement('div');
  7452. if (options === null || options === void 0 ? void 0 : options.attachTo) {
  7453. var to = void 0;
  7454. if (typeof options.attachTo === 'string') {
  7455. to = document.querySelector(options.attachTo);
  7456. if (!to) {
  7457. throw new Error("Unable to find the element matching the selector ".concat(options.attachTo, " given as the `attachTo` option"));
  7458. }
  7459. }
  7460. else {
  7461. to = options.attachTo;
  7462. }
  7463. to.appendChild(el);
  7464. }
  7465. var vm = app.mount(el);
  7466. if (errorOnMount) {
  7467. throw errorOnMount;
  7468. }
  7469. app.config.errorHandler = originalErrorHandler;
  7470. var appRef = componentRef.value;
  7471. // we add `hasOwnProperty` so Jest can spy on the proxied vm without throwing
  7472. // note that this is not necessary with Jest v27+ or Vitest, but is kept for compatibility with older Jest versions
  7473. if (!app.hasOwnProperty) {
  7474. appRef.hasOwnProperty = function (property) {
  7475. return Reflect.has(appRef, property);
  7476. };
  7477. }
  7478. var wrapper = createVueWrapper(app, appRef, setProps);
  7479. trackInstance(wrapper);
  7480. return wrapper;
  7481. }
  7482. var shallowMount = function (component, options) {
  7483. return mount(component, __assign(__assign({}, options), { shallow: true }));
  7484. };
  7485. function renderToString(component, options) {
  7486. if (options === null || options === void 0 ? void 0 : options.attachTo) {
  7487. console.warn('attachTo option is not available for renderToString');
  7488. }
  7489. var app = createInstance(component, options).app;
  7490. return serverRenderer.renderToString(app);
  7491. }
  7492. // match return type of router.resolve: RouteLocation & { href: string }
  7493. var defaultRoute = {
  7494. path: '/',
  7495. name: undefined,
  7496. redirectedFrom: undefined,
  7497. params: {},
  7498. query: {},
  7499. hash: '',
  7500. fullPath: '/',
  7501. matched: [],
  7502. meta: {},
  7503. href: '/'
  7504. };
  7505. // TODO: Borrow typings from vue-router-next
  7506. var RouterLinkStub = Vue.defineComponent({
  7507. name: 'RouterLinkStub',
  7508. compatConfig: { MODE: 3 },
  7509. props: {
  7510. to: {
  7511. type: [String, Object],
  7512. required: true
  7513. },
  7514. custom: {
  7515. type: Boolean,
  7516. default: false
  7517. }
  7518. },
  7519. render: function () {
  7520. var _this = this;
  7521. var _a, _b;
  7522. var route = Vue.computed(function () { return defaultRoute; });
  7523. // mock reasonable return values to mimic vue-router's useLink
  7524. var children = (_b = (_a = this.$slots) === null || _a === void 0 ? void 0 : _a.default) === null || _b === void 0 ? void 0 : _b.call(_a, {
  7525. route: route,
  7526. href: Vue.computed(function () { return route.value.href; }),
  7527. isActive: Vue.computed(function () { return false; }),
  7528. isExactActive: Vue.computed(function () { return false; }),
  7529. navigate: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
  7530. return [2 /*return*/];
  7531. }); }); }
  7532. });
  7533. return this.custom ? children : Vue.h('a', undefined, children);
  7534. }
  7535. });
  7536. var scheduler = typeof setImmediate === 'function' ? setImmediate : setTimeout;
  7537. // Credit to: https://github.com/kentor/flush-promises
  7538. function flushPromises() {
  7539. return new Promise(function (resolve) {
  7540. scheduler(resolve, 0);
  7541. });
  7542. }
  7543. exports.BaseWrapper = BaseWrapper;
  7544. exports.DOMWrapper = DOMWrapper;
  7545. exports.RouterLinkStub = RouterLinkStub;
  7546. exports.VueWrapper = VueWrapper;
  7547. exports.config = config;
  7548. exports.createWrapperError = createWrapperError;
  7549. exports.disableAutoUnmount = disableAutoUnmount;
  7550. exports.enableAutoUnmount = enableAutoUnmount;
  7551. exports.flushPromises = flushPromises;
  7552. exports.mount = mount;
  7553. exports.renderToString = renderToString;
  7554. exports.shallowMount = shallowMount;
  7555. return exports;
  7556. })({}, Vue, VueCompilerDOM, VueServerRenderer);