vue-test-utils.esm-bundler.mjs 298 KB

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