vue-test-utils.cjs.js 299 KB

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