index.js 1.5 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762
  1. 'use strict';
  2. var fs$3 = require('fs');
  3. var path$2 = require('path');
  4. var os$1 = require('os');
  5. var tty$1 = require('tty');
  6. var assert$1 = require('assert');
  7. var util$4 = require('util');
  8. var stream$6 = require('stream');
  9. var events$1 = require('events');
  10. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  11. var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$3);
  12. var path__default = /*#__PURE__*/_interopDefaultLegacy(path$2);
  13. var os__default = /*#__PURE__*/_interopDefaultLegacy(os$1);
  14. var tty__default = /*#__PURE__*/_interopDefaultLegacy(tty$1);
  15. var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert$1);
  16. var util__default = /*#__PURE__*/_interopDefaultLegacy(util$4);
  17. var stream__default = /*#__PURE__*/_interopDefaultLegacy(stream$6);
  18. var events__default = /*#__PURE__*/_interopDefaultLegacy(events$1);
  19. var name = "prettier";
  20. var version = "2.1.2";
  21. var description = "Prettier is an opinionated code formatter";
  22. var bin = "./bin/prettier.js";
  23. var repository = "prettier/prettier";
  24. var homepage = "https://prettier.io";
  25. var author = "James Long";
  26. var license = "MIT";
  27. var main = "./index.js";
  28. var browser = "./standalone.js";
  29. var unpkg = "./standalone.js";
  30. var engines = {
  31. node: ">=10.13.0"
  32. };
  33. var files = [
  34. "index.js",
  35. "standalone.js",
  36. "src",
  37. "bin"
  38. ];
  39. var dependencies = {
  40. "@angular/compiler": "10.0.12",
  41. "@babel/code-frame": "7.10.4",
  42. "@babel/parser": "7.11.2",
  43. "@glimmer/syntax": "0.59.0",
  44. "@iarna/toml": "2.2.5",
  45. "@typescript-eslint/typescript-estree": "3.10.0",
  46. "angular-estree-parser": "2.2.0",
  47. "angular-html-parser": "1.7.1",
  48. camelcase: "6.0.0",
  49. chalk: "4.1.0",
  50. "ci-info": "watson/ci-info#f43f6a1cefff47fb361c88cf4b943fdbcaafe540",
  51. "cjk-regex": "2.0.0",
  52. cosmiconfig: "7.0.0",
  53. dashify: "2.0.0",
  54. diff: "4.0.2",
  55. editorconfig: "0.15.3",
  56. "editorconfig-to-prettier": "0.1.1",
  57. "escape-string-regexp": "4.0.0",
  58. esutils: "2.0.3",
  59. "fast-glob": "3.2.4",
  60. "fast-json-stable-stringify": "2.1.0",
  61. "find-parent-dir": "0.3.0",
  62. "flow-parser": "0.132.0",
  63. "get-stream": "6.0.0",
  64. globby: "11.0.1",
  65. graphql: "15.3.0",
  66. "html-element-attributes": "2.2.1",
  67. "html-styles": "1.0.0",
  68. "html-tag-names": "1.1.5",
  69. "html-void-elements": "1.0.5",
  70. ignore: "4.0.6",
  71. "jest-docblock": "26.0.0",
  72. json5: "2.1.3",
  73. leven: "3.1.0",
  74. "lines-and-columns": "1.1.6",
  75. "linguist-languages": "7.10.0",
  76. lodash: "4.17.20",
  77. mem: "6.1.0",
  78. minimatch: "3.0.4",
  79. minimist: "1.2.5",
  80. "n-readlines": "1.0.0",
  81. outdent: "0.7.1",
  82. "parse-srcset": "ikatyang/parse-srcset#54eb9c1cb21db5c62b4d0e275d7249516df6f0ee",
  83. "please-upgrade-node": "3.2.0",
  84. "postcss-less": "3.1.4",
  85. "postcss-media-query-parser": "0.2.3",
  86. "postcss-scss": "2.1.1",
  87. "postcss-selector-parser": "2.2.3",
  88. "postcss-values-parser": "2.0.1",
  89. "regexp-util": "1.2.2",
  90. "remark-footnotes": "2.0.0",
  91. "remark-math": "1.0.6",
  92. "remark-parse": "8.0.3",
  93. resolve: "1.17.0",
  94. semver: "7.3.2",
  95. "string-width": "4.2.0",
  96. typescript: "4.0.2",
  97. "unicode-regex": "3.0.0",
  98. unified: "9.2.0",
  99. vnopts: "1.0.2",
  100. "yaml-unist-parser": "1.3.1"
  101. };
  102. var devDependencies = {
  103. "@babel/core": "7.11.4",
  104. "@babel/preset-env": "7.11.0",
  105. "@babel/types": "7.11.0",
  106. "@glimmer/reference": "0.59.0",
  107. "@rollup/plugin-alias": "3.1.1",
  108. "@rollup/plugin-babel": "5.2.0",
  109. "@rollup/plugin-commonjs": "14.0.0",
  110. "@rollup/plugin-json": "4.1.0",
  111. "@rollup/plugin-node-resolve": "9.0.0",
  112. "@rollup/plugin-replace": "2.3.3",
  113. "@types/estree": "0.0.45",
  114. "@types/node": "14.6.0",
  115. "@typescript-eslint/types": "3.10.0",
  116. "babel-loader": "8.1.0",
  117. benchmark: "2.1.4",
  118. "builtin-modules": "3.1.0",
  119. "cross-env": "7.0.2",
  120. cspell: "4.1.0",
  121. eslint: "7.7.0",
  122. "eslint-config-prettier": "6.11.0",
  123. "eslint-formatter-friendly": "7.0.0",
  124. "eslint-plugin-import": "2.22.0",
  125. "eslint-plugin-jest": "23.20.0",
  126. "eslint-plugin-prettier-internal-rules": "file:scripts/tools/eslint-plugin-prettier-internal-rules",
  127. "eslint-plugin-react": "7.20.6",
  128. "eslint-plugin-unicorn": "21.0.0",
  129. execa: "4.0.3",
  130. jest: "26.4.2",
  131. "jest-snapshot-serializer-ansi": "1.0.0",
  132. "jest-snapshot-serializer-raw": "1.1.0",
  133. "jest-watch-typeahead": "0.6.0",
  134. "npm-run-all": "4.1.5",
  135. prettier: "2.1.1",
  136. rimraf: "3.0.2",
  137. rollup: "2.26.5",
  138. "rollup-plugin-node-globals": "1.4.0",
  139. "rollup-plugin-terser": "7.0.0",
  140. shelljs: "0.8.4",
  141. "snapshot-diff": "0.8.1",
  142. "strip-ansi": "6.0.0",
  143. "synchronous-promise": "2.0.13",
  144. tempy: "0.6.0",
  145. "terser-webpack-plugin": "4.1.0",
  146. webpack: "4.44.1"
  147. };
  148. var scripts = {
  149. prepublishOnly: "echo \"Error: must publish from dist/\" && exit 1",
  150. "prepare-release": "yarn && yarn build && yarn test:dist",
  151. test: "jest",
  152. "test:dev-package": "cross-env INSTALL_PACKAGE=1 jest",
  153. "test:dist": "cross-env NODE_ENV=production jest",
  154. "test:dist-standalone": "cross-env NODE_ENV=production TEST_STANDALONE=1 jest",
  155. "test:integration": "jest tests_integration",
  156. "perf:repeat": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
  157. "perf:repeat-inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
  158. "perf:benchmark": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-benchmark --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
  159. lint: "run-p lint:*",
  160. "lint:typecheck": "tsc",
  161. "lint:eslint": "cross-env EFF_NO_LINK_RULES=true eslint . --format friendly",
  162. "lint:changelog": "node ./scripts/lint-changelog.js",
  163. "lint:prettier": "prettier . \"!test*\" --check",
  164. "lint:dist": "eslint --no-eslintrc --no-ignore --env=es6,browser --parser-options=ecmaVersion:2016 \"dist/!(bin-prettier|index|third-party).js\"",
  165. "lint:spellcheck": "cspell \"**/*\" \".github/**/*\"",
  166. "lint:deps": "node ./scripts/check-deps.js",
  167. fix: "run-s fix:eslint fix:prettier",
  168. "fix:eslint": "yarn lint:eslint --fix",
  169. "fix:prettier": "yarn lint:prettier --write",
  170. build: "node ./scripts/build/build.js",
  171. "build-docs": "node ./scripts/build-docs.js"
  172. };
  173. var _package = {
  174. name: name,
  175. version: version,
  176. description: description,
  177. bin: bin,
  178. repository: repository,
  179. homepage: homepage,
  180. author: author,
  181. license: license,
  182. main: main,
  183. browser: browser,
  184. unpkg: unpkg,
  185. engines: engines,
  186. files: files,
  187. dependencies: dependencies,
  188. devDependencies: devDependencies,
  189. scripts: scripts
  190. };
  191. var _package$1 = /*#__PURE__*/Object.freeze({
  192. __proto__: null,
  193. name: name,
  194. version: version,
  195. description: description,
  196. bin: bin,
  197. repository: repository,
  198. homepage: homepage,
  199. author: author,
  200. license: license,
  201. main: main,
  202. browser: browser,
  203. unpkg: unpkg,
  204. engines: engines,
  205. files: files,
  206. dependencies: dependencies,
  207. devDependencies: devDependencies,
  208. scripts: scripts,
  209. 'default': _package
  210. });
  211. function Diff() {}
  212. Diff.prototype = {
  213. diff: function diff(oldString, newString) {
  214. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  215. var callback = options.callback;
  216. if (typeof options === 'function') {
  217. callback = options;
  218. options = {};
  219. }
  220. this.options = options;
  221. var self = this;
  222. function done(value) {
  223. if (callback) {
  224. setTimeout(function () {
  225. callback(undefined, value);
  226. }, 0);
  227. return true;
  228. } else {
  229. return value;
  230. }
  231. } // Allow subclasses to massage the input prior to running
  232. oldString = this.castInput(oldString);
  233. newString = this.castInput(newString);
  234. oldString = this.removeEmpty(this.tokenize(oldString));
  235. newString = this.removeEmpty(this.tokenize(newString));
  236. var newLen = newString.length,
  237. oldLen = oldString.length;
  238. var editLength = 1;
  239. var maxEditLength = newLen + oldLen;
  240. var bestPath = [{
  241. newPos: -1,
  242. components: []
  243. }]; // Seed editLength = 0, i.e. the content starts with the same values
  244. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  245. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  246. // Identity per the equality and tokenizer
  247. return done([{
  248. value: this.join(newString),
  249. count: newString.length
  250. }]);
  251. } // Main worker method. checks all permutations of a given edit length for acceptance.
  252. function execEditLength() {
  253. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  254. var basePath = void 0;
  255. var addPath = bestPath[diagonalPath - 1],
  256. removePath = bestPath[diagonalPath + 1],
  257. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  258. if (addPath) {
  259. // No one else is going to attempt to use this value, clear it
  260. bestPath[diagonalPath - 1] = undefined;
  261. }
  262. var canAdd = addPath && addPath.newPos + 1 < newLen,
  263. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  264. if (!canAdd && !canRemove) {
  265. // If this path is a terminal then prune
  266. bestPath[diagonalPath] = undefined;
  267. continue;
  268. } // Select the diagonal that we want to branch from. We select the prior
  269. // path whose position in the new string is the farthest from the origin
  270. // and does not pass the bounds of the diff graph
  271. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  272. basePath = clonePath(removePath);
  273. self.pushComponent(basePath.components, undefined, true);
  274. } else {
  275. basePath = addPath; // No need to clone, we've pulled it from the list
  276. basePath.newPos++;
  277. self.pushComponent(basePath.components, true, undefined);
  278. }
  279. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
  280. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  281. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  282. } else {
  283. // Otherwise track this path as a potential candidate and continue.
  284. bestPath[diagonalPath] = basePath;
  285. }
  286. }
  287. editLength++;
  288. } // Performs the length of edit iteration. Is a bit fugly as this has to support the
  289. // sync and async mode which is never fun. Loops over execEditLength until a value
  290. // is produced.
  291. if (callback) {
  292. (function exec() {
  293. setTimeout(function () {
  294. // This should not happen, but we want to be safe.
  295. /* istanbul ignore next */
  296. if (editLength > maxEditLength) {
  297. return callback();
  298. }
  299. if (!execEditLength()) {
  300. exec();
  301. }
  302. }, 0);
  303. })();
  304. } else {
  305. while (editLength <= maxEditLength) {
  306. var ret = execEditLength();
  307. if (ret) {
  308. return ret;
  309. }
  310. }
  311. }
  312. },
  313. pushComponent: function pushComponent(components, added, removed) {
  314. var last = components[components.length - 1];
  315. if (last && last.added === added && last.removed === removed) {
  316. // We need to clone here as the component clone operation is just
  317. // as shallow array clone
  318. components[components.length - 1] = {
  319. count: last.count + 1,
  320. added: added,
  321. removed: removed
  322. };
  323. } else {
  324. components.push({
  325. count: 1,
  326. added: added,
  327. removed: removed
  328. });
  329. }
  330. },
  331. extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  332. var newLen = newString.length,
  333. oldLen = oldString.length,
  334. newPos = basePath.newPos,
  335. oldPos = newPos - diagonalPath,
  336. commonCount = 0;
  337. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  338. newPos++;
  339. oldPos++;
  340. commonCount++;
  341. }
  342. if (commonCount) {
  343. basePath.components.push({
  344. count: commonCount
  345. });
  346. }
  347. basePath.newPos = newPos;
  348. return oldPos;
  349. },
  350. equals: function equals(left, right) {
  351. if (this.options.comparator) {
  352. return this.options.comparator(left, right);
  353. } else {
  354. return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
  355. }
  356. },
  357. removeEmpty: function removeEmpty(array) {
  358. var ret = [];
  359. for (var i = 0; i < array.length; i++) {
  360. if (array[i]) {
  361. ret.push(array[i]);
  362. }
  363. }
  364. return ret;
  365. },
  366. castInput: function castInput(value) {
  367. return value;
  368. },
  369. tokenize: function tokenize(value) {
  370. return value.split('');
  371. },
  372. join: function join(chars) {
  373. return chars.join('');
  374. }
  375. };
  376. function buildValues(diff, components, newString, oldString, useLongestToken) {
  377. var componentPos = 0,
  378. componentLen = components.length,
  379. newPos = 0,
  380. oldPos = 0;
  381. for (; componentPos < componentLen; componentPos++) {
  382. var component = components[componentPos];
  383. if (!component.removed) {
  384. if (!component.added && useLongestToken) {
  385. var value = newString.slice(newPos, newPos + component.count);
  386. value = value.map(function (value, i) {
  387. var oldValue = oldString[oldPos + i];
  388. return oldValue.length > value.length ? oldValue : value;
  389. });
  390. component.value = diff.join(value);
  391. } else {
  392. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  393. }
  394. newPos += component.count; // Common case
  395. if (!component.added) {
  396. oldPos += component.count;
  397. }
  398. } else {
  399. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  400. oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
  401. // The diffing algorithm is tied to add then remove output and this is the simplest
  402. // route to get the desired output with minimal overhead.
  403. if (componentPos && components[componentPos - 1].added) {
  404. var tmp = components[componentPos - 1];
  405. components[componentPos - 1] = components[componentPos];
  406. components[componentPos] = tmp;
  407. }
  408. }
  409. } // Special case handle for when one terminal is ignored (i.e. whitespace).
  410. // For this case we merge the terminal into the prior string and drop the change.
  411. // This is only available for string mode.
  412. var lastComponent = components[componentLen - 1];
  413. if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  414. components[componentLen - 2].value += lastComponent.value;
  415. components.pop();
  416. }
  417. return components;
  418. }
  419. function clonePath(path) {
  420. return {
  421. newPos: path.newPos,
  422. components: path.components.slice(0)
  423. };
  424. }
  425. var characterDiff = new Diff();
  426. function diffChars(oldStr, newStr, options) {
  427. return characterDiff.diff(oldStr, newStr, options);
  428. }
  429. function generateOptions(options, defaults) {
  430. if (typeof options === 'function') {
  431. defaults.callback = options;
  432. } else if (options) {
  433. for (var name in options) {
  434. /* istanbul ignore else */
  435. if (options.hasOwnProperty(name)) {
  436. defaults[name] = options[name];
  437. }
  438. }
  439. }
  440. return defaults;
  441. } //
  442. // Ranges and exceptions:
  443. // Latin-1 Supplement, 0080–00FF
  444. // - U+00D7 × Multiplication sign
  445. // - U+00F7 ÷ Division sign
  446. // Latin Extended-A, 0100–017F
  447. // Latin Extended-B, 0180–024F
  448. // IPA Extensions, 0250–02AF
  449. // Spacing Modifier Letters, 02B0–02FF
  450. // - U+02C7 ˇ &#711; Caron
  451. // - U+02D8 ˘ &#728; Breve
  452. // - U+02D9 ˙ &#729; Dot Above
  453. // - U+02DA ˚ &#730; Ring Above
  454. // - U+02DB ˛ &#731; Ogonek
  455. // - U+02DC ˜ &#732; Small Tilde
  456. // - U+02DD ˝ &#733; Double Acute Accent
  457. // Latin Extended Additional, 1E00–1EFF
  458. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  459. var reWhitespace = /\S/;
  460. var wordDiff = new Diff();
  461. wordDiff.equals = function (left, right) {
  462. if (this.options.ignoreCase) {
  463. left = left.toLowerCase();
  464. right = right.toLowerCase();
  465. }
  466. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  467. };
  468. wordDiff.tokenize = function (value) {
  469. var tokens = value.split(/(\s+|[()[\]{}'"]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
  470. for (var i = 0; i < tokens.length - 1; i++) {
  471. // If we have an empty string in the next field and we have only word chars before and after, merge
  472. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  473. tokens[i] += tokens[i + 2];
  474. tokens.splice(i + 1, 2);
  475. i--;
  476. }
  477. }
  478. return tokens;
  479. };
  480. function diffWords(oldStr, newStr, options) {
  481. options = generateOptions(options, {
  482. ignoreWhitespace: true
  483. });
  484. return wordDiff.diff(oldStr, newStr, options);
  485. }
  486. function diffWordsWithSpace(oldStr, newStr, options) {
  487. return wordDiff.diff(oldStr, newStr, options);
  488. }
  489. var lineDiff = new Diff();
  490. lineDiff.tokenize = function (value) {
  491. var retLines = [],
  492. linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
  493. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  494. linesAndNewlines.pop();
  495. } // Merge the content and line separators into single tokens
  496. for (var i = 0; i < linesAndNewlines.length; i++) {
  497. var line = linesAndNewlines[i];
  498. if (i % 2 && !this.options.newlineIsToken) {
  499. retLines[retLines.length - 1] += line;
  500. } else {
  501. if (this.options.ignoreWhitespace) {
  502. line = line.trim();
  503. }
  504. retLines.push(line);
  505. }
  506. }
  507. return retLines;
  508. };
  509. function diffLines(oldStr, newStr, callback) {
  510. return lineDiff.diff(oldStr, newStr, callback);
  511. }
  512. function diffTrimmedLines(oldStr, newStr, callback) {
  513. var options = generateOptions(callback, {
  514. ignoreWhitespace: true
  515. });
  516. return lineDiff.diff(oldStr, newStr, options);
  517. }
  518. var sentenceDiff = new Diff();
  519. sentenceDiff.tokenize = function (value) {
  520. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  521. };
  522. function diffSentences(oldStr, newStr, callback) {
  523. return sentenceDiff.diff(oldStr, newStr, callback);
  524. }
  525. var cssDiff = new Diff();
  526. cssDiff.tokenize = function (value) {
  527. return value.split(/([{}:;,]|\s+)/);
  528. };
  529. function diffCss(oldStr, newStr, callback) {
  530. return cssDiff.diff(oldStr, newStr, callback);
  531. }
  532. function _typeof(obj) {
  533. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  534. _typeof = function (obj) {
  535. return typeof obj;
  536. };
  537. } else {
  538. _typeof = function (obj) {
  539. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  540. };
  541. }
  542. return _typeof(obj);
  543. }
  544. function _toConsumableArray(arr) {
  545. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  546. }
  547. function _arrayWithoutHoles(arr) {
  548. if (Array.isArray(arr)) {
  549. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  550. return arr2;
  551. }
  552. }
  553. function _iterableToArray(iter) {
  554. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  555. }
  556. function _nonIterableSpread() {
  557. throw new TypeError("Invalid attempt to spread non-iterable instance");
  558. }
  559. var objectPrototypeToString = Object.prototype.toString;
  560. var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  561. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  562. jsonDiff.useLongestToken = true;
  563. jsonDiff.tokenize = lineDiff.tokenize;
  564. jsonDiff.castInput = function (value) {
  565. var _this$options = this.options,
  566. undefinedReplacement = _this$options.undefinedReplacement,
  567. _this$options$stringi = _this$options.stringifyReplacer,
  568. stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
  569. return typeof v === 'undefined' ? undefinedReplacement : v;
  570. } : _this$options$stringi;
  571. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
  572. };
  573. jsonDiff.equals = function (left, right) {
  574. return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
  575. };
  576. function diffJson(oldObj, newObj, options) {
  577. return jsonDiff.diff(oldObj, newObj, options);
  578. } // This function handles the presence of circular references by bailing out when encountering an
  579. // object that is already on the "stack" of items being processed. Accepts an optional replacer
  580. function canonicalize(obj, stack, replacementStack, replacer, key) {
  581. stack = stack || [];
  582. replacementStack = replacementStack || [];
  583. if (replacer) {
  584. obj = replacer(key, obj);
  585. }
  586. var i;
  587. for (i = 0; i < stack.length; i += 1) {
  588. if (stack[i] === obj) {
  589. return replacementStack[i];
  590. }
  591. }
  592. var canonicalizedObj;
  593. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  594. stack.push(obj);
  595. canonicalizedObj = new Array(obj.length);
  596. replacementStack.push(canonicalizedObj);
  597. for (i = 0; i < obj.length; i += 1) {
  598. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
  599. }
  600. stack.pop();
  601. replacementStack.pop();
  602. return canonicalizedObj;
  603. }
  604. if (obj && obj.toJSON) {
  605. obj = obj.toJSON();
  606. }
  607. if (_typeof(obj) === 'object' && obj !== null) {
  608. stack.push(obj);
  609. canonicalizedObj = {};
  610. replacementStack.push(canonicalizedObj);
  611. var sortedKeys = [],
  612. _key;
  613. for (_key in obj) {
  614. /* istanbul ignore else */
  615. if (obj.hasOwnProperty(_key)) {
  616. sortedKeys.push(_key);
  617. }
  618. }
  619. sortedKeys.sort();
  620. for (i = 0; i < sortedKeys.length; i += 1) {
  621. _key = sortedKeys[i];
  622. canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
  623. }
  624. stack.pop();
  625. replacementStack.pop();
  626. } else {
  627. canonicalizedObj = obj;
  628. }
  629. return canonicalizedObj;
  630. }
  631. var arrayDiff = new Diff();
  632. arrayDiff.tokenize = function (value) {
  633. return value.slice();
  634. };
  635. arrayDiff.join = arrayDiff.removeEmpty = function (value) {
  636. return value;
  637. };
  638. function diffArrays(oldArr, newArr, callback) {
  639. return arrayDiff.diff(oldArr, newArr, callback);
  640. }
  641. function parsePatch(uniDiff) {
  642. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  643. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  644. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  645. list = [],
  646. i = 0;
  647. function parseIndex() {
  648. var index = {};
  649. list.push(index); // Parse diff metadata
  650. while (i < diffstr.length) {
  651. var line = diffstr[i]; // File header found, end parsing diff metadata
  652. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  653. break;
  654. } // Diff index
  655. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  656. if (header) {
  657. index.index = header[1];
  658. }
  659. i++;
  660. } // Parse file headers if they are defined. Unified diff requires them, but
  661. // there's no technical issues to have an isolated hunk without file header
  662. parseFileHeader(index);
  663. parseFileHeader(index); // Parse hunks
  664. index.hunks = [];
  665. while (i < diffstr.length) {
  666. var _line = diffstr[i];
  667. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  668. break;
  669. } else if (/^@@/.test(_line)) {
  670. index.hunks.push(parseHunk());
  671. } else if (_line && options.strict) {
  672. // Ignore unexpected content unless in strict mode
  673. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  674. } else {
  675. i++;
  676. }
  677. }
  678. } // Parses the --- and +++ headers, if none are found, no lines
  679. // are consumed.
  680. function parseFileHeader(index) {
  681. var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
  682. if (fileHeader) {
  683. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  684. var data = fileHeader[2].split('\t', 2);
  685. var fileName = data[0].replace(/\\\\/g, '\\');
  686. if (/^".*"$/.test(fileName)) {
  687. fileName = fileName.substr(1, fileName.length - 2);
  688. }
  689. index[keyPrefix + 'FileName'] = fileName;
  690. index[keyPrefix + 'Header'] = (data[1] || '').trim();
  691. i++;
  692. }
  693. } // Parses a hunk
  694. // This assumes that we are at the start of a hunk.
  695. function parseHunk() {
  696. var chunkHeaderIndex = i,
  697. chunkHeaderLine = diffstr[i++],
  698. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  699. var hunk = {
  700. oldStart: +chunkHeader[1],
  701. oldLines: +chunkHeader[2] || 1,
  702. newStart: +chunkHeader[3],
  703. newLines: +chunkHeader[4] || 1,
  704. lines: [],
  705. linedelimiters: []
  706. };
  707. var addCount = 0,
  708. removeCount = 0;
  709. for (; i < diffstr.length; i++) {
  710. // Lines starting with '---' could be mistaken for the "remove line" operation
  711. // But they could be the header for the next file. Therefore prune such cases out.
  712. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  713. break;
  714. }
  715. var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
  716. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  717. hunk.lines.push(diffstr[i]);
  718. hunk.linedelimiters.push(delimiters[i] || '\n');
  719. if (operation === '+') {
  720. addCount++;
  721. } else if (operation === '-') {
  722. removeCount++;
  723. } else if (operation === ' ') {
  724. addCount++;
  725. removeCount++;
  726. }
  727. } else {
  728. break;
  729. }
  730. } // Handle the empty block count case
  731. if (!addCount && hunk.newLines === 1) {
  732. hunk.newLines = 0;
  733. }
  734. if (!removeCount && hunk.oldLines === 1) {
  735. hunk.oldLines = 0;
  736. } // Perform optional sanity checking
  737. if (options.strict) {
  738. if (addCount !== hunk.newLines) {
  739. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  740. }
  741. if (removeCount !== hunk.oldLines) {
  742. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  743. }
  744. }
  745. return hunk;
  746. }
  747. while (i < diffstr.length) {
  748. parseIndex();
  749. }
  750. return list;
  751. } // Iterator that traverses in the range of [min, max], stepping
  752. // by distance from a given start position. I.e. for [0, 4], with
  753. // start of 2, this will iterate 2, 3, 1, 4, 0.
  754. function distanceIterator(start, minLine, maxLine) {
  755. var wantForward = true,
  756. backwardExhausted = false,
  757. forwardExhausted = false,
  758. localOffset = 1;
  759. return function iterator() {
  760. if (wantForward && !forwardExhausted) {
  761. if (backwardExhausted) {
  762. localOffset++;
  763. } else {
  764. wantForward = false;
  765. } // Check if trying to fit beyond text length, and if not, check it fits
  766. // after offset location (or desired location on first iteration)
  767. if (start + localOffset <= maxLine) {
  768. return localOffset;
  769. }
  770. forwardExhausted = true;
  771. }
  772. if (!backwardExhausted) {
  773. if (!forwardExhausted) {
  774. wantForward = true;
  775. } // Check if trying to fit before text beginning, and if not, check it fits
  776. // before offset location
  777. if (minLine <= start - localOffset) {
  778. return -localOffset++;
  779. }
  780. backwardExhausted = true;
  781. return iterator();
  782. } // We tried to fit hunk before text beginning and beyond text length, then
  783. // hunk can't fit on the text. Return undefined
  784. };
  785. }
  786. function applyPatch(source, uniDiff) {
  787. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  788. if (typeof uniDiff === 'string') {
  789. uniDiff = parsePatch(uniDiff);
  790. }
  791. if (Array.isArray(uniDiff)) {
  792. if (uniDiff.length > 1) {
  793. throw new Error('applyPatch only works with a single input.');
  794. }
  795. uniDiff = uniDiff[0];
  796. } // Apply the diff to the input
  797. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  798. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  799. hunks = uniDiff.hunks,
  800. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
  801. return line === patchContent;
  802. },
  803. errorCount = 0,
  804. fuzzFactor = options.fuzzFactor || 0,
  805. minLine = 0,
  806. offset = 0,
  807. removeEOFNL,
  808. addEOFNL;
  809. /**
  810. * Checks if the hunk exactly fits on the provided location
  811. */
  812. function hunkFits(hunk, toPos) {
  813. for (var j = 0; j < hunk.lines.length; j++) {
  814. var line = hunk.lines[j],
  815. operation = line.length > 0 ? line[0] : ' ',
  816. content = line.length > 0 ? line.substr(1) : line;
  817. if (operation === ' ' || operation === '-') {
  818. // Context sanity check
  819. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  820. errorCount++;
  821. if (errorCount > fuzzFactor) {
  822. return false;
  823. }
  824. }
  825. toPos++;
  826. }
  827. }
  828. return true;
  829. } // Search best fit offsets for each hunk based on the previous ones
  830. for (var i = 0; i < hunks.length; i++) {
  831. var hunk = hunks[i],
  832. maxLine = lines.length - hunk.oldLines,
  833. localOffset = 0,
  834. toPos = offset + hunk.oldStart - 1;
  835. var iterator = distanceIterator(toPos, minLine, maxLine);
  836. for (; localOffset !== undefined; localOffset = iterator()) {
  837. if (hunkFits(hunk, toPos + localOffset)) {
  838. hunk.offset = offset += localOffset;
  839. break;
  840. }
  841. }
  842. if (localOffset === undefined) {
  843. return false;
  844. } // Set lower text limit to end of the current hunk, so next ones don't try
  845. // to fit over already patched text
  846. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  847. } // Apply patch hunks
  848. var diffOffset = 0;
  849. for (var _i = 0; _i < hunks.length; _i++) {
  850. var _hunk = hunks[_i],
  851. _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
  852. diffOffset += _hunk.newLines - _hunk.oldLines;
  853. if (_toPos < 0) {
  854. // Creating a new file
  855. _toPos = 0;
  856. }
  857. for (var j = 0; j < _hunk.lines.length; j++) {
  858. var line = _hunk.lines[j],
  859. operation = line.length > 0 ? line[0] : ' ',
  860. content = line.length > 0 ? line.substr(1) : line,
  861. delimiter = _hunk.linedelimiters[j];
  862. if (operation === ' ') {
  863. _toPos++;
  864. } else if (operation === '-') {
  865. lines.splice(_toPos, 1);
  866. delimiters.splice(_toPos, 1);
  867. /* istanbul ignore else */
  868. } else if (operation === '+') {
  869. lines.splice(_toPos, 0, content);
  870. delimiters.splice(_toPos, 0, delimiter);
  871. _toPos++;
  872. } else if (operation === '\\') {
  873. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  874. if (previousOperation === '+') {
  875. removeEOFNL = true;
  876. } else if (previousOperation === '-') {
  877. addEOFNL = true;
  878. }
  879. }
  880. }
  881. } // Handle EOFNL insertion/removal
  882. if (removeEOFNL) {
  883. while (!lines[lines.length - 1]) {
  884. lines.pop();
  885. delimiters.pop();
  886. }
  887. } else if (addEOFNL) {
  888. lines.push('');
  889. delimiters.push('\n');
  890. }
  891. for (var _k = 0; _k < lines.length - 1; _k++) {
  892. lines[_k] = lines[_k] + delimiters[_k];
  893. }
  894. return lines.join('');
  895. } // Wrapper that supports multiple file patches via callbacks.
  896. function applyPatches(uniDiff, options) {
  897. if (typeof uniDiff === 'string') {
  898. uniDiff = parsePatch(uniDiff);
  899. }
  900. var currentIndex = 0;
  901. function processIndex() {
  902. var index = uniDiff[currentIndex++];
  903. if (!index) {
  904. return options.complete();
  905. }
  906. options.loadFile(index, function (err, data) {
  907. if (err) {
  908. return options.complete(err);
  909. }
  910. var updatedContent = applyPatch(data, index, options);
  911. options.patched(index, updatedContent, function (err) {
  912. if (err) {
  913. return options.complete(err);
  914. }
  915. processIndex();
  916. });
  917. });
  918. }
  919. processIndex();
  920. }
  921. function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  922. if (!options) {
  923. options = {};
  924. }
  925. if (typeof options.context === 'undefined') {
  926. options.context = 4;
  927. }
  928. var diff = diffLines(oldStr, newStr, options);
  929. diff.push({
  930. value: '',
  931. lines: []
  932. }); // Append an empty value to make cleanup easier
  933. function contextLines(lines) {
  934. return lines.map(function (entry) {
  935. return ' ' + entry;
  936. });
  937. }
  938. var hunks = [];
  939. var oldRangeStart = 0,
  940. newRangeStart = 0,
  941. curRange = [],
  942. oldLine = 1,
  943. newLine = 1;
  944. var _loop = function _loop(i) {
  945. var current = diff[i],
  946. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  947. current.lines = lines;
  948. if (current.added || current.removed) {
  949. var _curRange; // If we have previous context, start with that
  950. if (!oldRangeStart) {
  951. var prev = diff[i - 1];
  952. oldRangeStart = oldLine;
  953. newRangeStart = newLine;
  954. if (prev) {
  955. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  956. oldRangeStart -= curRange.length;
  957. newRangeStart -= curRange.length;
  958. }
  959. } // Output our changes
  960. (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
  961. return (current.added ? '+' : '-') + entry;
  962. }))); // Track the updated file position
  963. if (current.added) {
  964. newLine += lines.length;
  965. } else {
  966. oldLine += lines.length;
  967. }
  968. } else {
  969. // Identical context lines. Track line changes
  970. if (oldRangeStart) {
  971. // Close out any changes that have been output (or join overlapping)
  972. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  973. var _curRange2; // Overlapping
  974. (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
  975. } else {
  976. var _curRange3; // end the range and output
  977. var contextSize = Math.min(lines.length, options.context);
  978. (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
  979. var hunk = {
  980. oldStart: oldRangeStart,
  981. oldLines: oldLine - oldRangeStart + contextSize,
  982. newStart: newRangeStart,
  983. newLines: newLine - newRangeStart + contextSize,
  984. lines: curRange
  985. };
  986. if (i >= diff.length - 2 && lines.length <= options.context) {
  987. // EOF is inside this hunk
  988. var oldEOFNewline = /\n$/.test(oldStr);
  989. var newEOFNewline = /\n$/.test(newStr);
  990. var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
  991. if (!oldEOFNewline && noNlBeforeAdds) {
  992. // special case: old has no eol and no trailing context; no-nl can end up before adds
  993. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  994. }
  995. if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
  996. curRange.push('\\ No newline at end of file');
  997. }
  998. }
  999. hunks.push(hunk);
  1000. oldRangeStart = 0;
  1001. newRangeStart = 0;
  1002. curRange = [];
  1003. }
  1004. }
  1005. oldLine += lines.length;
  1006. newLine += lines.length;
  1007. }
  1008. };
  1009. for (var i = 0; i < diff.length; i++) {
  1010. _loop(i);
  1011. }
  1012. return {
  1013. oldFileName: oldFileName,
  1014. newFileName: newFileName,
  1015. oldHeader: oldHeader,
  1016. newHeader: newHeader,
  1017. hunks: hunks
  1018. };
  1019. }
  1020. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1021. var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
  1022. var ret = [];
  1023. if (oldFileName == newFileName) {
  1024. ret.push('Index: ' + oldFileName);
  1025. }
  1026. ret.push('===================================================================');
  1027. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  1028. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  1029. for (var i = 0; i < diff.hunks.length; i++) {
  1030. var hunk = diff.hunks[i];
  1031. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  1032. ret.push.apply(ret, hunk.lines);
  1033. }
  1034. return ret.join('\n') + '\n';
  1035. }
  1036. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  1037. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  1038. }
  1039. function arrayEqual(a, b) {
  1040. if (a.length !== b.length) {
  1041. return false;
  1042. }
  1043. return arrayStartsWith(a, b);
  1044. }
  1045. function arrayStartsWith(array, start) {
  1046. if (start.length > array.length) {
  1047. return false;
  1048. }
  1049. for (var i = 0; i < start.length; i++) {
  1050. if (start[i] !== array[i]) {
  1051. return false;
  1052. }
  1053. }
  1054. return true;
  1055. }
  1056. function calcLineCount(hunk) {
  1057. var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines),
  1058. oldLines = _calcOldNewLineCount.oldLines,
  1059. newLines = _calcOldNewLineCount.newLines;
  1060. if (oldLines !== undefined) {
  1061. hunk.oldLines = oldLines;
  1062. } else {
  1063. delete hunk.oldLines;
  1064. }
  1065. if (newLines !== undefined) {
  1066. hunk.newLines = newLines;
  1067. } else {
  1068. delete hunk.newLines;
  1069. }
  1070. }
  1071. function merge(mine, theirs, base) {
  1072. mine = loadPatch(mine, base);
  1073. theirs = loadPatch(theirs, base);
  1074. var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
  1075. // Leaving sanity checks on this to the API consumer that may know more about the
  1076. // meaning in their own context.
  1077. if (mine.index || theirs.index) {
  1078. ret.index = mine.index || theirs.index;
  1079. }
  1080. if (mine.newFileName || theirs.newFileName) {
  1081. if (!fileNameChanged(mine)) {
  1082. // No header or no change in ours, use theirs (and ours if theirs does not exist)
  1083. ret.oldFileName = theirs.oldFileName || mine.oldFileName;
  1084. ret.newFileName = theirs.newFileName || mine.newFileName;
  1085. ret.oldHeader = theirs.oldHeader || mine.oldHeader;
  1086. ret.newHeader = theirs.newHeader || mine.newHeader;
  1087. } else if (!fileNameChanged(theirs)) {
  1088. // No header or no change in theirs, use ours
  1089. ret.oldFileName = mine.oldFileName;
  1090. ret.newFileName = mine.newFileName;
  1091. ret.oldHeader = mine.oldHeader;
  1092. ret.newHeader = mine.newHeader;
  1093. } else {
  1094. // Both changed... figure it out
  1095. ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
  1096. ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
  1097. ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
  1098. ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
  1099. }
  1100. }
  1101. ret.hunks = [];
  1102. var mineIndex = 0,
  1103. theirsIndex = 0,
  1104. mineOffset = 0,
  1105. theirsOffset = 0;
  1106. while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
  1107. var mineCurrent = mine.hunks[mineIndex] || {
  1108. oldStart: Infinity
  1109. },
  1110. theirsCurrent = theirs.hunks[theirsIndex] || {
  1111. oldStart: Infinity
  1112. };
  1113. if (hunkBefore(mineCurrent, theirsCurrent)) {
  1114. // This patch does not overlap with any of the others, yay.
  1115. ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
  1116. mineIndex++;
  1117. theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
  1118. } else if (hunkBefore(theirsCurrent, mineCurrent)) {
  1119. // This patch does not overlap with any of the others, yay.
  1120. ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
  1121. theirsIndex++;
  1122. mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
  1123. } else {
  1124. // Overlap, merge as best we can
  1125. var mergedHunk = {
  1126. oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
  1127. oldLines: 0,
  1128. newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
  1129. newLines: 0,
  1130. lines: []
  1131. };
  1132. mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
  1133. theirsIndex++;
  1134. mineIndex++;
  1135. ret.hunks.push(mergedHunk);
  1136. }
  1137. }
  1138. return ret;
  1139. }
  1140. function loadPatch(param, base) {
  1141. if (typeof param === 'string') {
  1142. if (/^@@/m.test(param) || /^Index:/m.test(param)) {
  1143. return parsePatch(param)[0];
  1144. }
  1145. if (!base) {
  1146. throw new Error('Must provide a base reference or pass in a patch');
  1147. }
  1148. return structuredPatch(undefined, undefined, base, param);
  1149. }
  1150. return param;
  1151. }
  1152. function fileNameChanged(patch) {
  1153. return patch.newFileName && patch.newFileName !== patch.oldFileName;
  1154. }
  1155. function selectField(index, mine, theirs) {
  1156. if (mine === theirs) {
  1157. return mine;
  1158. } else {
  1159. index.conflict = true;
  1160. return {
  1161. mine: mine,
  1162. theirs: theirs
  1163. };
  1164. }
  1165. }
  1166. function hunkBefore(test, check) {
  1167. return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
  1168. }
  1169. function cloneHunk(hunk, offset) {
  1170. return {
  1171. oldStart: hunk.oldStart,
  1172. oldLines: hunk.oldLines,
  1173. newStart: hunk.newStart + offset,
  1174. newLines: hunk.newLines,
  1175. lines: hunk.lines
  1176. };
  1177. }
  1178. function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
  1179. // This will generally result in a conflicted hunk, but there are cases where the context
  1180. // is the only overlap where we can successfully merge the content here.
  1181. var mine = {
  1182. offset: mineOffset,
  1183. lines: mineLines,
  1184. index: 0
  1185. },
  1186. their = {
  1187. offset: theirOffset,
  1188. lines: theirLines,
  1189. index: 0
  1190. }; // Handle any leading content
  1191. insertLeading(hunk, mine, their);
  1192. insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
  1193. while (mine.index < mine.lines.length && their.index < their.lines.length) {
  1194. var mineCurrent = mine.lines[mine.index],
  1195. theirCurrent = their.lines[their.index];
  1196. if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
  1197. // Both modified ...
  1198. mutualChange(hunk, mine, their);
  1199. } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
  1200. var _hunk$lines; // Mine inserted
  1201. (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine)));
  1202. } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
  1203. var _hunk$lines2; // Theirs inserted
  1204. (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their)));
  1205. } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
  1206. // Mine removed or edited
  1207. removal(hunk, mine, their);
  1208. } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
  1209. // Their removed or edited
  1210. removal(hunk, their, mine, true);
  1211. } else if (mineCurrent === theirCurrent) {
  1212. // Context identity
  1213. hunk.lines.push(mineCurrent);
  1214. mine.index++;
  1215. their.index++;
  1216. } else {
  1217. // Context mismatch
  1218. conflict(hunk, collectChange(mine), collectChange(their));
  1219. }
  1220. } // Now push anything that may be remaining
  1221. insertTrailing(hunk, mine);
  1222. insertTrailing(hunk, their);
  1223. calcLineCount(hunk);
  1224. }
  1225. function mutualChange(hunk, mine, their) {
  1226. var myChanges = collectChange(mine),
  1227. theirChanges = collectChange(their);
  1228. if (allRemoves(myChanges) && allRemoves(theirChanges)) {
  1229. // Special case for remove changes that are supersets of one another
  1230. if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
  1231. var _hunk$lines3;
  1232. (_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray(myChanges));
  1233. return;
  1234. } else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
  1235. var _hunk$lines4;
  1236. (_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray(theirChanges));
  1237. return;
  1238. }
  1239. } else if (arrayEqual(myChanges, theirChanges)) {
  1240. var _hunk$lines5;
  1241. (_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray(myChanges));
  1242. return;
  1243. }
  1244. conflict(hunk, myChanges, theirChanges);
  1245. }
  1246. function removal(hunk, mine, their, swap) {
  1247. var myChanges = collectChange(mine),
  1248. theirChanges = collectContext(their, myChanges);
  1249. if (theirChanges.merged) {
  1250. var _hunk$lines6;
  1251. (_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray(theirChanges.merged));
  1252. } else {
  1253. conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
  1254. }
  1255. }
  1256. function conflict(hunk, mine, their) {
  1257. hunk.conflict = true;
  1258. hunk.lines.push({
  1259. conflict: true,
  1260. mine: mine,
  1261. theirs: their
  1262. });
  1263. }
  1264. function insertLeading(hunk, insert, their) {
  1265. while (insert.offset < their.offset && insert.index < insert.lines.length) {
  1266. var line = insert.lines[insert.index++];
  1267. hunk.lines.push(line);
  1268. insert.offset++;
  1269. }
  1270. }
  1271. function insertTrailing(hunk, insert) {
  1272. while (insert.index < insert.lines.length) {
  1273. var line = insert.lines[insert.index++];
  1274. hunk.lines.push(line);
  1275. }
  1276. }
  1277. function collectChange(state) {
  1278. var ret = [],
  1279. operation = state.lines[state.index][0];
  1280. while (state.index < state.lines.length) {
  1281. var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
  1282. if (operation === '-' && line[0] === '+') {
  1283. operation = '+';
  1284. }
  1285. if (operation === line[0]) {
  1286. ret.push(line);
  1287. state.index++;
  1288. } else {
  1289. break;
  1290. }
  1291. }
  1292. return ret;
  1293. }
  1294. function collectContext(state, matchChanges) {
  1295. var changes = [],
  1296. merged = [],
  1297. matchIndex = 0,
  1298. contextChanges = false,
  1299. conflicted = false;
  1300. while (matchIndex < matchChanges.length && state.index < state.lines.length) {
  1301. var change = state.lines[state.index],
  1302. match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
  1303. if (match[0] === '+') {
  1304. break;
  1305. }
  1306. contextChanges = contextChanges || change[0] !== ' ';
  1307. merged.push(match);
  1308. matchIndex++; // Consume any additions in the other block as a conflict to attempt
  1309. // to pull in the remaining context after this
  1310. if (change[0] === '+') {
  1311. conflicted = true;
  1312. while (change[0] === '+') {
  1313. changes.push(change);
  1314. change = state.lines[++state.index];
  1315. }
  1316. }
  1317. if (match.substr(1) === change.substr(1)) {
  1318. changes.push(change);
  1319. state.index++;
  1320. } else {
  1321. conflicted = true;
  1322. }
  1323. }
  1324. if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
  1325. conflicted = true;
  1326. }
  1327. if (conflicted) {
  1328. return changes;
  1329. }
  1330. while (matchIndex < matchChanges.length) {
  1331. merged.push(matchChanges[matchIndex++]);
  1332. }
  1333. return {
  1334. merged: merged,
  1335. changes: changes
  1336. };
  1337. }
  1338. function allRemoves(changes) {
  1339. return changes.reduce(function (prev, change) {
  1340. return prev && change[0] === '-';
  1341. }, true);
  1342. }
  1343. function skipRemoveSuperset(state, removeChanges, delta) {
  1344. for (var i = 0; i < delta; i++) {
  1345. var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
  1346. if (state.lines[state.index + i] !== ' ' + changeContent) {
  1347. return false;
  1348. }
  1349. }
  1350. state.index += delta;
  1351. return true;
  1352. }
  1353. function calcOldNewLineCount(lines) {
  1354. var oldLines = 0;
  1355. var newLines = 0;
  1356. lines.forEach(function (line) {
  1357. if (typeof line !== 'string') {
  1358. var myCount = calcOldNewLineCount(line.mine);
  1359. var theirCount = calcOldNewLineCount(line.theirs);
  1360. if (oldLines !== undefined) {
  1361. if (myCount.oldLines === theirCount.oldLines) {
  1362. oldLines += myCount.oldLines;
  1363. } else {
  1364. oldLines = undefined;
  1365. }
  1366. }
  1367. if (newLines !== undefined) {
  1368. if (myCount.newLines === theirCount.newLines) {
  1369. newLines += myCount.newLines;
  1370. } else {
  1371. newLines = undefined;
  1372. }
  1373. }
  1374. } else {
  1375. if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
  1376. newLines++;
  1377. }
  1378. if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
  1379. oldLines++;
  1380. }
  1381. }
  1382. });
  1383. return {
  1384. oldLines: oldLines,
  1385. newLines: newLines
  1386. };
  1387. } // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  1388. function convertChangesToDMP(changes) {
  1389. var ret = [],
  1390. change,
  1391. operation;
  1392. for (var i = 0; i < changes.length; i++) {
  1393. change = changes[i];
  1394. if (change.added) {
  1395. operation = 1;
  1396. } else if (change.removed) {
  1397. operation = -1;
  1398. } else {
  1399. operation = 0;
  1400. }
  1401. ret.push([operation, change.value]);
  1402. }
  1403. return ret;
  1404. }
  1405. function convertChangesToXML(changes) {
  1406. var ret = [];
  1407. for (var i = 0; i < changes.length; i++) {
  1408. var change = changes[i];
  1409. if (change.added) {
  1410. ret.push('<ins>');
  1411. } else if (change.removed) {
  1412. ret.push('<del>');
  1413. }
  1414. ret.push(escapeHTML(change.value));
  1415. if (change.added) {
  1416. ret.push('</ins>');
  1417. } else if (change.removed) {
  1418. ret.push('</del>');
  1419. }
  1420. }
  1421. return ret.join('');
  1422. }
  1423. function escapeHTML(s) {
  1424. var n = s;
  1425. n = n.replace(/&/g, '&amp;');
  1426. n = n.replace(/</g, '&lt;');
  1427. n = n.replace(/>/g, '&gt;');
  1428. n = n.replace(/"/g, '&quot;');
  1429. return n;
  1430. }
  1431. var index_es6 = /*#__PURE__*/Object.freeze({
  1432. __proto__: null,
  1433. Diff: Diff,
  1434. diffChars: diffChars,
  1435. diffWords: diffWords,
  1436. diffWordsWithSpace: diffWordsWithSpace,
  1437. diffLines: diffLines,
  1438. diffTrimmedLines: diffTrimmedLines,
  1439. diffSentences: diffSentences,
  1440. diffCss: diffCss,
  1441. diffJson: diffJson,
  1442. diffArrays: diffArrays,
  1443. structuredPatch: structuredPatch,
  1444. createTwoFilesPatch: createTwoFilesPatch,
  1445. createPatch: createPatch,
  1446. applyPatch: applyPatch,
  1447. applyPatches: applyPatches,
  1448. parsePatch: parsePatch,
  1449. merge: merge,
  1450. convertChangesToDMP: convertChangesToDMP,
  1451. convertChangesToXML: convertChangesToXML,
  1452. canonicalize: canonicalize
  1453. });
  1454. /**
  1455. * @param {Doc[]} parts
  1456. * @returns Doc
  1457. */
  1458. function concat(parts) {
  1459. // access the internals of a document directly.
  1460. // if(parts.length === 1) {
  1461. // // If it's a single document, no need to concat it.
  1462. // return parts[0];
  1463. // }
  1464. return {
  1465. type: "concat",
  1466. parts
  1467. };
  1468. }
  1469. /**
  1470. * @param {Doc} contents
  1471. * @returns Doc
  1472. */
  1473. function indent(contents) {
  1474. return {
  1475. type: "indent",
  1476. contents
  1477. };
  1478. }
  1479. /**
  1480. * @param {number | string} n
  1481. * @param {Doc} contents
  1482. * @returns Doc
  1483. */
  1484. function align(n, contents) {
  1485. return {
  1486. type: "align",
  1487. contents,
  1488. n
  1489. };
  1490. }
  1491. /**
  1492. * @param {Doc} contents
  1493. * @param {object} [opts] - TBD ???
  1494. * @returns Doc
  1495. */
  1496. function group(contents, opts) {
  1497. opts = opts || {};
  1498. return {
  1499. type: "group",
  1500. id: opts.id,
  1501. contents,
  1502. break: !!opts.shouldBreak,
  1503. expandedStates: opts.expandedStates
  1504. };
  1505. }
  1506. /**
  1507. * @param {Doc} contents
  1508. * @returns Doc
  1509. */
  1510. function dedentToRoot(contents) {
  1511. return align(-Infinity, contents);
  1512. }
  1513. /**
  1514. * @param {Doc} contents
  1515. * @returns Doc
  1516. */
  1517. function markAsRoot(contents) {
  1518. // @ts-ignore - TBD ???:
  1519. return align({
  1520. type: "root"
  1521. }, contents);
  1522. }
  1523. /**
  1524. * @param {Doc} contents
  1525. * @returns Doc
  1526. */
  1527. function dedent(contents) {
  1528. return align(-1, contents);
  1529. }
  1530. /**
  1531. * @param {Doc[]} states
  1532. * @param {object} [opts] - TBD ???
  1533. * @returns Doc
  1534. */
  1535. function conditionalGroup(states, opts) {
  1536. return group(states[0], Object.assign({}, opts, {
  1537. expandedStates: states
  1538. }));
  1539. }
  1540. /**
  1541. * @param {Doc[]} parts
  1542. * @returns Doc
  1543. */
  1544. function fill(parts) {
  1545. return {
  1546. type: "fill",
  1547. parts
  1548. };
  1549. }
  1550. /**
  1551. * @param {Doc} [breakContents]
  1552. * @param {Doc} [flatContents]
  1553. * @param {object} [opts] - TBD ???
  1554. * @returns Doc
  1555. */
  1556. function ifBreak(breakContents, flatContents, opts) {
  1557. opts = opts || {};
  1558. return {
  1559. type: "if-break",
  1560. breakContents,
  1561. flatContents,
  1562. groupId: opts.groupId
  1563. };
  1564. }
  1565. /**
  1566. * @param {Doc} contents
  1567. * @returns Doc
  1568. */
  1569. function lineSuffix(contents) {
  1570. return {
  1571. type: "line-suffix",
  1572. contents
  1573. };
  1574. }
  1575. const lineSuffixBoundary = {
  1576. type: "line-suffix-boundary"
  1577. };
  1578. const breakParent = {
  1579. type: "break-parent"
  1580. };
  1581. const trim = {
  1582. type: "trim"
  1583. };
  1584. const line = {
  1585. type: "line"
  1586. };
  1587. const softline = {
  1588. type: "line",
  1589. soft: true
  1590. };
  1591. const hardline = concat([{
  1592. type: "line",
  1593. hard: true
  1594. }, breakParent]);
  1595. const literalline = concat([{
  1596. type: "line",
  1597. hard: true,
  1598. literal: true
  1599. }, breakParent]);
  1600. const cursor = {
  1601. type: "cursor",
  1602. placeholder: Symbol("cursor")
  1603. };
  1604. /**
  1605. * @param {Doc} sep
  1606. * @param {Doc[]} arr
  1607. * @returns Doc
  1608. */
  1609. function join(sep, arr) {
  1610. const res = [];
  1611. for (let i = 0; i < arr.length; i++) {
  1612. if (i !== 0) {
  1613. res.push(sep);
  1614. }
  1615. res.push(arr[i]);
  1616. }
  1617. return concat(res);
  1618. }
  1619. /**
  1620. * @param {Doc} doc
  1621. * @param {number} size
  1622. * @param {number} tabWidth
  1623. */
  1624. function addAlignmentToDoc(doc, size, tabWidth) {
  1625. let aligned = doc;
  1626. if (size > 0) {
  1627. // Use indent to add tabs for all the levels of tabs we need
  1628. for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
  1629. aligned = indent(aligned);
  1630. } // Use align for all the spaces that are needed
  1631. aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current
  1632. // indentation, so we use -Infinity to reset the indentation to 0
  1633. aligned = align(-Infinity, aligned);
  1634. }
  1635. return aligned;
  1636. }
  1637. var docBuilders = {
  1638. concat,
  1639. join,
  1640. line,
  1641. softline,
  1642. hardline,
  1643. literalline,
  1644. group,
  1645. conditionalGroup,
  1646. fill,
  1647. lineSuffix,
  1648. lineSuffixBoundary,
  1649. cursor,
  1650. breakParent,
  1651. ifBreak,
  1652. trim,
  1653. indent,
  1654. align,
  1655. addAlignmentToDoc,
  1656. markAsRoot,
  1657. dedentToRoot,
  1658. dedent
  1659. };
  1660. var ansiRegex = ({
  1661. onlyFirst = false
  1662. } = {}) => {
  1663. const pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
  1664. return new RegExp(pattern, onlyFirst ? undefined : 'g');
  1665. };
  1666. var stripAnsi = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
  1667. /* eslint-disable yoda */
  1668. const isFullwidthCodePoint = codePoint => {
  1669. if (Number.isNaN(codePoint)) {
  1670. return false;
  1671. } // Code points are derived from:
  1672. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  1673. if (codePoint >= 0x1100 && (codePoint <= 0x115F || // Hangul Jamo
  1674. codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  1675. codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
  1676. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  1677. 0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  1678. 0x3250 <= codePoint && codePoint <= 0x4DBF || // CJK Unified Ideographs .. Yi Radicals
  1679. 0x4E00 <= codePoint && codePoint <= 0xA4C6 || // Hangul Jamo Extended-A
  1680. 0xA960 <= codePoint && codePoint <= 0xA97C || // Hangul Syllables
  1681. 0xAC00 <= codePoint && codePoint <= 0xD7A3 || // CJK Compatibility Ideographs
  1682. 0xF900 <= codePoint && codePoint <= 0xFAFF || // Vertical Forms
  1683. 0xFE10 <= codePoint && codePoint <= 0xFE19 || // CJK Compatibility Forms .. Small Form Variants
  1684. 0xFE30 <= codePoint && codePoint <= 0xFE6B || // Halfwidth and Fullwidth Forms
  1685. 0xFF01 <= codePoint && codePoint <= 0xFF60 || 0xFFE0 <= codePoint && codePoint <= 0xFFE6 || // Kana Supplement
  1686. 0x1B000 <= codePoint && codePoint <= 0x1B001 || // Enclosed Ideographic Supplement
  1687. 0x1F200 <= codePoint && codePoint <= 0x1F251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  1688. 0x20000 <= codePoint && codePoint <= 0x3FFFD)) {
  1689. return true;
  1690. }
  1691. return false;
  1692. };
  1693. var isFullwidthCodePoint_1 = isFullwidthCodePoint;
  1694. var _default = isFullwidthCodePoint;
  1695. isFullwidthCodePoint_1.default = _default;
  1696. var emojiRegex = function () {
  1697. // https://mths.be/emoji
  1698. return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
  1699. };
  1700. const stringWidth = string => {
  1701. string = string.replace(emojiRegex(), ' ');
  1702. if (typeof string !== 'string' || string.length === 0) {
  1703. return 0;
  1704. }
  1705. string = stripAnsi(string);
  1706. let width = 0;
  1707. for (let i = 0; i < string.length; i++) {
  1708. const code = string.codePointAt(i); // Ignore control characters
  1709. if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
  1710. continue;
  1711. } // Ignore combining characters
  1712. if (code >= 0x300 && code <= 0x36F) {
  1713. continue;
  1714. } // Surrogates
  1715. if (code > 0xFFFF) {
  1716. i++;
  1717. }
  1718. width += isFullwidthCodePoint_1(code) ? 2 : 1;
  1719. }
  1720. return width;
  1721. };
  1722. var stringWidth_1 = stringWidth; // TODO: remove this in the next major version
  1723. var _default$1 = stringWidth;
  1724. stringWidth_1.default = _default$1;
  1725. var escapeStringRegexp = string => {
  1726. if (typeof string !== 'string') {
  1727. throw new TypeError('Expected a string');
  1728. } // Escape characters with special meaning either inside or outside character sets.
  1729. // Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
  1730. return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
  1731. };
  1732. var getLast = arr => arr[arr.length - 1];
  1733. function _objectWithoutPropertiesLoose(source, excluded) {
  1734. if (source == null) return {};
  1735. var target = {};
  1736. var sourceKeys = Object.keys(source);
  1737. var key, i;
  1738. for (i = 0; i < sourceKeys.length; i++) {
  1739. key = sourceKeys[i];
  1740. if (excluded.indexOf(key) >= 0) continue;
  1741. target[key] = source[key];
  1742. }
  1743. return target;
  1744. }
  1745. const debug = typeof process === 'object' && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error('SEMVER', ...args) : () => {};
  1746. var debug_1 = debug;
  1747. // Note: this is the semver.org version of the spec that it implements
  1748. // Not necessarily the package version of this code.
  1749. const SEMVER_SPEC_VERSION = '2.0.0';
  1750. const MAX_LENGTH = 256;
  1751. const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
  1752. /* istanbul ignore next */
  1753. 9007199254740991; // Max safe segment length for coercion.
  1754. const MAX_SAFE_COMPONENT_LENGTH = 16;
  1755. var constants = {
  1756. SEMVER_SPEC_VERSION,
  1757. MAX_LENGTH,
  1758. MAX_SAFE_INTEGER,
  1759. MAX_SAFE_COMPONENT_LENGTH
  1760. };
  1761. function createCommonjsModule(fn, basedir, module) {
  1762. return module = {
  1763. path: basedir,
  1764. exports: {},
  1765. require: function (path, base) {
  1766. return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
  1767. }
  1768. }, fn(module, module.exports), module.exports;
  1769. }
  1770. function getCjsExportFromNamespace (n) {
  1771. return n && n['default'] || n;
  1772. }
  1773. function commonjsRequire () {
  1774. throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
  1775. }
  1776. var re_1 = createCommonjsModule(function (module, exports) {
  1777. const {
  1778. MAX_SAFE_COMPONENT_LENGTH
  1779. } = constants;
  1780. exports = module.exports = {}; // The actual regexps go on exports.re
  1781. const re = exports.re = [];
  1782. const src = exports.src = [];
  1783. const t = exports.t = {};
  1784. let R = 0;
  1785. const createToken = (name, value, isGlobal) => {
  1786. const index = R++;
  1787. debug_1(index, value);
  1788. t[name] = index;
  1789. src[index] = value;
  1790. re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
  1791. }; // The following Regular Expressions can be used for tokenizing,
  1792. // validating, and parsing SemVer version strings.
  1793. // ## Numeric Identifier
  1794. // A single `0`, or a non-zero digit followed by zero or more digits.
  1795. createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
  1796. createToken('NUMERICIDENTIFIERLOOSE', '[0-9]+'); // ## Non-numeric Identifier
  1797. // Zero or more digits, followed by a letter or hyphen, and then zero or
  1798. // more letters, digits, or hyphens.
  1799. createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*'); // ## Main Version
  1800. // Three dot-separated numeric identifiers.
  1801. createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` + `(${src[t.NUMERICIDENTIFIER]})\\.` + `(${src[t.NUMERICIDENTIFIER]})`);
  1802. createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` + `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` + `(${src[t.NUMERICIDENTIFIERLOOSE]})`); // ## Pre-release Version Identifier
  1803. // A numeric identifier, or a non-numeric identifier.
  1804. createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER]}|${src[t.NONNUMERICIDENTIFIER]})`);
  1805. createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE]}|${src[t.NONNUMERICIDENTIFIER]})`); // ## Pre-release Version
  1806. // Hyphen, followed by one or more dot-separated pre-release version
  1807. // identifiers.
  1808. createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
  1809. createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`); // ## Build Metadata Identifier
  1810. // Any combination of digits, letters, or hyphens.
  1811. createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+'); // ## Build Metadata
  1812. // Plus sign, followed by one or more period-separated build metadata
  1813. // identifiers.
  1814. createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`); // ## Full Version String
  1815. // A main version, followed optionally by a pre-release version and
  1816. // build metadata.
  1817. // Note that the only major, minor, patch, and pre-release sections of
  1818. // the version string are capturing groups. The build metadata is not a
  1819. // capturing group, because it should not ever be used in version
  1820. // comparison.
  1821. createToken('FULLPLAIN', `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`);
  1822. createToken('FULL', `^${src[t.FULLPLAIN]}$`); // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  1823. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  1824. // common in the npm registry.
  1825. createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`);
  1826. createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
  1827. createToken('GTLT', '((?:<|>)?=?)'); // Something like "2.*" or "1.2.x".
  1828. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  1829. // Only the first item is strictly required.
  1830. createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
  1831. createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
  1832. createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` + `(?:\\.(${src[t.XRANGEIDENTIFIER]})` + `(?:\\.(${src[t.XRANGEIDENTIFIER]})` + `(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?` + `)?)?`);
  1833. createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` + `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` + `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` + `(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?` + `)?)?`);
  1834. createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
  1835. createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`); // Coercion.
  1836. // Extract anything that could conceivably be a part of a valid semver
  1837. createToken('COERCE', `${'(^|[^\\d])' + '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` + `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` + `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` + `(?:$|[^\\d])`);
  1838. createToken('COERCERTL', src[t.COERCE], true); // Tilde ranges.
  1839. // Meaning is "reasonably at or greater than"
  1840. createToken('LONETILDE', '(?:~>?)');
  1841. createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
  1842. exports.tildeTrimReplace = '$1~';
  1843. createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
  1844. createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`); // Caret ranges.
  1845. // Meaning is "at least and backwards compatible with"
  1846. createToken('LONECARET', '(?:\\^)');
  1847. createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
  1848. exports.caretTrimReplace = '$1^';
  1849. createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
  1850. createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`); // A simple gt/lt/eq thing, or just "" to indicate "any version"
  1851. createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
  1852. createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`); // An expression to strip any whitespace between the gtlt and the thing
  1853. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  1854. createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
  1855. exports.comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  1856. // Note that these all use the loose form, because they'll be
  1857. // checked against either the strict or loose comparator form
  1858. // later.
  1859. createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` + `\\s+-\\s+` + `(${src[t.XRANGEPLAIN]})` + `\\s*$`);
  1860. createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` + `\\s+-\\s+` + `(${src[t.XRANGEPLAINLOOSE]})` + `\\s*$`); // Star ranges basically just allow anything at all.
  1861. createToken('STAR', '(<|>)?=?\\s*\\*'); // >=0.0.0 is like a star
  1862. createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$');
  1863. createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$');
  1864. });
  1865. const numeric = /^[0-9]+$/;
  1866. const compareIdentifiers = (a, b) => {
  1867. const anum = numeric.test(a);
  1868. const bnum = numeric.test(b);
  1869. if (anum && bnum) {
  1870. a = +a;
  1871. b = +b;
  1872. }
  1873. return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
  1874. };
  1875. const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
  1876. var identifiers = {
  1877. compareIdentifiers,
  1878. rcompareIdentifiers
  1879. };
  1880. const {
  1881. MAX_LENGTH: MAX_LENGTH$1,
  1882. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1
  1883. } = constants;
  1884. const {
  1885. re,
  1886. t
  1887. } = re_1;
  1888. const {
  1889. compareIdentifiers: compareIdentifiers$1
  1890. } = identifiers;
  1891. class SemVer {
  1892. constructor(version, options) {
  1893. if (!options || typeof options !== 'object') {
  1894. options = {
  1895. loose: !!options,
  1896. includePrerelease: false
  1897. };
  1898. }
  1899. if (version instanceof SemVer) {
  1900. if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) {
  1901. return version;
  1902. } else {
  1903. version = version.version;
  1904. }
  1905. } else if (typeof version !== 'string') {
  1906. throw new TypeError(`Invalid Version: ${version}`);
  1907. }
  1908. if (version.length > MAX_LENGTH$1) {
  1909. throw new TypeError(`version is longer than ${MAX_LENGTH$1} characters`);
  1910. }
  1911. debug_1('SemVer', version, options);
  1912. this.options = options;
  1913. this.loose = !!options.loose; // this isn't actually relevant for versions, but keep it so that we
  1914. // don't run into trouble passing this.options around.
  1915. this.includePrerelease = !!options.includePrerelease;
  1916. const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
  1917. if (!m) {
  1918. throw new TypeError(`Invalid Version: ${version}`);
  1919. }
  1920. this.raw = version; // these are actually numbers
  1921. this.major = +m[1];
  1922. this.minor = +m[2];
  1923. this.patch = +m[3];
  1924. if (this.major > MAX_SAFE_INTEGER$1 || this.major < 0) {
  1925. throw new TypeError('Invalid major version');
  1926. }
  1927. if (this.minor > MAX_SAFE_INTEGER$1 || this.minor < 0) {
  1928. throw new TypeError('Invalid minor version');
  1929. }
  1930. if (this.patch > MAX_SAFE_INTEGER$1 || this.patch < 0) {
  1931. throw new TypeError('Invalid patch version');
  1932. } // numberify any prerelease numeric ids
  1933. if (!m[4]) {
  1934. this.prerelease = [];
  1935. } else {
  1936. this.prerelease = m[4].split('.').map(id => {
  1937. if (/^[0-9]+$/.test(id)) {
  1938. const num = +id;
  1939. if (num >= 0 && num < MAX_SAFE_INTEGER$1) {
  1940. return num;
  1941. }
  1942. }
  1943. return id;
  1944. });
  1945. }
  1946. this.build = m[5] ? m[5].split('.') : [];
  1947. this.format();
  1948. }
  1949. format() {
  1950. this.version = `${this.major}.${this.minor}.${this.patch}`;
  1951. if (this.prerelease.length) {
  1952. this.version += `-${this.prerelease.join('.')}`;
  1953. }
  1954. return this.version;
  1955. }
  1956. toString() {
  1957. return this.version;
  1958. }
  1959. compare(other) {
  1960. debug_1('SemVer.compare', this.version, this.options, other);
  1961. if (!(other instanceof SemVer)) {
  1962. if (typeof other === 'string' && other === this.version) {
  1963. return 0;
  1964. }
  1965. other = new SemVer(other, this.options);
  1966. }
  1967. if (other.version === this.version) {
  1968. return 0;
  1969. }
  1970. return this.compareMain(other) || this.comparePre(other);
  1971. }
  1972. compareMain(other) {
  1973. if (!(other instanceof SemVer)) {
  1974. other = new SemVer(other, this.options);
  1975. }
  1976. return compareIdentifiers$1(this.major, other.major) || compareIdentifiers$1(this.minor, other.minor) || compareIdentifiers$1(this.patch, other.patch);
  1977. }
  1978. comparePre(other) {
  1979. if (!(other instanceof SemVer)) {
  1980. other = new SemVer(other, this.options);
  1981. } // NOT having a prerelease is > having one
  1982. if (this.prerelease.length && !other.prerelease.length) {
  1983. return -1;
  1984. } else if (!this.prerelease.length && other.prerelease.length) {
  1985. return 1;
  1986. } else if (!this.prerelease.length && !other.prerelease.length) {
  1987. return 0;
  1988. }
  1989. let i = 0;
  1990. do {
  1991. const a = this.prerelease[i];
  1992. const b = other.prerelease[i];
  1993. debug_1('prerelease compare', i, a, b);
  1994. if (a === undefined && b === undefined) {
  1995. return 0;
  1996. } else if (b === undefined) {
  1997. return 1;
  1998. } else if (a === undefined) {
  1999. return -1;
  2000. } else if (a === b) {
  2001. continue;
  2002. } else {
  2003. return compareIdentifiers$1(a, b);
  2004. }
  2005. } while (++i);
  2006. }
  2007. compareBuild(other) {
  2008. if (!(other instanceof SemVer)) {
  2009. other = new SemVer(other, this.options);
  2010. }
  2011. let i = 0;
  2012. do {
  2013. const a = this.build[i];
  2014. const b = other.build[i];
  2015. debug_1('prerelease compare', i, a, b);
  2016. if (a === undefined && b === undefined) {
  2017. return 0;
  2018. } else if (b === undefined) {
  2019. return 1;
  2020. } else if (a === undefined) {
  2021. return -1;
  2022. } else if (a === b) {
  2023. continue;
  2024. } else {
  2025. return compareIdentifiers$1(a, b);
  2026. }
  2027. } while (++i);
  2028. } // preminor will bump the version up to the next minor release, and immediately
  2029. // down to pre-release. premajor and prepatch work the same way.
  2030. inc(release, identifier) {
  2031. switch (release) {
  2032. case 'premajor':
  2033. this.prerelease.length = 0;
  2034. this.patch = 0;
  2035. this.minor = 0;
  2036. this.major++;
  2037. this.inc('pre', identifier);
  2038. break;
  2039. case 'preminor':
  2040. this.prerelease.length = 0;
  2041. this.patch = 0;
  2042. this.minor++;
  2043. this.inc('pre', identifier);
  2044. break;
  2045. case 'prepatch':
  2046. // If this is already a prerelease, it will bump to the next version
  2047. // drop any prereleases that might already exist, since they are not
  2048. // relevant at this point.
  2049. this.prerelease.length = 0;
  2050. this.inc('patch', identifier);
  2051. this.inc('pre', identifier);
  2052. break;
  2053. // If the input is a non-prerelease version, this acts the same as
  2054. // prepatch.
  2055. case 'prerelease':
  2056. if (this.prerelease.length === 0) {
  2057. this.inc('patch', identifier);
  2058. }
  2059. this.inc('pre', identifier);
  2060. break;
  2061. case 'major':
  2062. // If this is a pre-major version, bump up to the same major version.
  2063. // Otherwise increment major.
  2064. // 1.0.0-5 bumps to 1.0.0
  2065. // 1.1.0 bumps to 2.0.0
  2066. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
  2067. this.major++;
  2068. }
  2069. this.minor = 0;
  2070. this.patch = 0;
  2071. this.prerelease = [];
  2072. break;
  2073. case 'minor':
  2074. // If this is a pre-minor version, bump up to the same minor version.
  2075. // Otherwise increment minor.
  2076. // 1.2.0-5 bumps to 1.2.0
  2077. // 1.2.1 bumps to 1.3.0
  2078. if (this.patch !== 0 || this.prerelease.length === 0) {
  2079. this.minor++;
  2080. }
  2081. this.patch = 0;
  2082. this.prerelease = [];
  2083. break;
  2084. case 'patch':
  2085. // If this is not a pre-release version, it will increment the patch.
  2086. // If it is a pre-release it will bump up to the same patch version.
  2087. // 1.2.0-5 patches to 1.2.0
  2088. // 1.2.0 patches to 1.2.1
  2089. if (this.prerelease.length === 0) {
  2090. this.patch++;
  2091. }
  2092. this.prerelease = [];
  2093. break;
  2094. // This probably shouldn't be used publicly.
  2095. // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
  2096. case 'pre':
  2097. if (this.prerelease.length === 0) {
  2098. this.prerelease = [0];
  2099. } else {
  2100. let i = this.prerelease.length;
  2101. while (--i >= 0) {
  2102. if (typeof this.prerelease[i] === 'number') {
  2103. this.prerelease[i]++;
  2104. i = -2;
  2105. }
  2106. }
  2107. if (i === -1) {
  2108. // didn't increment anything
  2109. this.prerelease.push(0);
  2110. }
  2111. }
  2112. if (identifier) {
  2113. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  2114. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  2115. if (this.prerelease[0] === identifier) {
  2116. if (isNaN(this.prerelease[1])) {
  2117. this.prerelease = [identifier, 0];
  2118. }
  2119. } else {
  2120. this.prerelease = [identifier, 0];
  2121. }
  2122. }
  2123. break;
  2124. default:
  2125. throw new Error(`invalid increment argument: ${release}`);
  2126. }
  2127. this.format();
  2128. this.raw = this.version;
  2129. return this;
  2130. }
  2131. }
  2132. var semver = SemVer;
  2133. const compare = (a, b, loose) => new semver(a, loose).compare(new semver(b, loose));
  2134. var compare_1 = compare;
  2135. const lt = (a, b, loose) => compare_1(a, b, loose) < 0;
  2136. var lt_1 = lt;
  2137. const gte = (a, b, loose) => compare_1(a, b, loose) >= 0;
  2138. var gte_1 = gte;
  2139. var arrayify = (object, keyName) => Object.entries(object).map(([key, value]) => Object.assign({
  2140. [keyName]: key
  2141. }, value));
  2142. var lib = createCommonjsModule(function (module, exports) {
  2143. Object.defineProperty(exports, "__esModule", {
  2144. value: true
  2145. }); // In the absence of a WeakSet or WeakMap implementation, don't break, but don't cache either.
  2146. function noop() {
  2147. var args = [];
  2148. for (var _i = 0; _i < arguments.length; _i++) {
  2149. args[_i] = arguments[_i];
  2150. }
  2151. }
  2152. function createWeakMap() {
  2153. if (typeof WeakMap !== 'undefined') {
  2154. return new WeakMap();
  2155. } else {
  2156. return fakeSetOrMap();
  2157. }
  2158. }
  2159. /**
  2160. * Creates and returns a no-op implementation of a WeakMap / WeakSet that never stores anything.
  2161. */
  2162. function fakeSetOrMap() {
  2163. return {
  2164. add: noop,
  2165. delete: noop,
  2166. get: noop,
  2167. set: noop,
  2168. has: function (k) {
  2169. return false;
  2170. }
  2171. };
  2172. } // Safe hasOwnProperty
  2173. var hop = Object.prototype.hasOwnProperty;
  2174. var has = function (obj, prop) {
  2175. return hop.call(obj, prop);
  2176. }; // Copy all own enumerable properties from source to target
  2177. function extend(target, source) {
  2178. for (var prop in source) {
  2179. if (has(source, prop)) {
  2180. target[prop] = source[prop];
  2181. }
  2182. }
  2183. return target;
  2184. }
  2185. var reLeadingNewline = /^[ \t]*(?:\r\n|\r|\n)/;
  2186. var reTrailingNewline = /(?:\r\n|\r|\n)[ \t]*$/;
  2187. var reStartsWithNewlineOrIsEmpty = /^(?:[\r\n]|$)/;
  2188. var reDetectIndentation = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
  2189. var reOnlyWhitespaceWithAtLeastOneNewline = /^[ \t]*[\r\n][ \t\r\n]*$/;
  2190. function _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options) {
  2191. // If first interpolated value is a reference to outdent,
  2192. // determine indentation level from the indentation of the interpolated value.
  2193. var indentationLevel = 0;
  2194. var match = strings[0].match(reDetectIndentation);
  2195. if (match) {
  2196. indentationLevel = match[1].length;
  2197. }
  2198. var reSource = "(\\r\\n|\\r|\\n).{0," + indentationLevel + "}";
  2199. var reMatchIndent = new RegExp(reSource, 'g');
  2200. if (firstInterpolatedValueSetsIndentationLevel) {
  2201. strings = strings.slice(1);
  2202. }
  2203. var newline = options.newline,
  2204. trimLeadingNewline = options.trimLeadingNewline,
  2205. trimTrailingNewline = options.trimTrailingNewline;
  2206. var normalizeNewlines = typeof newline === 'string';
  2207. var l = strings.length;
  2208. var outdentedStrings = strings.map(function (v, i) {
  2209. // Remove leading indentation from all lines
  2210. v = v.replace(reMatchIndent, '$1'); // Trim a leading newline from the first string
  2211. if (i === 0 && trimLeadingNewline) {
  2212. v = v.replace(reLeadingNewline, '');
  2213. } // Trim a trailing newline from the last string
  2214. if (i === l - 1 && trimTrailingNewline) {
  2215. v = v.replace(reTrailingNewline, '');
  2216. } // Normalize newlines
  2217. if (normalizeNewlines) {
  2218. v = v.replace(/\r\n|\n|\r/g, function (_) {
  2219. return newline;
  2220. });
  2221. }
  2222. return v;
  2223. });
  2224. return outdentedStrings;
  2225. }
  2226. function concatStringsAndValues(strings, values) {
  2227. var ret = '';
  2228. for (var i = 0, l = strings.length; i < l; i++) {
  2229. ret += strings[i];
  2230. if (i < l - 1) {
  2231. ret += values[i];
  2232. }
  2233. }
  2234. return ret;
  2235. }
  2236. function isTemplateStringsArray(v) {
  2237. return has(v, 'raw') && has(v, 'length');
  2238. }
  2239. /**
  2240. * It is assumed that opts will not change. If this is a problem, clone your options object and pass the clone to
  2241. * makeInstance
  2242. * @param options
  2243. * @return {outdent}
  2244. */
  2245. function createInstance(options) {
  2246. /** Cache of pre-processed template literal arrays */
  2247. var arrayAutoIndentCache = createWeakMap();
  2248. /**
  2249. * Cache of pre-processed template literal arrays, where first interpolated value is a reference to outdent,
  2250. * before interpolated values are injected.
  2251. */
  2252. var arrayFirstInterpSetsIndentCache = createWeakMap();
  2253. function outdent(stringsOrOptions) {
  2254. var values = [];
  2255. for (var _i = 1; _i < arguments.length; _i++) {
  2256. values[_i - 1] = arguments[_i];
  2257. }
  2258. /* tslint:enable:no-shadowed-variable */
  2259. if (isTemplateStringsArray(stringsOrOptions)) {
  2260. var strings = stringsOrOptions; // Is first interpolated value a reference to outdent, alone on its own line, without any preceding non-whitespace?
  2261. var firstInterpolatedValueSetsIndentationLevel = (values[0] === outdent || values[0] === defaultOutdent) && reOnlyWhitespaceWithAtLeastOneNewline.test(strings[0]) && reStartsWithNewlineOrIsEmpty.test(strings[1]); // Perform outdentation
  2262. var cache = firstInterpolatedValueSetsIndentationLevel ? arrayFirstInterpSetsIndentCache : arrayAutoIndentCache;
  2263. var renderedArray = cache.get(strings);
  2264. if (!renderedArray) {
  2265. renderedArray = _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options);
  2266. cache.set(strings, renderedArray);
  2267. }
  2268. /** If no interpolated values, skip concatenation step */
  2269. if (values.length === 0) {
  2270. return renderedArray[0];
  2271. }
  2272. /** Concatenate string literals with interpolated values */
  2273. var rendered = concatStringsAndValues(renderedArray, firstInterpolatedValueSetsIndentationLevel ? values.slice(1) : values);
  2274. return rendered;
  2275. } else {
  2276. // Create and return a new instance of outdent with the given options
  2277. return createInstance(extend(extend({}, options), stringsOrOptions || {}));
  2278. }
  2279. }
  2280. var fullOutdent = extend(outdent, {
  2281. string: function (str) {
  2282. return _outdentArray([str], false, options)[0];
  2283. }
  2284. });
  2285. return fullOutdent;
  2286. }
  2287. var defaultOutdent = createInstance({
  2288. trimLeadingNewline: true,
  2289. trimTrailingNewline: true
  2290. });
  2291. exports.outdent = defaultOutdent; // Named exports. Simple and preferred.
  2292. // import outdent from 'outdent';
  2293. exports.default = defaultOutdent;
  2294. {
  2295. // In webpack harmony-modules environments, module.exports is read-only,
  2296. // so we fail gracefully.
  2297. try {
  2298. module.exports = defaultOutdent;
  2299. Object.defineProperty(defaultOutdent, '__esModule', {
  2300. value: true
  2301. });
  2302. defaultOutdent.default = defaultOutdent;
  2303. defaultOutdent.outdent = defaultOutdent;
  2304. } catch (e) {}
  2305. }
  2306. });
  2307. const {
  2308. outdent
  2309. } = lib;
  2310. const CATEGORY_CONFIG = "Config";
  2311. const CATEGORY_EDITOR = "Editor";
  2312. const CATEGORY_FORMAT = "Format";
  2313. const CATEGORY_OTHER = "Other";
  2314. const CATEGORY_OUTPUT = "Output";
  2315. const CATEGORY_GLOBAL = "Global";
  2316. const CATEGORY_SPECIAL = "Special";
  2317. /**
  2318. * @typedef {Object} OptionInfo
  2319. * @property {string} [since] - available since version
  2320. * @property {string} category
  2321. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  2322. * @property {boolean} [array] - indicate it's an array of the specified type
  2323. * @property {OptionValueInfo} [default]
  2324. * @property {OptionRangeInfo} [range] - for type int
  2325. * @property {string} description
  2326. * @property {string} [deprecated] - deprecated since version
  2327. * @property {OptionRedirectInfo} [redirect] - redirect deprecated option
  2328. * @property {(value: any) => boolean} [exception]
  2329. * @property {OptionChoiceInfo[]} [choices] - for type choice
  2330. * @property {string} [cliName]
  2331. * @property {string} [cliCategory]
  2332. * @property {string} [cliDescription]
  2333. *
  2334. * @typedef {number | boolean | string} OptionValue
  2335. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  2336. *
  2337. * @typedef {Object} OptionRedirectInfo
  2338. * @property {string} option
  2339. * @property {OptionValue} value
  2340. *
  2341. * @typedef {Object} OptionRangeInfo
  2342. * @property {number} start - recommended range start
  2343. * @property {number} end - recommended range end
  2344. * @property {number} step - recommended range step
  2345. *
  2346. * @typedef {Object} OptionChoiceInfo
  2347. * @property {boolean | string} value - boolean for the option that is originally boolean type
  2348. * @property {string} description
  2349. * @property {string} [since] - undefined if available since the first version of the option
  2350. * @property {string} [deprecated] - deprecated since version
  2351. * @property {OptionValueInfo} [redirect] - redirect deprecated value
  2352. */
  2353. /** @type {{ [name: string]: OptionInfo }} */
  2354. const options = {
  2355. cursorOffset: {
  2356. since: "1.4.0",
  2357. category: CATEGORY_SPECIAL,
  2358. type: "int",
  2359. default: -1,
  2360. range: {
  2361. start: -1,
  2362. end: Infinity,
  2363. step: 1
  2364. },
  2365. description: outdent`
  2366. Print (to stderr) where a cursor at the given position would move to after formatting.
  2367. This option cannot be used with --range-start and --range-end.
  2368. `,
  2369. cliCategory: CATEGORY_EDITOR
  2370. },
  2371. endOfLine: {
  2372. since: "1.15.0",
  2373. category: CATEGORY_GLOBAL,
  2374. type: "choice",
  2375. default: [{
  2376. since: "1.15.0",
  2377. value: "auto"
  2378. }, {
  2379. since: "2.0.0",
  2380. value: "lf"
  2381. }],
  2382. description: "Which end of line characters to apply.",
  2383. choices: [{
  2384. value: "lf",
  2385. description: "Line Feed only (\\n), common on Linux and macOS as well as inside git repos"
  2386. }, {
  2387. value: "crlf",
  2388. description: "Carriage Return + Line Feed characters (\\r\\n), common on Windows"
  2389. }, {
  2390. value: "cr",
  2391. description: "Carriage Return character only (\\r), used very rarely"
  2392. }, {
  2393. value: "auto",
  2394. description: outdent`
  2395. Maintain existing
  2396. (mixed values within one file are normalised by looking at what's used after the first line)
  2397. `
  2398. }]
  2399. },
  2400. filepath: {
  2401. since: "1.4.0",
  2402. category: CATEGORY_SPECIAL,
  2403. type: "path",
  2404. description: "Specify the input filepath. This will be used to do parser inference.",
  2405. cliName: "stdin-filepath",
  2406. cliCategory: CATEGORY_OTHER,
  2407. cliDescription: "Path to the file to pretend that stdin comes from."
  2408. },
  2409. insertPragma: {
  2410. since: "1.8.0",
  2411. category: CATEGORY_SPECIAL,
  2412. type: "boolean",
  2413. default: false,
  2414. description: "Insert @format pragma into file's first docblock comment.",
  2415. cliCategory: CATEGORY_OTHER
  2416. },
  2417. parser: {
  2418. since: "0.0.10",
  2419. category: CATEGORY_GLOBAL,
  2420. type: "choice",
  2421. default: [{
  2422. since: "0.0.10",
  2423. value: "babylon"
  2424. }, {
  2425. since: "1.13.0",
  2426. value: undefined
  2427. }],
  2428. description: "Which parser to use.",
  2429. exception: value => typeof value === "string" || typeof value === "function",
  2430. choices: [{
  2431. value: "flow",
  2432. description: "Flow"
  2433. }, {
  2434. value: "babel",
  2435. since: "1.16.0",
  2436. description: "JavaScript"
  2437. }, {
  2438. value: "babel-flow",
  2439. since: "1.16.0",
  2440. description: "Flow"
  2441. }, {
  2442. value: "babel-ts",
  2443. since: "2.0.0",
  2444. description: "TypeScript"
  2445. }, {
  2446. value: "typescript",
  2447. since: "1.4.0",
  2448. description: "TypeScript"
  2449. }, {
  2450. value: "css",
  2451. since: "1.7.1",
  2452. description: "CSS"
  2453. }, {
  2454. value: "less",
  2455. since: "1.7.1",
  2456. description: "Less"
  2457. }, {
  2458. value: "scss",
  2459. since: "1.7.1",
  2460. description: "SCSS"
  2461. }, {
  2462. value: "json",
  2463. since: "1.5.0",
  2464. description: "JSON"
  2465. }, {
  2466. value: "json5",
  2467. since: "1.13.0",
  2468. description: "JSON5"
  2469. }, {
  2470. value: "json-stringify",
  2471. since: "1.13.0",
  2472. description: "JSON.stringify"
  2473. }, {
  2474. value: "graphql",
  2475. since: "1.5.0",
  2476. description: "GraphQL"
  2477. }, {
  2478. value: "markdown",
  2479. since: "1.8.0",
  2480. description: "Markdown"
  2481. }, {
  2482. value: "mdx",
  2483. since: "1.15.0",
  2484. description: "MDX"
  2485. }, {
  2486. value: "vue",
  2487. since: "1.10.0",
  2488. description: "Vue"
  2489. }, {
  2490. value: "yaml",
  2491. since: "1.14.0",
  2492. description: "YAML"
  2493. }, {
  2494. value: "glimmer",
  2495. since: null,
  2496. description: "Handlebars"
  2497. }, {
  2498. value: "html",
  2499. since: "1.15.0",
  2500. description: "HTML"
  2501. }, {
  2502. value: "angular",
  2503. since: "1.15.0",
  2504. description: "Angular"
  2505. }, {
  2506. value: "lwc",
  2507. since: "1.17.0",
  2508. description: "Lightning Web Components"
  2509. }]
  2510. },
  2511. plugins: {
  2512. since: "1.10.0",
  2513. type: "path",
  2514. array: true,
  2515. default: [{
  2516. value: []
  2517. }],
  2518. category: CATEGORY_GLOBAL,
  2519. description: "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  2520. exception: value => typeof value === "string" || typeof value === "object",
  2521. cliName: "plugin",
  2522. cliCategory: CATEGORY_CONFIG
  2523. },
  2524. pluginSearchDirs: {
  2525. since: "1.13.0",
  2526. type: "path",
  2527. array: true,
  2528. default: [{
  2529. value: []
  2530. }],
  2531. category: CATEGORY_GLOBAL,
  2532. description: outdent`
  2533. Custom directory that contains prettier plugins in node_modules subdirectory.
  2534. Overrides default behavior when plugins are searched relatively to the location of Prettier.
  2535. Multiple values are accepted.
  2536. `,
  2537. exception: value => typeof value === "string" || typeof value === "object",
  2538. cliName: "plugin-search-dir",
  2539. cliCategory: CATEGORY_CONFIG
  2540. },
  2541. printWidth: {
  2542. since: "0.0.0",
  2543. category: CATEGORY_GLOBAL,
  2544. type: "int",
  2545. default: 80,
  2546. description: "The line length where Prettier will try wrap.",
  2547. range: {
  2548. start: 0,
  2549. end: Infinity,
  2550. step: 1
  2551. }
  2552. },
  2553. rangeEnd: {
  2554. since: "1.4.0",
  2555. category: CATEGORY_SPECIAL,
  2556. type: "int",
  2557. default: Infinity,
  2558. range: {
  2559. start: 0,
  2560. end: Infinity,
  2561. step: 1
  2562. },
  2563. description: outdent`
  2564. Format code ending at a given character offset (exclusive).
  2565. The range will extend forwards to the end of the selected statement.
  2566. This option cannot be used with --cursor-offset.
  2567. `,
  2568. cliCategory: CATEGORY_EDITOR
  2569. },
  2570. rangeStart: {
  2571. since: "1.4.0",
  2572. category: CATEGORY_SPECIAL,
  2573. type: "int",
  2574. default: 0,
  2575. range: {
  2576. start: 0,
  2577. end: Infinity,
  2578. step: 1
  2579. },
  2580. description: outdent`
  2581. Format code starting at a given character offset.
  2582. The range will extend backwards to the start of the first line containing the selected statement.
  2583. This option cannot be used with --cursor-offset.
  2584. `,
  2585. cliCategory: CATEGORY_EDITOR
  2586. },
  2587. requirePragma: {
  2588. since: "1.7.0",
  2589. category: CATEGORY_SPECIAL,
  2590. type: "boolean",
  2591. default: false,
  2592. description: outdent`
  2593. Require either '@prettier' or '@format' to be present in the file's first docblock comment
  2594. in order for it to be formatted.
  2595. `,
  2596. cliCategory: CATEGORY_OTHER
  2597. },
  2598. tabWidth: {
  2599. type: "int",
  2600. category: CATEGORY_GLOBAL,
  2601. default: 2,
  2602. description: "Number of spaces per indentation level.",
  2603. range: {
  2604. start: 0,
  2605. end: Infinity,
  2606. step: 1
  2607. }
  2608. },
  2609. useTabs: {
  2610. since: "1.0.0",
  2611. category: CATEGORY_GLOBAL,
  2612. type: "boolean",
  2613. default: false,
  2614. description: "Indent with tabs instead of spaces."
  2615. },
  2616. embeddedLanguageFormatting: {
  2617. since: "2.1.0",
  2618. category: CATEGORY_GLOBAL,
  2619. type: "choice",
  2620. default: [{
  2621. since: "2.1.0",
  2622. value: "auto"
  2623. }],
  2624. description: "Control how Prettier formats quoted code embedded in the file.",
  2625. choices: [{
  2626. value: "auto",
  2627. description: "Format embedded code if Prettier can automatically identify it."
  2628. }, {
  2629. value: "off",
  2630. description: "Never automatically format embedded code."
  2631. }]
  2632. }
  2633. };
  2634. var coreOptions = {
  2635. CATEGORY_CONFIG,
  2636. CATEGORY_EDITOR,
  2637. CATEGORY_FORMAT,
  2638. CATEGORY_OTHER,
  2639. CATEGORY_OUTPUT,
  2640. CATEGORY_GLOBAL,
  2641. CATEGORY_SPECIAL,
  2642. options
  2643. };
  2644. var require$$0 = getCjsExportFromNamespace(_package$1);
  2645. const semver$1 = {
  2646. compare: compare_1,
  2647. lt: lt_1,
  2648. gte: gte_1
  2649. };
  2650. const currentVersion = require$$0.version;
  2651. const coreOptions$1 = coreOptions.options;
  2652. /**
  2653. * Strings in `plugins` and `pluginSearchDirs` are handled by a wrapped version
  2654. * of this function created by `withPlugins`. Don't pass them here directly.
  2655. * @param {object} param0
  2656. * @param {(string | object)[]=} param0.plugins Strings are resolved by `withPlugins`.
  2657. * @param {string[]=} param0.pluginSearchDirs Added by `withPlugins`.
  2658. * @param {boolean=} param0.showUnreleased
  2659. * @param {boolean=} param0.showDeprecated
  2660. * @param {boolean=} param0.showInternal
  2661. */
  2662. function getSupportInfo({
  2663. plugins = [],
  2664. showUnreleased = false,
  2665. showDeprecated = false,
  2666. showInternal = false
  2667. } = {}) {
  2668. // pre-release version is smaller than the normal version in semver,
  2669. // we need to treat it as the normal one so as to test new features.
  2670. const version = currentVersion.split("-", 1)[0];
  2671. const languages = plugins.reduce((all, plugin) => all.concat(plugin.languages || []), []).filter(filterSince);
  2672. const options = arrayify(Object.assign({}, ...plugins.map(({
  2673. options
  2674. }) => options), coreOptions$1), "name").filter(option => filterSince(option) && filterDeprecated(option)).sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1).map(mapInternal).map(option => {
  2675. option = Object.assign({}, option);
  2676. if (Array.isArray(option.default)) {
  2677. option.default = option.default.length === 1 ? option.default[0].value : option.default.filter(filterSince).sort((info1, info2) => semver$1.compare(info2.since, info1.since))[0].value;
  2678. }
  2679. if (Array.isArray(option.choices)) {
  2680. option.choices = option.choices.filter(option => filterSince(option) && filterDeprecated(option));
  2681. if (option.name === "parser") {
  2682. collectParsersFromLanguages(option, languages, plugins);
  2683. }
  2684. }
  2685. const pluginDefaults = plugins.filter(plugin => plugin.defaultOptions && plugin.defaultOptions[option.name] !== undefined).reduce((reduced, plugin) => {
  2686. reduced[plugin.name] = plugin.defaultOptions[option.name];
  2687. return reduced;
  2688. }, {});
  2689. return Object.assign({}, option, {
  2690. pluginDefaults
  2691. });
  2692. });
  2693. return {
  2694. languages,
  2695. options
  2696. };
  2697. function filterSince(object) {
  2698. return showUnreleased || !("since" in object) || object.since && semver$1.gte(version, object.since);
  2699. }
  2700. function filterDeprecated(object) {
  2701. return showDeprecated || !("deprecated" in object) || object.deprecated && semver$1.lt(version, object.deprecated);
  2702. }
  2703. function mapInternal(object) {
  2704. if (showInternal) {
  2705. return object;
  2706. }
  2707. const newObject = _objectWithoutPropertiesLoose(object, ["cliName", "cliCategory", "cliDescription"]);
  2708. return newObject;
  2709. }
  2710. }
  2711. function collectParsersFromLanguages(option, languages, plugins) {
  2712. const existingValues = new Set(option.choices.map(choice => choice.value));
  2713. for (const language of languages) {
  2714. if (language.parsers) {
  2715. for (const value of language.parsers) {
  2716. if (!existingValues.has(value)) {
  2717. existingValues.add(value);
  2718. const plugin = plugins.find(plugin => plugin.parsers && plugin.parsers[value]);
  2719. let description = language.name;
  2720. if (plugin && plugin.name) {
  2721. description += ` (plugin: ${plugin.name})`;
  2722. }
  2723. option.choices.push({
  2724. value,
  2725. description
  2726. });
  2727. }
  2728. }
  2729. }
  2730. }
  2731. }
  2732. var support = {
  2733. getSupportInfo
  2734. };
  2735. const notAsciiRegex = /[^\x20-\x7F]/;
  2736. const getPenultimate = arr => arr[arr.length - 2];
  2737. /**
  2738. * @typedef {{backwards?: boolean}} SkipOptions
  2739. */
  2740. /**
  2741. * @param {string | RegExp} chars
  2742. * @returns {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  2743. */
  2744. function skip(chars) {
  2745. return (text, index, opts) => {
  2746. const backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
  2747. // to check for failures (did someone say monads?).
  2748. /* istanbul ignore next */
  2749. if (index === false) {
  2750. return false;
  2751. }
  2752. const {
  2753. length
  2754. } = text;
  2755. let cursor = index;
  2756. while (cursor >= 0 && cursor < length) {
  2757. const c = text.charAt(cursor);
  2758. if (chars instanceof RegExp) {
  2759. if (!chars.test(c)) {
  2760. return cursor;
  2761. }
  2762. } else if (!chars.includes(c)) {
  2763. return cursor;
  2764. }
  2765. backwards ? cursor-- : cursor++;
  2766. }
  2767. if (cursor === -1 || cursor === length) {
  2768. // If we reached the beginning or end of the file, return the
  2769. // out-of-bounds cursor. It's up to the caller to handle this
  2770. // correctly. We don't want to indicate `false` though if it
  2771. // actually skipped valid characters.
  2772. return cursor;
  2773. }
  2774. return false;
  2775. };
  2776. }
  2777. /**
  2778. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  2779. */
  2780. const skipWhitespace = skip(/\s/);
  2781. /**
  2782. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  2783. */
  2784. const skipSpaces = skip(" \t");
  2785. /**
  2786. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  2787. */
  2788. const skipToLineEnd = skip(",; \t");
  2789. /**
  2790. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  2791. */
  2792. const skipEverythingButNewLine = skip(/[^\n\r]/);
  2793. /**
  2794. * @param {string} text
  2795. * @param {number | false} index
  2796. * @returns {number | false}
  2797. */
  2798. function skipInlineComment(text, index) {
  2799. /* istanbul ignore next */
  2800. if (index === false) {
  2801. return false;
  2802. }
  2803. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  2804. for (let i = index + 2; i < text.length; ++i) {
  2805. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  2806. return i + 2;
  2807. }
  2808. }
  2809. }
  2810. return index;
  2811. }
  2812. /**
  2813. * @param {string} text
  2814. * @param {number | false} index
  2815. * @returns {number | false}
  2816. */
  2817. function skipTrailingComment(text, index) {
  2818. /* istanbul ignore next */
  2819. if (index === false) {
  2820. return false;
  2821. }
  2822. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  2823. return skipEverythingButNewLine(text, index);
  2824. }
  2825. return index;
  2826. } // This one doesn't use the above helper function because it wants to
  2827. // test \r\n in order and `skip` doesn't support ordering and we only
  2828. // want to skip one newline. It's simple to implement.
  2829. /**
  2830. * @param {string} text
  2831. * @param {number | false} index
  2832. * @param {SkipOptions=} opts
  2833. * @returns {number | false}
  2834. */
  2835. function skipNewline(text, index, opts) {
  2836. const backwards = opts && opts.backwards;
  2837. if (index === false) {
  2838. return false;
  2839. }
  2840. const atIndex = text.charAt(index);
  2841. if (backwards) {
  2842. // We already replace `\r\n` with `\n` before parsing
  2843. /* istanbul ignore next */
  2844. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  2845. return index - 2;
  2846. }
  2847. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  2848. return index - 1;
  2849. }
  2850. } else {
  2851. // We already replace `\r\n` with `\n` before parsing
  2852. /* istanbul ignore next */
  2853. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  2854. return index + 2;
  2855. }
  2856. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  2857. return index + 1;
  2858. }
  2859. }
  2860. return index;
  2861. }
  2862. /**
  2863. * @param {string} text
  2864. * @param {number} index
  2865. * @param {SkipOptions=} opts
  2866. * @returns {boolean}
  2867. */
  2868. function hasNewline(text, index, opts) {
  2869. opts = opts || {};
  2870. const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  2871. const idx2 = skipNewline(text, idx, opts);
  2872. return idx !== idx2;
  2873. }
  2874. /**
  2875. * @param {string} text
  2876. * @param {number} start
  2877. * @param {number} end
  2878. * @returns {boolean}
  2879. */
  2880. function hasNewlineInRange(text, start, end) {
  2881. for (let i = start; i < end; ++i) {
  2882. if (text.charAt(i) === "\n") {
  2883. return true;
  2884. }
  2885. }
  2886. return false;
  2887. } // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  2888. /**
  2889. * @template N
  2890. * @param {string} text
  2891. * @param {N} node
  2892. * @param {(node: N) => number} locStart
  2893. */
  2894. function isPreviousLineEmpty(text, node, locStart) {
  2895. /** @type {number | false} */
  2896. let idx = locStart(node) - 1;
  2897. idx = skipSpaces(text, idx, {
  2898. backwards: true
  2899. });
  2900. idx = skipNewline(text, idx, {
  2901. backwards: true
  2902. });
  2903. idx = skipSpaces(text, idx, {
  2904. backwards: true
  2905. });
  2906. const idx2 = skipNewline(text, idx, {
  2907. backwards: true
  2908. });
  2909. return idx !== idx2;
  2910. }
  2911. /**
  2912. * @param {string} text
  2913. * @param {number} index
  2914. * @returns {boolean}
  2915. */
  2916. function isNextLineEmptyAfterIndex(text, index) {
  2917. /** @type {number | false} */
  2918. let oldIdx = null;
  2919. /** @type {number | false} */
  2920. let idx = index;
  2921. while (idx !== oldIdx) {
  2922. // We need to skip all the potential trailing inline comments
  2923. oldIdx = idx;
  2924. idx = skipToLineEnd(text, idx);
  2925. idx = skipInlineComment(text, idx);
  2926. idx = skipSpaces(text, idx);
  2927. }
  2928. idx = skipTrailingComment(text, idx);
  2929. idx = skipNewline(text, idx);
  2930. return idx !== false && hasNewline(text, idx);
  2931. }
  2932. /**
  2933. * @template N
  2934. * @param {string} text
  2935. * @param {N} node
  2936. * @param {(node: N) => number} locEnd
  2937. * @returns {boolean}
  2938. */
  2939. function isNextLineEmpty(text, node, locEnd) {
  2940. return isNextLineEmptyAfterIndex(text, locEnd(node));
  2941. }
  2942. /**
  2943. * @param {string} text
  2944. * @param {number} idx
  2945. * @returns {number | false}
  2946. */
  2947. function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
  2948. /** @type {number | false} */
  2949. let oldIdx = null;
  2950. /** @type {number | false} */
  2951. let nextIdx = idx;
  2952. while (nextIdx !== oldIdx) {
  2953. oldIdx = nextIdx;
  2954. nextIdx = skipSpaces(text, nextIdx);
  2955. nextIdx = skipInlineComment(text, nextIdx);
  2956. nextIdx = skipTrailingComment(text, nextIdx);
  2957. nextIdx = skipNewline(text, nextIdx);
  2958. }
  2959. return nextIdx;
  2960. }
  2961. /**
  2962. * @template N
  2963. * @param {string} text
  2964. * @param {N} node
  2965. * @param {(node: N) => number} locEnd
  2966. * @returns {number | false}
  2967. */
  2968. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  2969. return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node));
  2970. }
  2971. /**
  2972. * @template N
  2973. * @param {string} text
  2974. * @param {N} node
  2975. * @param {(node: N) => number} locEnd
  2976. * @returns {string}
  2977. */
  2978. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  2979. return text.charAt( // @ts-ignore => TBD: can return false, should we define a fallback?
  2980. getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
  2981. } // Not using, but it's public utils
  2982. /* istanbul ignore next */
  2983. /**
  2984. * @param {string} text
  2985. * @param {number} index
  2986. * @param {SkipOptions=} opts
  2987. * @returns {boolean}
  2988. */
  2989. function hasSpaces(text, index, opts) {
  2990. opts = opts || {};
  2991. const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  2992. return idx !== index;
  2993. }
  2994. /**
  2995. * @param {string} value
  2996. * @param {number} tabWidth
  2997. * @param {number=} startIndex
  2998. * @returns {number}
  2999. */
  3000. function getAlignmentSize(value, tabWidth, startIndex) {
  3001. startIndex = startIndex || 0;
  3002. let size = 0;
  3003. for (let i = startIndex; i < value.length; ++i) {
  3004. if (value[i] === "\t") {
  3005. // Tabs behave in a way that they are aligned to the nearest
  3006. // multiple of tabWidth:
  3007. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  3008. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  3009. size = size + tabWidth - size % tabWidth;
  3010. } else {
  3011. size++;
  3012. }
  3013. }
  3014. return size;
  3015. }
  3016. /**
  3017. * @param {string} value
  3018. * @param {number} tabWidth
  3019. * @returns {number}
  3020. */
  3021. function getIndentSize(value, tabWidth) {
  3022. const lastNewlineIndex = value.lastIndexOf("\n");
  3023. if (lastNewlineIndex === -1) {
  3024. return 0;
  3025. }
  3026. return getAlignmentSize( // All the leading whitespaces
  3027. value.slice(lastNewlineIndex + 1).match(/^[\t ]*/)[0], tabWidth);
  3028. }
  3029. /**
  3030. * @typedef {'"' | "'"} Quote
  3031. */
  3032. /**
  3033. *
  3034. * @param {string} raw
  3035. * @param {Quote} preferredQuote
  3036. * @returns {Quote}
  3037. */
  3038. function getPreferredQuote(raw, preferredQuote) {
  3039. // `rawContent` is the string exactly like it appeared in the input source
  3040. // code, without its enclosing quotes.
  3041. const rawContent = raw.slice(1, -1);
  3042. /** @type {{ quote: '"', regex: RegExp }} */
  3043. const double = {
  3044. quote: '"',
  3045. regex: /"/g
  3046. };
  3047. /** @type {{ quote: "'", regex: RegExp }} */
  3048. const single = {
  3049. quote: "'",
  3050. regex: /'/g
  3051. };
  3052. const preferred = preferredQuote === "'" ? single : double;
  3053. const alternate = preferred === single ? double : single;
  3054. let result = preferred.quote; // If `rawContent` contains at least one of the quote preferred for enclosing
  3055. // the string, we might want to enclose with the alternate quote instead, to
  3056. // minimize the number of escaped quotes.
  3057. if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
  3058. const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  3059. const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  3060. result = numPreferredQuotes > numAlternateQuotes ? alternate.quote : preferred.quote;
  3061. }
  3062. return result;
  3063. }
  3064. function printString(raw, options, isDirectiveLiteral) {
  3065. // `rawContent` is the string exactly like it appeared in the input source
  3066. // code, without its enclosing quotes.
  3067. const rawContent = raw.slice(1, -1); // Check for the alternate quote, to determine if we're allowed to swap
  3068. // the quotes on a DirectiveLiteral.
  3069. const canChangeDirectiveQuotes = !rawContent.includes('"') && !rawContent.includes("'");
  3070. /** @type {Quote} */
  3071. const enclosingQuote = options.parser === "json" ? '"' : options.__isInHtmlAttribute ? "'" : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); // Directives are exact code unit sequences, which means that you can't
  3072. // change the escape sequences they use.
  3073. // See https://github.com/prettier/prettier/issues/1555
  3074. // and https://tc39.github.io/ecma262/#directive-prologue
  3075. if (isDirectiveLiteral) {
  3076. if (canChangeDirectiveQuotes) {
  3077. return enclosingQuote + rawContent + enclosingQuote;
  3078. }
  3079. return raw;
  3080. } // It might sound unnecessary to use `makeString` even if the string already
  3081. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  3082. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  3083. // sure that we consistently output the minimum amount of escaped quotes.
  3084. return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss" || options.embeddedInHtml));
  3085. }
  3086. /**
  3087. * @param {string} rawContent
  3088. * @param {Quote} enclosingQuote
  3089. * @param {boolean=} unescapeUnnecessaryEscapes
  3090. * @returns {string}
  3091. */
  3092. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  3093. const otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
  3094. const regex = /\\([\S\s])|(["'])/g; // Escape and unescape single and double quotes as needed to be able to
  3095. // enclose `rawContent` with `enclosingQuote`.
  3096. const newContent = rawContent.replace(regex, (match, escaped, quote) => {
  3097. // If we matched an escape, and the escaped character is a quote of the
  3098. // other type than we intend to enclose the string with, there's no need for
  3099. // it to be escaped, so return it _without_ the backslash.
  3100. if (escaped === otherQuote) {
  3101. return escaped;
  3102. } // If we matched an unescaped quote and it is of the _same_ type as we
  3103. // intend to enclose the string with, it must be escaped, so return it with
  3104. // a backslash.
  3105. if (quote === enclosingQuote) {
  3106. return "\\" + quote;
  3107. }
  3108. if (quote) {
  3109. return quote;
  3110. } // Unescape any unnecessarily escaped character.
  3111. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  3112. return unescapeUnnecessaryEscapes && /^[^\n\r"'0-7\\bfnrt-vx\u2028\u2029]$/.test(escaped) ? escaped : "\\" + escaped;
  3113. });
  3114. return enclosingQuote + newContent + enclosingQuote;
  3115. }
  3116. function printNumber(rawNumber) {
  3117. return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation.
  3118. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0).
  3119. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit.
  3120. .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes.
  3121. .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot.
  3122. .replace(/\.(?=e|$)/, "");
  3123. }
  3124. /**
  3125. * @param {string} str
  3126. * @param {string} target
  3127. * @returns {number}
  3128. */
  3129. function getMaxContinuousCount(str, target) {
  3130. const results = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  3131. if (results === null) {
  3132. return 0;
  3133. }
  3134. return results.reduce((maxCount, result) => Math.max(maxCount, result.length / target.length), 0);
  3135. }
  3136. function getMinNotPresentContinuousCount(str, target) {
  3137. const matches = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  3138. if (matches === null) {
  3139. return 0;
  3140. }
  3141. const countPresent = new Map();
  3142. let max = 0;
  3143. for (const match of matches) {
  3144. const count = match.length / target.length;
  3145. countPresent.set(count, true);
  3146. if (count > max) {
  3147. max = count;
  3148. }
  3149. }
  3150. for (let i = 1; i < max; i++) {
  3151. if (!countPresent.get(i)) {
  3152. return i;
  3153. }
  3154. }
  3155. return max + 1;
  3156. }
  3157. /**
  3158. * @param {string} text
  3159. * @returns {number}
  3160. */
  3161. function getStringWidth(text) {
  3162. if (!text) {
  3163. return 0;
  3164. } // shortcut to avoid needless string `RegExp`s, replacements, and allocations within `string-width`
  3165. if (!notAsciiRegex.test(text)) {
  3166. return text.length;
  3167. }
  3168. return stringWidth_1(text);
  3169. }
  3170. function hasIgnoreComment(path) {
  3171. const node = path.getValue();
  3172. return hasNodeIgnoreComment(node);
  3173. }
  3174. function hasNodeIgnoreComment(node) {
  3175. return node && (node.comments && node.comments.length > 0 && node.comments.some(comment => isNodeIgnoreComment(comment) && !comment.unignore) || node.prettierIgnore);
  3176. }
  3177. function isNodeIgnoreComment(comment) {
  3178. return comment.value.trim() === "prettier-ignore";
  3179. }
  3180. function addCommentHelper(node, comment) {
  3181. const comments = node.comments || (node.comments = []);
  3182. comments.push(comment);
  3183. comment.printed = false; // For some reason, TypeScript parses `// x` inside of JSXText as a comment
  3184. // We already "print" it via the raw text, we don't need to re-print it as a
  3185. // comment
  3186. /* istanbul ignore next */
  3187. if (node.type === "JSXText") {
  3188. comment.printed = true;
  3189. }
  3190. }
  3191. function addLeadingComment(node, comment) {
  3192. comment.leading = true;
  3193. comment.trailing = false;
  3194. addCommentHelper(node, comment);
  3195. }
  3196. function addDanglingComment(node, comment, marker) {
  3197. comment.leading = false;
  3198. comment.trailing = false;
  3199. if (marker) {
  3200. comment.marker = marker;
  3201. }
  3202. addCommentHelper(node, comment);
  3203. }
  3204. function addTrailingComment(node, comment) {
  3205. comment.leading = false;
  3206. comment.trailing = true;
  3207. addCommentHelper(node, comment);
  3208. } // Not using
  3209. /* istanbul ignore next */
  3210. function isWithinParentArrayProperty(path, propertyName) {
  3211. const node = path.getValue();
  3212. const parent = path.getParentNode();
  3213. if (parent == null) {
  3214. return false;
  3215. }
  3216. if (!Array.isArray(parent[propertyName])) {
  3217. return false;
  3218. }
  3219. const key = path.getName();
  3220. return parent[propertyName][key] === node;
  3221. }
  3222. function replaceEndOfLineWith(text, replacement) {
  3223. const parts = [];
  3224. for (const part of text.split("\n")) {
  3225. if (parts.length !== 0) {
  3226. parts.push(replacement);
  3227. }
  3228. parts.push(part);
  3229. }
  3230. return parts;
  3231. }
  3232. function getParserName(lang, options) {
  3233. const supportInfo = support.getSupportInfo({
  3234. plugins: options.plugins
  3235. });
  3236. const language = supportInfo.languages.find(language => language.name.toLowerCase() === lang || language.aliases && language.aliases.includes(lang) || language.extensions && language.extensions.some(ext => ext === `.${lang}`));
  3237. if (language) {
  3238. return language.parsers[0];
  3239. }
  3240. return null;
  3241. }
  3242. function isFrontMatterNode(node) {
  3243. return node && node.type === "front-matter";
  3244. }
  3245. function getShebang(text) {
  3246. if (!text.startsWith("#!")) {
  3247. return "";
  3248. }
  3249. const index = text.indexOf("\n");
  3250. if (index === -1) {
  3251. return text;
  3252. }
  3253. return text.slice(0, index);
  3254. }
  3255. var util = {
  3256. replaceEndOfLineWith,
  3257. getStringWidth,
  3258. getMaxContinuousCount,
  3259. getMinNotPresentContinuousCount,
  3260. getParserName,
  3261. getPenultimate,
  3262. getLast,
  3263. getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
  3264. getNextNonSpaceNonCommentCharacterIndex,
  3265. getNextNonSpaceNonCommentCharacter,
  3266. skip,
  3267. skipWhitespace,
  3268. skipSpaces,
  3269. skipToLineEnd,
  3270. skipEverythingButNewLine,
  3271. skipInlineComment,
  3272. skipTrailingComment,
  3273. skipNewline,
  3274. isNextLineEmptyAfterIndex,
  3275. isNextLineEmpty,
  3276. isPreviousLineEmpty,
  3277. hasNewline,
  3278. hasNewlineInRange,
  3279. hasSpaces,
  3280. getAlignmentSize,
  3281. getIndentSize,
  3282. getPreferredQuote,
  3283. printString,
  3284. printNumber,
  3285. hasIgnoreComment,
  3286. hasNodeIgnoreComment,
  3287. isNodeIgnoreComment,
  3288. makeString,
  3289. addLeadingComment,
  3290. addDanglingComment,
  3291. addTrailingComment,
  3292. isWithinParentArrayProperty,
  3293. isFrontMatterNode,
  3294. getShebang
  3295. };
  3296. function guessEndOfLine(text) {
  3297. const index = text.indexOf("\r");
  3298. if (index >= 0) {
  3299. return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
  3300. }
  3301. return "lf";
  3302. }
  3303. function convertEndOfLineToChars(value) {
  3304. switch (value) {
  3305. case "cr":
  3306. return "\r";
  3307. case "crlf":
  3308. return "\r\n";
  3309. default:
  3310. return "\n";
  3311. }
  3312. }
  3313. function countEndOfLineChars(text, eol) {
  3314. let regex;
  3315. /* istanbul ignore else */
  3316. if (eol === "\n") {
  3317. regex = /\n/g;
  3318. } else if (eol === "\r") {
  3319. regex = /\r/g;
  3320. } else if (eol === "\r\n") {
  3321. regex = /\r\n/g;
  3322. } else {
  3323. throw new Error(`Unexpected "eol" ${JSON.stringify(eol)}.`);
  3324. }
  3325. const endOfLines = text.match(regex);
  3326. return endOfLines ? endOfLines.length : 0;
  3327. }
  3328. function normalizeEndOfLine(text) {
  3329. return text.replace(/\r\n?/g, "\n");
  3330. }
  3331. var endOfLine = {
  3332. guessEndOfLine,
  3333. convertEndOfLineToChars,
  3334. countEndOfLineChars,
  3335. normalizeEndOfLine
  3336. };
  3337. const {
  3338. getStringWidth: getStringWidth$1
  3339. } = util;
  3340. const {
  3341. convertEndOfLineToChars: convertEndOfLineToChars$1
  3342. } = endOfLine;
  3343. const {
  3344. concat: concat$1,
  3345. fill: fill$1,
  3346. cursor: cursor$1
  3347. } = docBuilders;
  3348. /** @type {Record<symbol, typeof MODE_BREAK | typeof MODE_FLAT>} */
  3349. let groupModeMap;
  3350. const MODE_BREAK = 1;
  3351. const MODE_FLAT = 2;
  3352. function rootIndent() {
  3353. return {
  3354. value: "",
  3355. length: 0,
  3356. queue: []
  3357. };
  3358. }
  3359. function makeIndent(ind, options) {
  3360. return generateInd(ind, {
  3361. type: "indent"
  3362. }, options);
  3363. }
  3364. function makeAlign(indent, n, options) {
  3365. if (n === -Infinity) {
  3366. return indent.root || rootIndent();
  3367. }
  3368. if (n < 0) {
  3369. return generateInd(indent, {
  3370. type: "dedent"
  3371. }, options);
  3372. }
  3373. if (!n) {
  3374. return indent;
  3375. }
  3376. if (n.type === "root") {
  3377. return Object.assign({}, indent, {
  3378. root: indent
  3379. });
  3380. }
  3381. const alignType = typeof n === "string" ? "stringAlign" : "numberAlign";
  3382. return generateInd(indent, {
  3383. type: alignType,
  3384. n
  3385. }, options);
  3386. }
  3387. function generateInd(ind, newPart, options) {
  3388. const queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : ind.queue.concat(newPart);
  3389. let value = "";
  3390. let length = 0;
  3391. let lastTabs = 0;
  3392. let lastSpaces = 0;
  3393. for (const part of queue) {
  3394. switch (part.type) {
  3395. case "indent":
  3396. flush();
  3397. if (options.useTabs) {
  3398. addTabs(1);
  3399. } else {
  3400. addSpaces(options.tabWidth);
  3401. }
  3402. break;
  3403. case "stringAlign":
  3404. flush();
  3405. value += part.n;
  3406. length += part.n.length;
  3407. break;
  3408. case "numberAlign":
  3409. lastTabs += 1;
  3410. lastSpaces += part.n;
  3411. break;
  3412. /* istanbul ignore next */
  3413. default:
  3414. throw new Error(`Unexpected type '${part.type}'`);
  3415. }
  3416. }
  3417. flushSpaces();
  3418. return Object.assign({}, ind, {
  3419. value,
  3420. length,
  3421. queue
  3422. });
  3423. function addTabs(count) {
  3424. value += "\t".repeat(count);
  3425. length += options.tabWidth * count;
  3426. }
  3427. function addSpaces(count) {
  3428. value += " ".repeat(count);
  3429. length += count;
  3430. }
  3431. function flush() {
  3432. if (options.useTabs) {
  3433. flushTabs();
  3434. } else {
  3435. flushSpaces();
  3436. }
  3437. }
  3438. function flushTabs() {
  3439. if (lastTabs > 0) {
  3440. addTabs(lastTabs);
  3441. }
  3442. resetLast();
  3443. }
  3444. function flushSpaces() {
  3445. if (lastSpaces > 0) {
  3446. addSpaces(lastSpaces);
  3447. }
  3448. resetLast();
  3449. }
  3450. function resetLast() {
  3451. lastTabs = 0;
  3452. lastSpaces = 0;
  3453. }
  3454. }
  3455. function trim$1(out) {
  3456. if (out.length === 0) {
  3457. return 0;
  3458. }
  3459. let trimCount = 0; // Trim whitespace at the end of line
  3460. while (out.length > 0 && typeof out[out.length - 1] === "string" && out[out.length - 1].match(/^[\t ]*$/)) {
  3461. trimCount += out.pop().length;
  3462. }
  3463. if (out.length && typeof out[out.length - 1] === "string") {
  3464. const trimmed = out[out.length - 1].replace(/[\t ]*$/, "");
  3465. trimCount += out[out.length - 1].length - trimmed.length;
  3466. out[out.length - 1] = trimmed;
  3467. }
  3468. return trimCount;
  3469. }
  3470. function fits(next, restCommands, width, options, mustBeFlat) {
  3471. let restIdx = restCommands.length;
  3472. const cmds = [next]; // `out` is only used for width counting because `trim` requires to look
  3473. // backwards for space characters.
  3474. const out = [];
  3475. while (width >= 0) {
  3476. if (cmds.length === 0) {
  3477. if (restIdx === 0) {
  3478. return true;
  3479. }
  3480. cmds.push(restCommands[restIdx - 1]);
  3481. restIdx--;
  3482. continue;
  3483. }
  3484. const [ind, mode, doc] = cmds.pop();
  3485. if (typeof doc === "string") {
  3486. out.push(doc);
  3487. width -= getStringWidth$1(doc);
  3488. } else {
  3489. switch (doc.type) {
  3490. case "concat":
  3491. for (let i = doc.parts.length - 1; i >= 0; i--) {
  3492. cmds.push([ind, mode, doc.parts[i]]);
  3493. }
  3494. break;
  3495. case "indent":
  3496. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  3497. break;
  3498. case "align":
  3499. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  3500. break;
  3501. case "trim":
  3502. width += trim$1(out);
  3503. break;
  3504. case "group":
  3505. if (mustBeFlat && doc.break) {
  3506. return false;
  3507. }
  3508. cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
  3509. if (doc.id) {
  3510. groupModeMap[doc.id] = cmds[cmds.length - 1][1];
  3511. }
  3512. break;
  3513. case "fill":
  3514. for (let i = doc.parts.length - 1; i >= 0; i--) {
  3515. cmds.push([ind, mode, doc.parts[i]]);
  3516. }
  3517. break;
  3518. case "if-break":
  3519. {
  3520. const groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  3521. if (groupMode === MODE_BREAK) {
  3522. if (doc.breakContents) {
  3523. cmds.push([ind, mode, doc.breakContents]);
  3524. }
  3525. }
  3526. if (groupMode === MODE_FLAT) {
  3527. if (doc.flatContents) {
  3528. cmds.push([ind, mode, doc.flatContents]);
  3529. }
  3530. }
  3531. break;
  3532. }
  3533. case "line":
  3534. switch (mode) {
  3535. // fallthrough
  3536. case MODE_FLAT:
  3537. if (!doc.hard) {
  3538. if (!doc.soft) {
  3539. out.push(" ");
  3540. width -= 1;
  3541. }
  3542. break;
  3543. }
  3544. return true;
  3545. case MODE_BREAK:
  3546. return true;
  3547. }
  3548. break;
  3549. }
  3550. }
  3551. }
  3552. return false;
  3553. }
  3554. function printDocToString(doc, options) {
  3555. groupModeMap = {};
  3556. const width = options.printWidth;
  3557. const newLine = convertEndOfLineToChars$1(options.endOfLine);
  3558. let pos = 0; // cmds is basically a stack. We've turned a recursive call into a
  3559. // while loop which is much faster. The while loop below adds new
  3560. // cmds to the array instead of recursively calling `print`.
  3561. const cmds = [[rootIndent(), MODE_BREAK, doc]];
  3562. const out = [];
  3563. let shouldRemeasure = false;
  3564. let lineSuffix = [];
  3565. while (cmds.length !== 0) {
  3566. const [ind, mode, doc] = cmds.pop();
  3567. if (typeof doc === "string") {
  3568. const formatted = newLine !== "\n" && doc.includes("\n") ? doc.replace(/\n/g, newLine) : doc;
  3569. out.push(formatted);
  3570. pos += getStringWidth$1(formatted);
  3571. } else {
  3572. switch (doc.type) {
  3573. case "cursor":
  3574. out.push(cursor$1.placeholder);
  3575. break;
  3576. case "concat":
  3577. for (let i = doc.parts.length - 1; i >= 0; i--) {
  3578. cmds.push([ind, mode, doc.parts[i]]);
  3579. }
  3580. break;
  3581. case "indent":
  3582. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  3583. break;
  3584. case "align":
  3585. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  3586. break;
  3587. case "trim":
  3588. pos -= trim$1(out);
  3589. break;
  3590. case "group":
  3591. switch (mode) {
  3592. case MODE_FLAT:
  3593. if (!shouldRemeasure) {
  3594. cmds.push([ind, doc.break ? MODE_BREAK : MODE_FLAT, doc.contents]);
  3595. break;
  3596. }
  3597. // fallthrough
  3598. case MODE_BREAK:
  3599. {
  3600. shouldRemeasure = false;
  3601. const next = [ind, MODE_FLAT, doc.contents];
  3602. const rem = width - pos;
  3603. if (!doc.break && fits(next, cmds, rem, options)) {
  3604. cmds.push(next);
  3605. } else {
  3606. // Expanded states are a rare case where a document
  3607. // can manually provide multiple representations of
  3608. // itself. It provides an array of documents
  3609. // going from the least expanded (most flattened)
  3610. // representation first to the most expanded. If a
  3611. // group has these, we need to manually go through
  3612. // these states and find the first one that fits.
  3613. if (doc.expandedStates) {
  3614. const mostExpanded = doc.expandedStates[doc.expandedStates.length - 1];
  3615. if (doc.break) {
  3616. cmds.push([ind, MODE_BREAK, mostExpanded]);
  3617. break;
  3618. } else {
  3619. for (let i = 1; i < doc.expandedStates.length + 1; i++) {
  3620. if (i >= doc.expandedStates.length) {
  3621. cmds.push([ind, MODE_BREAK, mostExpanded]);
  3622. break;
  3623. } else {
  3624. const state = doc.expandedStates[i];
  3625. const cmd = [ind, MODE_FLAT, state];
  3626. if (fits(cmd, cmds, rem, options)) {
  3627. cmds.push(cmd);
  3628. break;
  3629. }
  3630. }
  3631. }
  3632. }
  3633. } else {
  3634. cmds.push([ind, MODE_BREAK, doc.contents]);
  3635. }
  3636. }
  3637. break;
  3638. }
  3639. }
  3640. if (doc.id) {
  3641. groupModeMap[doc.id] = cmds[cmds.length - 1][1];
  3642. }
  3643. break;
  3644. // Fills each line with as much code as possible before moving to a new
  3645. // line with the same indentation.
  3646. //
  3647. // Expects doc.parts to be an array of alternating content and
  3648. // whitespace. The whitespace contains the linebreaks.
  3649. //
  3650. // For example:
  3651. // ["I", line, "love", line, "monkeys"]
  3652. // or
  3653. // [{ type: group, ... }, softline, { type: group, ... }]
  3654. //
  3655. // It uses this parts structure to handle three main layout cases:
  3656. // * The first two content items fit on the same line without
  3657. // breaking
  3658. // -> output the first content item and the whitespace "flat".
  3659. // * Only the first content item fits on the line without breaking
  3660. // -> output the first content item "flat" and the whitespace with
  3661. // "break".
  3662. // * Neither content item fits on the line without breaking
  3663. // -> output the first content item and the whitespace with "break".
  3664. case "fill":
  3665. {
  3666. const rem = width - pos;
  3667. const {
  3668. parts
  3669. } = doc;
  3670. if (parts.length === 0) {
  3671. break;
  3672. }
  3673. const [content, whitespace] = parts;
  3674. const contentFlatCmd = [ind, MODE_FLAT, content];
  3675. const contentBreakCmd = [ind, MODE_BREAK, content];
  3676. const contentFits = fits(contentFlatCmd, [], rem, options, true);
  3677. if (parts.length === 1) {
  3678. if (contentFits) {
  3679. cmds.push(contentFlatCmd);
  3680. } else {
  3681. cmds.push(contentBreakCmd);
  3682. }
  3683. break;
  3684. }
  3685. const whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  3686. const whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  3687. if (parts.length === 2) {
  3688. if (contentFits) {
  3689. cmds.push(whitespaceFlatCmd);
  3690. cmds.push(contentFlatCmd);
  3691. } else {
  3692. cmds.push(whitespaceBreakCmd);
  3693. cmds.push(contentBreakCmd);
  3694. }
  3695. break;
  3696. } // At this point we've handled the first pair (context, separator)
  3697. // and will create a new fill doc for the rest of the content.
  3698. // Ideally we wouldn't mutate the array here but copying all the
  3699. // elements to a new array would make this algorithm quadratic,
  3700. // which is unusable for large arrays (e.g. large texts in JSX).
  3701. parts.splice(0, 2);
  3702. const remainingCmd = [ind, mode, fill$1(parts)];
  3703. const secondContent = parts[0];
  3704. const firstAndSecondContentFlatCmd = [ind, MODE_FLAT, concat$1([content, whitespace, secondContent])];
  3705. const firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], rem, options, true);
  3706. if (firstAndSecondContentFits) {
  3707. cmds.push(remainingCmd);
  3708. cmds.push(whitespaceFlatCmd);
  3709. cmds.push(contentFlatCmd);
  3710. } else if (contentFits) {
  3711. cmds.push(remainingCmd);
  3712. cmds.push(whitespaceBreakCmd);
  3713. cmds.push(contentFlatCmd);
  3714. } else {
  3715. cmds.push(remainingCmd);
  3716. cmds.push(whitespaceBreakCmd);
  3717. cmds.push(contentBreakCmd);
  3718. }
  3719. break;
  3720. }
  3721. case "if-break":
  3722. {
  3723. const groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  3724. if (groupMode === MODE_BREAK) {
  3725. if (doc.breakContents) {
  3726. cmds.push([ind, mode, doc.breakContents]);
  3727. }
  3728. }
  3729. if (groupMode === MODE_FLAT) {
  3730. if (doc.flatContents) {
  3731. cmds.push([ind, mode, doc.flatContents]);
  3732. }
  3733. }
  3734. break;
  3735. }
  3736. case "line-suffix":
  3737. lineSuffix.push([ind, mode, doc.contents]);
  3738. break;
  3739. case "line-suffix-boundary":
  3740. if (lineSuffix.length > 0) {
  3741. cmds.push([ind, mode, {
  3742. type: "line",
  3743. hard: true
  3744. }]);
  3745. }
  3746. break;
  3747. case "line":
  3748. switch (mode) {
  3749. case MODE_FLAT:
  3750. if (!doc.hard) {
  3751. if (!doc.soft) {
  3752. out.push(" ");
  3753. pos += 1;
  3754. }
  3755. break;
  3756. } else {
  3757. // This line was forced into the output even if we
  3758. // were in flattened mode, so we need to tell the next
  3759. // group that no matter what, it needs to remeasure
  3760. // because the previous measurement didn't accurately
  3761. // capture the entire expression (this is necessary
  3762. // for nested groups)
  3763. shouldRemeasure = true;
  3764. }
  3765. // fallthrough
  3766. case MODE_BREAK:
  3767. if (lineSuffix.length) {
  3768. cmds.push([ind, mode, doc]);
  3769. cmds.push(...lineSuffix.reverse());
  3770. lineSuffix = [];
  3771. break;
  3772. }
  3773. if (doc.literal) {
  3774. if (ind.root) {
  3775. out.push(newLine, ind.root.value);
  3776. pos = ind.root.length;
  3777. } else {
  3778. out.push(newLine);
  3779. pos = 0;
  3780. }
  3781. } else {
  3782. pos -= trim$1(out);
  3783. out.push(newLine + ind.value);
  3784. pos = ind.length;
  3785. }
  3786. break;
  3787. }
  3788. break;
  3789. }
  3790. }
  3791. }
  3792. const cursorPlaceholderIndex = out.indexOf(cursor$1.placeholder);
  3793. if (cursorPlaceholderIndex !== -1) {
  3794. const otherCursorPlaceholderIndex = out.indexOf(cursor$1.placeholder, cursorPlaceholderIndex + 1);
  3795. const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  3796. const aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
  3797. const afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
  3798. return {
  3799. formatted: beforeCursor + aroundCursor + afterCursor,
  3800. cursorNodeStart: beforeCursor.length,
  3801. cursorNodeText: aroundCursor
  3802. };
  3803. }
  3804. return {
  3805. formatted: out.join("")
  3806. };
  3807. }
  3808. var docPrinter = {
  3809. printDocToString
  3810. };
  3811. const {
  3812. literalline: literalline$1,
  3813. concat: concat$2
  3814. } = docBuilders; // Using a unique object to compare by reference.
  3815. const traverseDocOnExitStackMarker = {};
  3816. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  3817. const docsStack = [doc];
  3818. while (docsStack.length !== 0) {
  3819. const doc = docsStack.pop();
  3820. if (doc === traverseDocOnExitStackMarker) {
  3821. onExit(docsStack.pop());
  3822. continue;
  3823. }
  3824. if (onExit) {
  3825. docsStack.push(doc, traverseDocOnExitStackMarker);
  3826. }
  3827. if ( // Should Recurse
  3828. !onEnter || onEnter(doc) !== false) {
  3829. // When there are multiple parts to process,
  3830. // the parts need to be pushed onto the stack in reverse order,
  3831. // so that they are processed in the original order
  3832. // when the stack is popped.
  3833. if (doc.type === "concat" || doc.type === "fill") {
  3834. for (let ic = doc.parts.length, i = ic - 1; i >= 0; --i) {
  3835. docsStack.push(doc.parts[i]);
  3836. }
  3837. } else if (doc.type === "if-break") {
  3838. if (doc.flatContents) {
  3839. docsStack.push(doc.flatContents);
  3840. }
  3841. if (doc.breakContents) {
  3842. docsStack.push(doc.breakContents);
  3843. }
  3844. } else if (doc.type === "group" && doc.expandedStates) {
  3845. if (shouldTraverseConditionalGroups) {
  3846. for (let ic = doc.expandedStates.length, i = ic - 1; i >= 0; --i) {
  3847. docsStack.push(doc.expandedStates[i]);
  3848. }
  3849. } else {
  3850. docsStack.push(doc.contents);
  3851. }
  3852. } else if (doc.contents) {
  3853. docsStack.push(doc.contents);
  3854. }
  3855. }
  3856. }
  3857. }
  3858. function mapDoc(doc, cb) {
  3859. if (doc.type === "concat" || doc.type === "fill") {
  3860. const parts = doc.parts.map(part => mapDoc(part, cb));
  3861. return cb(Object.assign({}, doc, {
  3862. parts
  3863. }));
  3864. } else if (doc.type === "if-break") {
  3865. const breakContents = doc.breakContents && mapDoc(doc.breakContents, cb);
  3866. const flatContents = doc.flatContents && mapDoc(doc.flatContents, cb);
  3867. return cb(Object.assign({}, doc, {
  3868. breakContents,
  3869. flatContents
  3870. }));
  3871. } else if (doc.contents) {
  3872. const contents = mapDoc(doc.contents, cb);
  3873. return cb(Object.assign({}, doc, {
  3874. contents
  3875. }));
  3876. }
  3877. return cb(doc);
  3878. }
  3879. function findInDoc(doc, fn, defaultValue) {
  3880. let result = defaultValue;
  3881. let hasStopped = false;
  3882. function findInDocOnEnterFn(doc) {
  3883. const maybeResult = fn(doc);
  3884. if (maybeResult !== undefined) {
  3885. hasStopped = true;
  3886. result = maybeResult;
  3887. }
  3888. if (hasStopped) {
  3889. return false;
  3890. }
  3891. }
  3892. traverseDoc(doc, findInDocOnEnterFn);
  3893. return result;
  3894. }
  3895. function isEmpty(n) {
  3896. return typeof n === "string" && n.length === 0;
  3897. }
  3898. function isLineNextFn(doc) {
  3899. if (typeof doc === "string") {
  3900. return false;
  3901. }
  3902. if (doc.type === "line") {
  3903. return true;
  3904. }
  3905. }
  3906. function isLineNext(doc) {
  3907. return findInDoc(doc, isLineNextFn, false);
  3908. }
  3909. function willBreakFn(doc) {
  3910. if (doc.type === "group" && doc.break) {
  3911. return true;
  3912. }
  3913. if (doc.type === "line" && doc.hard) {
  3914. return true;
  3915. }
  3916. if (doc.type === "break-parent") {
  3917. return true;
  3918. }
  3919. }
  3920. function willBreak(doc) {
  3921. return findInDoc(doc, willBreakFn, false);
  3922. }
  3923. function breakParentGroup(groupStack) {
  3924. if (groupStack.length > 0) {
  3925. const parentGroup = groupStack[groupStack.length - 1]; // Breaks are not propagated through conditional groups because
  3926. // the user is expected to manually handle what breaks.
  3927. if (!parentGroup.expandedStates) {
  3928. parentGroup.break = true;
  3929. }
  3930. }
  3931. return null;
  3932. }
  3933. function propagateBreaks(doc) {
  3934. const alreadyVisitedSet = new Set();
  3935. const groupStack = [];
  3936. function propagateBreaksOnEnterFn(doc) {
  3937. if (doc.type === "break-parent") {
  3938. breakParentGroup(groupStack);
  3939. }
  3940. if (doc.type === "group") {
  3941. groupStack.push(doc);
  3942. if (alreadyVisitedSet.has(doc)) {
  3943. return false;
  3944. }
  3945. alreadyVisitedSet.add(doc);
  3946. }
  3947. }
  3948. function propagateBreaksOnExitFn(doc) {
  3949. if (doc.type === "group") {
  3950. const group = groupStack.pop();
  3951. if (group.break) {
  3952. breakParentGroup(groupStack);
  3953. }
  3954. }
  3955. }
  3956. traverseDoc(doc, propagateBreaksOnEnterFn, propagateBreaksOnExitFn,
  3957. /* shouldTraverseConditionalGroups */
  3958. true);
  3959. }
  3960. function removeLinesFn(doc) {
  3961. // Force this doc into flat mode by statically converting all
  3962. // lines into spaces (or soft lines into nothing). Hard lines
  3963. // should still output because there's too great of a chance
  3964. // of breaking existing assumptions otherwise.
  3965. if (doc.type === "line" && !doc.hard) {
  3966. return doc.soft ? "" : " ";
  3967. } else if (doc.type === "if-break") {
  3968. return doc.flatContents || "";
  3969. }
  3970. return doc;
  3971. }
  3972. function removeLines(doc) {
  3973. return mapDoc(doc, removeLinesFn);
  3974. }
  3975. function getInnerParts(doc) {
  3976. let {
  3977. parts
  3978. } = doc;
  3979. let lastPart; // Avoid a falsy element like ""
  3980. for (let i = doc.parts.length; i > 0 && !lastPart; i--) {
  3981. lastPart = parts[i - 1];
  3982. }
  3983. if (lastPart.type === "group") {
  3984. parts = lastPart.contents.parts;
  3985. }
  3986. return parts;
  3987. }
  3988. function stripTrailingHardline(doc, withInnerParts = false) {
  3989. // HACK remove ending hardline, original PR: #1984
  3990. if (doc.type === "concat" && doc.parts.length !== 0) {
  3991. const parts = withInnerParts ? getInnerParts(doc) : doc.parts;
  3992. const lastPart = parts[parts.length - 1];
  3993. if (lastPart.type === "concat") {
  3994. if (lastPart.parts.length === 2 && lastPart.parts[0].hard && lastPart.parts[1].type === "break-parent") {
  3995. return {
  3996. type: "concat",
  3997. parts: parts.slice(0, -1)
  3998. };
  3999. }
  4000. return {
  4001. type: "concat",
  4002. parts: doc.parts.slice(0, -1).concat(stripTrailingHardline(lastPart))
  4003. };
  4004. }
  4005. }
  4006. return doc;
  4007. }
  4008. function normalizeParts(parts) {
  4009. const newParts = [];
  4010. const restParts = parts.filter(Boolean);
  4011. while (restParts.length !== 0) {
  4012. const part = restParts.shift();
  4013. if (!part) {
  4014. continue;
  4015. }
  4016. if (part.type === "concat") {
  4017. restParts.unshift(...part.parts);
  4018. continue;
  4019. }
  4020. if (newParts.length !== 0 && typeof newParts[newParts.length - 1] === "string" && typeof part === "string") {
  4021. newParts[newParts.length - 1] += part;
  4022. continue;
  4023. }
  4024. newParts.push(part);
  4025. }
  4026. return newParts;
  4027. }
  4028. function normalizeDoc(doc) {
  4029. return mapDoc(doc, currentDoc => {
  4030. if (!currentDoc.parts) {
  4031. return currentDoc;
  4032. }
  4033. return Object.assign({}, currentDoc, {
  4034. parts: normalizeParts(currentDoc.parts)
  4035. });
  4036. });
  4037. }
  4038. function replaceNewlinesWithLiterallines(doc) {
  4039. return mapDoc(doc, currentDoc => typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$2(currentDoc.split(/(\n)/g).map((v, i) => i % 2 === 0 ? v : literalline$1)) : currentDoc);
  4040. }
  4041. var docUtils = {
  4042. isEmpty,
  4043. willBreak,
  4044. isLineNext,
  4045. traverseDoc,
  4046. findInDoc,
  4047. mapDoc,
  4048. propagateBreaks,
  4049. removeLines,
  4050. stripTrailingHardline,
  4051. normalizeParts,
  4052. normalizeDoc,
  4053. replaceNewlinesWithLiterallines
  4054. };
  4055. function flattenDoc(doc) {
  4056. if (doc.type === "concat") {
  4057. const res = [];
  4058. for (let i = 0; i < doc.parts.length; ++i) {
  4059. const doc2 = doc.parts[i];
  4060. if (typeof doc2 !== "string" && doc2.type === "concat") {
  4061. res.push(...flattenDoc(doc2).parts);
  4062. } else {
  4063. const flattened = flattenDoc(doc2);
  4064. if (flattened !== "") {
  4065. res.push(flattened);
  4066. }
  4067. }
  4068. }
  4069. return Object.assign({}, doc, {
  4070. parts: res
  4071. });
  4072. } else if (doc.type === "if-break") {
  4073. return Object.assign({}, doc, {
  4074. breakContents: doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
  4075. flatContents: doc.flatContents != null ? flattenDoc(doc.flatContents) : null
  4076. });
  4077. } else if (doc.type === "group") {
  4078. return Object.assign({}, doc, {
  4079. contents: flattenDoc(doc.contents),
  4080. expandedStates: doc.expandedStates ? doc.expandedStates.map(flattenDoc) : doc.expandedStates
  4081. });
  4082. } else if (doc.contents) {
  4083. return Object.assign({}, doc, {
  4084. contents: flattenDoc(doc.contents)
  4085. });
  4086. }
  4087. return doc;
  4088. }
  4089. function printDoc(doc) {
  4090. if (typeof doc === "string") {
  4091. return JSON.stringify(doc);
  4092. }
  4093. if (doc.type === "line") {
  4094. if (doc.literal) {
  4095. return "literalline";
  4096. }
  4097. if (doc.hard) {
  4098. return "hardline";
  4099. }
  4100. if (doc.soft) {
  4101. return "softline";
  4102. }
  4103. return "line";
  4104. }
  4105. if (doc.type === "break-parent") {
  4106. return "breakParent";
  4107. }
  4108. if (doc.type === "trim") {
  4109. return "trim";
  4110. }
  4111. if (doc.type === "concat") {
  4112. return "[" + doc.parts.map(printDoc).join(", ") + "]";
  4113. }
  4114. if (doc.type === "indent") {
  4115. return "indent(" + printDoc(doc.contents) + ")";
  4116. }
  4117. if (doc.type === "align") {
  4118. return doc.n === -Infinity ? "dedentToRoot(" + printDoc(doc.contents) + ")" : doc.n < 0 ? "dedent(" + printDoc(doc.contents) + ")" : doc.n.type === "root" ? "markAsRoot(" + printDoc(doc.contents) + ")" : "align(" + JSON.stringify(doc.n) + ", " + printDoc(doc.contents) + ")";
  4119. }
  4120. if (doc.type === "if-break") {
  4121. return "ifBreak(" + printDoc(doc.breakContents) + (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") + ")";
  4122. }
  4123. if (doc.type === "group") {
  4124. if (doc.expandedStates) {
  4125. return "conditionalGroup(" + "[" + doc.expandedStates.map(printDoc).join(",") + "])";
  4126. }
  4127. return (doc.break ? "wrappedGroup" : "group") + "(" + printDoc(doc.contents) + ")";
  4128. }
  4129. if (doc.type === "fill") {
  4130. return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  4131. }
  4132. if (doc.type === "line-suffix") {
  4133. return "lineSuffix(" + printDoc(doc.contents) + ")";
  4134. }
  4135. if (doc.type === "line-suffix-boundary") {
  4136. return "lineSuffixBoundary";
  4137. }
  4138. throw new Error("Unknown doc type " + doc.type);
  4139. }
  4140. var docDebug = {
  4141. printDocToDebug(doc) {
  4142. return printDoc(flattenDoc(doc));
  4143. }
  4144. };
  4145. /**
  4146. * @typedef {import("./doc-builders").Doc} Doc
  4147. */
  4148. var document = {
  4149. builders: docBuilders,
  4150. printer: docPrinter,
  4151. utils: docUtils,
  4152. debug: docDebug
  4153. };
  4154. /**
  4155. * @class
  4156. */
  4157. class LineByLine {
  4158. constructor(file, options) {
  4159. options = options || {};
  4160. if (!options.readChunk) options.readChunk = 1024;
  4161. if (!options.newLineCharacter) {
  4162. options.newLineCharacter = 0x0a; //linux line ending
  4163. } else {
  4164. options.newLineCharacter = options.newLineCharacter.charCodeAt(0);
  4165. }
  4166. if (typeof file === 'number') {
  4167. this.fd = file;
  4168. } else {
  4169. this.fd = fs__default['default'].openSync(file, 'r');
  4170. }
  4171. this.options = options;
  4172. this.newLineCharacter = options.newLineCharacter;
  4173. this.reset();
  4174. }
  4175. _searchInBuffer(buffer, hexNeedle) {
  4176. let found = -1;
  4177. for (let i = 0; i <= buffer.length; i++) {
  4178. let b_byte = buffer[i];
  4179. if (b_byte === hexNeedle) {
  4180. found = i;
  4181. break;
  4182. }
  4183. }
  4184. return found;
  4185. }
  4186. reset() {
  4187. this.eofReached = false;
  4188. this.linesCache = [];
  4189. this.fdPosition = 0;
  4190. }
  4191. close() {
  4192. fs__default['default'].closeSync(this.fd);
  4193. this.fd = null;
  4194. }
  4195. _extractLines(buffer) {
  4196. let line;
  4197. const lines = [];
  4198. let bufferPosition = 0;
  4199. let lastNewLineBufferPosition = 0;
  4200. while (true) {
  4201. let bufferPositionValue = buffer[bufferPosition++];
  4202. if (bufferPositionValue === this.newLineCharacter) {
  4203. line = buffer.slice(lastNewLineBufferPosition, bufferPosition);
  4204. lines.push(line);
  4205. lastNewLineBufferPosition = bufferPosition;
  4206. } else if (!bufferPositionValue) {
  4207. break;
  4208. }
  4209. }
  4210. let leftovers = buffer.slice(lastNewLineBufferPosition, bufferPosition);
  4211. if (leftovers.length) {
  4212. lines.push(leftovers);
  4213. }
  4214. return lines;
  4215. }
  4216. _readChunk(lineLeftovers) {
  4217. let totalBytesRead = 0;
  4218. let bytesRead;
  4219. const buffers = [];
  4220. do {
  4221. const readBuffer = new Buffer(this.options.readChunk);
  4222. bytesRead = fs__default['default'].readSync(this.fd, readBuffer, 0, this.options.readChunk, this.fdPosition);
  4223. totalBytesRead = totalBytesRead + bytesRead;
  4224. this.fdPosition = this.fdPosition + bytesRead;
  4225. buffers.push(readBuffer);
  4226. } while (bytesRead && this._searchInBuffer(buffers[buffers.length - 1], this.options.newLineCharacter) === -1);
  4227. let bufferData = Buffer.concat(buffers);
  4228. if (bytesRead < this.options.readChunk) {
  4229. this.eofReached = true;
  4230. bufferData = bufferData.slice(0, totalBytesRead);
  4231. }
  4232. if (totalBytesRead) {
  4233. this.linesCache = this._extractLines(bufferData);
  4234. if (lineLeftovers) {
  4235. this.linesCache[0] = Buffer.concat([lineLeftovers, this.linesCache[0]]);
  4236. }
  4237. }
  4238. return totalBytesRead;
  4239. }
  4240. next() {
  4241. if (!this.fd) return false;
  4242. let line = false;
  4243. if (this.eofReached && this.linesCache.length === 0) {
  4244. return line;
  4245. }
  4246. let bytesRead;
  4247. if (!this.linesCache.length) {
  4248. bytesRead = this._readChunk();
  4249. }
  4250. if (this.linesCache.length) {
  4251. line = this.linesCache.shift();
  4252. const lastLineCharacter = line[line.length - 1];
  4253. if (lastLineCharacter !== 0x0a) {
  4254. bytesRead = this._readChunk(line);
  4255. if (bytesRead) {
  4256. line = this.linesCache.shift();
  4257. }
  4258. }
  4259. }
  4260. if (this.eofReached && this.linesCache.length === 0) {
  4261. this.close();
  4262. }
  4263. if (line && line[line.length - 1] === this.newLineCharacter) {
  4264. line = line.slice(0, line.length - 1);
  4265. }
  4266. return line;
  4267. }
  4268. }
  4269. var readlines = LineByLine;
  4270. /**
  4271. * The inverse of `_.toPairs`; this method returns an object composed
  4272. * from key-value `pairs`.
  4273. *
  4274. * @static
  4275. * @memberOf _
  4276. * @since 4.0.0
  4277. * @category Array
  4278. * @param {Array} pairs The key-value pairs.
  4279. * @returns {Object} Returns the new object.
  4280. * @example
  4281. *
  4282. * _.fromPairs([['a', 1], ['b', 2]]);
  4283. * // => { 'a': 1, 'b': 2 }
  4284. */
  4285. function fromPairs(pairs) {
  4286. var index = -1,
  4287. length = pairs == null ? 0 : pairs.length,
  4288. result = {};
  4289. while (++index < length) {
  4290. var pair = pairs[index];
  4291. result[pair[0]] = pair[1];
  4292. }
  4293. return result;
  4294. }
  4295. var fromPairs_1 = fromPairs;
  4296. class ConfigError extends Error {}
  4297. class DebugError extends Error {}
  4298. class UndefinedParserError extends Error {}
  4299. var errors = {
  4300. ConfigError,
  4301. DebugError,
  4302. UndefinedParserError
  4303. };
  4304. /*! *****************************************************************************
  4305. Copyright (c) Microsoft Corporation.
  4306. Permission to use, copy, modify, and/or distribute this software for any
  4307. purpose with or without fee is hereby granted.
  4308. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  4309. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  4310. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  4311. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  4312. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  4313. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  4314. PERFORMANCE OF THIS SOFTWARE.
  4315. ***************************************************************************** */
  4316. /* global Reflect, Promise */
  4317. var extendStatics = function (d, b) {
  4318. extendStatics = Object.setPrototypeOf || {
  4319. __proto__: []
  4320. } instanceof Array && function (d, b) {
  4321. d.__proto__ = b;
  4322. } || function (d, b) {
  4323. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4324. };
  4325. return extendStatics(d, b);
  4326. };
  4327. function __extends(d, b) {
  4328. extendStatics(d, b);
  4329. function __() {
  4330. this.constructor = d;
  4331. }
  4332. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  4333. }
  4334. var __assign = function () {
  4335. __assign = Object.assign || function __assign(t) {
  4336. for (var s, i = 1, n = arguments.length; i < n; i++) {
  4337. s = arguments[i];
  4338. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  4339. }
  4340. return t;
  4341. };
  4342. return __assign.apply(this, arguments);
  4343. };
  4344. function __rest(s, e) {
  4345. var t = {};
  4346. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  4347. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  4348. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  4349. }
  4350. return t;
  4351. }
  4352. function __decorate(decorators, target, key, desc) {
  4353. var c = arguments.length,
  4354. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  4355. d;
  4356. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  4357. return c > 3 && r && Object.defineProperty(target, key, r), r;
  4358. }
  4359. function __param(paramIndex, decorator) {
  4360. return function (target, key) {
  4361. decorator(target, key, paramIndex);
  4362. };
  4363. }
  4364. function __metadata(metadataKey, metadataValue) {
  4365. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  4366. }
  4367. function __awaiter(thisArg, _arguments, P, generator) {
  4368. function adopt(value) {
  4369. return value instanceof P ? value : new P(function (resolve) {
  4370. resolve(value);
  4371. });
  4372. }
  4373. return new (P || (P = Promise))(function (resolve, reject) {
  4374. function fulfilled(value) {
  4375. try {
  4376. step(generator.next(value));
  4377. } catch (e) {
  4378. reject(e);
  4379. }
  4380. }
  4381. function rejected(value) {
  4382. try {
  4383. step(generator["throw"](value));
  4384. } catch (e) {
  4385. reject(e);
  4386. }
  4387. }
  4388. function step(result) {
  4389. result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
  4390. }
  4391. step((generator = generator.apply(thisArg, _arguments || [])).next());
  4392. });
  4393. }
  4394. function __generator(thisArg, body) {
  4395. var _ = {
  4396. label: 0,
  4397. sent: function () {
  4398. if (t[0] & 1) throw t[1];
  4399. return t[1];
  4400. },
  4401. trys: [],
  4402. ops: []
  4403. },
  4404. f,
  4405. y,
  4406. t,
  4407. g;
  4408. return g = {
  4409. next: verb(0),
  4410. "throw": verb(1),
  4411. "return": verb(2)
  4412. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  4413. return this;
  4414. }), g;
  4415. function verb(n) {
  4416. return function (v) {
  4417. return step([n, v]);
  4418. };
  4419. }
  4420. function step(op) {
  4421. if (f) throw new TypeError("Generator is already executing.");
  4422. while (_) try {
  4423. 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;
  4424. if (y = 0, t) op = [op[0] & 2, t.value];
  4425. switch (op[0]) {
  4426. case 0:
  4427. case 1:
  4428. t = op;
  4429. break;
  4430. case 4:
  4431. _.label++;
  4432. return {
  4433. value: op[1],
  4434. done: false
  4435. };
  4436. case 5:
  4437. _.label++;
  4438. y = op[1];
  4439. op = [0];
  4440. continue;
  4441. case 7:
  4442. op = _.ops.pop();
  4443. _.trys.pop();
  4444. continue;
  4445. default:
  4446. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  4447. _ = 0;
  4448. continue;
  4449. }
  4450. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  4451. _.label = op[1];
  4452. break;
  4453. }
  4454. if (op[0] === 6 && _.label < t[1]) {
  4455. _.label = t[1];
  4456. t = op;
  4457. break;
  4458. }
  4459. if (t && _.label < t[2]) {
  4460. _.label = t[2];
  4461. _.ops.push(op);
  4462. break;
  4463. }
  4464. if (t[2]) _.ops.pop();
  4465. _.trys.pop();
  4466. continue;
  4467. }
  4468. op = body.call(thisArg, _);
  4469. } catch (e) {
  4470. op = [6, e];
  4471. y = 0;
  4472. } finally {
  4473. f = t = 0;
  4474. }
  4475. if (op[0] & 5) throw op[1];
  4476. return {
  4477. value: op[0] ? op[1] : void 0,
  4478. done: true
  4479. };
  4480. }
  4481. }
  4482. function __createBinding(o, m, k, k2) {
  4483. if (k2 === undefined) k2 = k;
  4484. o[k2] = m[k];
  4485. }
  4486. function __exportStar(m, exports) {
  4487. for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) exports[p] = m[p];
  4488. }
  4489. function __values(o) {
  4490. var s = typeof Symbol === "function" && Symbol.iterator,
  4491. m = s && o[s],
  4492. i = 0;
  4493. if (m) return m.call(o);
  4494. if (o && typeof o.length === "number") return {
  4495. next: function () {
  4496. if (o && i >= o.length) o = void 0;
  4497. return {
  4498. value: o && o[i++],
  4499. done: !o
  4500. };
  4501. }
  4502. };
  4503. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  4504. }
  4505. function __read(o, n) {
  4506. var m = typeof Symbol === "function" && o[Symbol.iterator];
  4507. if (!m) return o;
  4508. var i = m.call(o),
  4509. r,
  4510. ar = [],
  4511. e;
  4512. try {
  4513. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  4514. } catch (error) {
  4515. e = {
  4516. error: error
  4517. };
  4518. } finally {
  4519. try {
  4520. if (r && !r.done && (m = i["return"])) m.call(i);
  4521. } finally {
  4522. if (e) throw e.error;
  4523. }
  4524. }
  4525. return ar;
  4526. }
  4527. function __spread() {
  4528. for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
  4529. return ar;
  4530. }
  4531. function __spreadArrays() {
  4532. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  4533. for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
  4534. return r;
  4535. }
  4536. function __await(v) {
  4537. return this instanceof __await ? (this.v = v, this) : new __await(v);
  4538. }
  4539. function __asyncGenerator(thisArg, _arguments, generator) {
  4540. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  4541. var g = generator.apply(thisArg, _arguments || []),
  4542. i,
  4543. q = [];
  4544. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
  4545. return this;
  4546. }, i;
  4547. function verb(n) {
  4548. if (g[n]) i[n] = function (v) {
  4549. return new Promise(function (a, b) {
  4550. q.push([n, v, a, b]) > 1 || resume(n, v);
  4551. });
  4552. };
  4553. }
  4554. function resume(n, v) {
  4555. try {
  4556. step(g[n](v));
  4557. } catch (e) {
  4558. settle(q[0][3], e);
  4559. }
  4560. }
  4561. function step(r) {
  4562. r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
  4563. }
  4564. function fulfill(value) {
  4565. resume("next", value);
  4566. }
  4567. function reject(value) {
  4568. resume("throw", value);
  4569. }
  4570. function settle(f, v) {
  4571. if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
  4572. }
  4573. }
  4574. function __asyncDelegator(o) {
  4575. var i, p;
  4576. return i = {}, verb("next"), verb("throw", function (e) {
  4577. throw e;
  4578. }), verb("return"), i[Symbol.iterator] = function () {
  4579. return this;
  4580. }, i;
  4581. function verb(n, f) {
  4582. i[n] = o[n] ? function (v) {
  4583. return (p = !p) ? {
  4584. value: __await(o[n](v)),
  4585. done: n === "return"
  4586. } : f ? f(v) : v;
  4587. } : f;
  4588. }
  4589. }
  4590. function __asyncValues(o) {
  4591. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  4592. var m = o[Symbol.asyncIterator],
  4593. i;
  4594. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
  4595. return this;
  4596. }, i);
  4597. function verb(n) {
  4598. i[n] = o[n] && function (v) {
  4599. return new Promise(function (resolve, reject) {
  4600. v = o[n](v), settle(resolve, reject, v.done, v.value);
  4601. });
  4602. };
  4603. }
  4604. function settle(resolve, reject, d, v) {
  4605. Promise.resolve(v).then(function (v) {
  4606. resolve({
  4607. value: v,
  4608. done: d
  4609. });
  4610. }, reject);
  4611. }
  4612. }
  4613. function __makeTemplateObject(cooked, raw) {
  4614. if (Object.defineProperty) {
  4615. Object.defineProperty(cooked, "raw", {
  4616. value: raw
  4617. });
  4618. } else {
  4619. cooked.raw = raw;
  4620. }
  4621. return cooked;
  4622. }
  4623. function __importStar(mod) {
  4624. if (mod && mod.__esModule) return mod;
  4625. var result = {};
  4626. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  4627. result.default = mod;
  4628. return result;
  4629. }
  4630. function __importDefault(mod) {
  4631. return mod && mod.__esModule ? mod : {
  4632. default: mod
  4633. };
  4634. }
  4635. function __classPrivateFieldGet(receiver, privateMap) {
  4636. if (!privateMap.has(receiver)) {
  4637. throw new TypeError("attempted to get private field on non-instance");
  4638. }
  4639. return privateMap.get(receiver);
  4640. }
  4641. function __classPrivateFieldSet(receiver, privateMap, value) {
  4642. if (!privateMap.has(receiver)) {
  4643. throw new TypeError("attempted to set private field on non-instance");
  4644. }
  4645. privateMap.set(receiver, value);
  4646. return value;
  4647. }
  4648. var tslib_es6 = /*#__PURE__*/Object.freeze({
  4649. __proto__: null,
  4650. __extends: __extends,
  4651. get __assign () { return __assign; },
  4652. __rest: __rest,
  4653. __decorate: __decorate,
  4654. __param: __param,
  4655. __metadata: __metadata,
  4656. __awaiter: __awaiter,
  4657. __generator: __generator,
  4658. __createBinding: __createBinding,
  4659. __exportStar: __exportStar,
  4660. __values: __values,
  4661. __read: __read,
  4662. __spread: __spread,
  4663. __spreadArrays: __spreadArrays,
  4664. __await: __await,
  4665. __asyncGenerator: __asyncGenerator,
  4666. __asyncDelegator: __asyncDelegator,
  4667. __asyncValues: __asyncValues,
  4668. __makeTemplateObject: __makeTemplateObject,
  4669. __importStar: __importStar,
  4670. __importDefault: __importDefault,
  4671. __classPrivateFieldGet: __classPrivateFieldGet,
  4672. __classPrivateFieldSet: __classPrivateFieldSet
  4673. });
  4674. var api = createCommonjsModule(function (module, exports) {
  4675. Object.defineProperty(exports, "__esModule", {
  4676. value: true
  4677. });
  4678. exports.apiDescriptor = {
  4679. key: key => /^[$_a-zA-Z][$_a-zA-Z0-9]*$/.test(key) ? key : JSON.stringify(key),
  4680. value(value) {
  4681. if (value === null || typeof value !== 'object') {
  4682. return JSON.stringify(value);
  4683. }
  4684. if (Array.isArray(value)) {
  4685. return `[${value.map(subValue => exports.apiDescriptor.value(subValue)).join(', ')}]`;
  4686. }
  4687. const keys = Object.keys(value);
  4688. return keys.length === 0 ? '{}' : `{ ${keys.map(key => `${exports.apiDescriptor.key(key)}: ${exports.apiDescriptor.value(value[key])}`).join(', ')} }`;
  4689. },
  4690. pair: ({
  4691. key,
  4692. value
  4693. }) => exports.apiDescriptor.value({
  4694. [key]: value
  4695. })
  4696. };
  4697. });
  4698. var descriptors = createCommonjsModule(function (module, exports) {
  4699. Object.defineProperty(exports, "__esModule", {
  4700. value: true
  4701. });
  4702. tslib_es6.__exportStar(api, exports);
  4703. });
  4704. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  4705. var escapeStringRegexp$1 = function (str) {
  4706. if (typeof str !== 'string') {
  4707. throw new TypeError('Expected a string');
  4708. }
  4709. return str.replace(matchOperatorsRe, '\\$&');
  4710. };
  4711. var colorName = {
  4712. "aliceblue": [240, 248, 255],
  4713. "antiquewhite": [250, 235, 215],
  4714. "aqua": [0, 255, 255],
  4715. "aquamarine": [127, 255, 212],
  4716. "azure": [240, 255, 255],
  4717. "beige": [245, 245, 220],
  4718. "bisque": [255, 228, 196],
  4719. "black": [0, 0, 0],
  4720. "blanchedalmond": [255, 235, 205],
  4721. "blue": [0, 0, 255],
  4722. "blueviolet": [138, 43, 226],
  4723. "brown": [165, 42, 42],
  4724. "burlywood": [222, 184, 135],
  4725. "cadetblue": [95, 158, 160],
  4726. "chartreuse": [127, 255, 0],
  4727. "chocolate": [210, 105, 30],
  4728. "coral": [255, 127, 80],
  4729. "cornflowerblue": [100, 149, 237],
  4730. "cornsilk": [255, 248, 220],
  4731. "crimson": [220, 20, 60],
  4732. "cyan": [0, 255, 255],
  4733. "darkblue": [0, 0, 139],
  4734. "darkcyan": [0, 139, 139],
  4735. "darkgoldenrod": [184, 134, 11],
  4736. "darkgray": [169, 169, 169],
  4737. "darkgreen": [0, 100, 0],
  4738. "darkgrey": [169, 169, 169],
  4739. "darkkhaki": [189, 183, 107],
  4740. "darkmagenta": [139, 0, 139],
  4741. "darkolivegreen": [85, 107, 47],
  4742. "darkorange": [255, 140, 0],
  4743. "darkorchid": [153, 50, 204],
  4744. "darkred": [139, 0, 0],
  4745. "darksalmon": [233, 150, 122],
  4746. "darkseagreen": [143, 188, 143],
  4747. "darkslateblue": [72, 61, 139],
  4748. "darkslategray": [47, 79, 79],
  4749. "darkslategrey": [47, 79, 79],
  4750. "darkturquoise": [0, 206, 209],
  4751. "darkviolet": [148, 0, 211],
  4752. "deeppink": [255, 20, 147],
  4753. "deepskyblue": [0, 191, 255],
  4754. "dimgray": [105, 105, 105],
  4755. "dimgrey": [105, 105, 105],
  4756. "dodgerblue": [30, 144, 255],
  4757. "firebrick": [178, 34, 34],
  4758. "floralwhite": [255, 250, 240],
  4759. "forestgreen": [34, 139, 34],
  4760. "fuchsia": [255, 0, 255],
  4761. "gainsboro": [220, 220, 220],
  4762. "ghostwhite": [248, 248, 255],
  4763. "gold": [255, 215, 0],
  4764. "goldenrod": [218, 165, 32],
  4765. "gray": [128, 128, 128],
  4766. "green": [0, 128, 0],
  4767. "greenyellow": [173, 255, 47],
  4768. "grey": [128, 128, 128],
  4769. "honeydew": [240, 255, 240],
  4770. "hotpink": [255, 105, 180],
  4771. "indianred": [205, 92, 92],
  4772. "indigo": [75, 0, 130],
  4773. "ivory": [255, 255, 240],
  4774. "khaki": [240, 230, 140],
  4775. "lavender": [230, 230, 250],
  4776. "lavenderblush": [255, 240, 245],
  4777. "lawngreen": [124, 252, 0],
  4778. "lemonchiffon": [255, 250, 205],
  4779. "lightblue": [173, 216, 230],
  4780. "lightcoral": [240, 128, 128],
  4781. "lightcyan": [224, 255, 255],
  4782. "lightgoldenrodyellow": [250, 250, 210],
  4783. "lightgray": [211, 211, 211],
  4784. "lightgreen": [144, 238, 144],
  4785. "lightgrey": [211, 211, 211],
  4786. "lightpink": [255, 182, 193],
  4787. "lightsalmon": [255, 160, 122],
  4788. "lightseagreen": [32, 178, 170],
  4789. "lightskyblue": [135, 206, 250],
  4790. "lightslategray": [119, 136, 153],
  4791. "lightslategrey": [119, 136, 153],
  4792. "lightsteelblue": [176, 196, 222],
  4793. "lightyellow": [255, 255, 224],
  4794. "lime": [0, 255, 0],
  4795. "limegreen": [50, 205, 50],
  4796. "linen": [250, 240, 230],
  4797. "magenta": [255, 0, 255],
  4798. "maroon": [128, 0, 0],
  4799. "mediumaquamarine": [102, 205, 170],
  4800. "mediumblue": [0, 0, 205],
  4801. "mediumorchid": [186, 85, 211],
  4802. "mediumpurple": [147, 112, 219],
  4803. "mediumseagreen": [60, 179, 113],
  4804. "mediumslateblue": [123, 104, 238],
  4805. "mediumspringgreen": [0, 250, 154],
  4806. "mediumturquoise": [72, 209, 204],
  4807. "mediumvioletred": [199, 21, 133],
  4808. "midnightblue": [25, 25, 112],
  4809. "mintcream": [245, 255, 250],
  4810. "mistyrose": [255, 228, 225],
  4811. "moccasin": [255, 228, 181],
  4812. "navajowhite": [255, 222, 173],
  4813. "navy": [0, 0, 128],
  4814. "oldlace": [253, 245, 230],
  4815. "olive": [128, 128, 0],
  4816. "olivedrab": [107, 142, 35],
  4817. "orange": [255, 165, 0],
  4818. "orangered": [255, 69, 0],
  4819. "orchid": [218, 112, 214],
  4820. "palegoldenrod": [238, 232, 170],
  4821. "palegreen": [152, 251, 152],
  4822. "paleturquoise": [175, 238, 238],
  4823. "palevioletred": [219, 112, 147],
  4824. "papayawhip": [255, 239, 213],
  4825. "peachpuff": [255, 218, 185],
  4826. "peru": [205, 133, 63],
  4827. "pink": [255, 192, 203],
  4828. "plum": [221, 160, 221],
  4829. "powderblue": [176, 224, 230],
  4830. "purple": [128, 0, 128],
  4831. "rebeccapurple": [102, 51, 153],
  4832. "red": [255, 0, 0],
  4833. "rosybrown": [188, 143, 143],
  4834. "royalblue": [65, 105, 225],
  4835. "saddlebrown": [139, 69, 19],
  4836. "salmon": [250, 128, 114],
  4837. "sandybrown": [244, 164, 96],
  4838. "seagreen": [46, 139, 87],
  4839. "seashell": [255, 245, 238],
  4840. "sienna": [160, 82, 45],
  4841. "silver": [192, 192, 192],
  4842. "skyblue": [135, 206, 235],
  4843. "slateblue": [106, 90, 205],
  4844. "slategray": [112, 128, 144],
  4845. "slategrey": [112, 128, 144],
  4846. "snow": [255, 250, 250],
  4847. "springgreen": [0, 255, 127],
  4848. "steelblue": [70, 130, 180],
  4849. "tan": [210, 180, 140],
  4850. "teal": [0, 128, 128],
  4851. "thistle": [216, 191, 216],
  4852. "tomato": [255, 99, 71],
  4853. "turquoise": [64, 224, 208],
  4854. "violet": [238, 130, 238],
  4855. "wheat": [245, 222, 179],
  4856. "white": [255, 255, 255],
  4857. "whitesmoke": [245, 245, 245],
  4858. "yellow": [255, 255, 0],
  4859. "yellowgreen": [154, 205, 50]
  4860. };
  4861. var conversions = createCommonjsModule(function (module) {
  4862. /* MIT license */
  4863. // NOTE: conversions should only return primitive values (i.e. arrays, or
  4864. // values that give correct `typeof` results).
  4865. // do not use box values types (i.e. Number(), String(), etc.)
  4866. var reverseKeywords = {};
  4867. for (var key in colorName) {
  4868. if (colorName.hasOwnProperty(key)) {
  4869. reverseKeywords[colorName[key]] = key;
  4870. }
  4871. }
  4872. var convert = module.exports = {
  4873. rgb: {
  4874. channels: 3,
  4875. labels: 'rgb'
  4876. },
  4877. hsl: {
  4878. channels: 3,
  4879. labels: 'hsl'
  4880. },
  4881. hsv: {
  4882. channels: 3,
  4883. labels: 'hsv'
  4884. },
  4885. hwb: {
  4886. channels: 3,
  4887. labels: 'hwb'
  4888. },
  4889. cmyk: {
  4890. channels: 4,
  4891. labels: 'cmyk'
  4892. },
  4893. xyz: {
  4894. channels: 3,
  4895. labels: 'xyz'
  4896. },
  4897. lab: {
  4898. channels: 3,
  4899. labels: 'lab'
  4900. },
  4901. lch: {
  4902. channels: 3,
  4903. labels: 'lch'
  4904. },
  4905. hex: {
  4906. channels: 1,
  4907. labels: ['hex']
  4908. },
  4909. keyword: {
  4910. channels: 1,
  4911. labels: ['keyword']
  4912. },
  4913. ansi16: {
  4914. channels: 1,
  4915. labels: ['ansi16']
  4916. },
  4917. ansi256: {
  4918. channels: 1,
  4919. labels: ['ansi256']
  4920. },
  4921. hcg: {
  4922. channels: 3,
  4923. labels: ['h', 'c', 'g']
  4924. },
  4925. apple: {
  4926. channels: 3,
  4927. labels: ['r16', 'g16', 'b16']
  4928. },
  4929. gray: {
  4930. channels: 1,
  4931. labels: ['gray']
  4932. }
  4933. }; // hide .channels and .labels properties
  4934. for (var model in convert) {
  4935. if (convert.hasOwnProperty(model)) {
  4936. if (!('channels' in convert[model])) {
  4937. throw new Error('missing channels property: ' + model);
  4938. }
  4939. if (!('labels' in convert[model])) {
  4940. throw new Error('missing channel labels property: ' + model);
  4941. }
  4942. if (convert[model].labels.length !== convert[model].channels) {
  4943. throw new Error('channel and label counts mismatch: ' + model);
  4944. }
  4945. var channels = convert[model].channels;
  4946. var labels = convert[model].labels;
  4947. delete convert[model].channels;
  4948. delete convert[model].labels;
  4949. Object.defineProperty(convert[model], 'channels', {
  4950. value: channels
  4951. });
  4952. Object.defineProperty(convert[model], 'labels', {
  4953. value: labels
  4954. });
  4955. }
  4956. }
  4957. convert.rgb.hsl = function (rgb) {
  4958. var r = rgb[0] / 255;
  4959. var g = rgb[1] / 255;
  4960. var b = rgb[2] / 255;
  4961. var min = Math.min(r, g, b);
  4962. var max = Math.max(r, g, b);
  4963. var delta = max - min;
  4964. var h;
  4965. var s;
  4966. var l;
  4967. if (max === min) {
  4968. h = 0;
  4969. } else if (r === max) {
  4970. h = (g - b) / delta;
  4971. } else if (g === max) {
  4972. h = 2 + (b - r) / delta;
  4973. } else if (b === max) {
  4974. h = 4 + (r - g) / delta;
  4975. }
  4976. h = Math.min(h * 60, 360);
  4977. if (h < 0) {
  4978. h += 360;
  4979. }
  4980. l = (min + max) / 2;
  4981. if (max === min) {
  4982. s = 0;
  4983. } else if (l <= 0.5) {
  4984. s = delta / (max + min);
  4985. } else {
  4986. s = delta / (2 - max - min);
  4987. }
  4988. return [h, s * 100, l * 100];
  4989. };
  4990. convert.rgb.hsv = function (rgb) {
  4991. var rdif;
  4992. var gdif;
  4993. var bdif;
  4994. var h;
  4995. var s;
  4996. var r = rgb[0] / 255;
  4997. var g = rgb[1] / 255;
  4998. var b = rgb[2] / 255;
  4999. var v = Math.max(r, g, b);
  5000. var diff = v - Math.min(r, g, b);
  5001. var diffc = function (c) {
  5002. return (v - c) / 6 / diff + 1 / 2;
  5003. };
  5004. if (diff === 0) {
  5005. h = s = 0;
  5006. } else {
  5007. s = diff / v;
  5008. rdif = diffc(r);
  5009. gdif = diffc(g);
  5010. bdif = diffc(b);
  5011. if (r === v) {
  5012. h = bdif - gdif;
  5013. } else if (g === v) {
  5014. h = 1 / 3 + rdif - bdif;
  5015. } else if (b === v) {
  5016. h = 2 / 3 + gdif - rdif;
  5017. }
  5018. if (h < 0) {
  5019. h += 1;
  5020. } else if (h > 1) {
  5021. h -= 1;
  5022. }
  5023. }
  5024. return [h * 360, s * 100, v * 100];
  5025. };
  5026. convert.rgb.hwb = function (rgb) {
  5027. var r = rgb[0];
  5028. var g = rgb[1];
  5029. var b = rgb[2];
  5030. var h = convert.rgb.hsl(rgb)[0];
  5031. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  5032. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  5033. return [h, w * 100, b * 100];
  5034. };
  5035. convert.rgb.cmyk = function (rgb) {
  5036. var r = rgb[0] / 255;
  5037. var g = rgb[1] / 255;
  5038. var b = rgb[2] / 255;
  5039. var c;
  5040. var m;
  5041. var y;
  5042. var k;
  5043. k = Math.min(1 - r, 1 - g, 1 - b);
  5044. c = (1 - r - k) / (1 - k) || 0;
  5045. m = (1 - g - k) / (1 - k) || 0;
  5046. y = (1 - b - k) / (1 - k) || 0;
  5047. return [c * 100, m * 100, y * 100, k * 100];
  5048. };
  5049. /**
  5050. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  5051. * */
  5052. function comparativeDistance(x, y) {
  5053. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  5054. }
  5055. convert.rgb.keyword = function (rgb) {
  5056. var reversed = reverseKeywords[rgb];
  5057. if (reversed) {
  5058. return reversed;
  5059. }
  5060. var currentClosestDistance = Infinity;
  5061. var currentClosestKeyword;
  5062. for (var keyword in colorName) {
  5063. if (colorName.hasOwnProperty(keyword)) {
  5064. var value = colorName[keyword]; // Compute comparative distance
  5065. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  5066. if (distance < currentClosestDistance) {
  5067. currentClosestDistance = distance;
  5068. currentClosestKeyword = keyword;
  5069. }
  5070. }
  5071. }
  5072. return currentClosestKeyword;
  5073. };
  5074. convert.keyword.rgb = function (keyword) {
  5075. return colorName[keyword];
  5076. };
  5077. convert.rgb.xyz = function (rgb) {
  5078. var r = rgb[0] / 255;
  5079. var g = rgb[1] / 255;
  5080. var b = rgb[2] / 255; // assume sRGB
  5081. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  5082. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  5083. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  5084. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  5085. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  5086. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  5087. return [x * 100, y * 100, z * 100];
  5088. };
  5089. convert.rgb.lab = function (rgb) {
  5090. var xyz = convert.rgb.xyz(rgb);
  5091. var x = xyz[0];
  5092. var y = xyz[1];
  5093. var z = xyz[2];
  5094. var l;
  5095. var a;
  5096. var b;
  5097. x /= 95.047;
  5098. y /= 100;
  5099. z /= 108.883;
  5100. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  5101. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  5102. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  5103. l = 116 * y - 16;
  5104. a = 500 * (x - y);
  5105. b = 200 * (y - z);
  5106. return [l, a, b];
  5107. };
  5108. convert.hsl.rgb = function (hsl) {
  5109. var h = hsl[0] / 360;
  5110. var s = hsl[1] / 100;
  5111. var l = hsl[2] / 100;
  5112. var t1;
  5113. var t2;
  5114. var t3;
  5115. var rgb;
  5116. var val;
  5117. if (s === 0) {
  5118. val = l * 255;
  5119. return [val, val, val];
  5120. }
  5121. if (l < 0.5) {
  5122. t2 = l * (1 + s);
  5123. } else {
  5124. t2 = l + s - l * s;
  5125. }
  5126. t1 = 2 * l - t2;
  5127. rgb = [0, 0, 0];
  5128. for (var i = 0; i < 3; i++) {
  5129. t3 = h + 1 / 3 * -(i - 1);
  5130. if (t3 < 0) {
  5131. t3++;
  5132. }
  5133. if (t3 > 1) {
  5134. t3--;
  5135. }
  5136. if (6 * t3 < 1) {
  5137. val = t1 + (t2 - t1) * 6 * t3;
  5138. } else if (2 * t3 < 1) {
  5139. val = t2;
  5140. } else if (3 * t3 < 2) {
  5141. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  5142. } else {
  5143. val = t1;
  5144. }
  5145. rgb[i] = val * 255;
  5146. }
  5147. return rgb;
  5148. };
  5149. convert.hsl.hsv = function (hsl) {
  5150. var h = hsl[0];
  5151. var s = hsl[1] / 100;
  5152. var l = hsl[2] / 100;
  5153. var smin = s;
  5154. var lmin = Math.max(l, 0.01);
  5155. var sv;
  5156. var v;
  5157. l *= 2;
  5158. s *= l <= 1 ? l : 2 - l;
  5159. smin *= lmin <= 1 ? lmin : 2 - lmin;
  5160. v = (l + s) / 2;
  5161. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  5162. return [h, sv * 100, v * 100];
  5163. };
  5164. convert.hsv.rgb = function (hsv) {
  5165. var h = hsv[0] / 60;
  5166. var s = hsv[1] / 100;
  5167. var v = hsv[2] / 100;
  5168. var hi = Math.floor(h) % 6;
  5169. var f = h - Math.floor(h);
  5170. var p = 255 * v * (1 - s);
  5171. var q = 255 * v * (1 - s * f);
  5172. var t = 255 * v * (1 - s * (1 - f));
  5173. v *= 255;
  5174. switch (hi) {
  5175. case 0:
  5176. return [v, t, p];
  5177. case 1:
  5178. return [q, v, p];
  5179. case 2:
  5180. return [p, v, t];
  5181. case 3:
  5182. return [p, q, v];
  5183. case 4:
  5184. return [t, p, v];
  5185. case 5:
  5186. return [v, p, q];
  5187. }
  5188. };
  5189. convert.hsv.hsl = function (hsv) {
  5190. var h = hsv[0];
  5191. var s = hsv[1] / 100;
  5192. var v = hsv[2] / 100;
  5193. var vmin = Math.max(v, 0.01);
  5194. var lmin;
  5195. var sl;
  5196. var l;
  5197. l = (2 - s) * v;
  5198. lmin = (2 - s) * vmin;
  5199. sl = s * vmin;
  5200. sl /= lmin <= 1 ? lmin : 2 - lmin;
  5201. sl = sl || 0;
  5202. l /= 2;
  5203. return [h, sl * 100, l * 100];
  5204. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  5205. convert.hwb.rgb = function (hwb) {
  5206. var h = hwb[0] / 360;
  5207. var wh = hwb[1] / 100;
  5208. var bl = hwb[2] / 100;
  5209. var ratio = wh + bl;
  5210. var i;
  5211. var v;
  5212. var f;
  5213. var n; // wh + bl cant be > 1
  5214. if (ratio > 1) {
  5215. wh /= ratio;
  5216. bl /= ratio;
  5217. }
  5218. i = Math.floor(6 * h);
  5219. v = 1 - bl;
  5220. f = 6 * h - i;
  5221. if ((i & 0x01) !== 0) {
  5222. f = 1 - f;
  5223. }
  5224. n = wh + f * (v - wh); // linear interpolation
  5225. var r;
  5226. var g;
  5227. var b;
  5228. switch (i) {
  5229. default:
  5230. case 6:
  5231. case 0:
  5232. r = v;
  5233. g = n;
  5234. b = wh;
  5235. break;
  5236. case 1:
  5237. r = n;
  5238. g = v;
  5239. b = wh;
  5240. break;
  5241. case 2:
  5242. r = wh;
  5243. g = v;
  5244. b = n;
  5245. break;
  5246. case 3:
  5247. r = wh;
  5248. g = n;
  5249. b = v;
  5250. break;
  5251. case 4:
  5252. r = n;
  5253. g = wh;
  5254. b = v;
  5255. break;
  5256. case 5:
  5257. r = v;
  5258. g = wh;
  5259. b = n;
  5260. break;
  5261. }
  5262. return [r * 255, g * 255, b * 255];
  5263. };
  5264. convert.cmyk.rgb = function (cmyk) {
  5265. var c = cmyk[0] / 100;
  5266. var m = cmyk[1] / 100;
  5267. var y = cmyk[2] / 100;
  5268. var k = cmyk[3] / 100;
  5269. var r;
  5270. var g;
  5271. var b;
  5272. r = 1 - Math.min(1, c * (1 - k) + k);
  5273. g = 1 - Math.min(1, m * (1 - k) + k);
  5274. b = 1 - Math.min(1, y * (1 - k) + k);
  5275. return [r * 255, g * 255, b * 255];
  5276. };
  5277. convert.xyz.rgb = function (xyz) {
  5278. var x = xyz[0] / 100;
  5279. var y = xyz[1] / 100;
  5280. var z = xyz[2] / 100;
  5281. var r;
  5282. var g;
  5283. var b;
  5284. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  5285. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  5286. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  5287. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  5288. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  5289. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  5290. r = Math.min(Math.max(0, r), 1);
  5291. g = Math.min(Math.max(0, g), 1);
  5292. b = Math.min(Math.max(0, b), 1);
  5293. return [r * 255, g * 255, b * 255];
  5294. };
  5295. convert.xyz.lab = function (xyz) {
  5296. var x = xyz[0];
  5297. var y = xyz[1];
  5298. var z = xyz[2];
  5299. var l;
  5300. var a;
  5301. var b;
  5302. x /= 95.047;
  5303. y /= 100;
  5304. z /= 108.883;
  5305. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  5306. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  5307. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  5308. l = 116 * y - 16;
  5309. a = 500 * (x - y);
  5310. b = 200 * (y - z);
  5311. return [l, a, b];
  5312. };
  5313. convert.lab.xyz = function (lab) {
  5314. var l = lab[0];
  5315. var a = lab[1];
  5316. var b = lab[2];
  5317. var x;
  5318. var y;
  5319. var z;
  5320. y = (l + 16) / 116;
  5321. x = a / 500 + y;
  5322. z = y - b / 200;
  5323. var y2 = Math.pow(y, 3);
  5324. var x2 = Math.pow(x, 3);
  5325. var z2 = Math.pow(z, 3);
  5326. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  5327. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  5328. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  5329. x *= 95.047;
  5330. y *= 100;
  5331. z *= 108.883;
  5332. return [x, y, z];
  5333. };
  5334. convert.lab.lch = function (lab) {
  5335. var l = lab[0];
  5336. var a = lab[1];
  5337. var b = lab[2];
  5338. var hr;
  5339. var h;
  5340. var c;
  5341. hr = Math.atan2(b, a);
  5342. h = hr * 360 / 2 / Math.PI;
  5343. if (h < 0) {
  5344. h += 360;
  5345. }
  5346. c = Math.sqrt(a * a + b * b);
  5347. return [l, c, h];
  5348. };
  5349. convert.lch.lab = function (lch) {
  5350. var l = lch[0];
  5351. var c = lch[1];
  5352. var h = lch[2];
  5353. var a;
  5354. var b;
  5355. var hr;
  5356. hr = h / 360 * 2 * Math.PI;
  5357. a = c * Math.cos(hr);
  5358. b = c * Math.sin(hr);
  5359. return [l, a, b];
  5360. };
  5361. convert.rgb.ansi16 = function (args) {
  5362. var r = args[0];
  5363. var g = args[1];
  5364. var b = args[2];
  5365. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  5366. value = Math.round(value / 50);
  5367. if (value === 0) {
  5368. return 30;
  5369. }
  5370. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  5371. if (value === 2) {
  5372. ansi += 60;
  5373. }
  5374. return ansi;
  5375. };
  5376. convert.hsv.ansi16 = function (args) {
  5377. // optimization here; we already know the value and don't need to get
  5378. // it converted for us.
  5379. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  5380. };
  5381. convert.rgb.ansi256 = function (args) {
  5382. var r = args[0];
  5383. var g = args[1];
  5384. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  5385. // black and white. normal palette only has 4 greyscale shades.
  5386. if (r === g && g === b) {
  5387. if (r < 8) {
  5388. return 16;
  5389. }
  5390. if (r > 248) {
  5391. return 231;
  5392. }
  5393. return Math.round((r - 8) / 247 * 24) + 232;
  5394. }
  5395. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  5396. return ansi;
  5397. };
  5398. convert.ansi16.rgb = function (args) {
  5399. var color = args % 10; // handle greyscale
  5400. if (color === 0 || color === 7) {
  5401. if (args > 50) {
  5402. color += 3.5;
  5403. }
  5404. color = color / 10.5 * 255;
  5405. return [color, color, color];
  5406. }
  5407. var mult = (~~(args > 50) + 1) * 0.5;
  5408. var r = (color & 1) * mult * 255;
  5409. var g = (color >> 1 & 1) * mult * 255;
  5410. var b = (color >> 2 & 1) * mult * 255;
  5411. return [r, g, b];
  5412. };
  5413. convert.ansi256.rgb = function (args) {
  5414. // handle greyscale
  5415. if (args >= 232) {
  5416. var c = (args - 232) * 10 + 8;
  5417. return [c, c, c];
  5418. }
  5419. args -= 16;
  5420. var rem;
  5421. var r = Math.floor(args / 36) / 5 * 255;
  5422. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  5423. var b = rem % 6 / 5 * 255;
  5424. return [r, g, b];
  5425. };
  5426. convert.rgb.hex = function (args) {
  5427. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  5428. var string = integer.toString(16).toUpperCase();
  5429. return '000000'.substring(string.length) + string;
  5430. };
  5431. convert.hex.rgb = function (args) {
  5432. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  5433. if (!match) {
  5434. return [0, 0, 0];
  5435. }
  5436. var colorString = match[0];
  5437. if (match[0].length === 3) {
  5438. colorString = colorString.split('').map(function (char) {
  5439. return char + char;
  5440. }).join('');
  5441. }
  5442. var integer = parseInt(colorString, 16);
  5443. var r = integer >> 16 & 0xFF;
  5444. var g = integer >> 8 & 0xFF;
  5445. var b = integer & 0xFF;
  5446. return [r, g, b];
  5447. };
  5448. convert.rgb.hcg = function (rgb) {
  5449. var r = rgb[0] / 255;
  5450. var g = rgb[1] / 255;
  5451. var b = rgb[2] / 255;
  5452. var max = Math.max(Math.max(r, g), b);
  5453. var min = Math.min(Math.min(r, g), b);
  5454. var chroma = max - min;
  5455. var grayscale;
  5456. var hue;
  5457. if (chroma < 1) {
  5458. grayscale = min / (1 - chroma);
  5459. } else {
  5460. grayscale = 0;
  5461. }
  5462. if (chroma <= 0) {
  5463. hue = 0;
  5464. } else if (max === r) {
  5465. hue = (g - b) / chroma % 6;
  5466. } else if (max === g) {
  5467. hue = 2 + (b - r) / chroma;
  5468. } else {
  5469. hue = 4 + (r - g) / chroma + 4;
  5470. }
  5471. hue /= 6;
  5472. hue %= 1;
  5473. return [hue * 360, chroma * 100, grayscale * 100];
  5474. };
  5475. convert.hsl.hcg = function (hsl) {
  5476. var s = hsl[1] / 100;
  5477. var l = hsl[2] / 100;
  5478. var c = 1;
  5479. var f = 0;
  5480. if (l < 0.5) {
  5481. c = 2.0 * s * l;
  5482. } else {
  5483. c = 2.0 * s * (1.0 - l);
  5484. }
  5485. if (c < 1.0) {
  5486. f = (l - 0.5 * c) / (1.0 - c);
  5487. }
  5488. return [hsl[0], c * 100, f * 100];
  5489. };
  5490. convert.hsv.hcg = function (hsv) {
  5491. var s = hsv[1] / 100;
  5492. var v = hsv[2] / 100;
  5493. var c = s * v;
  5494. var f = 0;
  5495. if (c < 1.0) {
  5496. f = (v - c) / (1 - c);
  5497. }
  5498. return [hsv[0], c * 100, f * 100];
  5499. };
  5500. convert.hcg.rgb = function (hcg) {
  5501. var h = hcg[0] / 360;
  5502. var c = hcg[1] / 100;
  5503. var g = hcg[2] / 100;
  5504. if (c === 0.0) {
  5505. return [g * 255, g * 255, g * 255];
  5506. }
  5507. var pure = [0, 0, 0];
  5508. var hi = h % 1 * 6;
  5509. var v = hi % 1;
  5510. var w = 1 - v;
  5511. var mg = 0;
  5512. switch (Math.floor(hi)) {
  5513. case 0:
  5514. pure[0] = 1;
  5515. pure[1] = v;
  5516. pure[2] = 0;
  5517. break;
  5518. case 1:
  5519. pure[0] = w;
  5520. pure[1] = 1;
  5521. pure[2] = 0;
  5522. break;
  5523. case 2:
  5524. pure[0] = 0;
  5525. pure[1] = 1;
  5526. pure[2] = v;
  5527. break;
  5528. case 3:
  5529. pure[0] = 0;
  5530. pure[1] = w;
  5531. pure[2] = 1;
  5532. break;
  5533. case 4:
  5534. pure[0] = v;
  5535. pure[1] = 0;
  5536. pure[2] = 1;
  5537. break;
  5538. default:
  5539. pure[0] = 1;
  5540. pure[1] = 0;
  5541. pure[2] = w;
  5542. }
  5543. mg = (1.0 - c) * g;
  5544. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  5545. };
  5546. convert.hcg.hsv = function (hcg) {
  5547. var c = hcg[1] / 100;
  5548. var g = hcg[2] / 100;
  5549. var v = c + g * (1.0 - c);
  5550. var f = 0;
  5551. if (v > 0.0) {
  5552. f = c / v;
  5553. }
  5554. return [hcg[0], f * 100, v * 100];
  5555. };
  5556. convert.hcg.hsl = function (hcg) {
  5557. var c = hcg[1] / 100;
  5558. var g = hcg[2] / 100;
  5559. var l = g * (1.0 - c) + 0.5 * c;
  5560. var s = 0;
  5561. if (l > 0.0 && l < 0.5) {
  5562. s = c / (2 * l);
  5563. } else if (l >= 0.5 && l < 1.0) {
  5564. s = c / (2 * (1 - l));
  5565. }
  5566. return [hcg[0], s * 100, l * 100];
  5567. };
  5568. convert.hcg.hwb = function (hcg) {
  5569. var c = hcg[1] / 100;
  5570. var g = hcg[2] / 100;
  5571. var v = c + g * (1.0 - c);
  5572. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  5573. };
  5574. convert.hwb.hcg = function (hwb) {
  5575. var w = hwb[1] / 100;
  5576. var b = hwb[2] / 100;
  5577. var v = 1 - b;
  5578. var c = v - w;
  5579. var g = 0;
  5580. if (c < 1) {
  5581. g = (v - c) / (1 - c);
  5582. }
  5583. return [hwb[0], c * 100, g * 100];
  5584. };
  5585. convert.apple.rgb = function (apple) {
  5586. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  5587. };
  5588. convert.rgb.apple = function (rgb) {
  5589. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  5590. };
  5591. convert.gray.rgb = function (args) {
  5592. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  5593. };
  5594. convert.gray.hsl = convert.gray.hsv = function (args) {
  5595. return [0, 0, args[0]];
  5596. };
  5597. convert.gray.hwb = function (gray) {
  5598. return [0, 100, gray[0]];
  5599. };
  5600. convert.gray.cmyk = function (gray) {
  5601. return [0, 0, 0, gray[0]];
  5602. };
  5603. convert.gray.lab = function (gray) {
  5604. return [gray[0], 0, 0];
  5605. };
  5606. convert.gray.hex = function (gray) {
  5607. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  5608. var integer = (val << 16) + (val << 8) + val;
  5609. var string = integer.toString(16).toUpperCase();
  5610. return '000000'.substring(string.length) + string;
  5611. };
  5612. convert.rgb.gray = function (rgb) {
  5613. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  5614. return [val / 255 * 100];
  5615. };
  5616. });
  5617. /*
  5618. this function routes a model to all other models.
  5619. all functions that are routed have a property `.conversion` attached
  5620. to the returned synthetic function. This property is an array
  5621. of strings, each with the steps in between the 'from' and 'to'
  5622. color models (inclusive).
  5623. conversions that are not possible simply are not included.
  5624. */
  5625. function buildGraph() {
  5626. var graph = {}; // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  5627. var models = Object.keys(conversions);
  5628. for (var len = models.length, i = 0; i < len; i++) {
  5629. graph[models[i]] = {
  5630. // http://jsperf.com/1-vs-infinity
  5631. // micro-opt, but this is simple.
  5632. distance: -1,
  5633. parent: null
  5634. };
  5635. }
  5636. return graph;
  5637. } // https://en.wikipedia.org/wiki/Breadth-first_search
  5638. function deriveBFS(fromModel) {
  5639. var graph = buildGraph();
  5640. var queue = [fromModel]; // unshift -> queue -> pop
  5641. graph[fromModel].distance = 0;
  5642. while (queue.length) {
  5643. var current = queue.pop();
  5644. var adjacents = Object.keys(conversions[current]);
  5645. for (var len = adjacents.length, i = 0; i < len; i++) {
  5646. var adjacent = adjacents[i];
  5647. var node = graph[adjacent];
  5648. if (node.distance === -1) {
  5649. node.distance = graph[current].distance + 1;
  5650. node.parent = current;
  5651. queue.unshift(adjacent);
  5652. }
  5653. }
  5654. }
  5655. return graph;
  5656. }
  5657. function link(from, to) {
  5658. return function (args) {
  5659. return to(from(args));
  5660. };
  5661. }
  5662. function wrapConversion(toModel, graph) {
  5663. var path = [graph[toModel].parent, toModel];
  5664. var fn = conversions[graph[toModel].parent][toModel];
  5665. var cur = graph[toModel].parent;
  5666. while (graph[cur].parent) {
  5667. path.unshift(graph[cur].parent);
  5668. fn = link(conversions[graph[cur].parent][cur], fn);
  5669. cur = graph[cur].parent;
  5670. }
  5671. fn.conversion = path;
  5672. return fn;
  5673. }
  5674. var route = function (fromModel) {
  5675. var graph = deriveBFS(fromModel);
  5676. var conversion = {};
  5677. var models = Object.keys(graph);
  5678. for (var len = models.length, i = 0; i < len; i++) {
  5679. var toModel = models[i];
  5680. var node = graph[toModel];
  5681. if (node.parent === null) {
  5682. // no possible conversion, or this node is the source model.
  5683. continue;
  5684. }
  5685. conversion[toModel] = wrapConversion(toModel, graph);
  5686. }
  5687. return conversion;
  5688. };
  5689. var convert = {};
  5690. var models = Object.keys(conversions);
  5691. function wrapRaw(fn) {
  5692. var wrappedFn = function (args) {
  5693. if (args === undefined || args === null) {
  5694. return args;
  5695. }
  5696. if (arguments.length > 1) {
  5697. args = Array.prototype.slice.call(arguments);
  5698. }
  5699. return fn(args);
  5700. }; // preserve .conversion property if there is one
  5701. if ('conversion' in fn) {
  5702. wrappedFn.conversion = fn.conversion;
  5703. }
  5704. return wrappedFn;
  5705. }
  5706. function wrapRounded(fn) {
  5707. var wrappedFn = function (args) {
  5708. if (args === undefined || args === null) {
  5709. return args;
  5710. }
  5711. if (arguments.length > 1) {
  5712. args = Array.prototype.slice.call(arguments);
  5713. }
  5714. var result = fn(args); // we're assuming the result is an array here.
  5715. // see notice in conversions.js; don't use box types
  5716. // in conversion functions.
  5717. if (typeof result === 'object') {
  5718. for (var len = result.length, i = 0; i < len; i++) {
  5719. result[i] = Math.round(result[i]);
  5720. }
  5721. }
  5722. return result;
  5723. }; // preserve .conversion property if there is one
  5724. if ('conversion' in fn) {
  5725. wrappedFn.conversion = fn.conversion;
  5726. }
  5727. return wrappedFn;
  5728. }
  5729. models.forEach(function (fromModel) {
  5730. convert[fromModel] = {};
  5731. Object.defineProperty(convert[fromModel], 'channels', {
  5732. value: conversions[fromModel].channels
  5733. });
  5734. Object.defineProperty(convert[fromModel], 'labels', {
  5735. value: conversions[fromModel].labels
  5736. });
  5737. var routes = route(fromModel);
  5738. var routeModels = Object.keys(routes);
  5739. routeModels.forEach(function (toModel) {
  5740. var fn = routes[toModel];
  5741. convert[fromModel][toModel] = wrapRounded(fn);
  5742. convert[fromModel][toModel].raw = wrapRaw(fn);
  5743. });
  5744. });
  5745. var colorConvert = convert;
  5746. var ansiStyles = createCommonjsModule(function (module) {
  5747. const wrapAnsi16 = (fn, offset) => function () {
  5748. const code = fn.apply(colorConvert, arguments);
  5749. return `\u001B[${code + offset}m`;
  5750. };
  5751. const wrapAnsi256 = (fn, offset) => function () {
  5752. const code = fn.apply(colorConvert, arguments);
  5753. return `\u001B[${38 + offset};5;${code}m`;
  5754. };
  5755. const wrapAnsi16m = (fn, offset) => function () {
  5756. const rgb = fn.apply(colorConvert, arguments);
  5757. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  5758. };
  5759. function assembleStyles() {
  5760. const codes = new Map();
  5761. const styles = {
  5762. modifier: {
  5763. reset: [0, 0],
  5764. // 21 isn't widely supported and 22 does the same thing
  5765. bold: [1, 22],
  5766. dim: [2, 22],
  5767. italic: [3, 23],
  5768. underline: [4, 24],
  5769. inverse: [7, 27],
  5770. hidden: [8, 28],
  5771. strikethrough: [9, 29]
  5772. },
  5773. color: {
  5774. black: [30, 39],
  5775. red: [31, 39],
  5776. green: [32, 39],
  5777. yellow: [33, 39],
  5778. blue: [34, 39],
  5779. magenta: [35, 39],
  5780. cyan: [36, 39],
  5781. white: [37, 39],
  5782. gray: [90, 39],
  5783. // Bright color
  5784. redBright: [91, 39],
  5785. greenBright: [92, 39],
  5786. yellowBright: [93, 39],
  5787. blueBright: [94, 39],
  5788. magentaBright: [95, 39],
  5789. cyanBright: [96, 39],
  5790. whiteBright: [97, 39]
  5791. },
  5792. bgColor: {
  5793. bgBlack: [40, 49],
  5794. bgRed: [41, 49],
  5795. bgGreen: [42, 49],
  5796. bgYellow: [43, 49],
  5797. bgBlue: [44, 49],
  5798. bgMagenta: [45, 49],
  5799. bgCyan: [46, 49],
  5800. bgWhite: [47, 49],
  5801. // Bright color
  5802. bgBlackBright: [100, 49],
  5803. bgRedBright: [101, 49],
  5804. bgGreenBright: [102, 49],
  5805. bgYellowBright: [103, 49],
  5806. bgBlueBright: [104, 49],
  5807. bgMagentaBright: [105, 49],
  5808. bgCyanBright: [106, 49],
  5809. bgWhiteBright: [107, 49]
  5810. }
  5811. }; // Fix humans
  5812. styles.color.grey = styles.color.gray;
  5813. for (const groupName of Object.keys(styles)) {
  5814. const group = styles[groupName];
  5815. for (const styleName of Object.keys(group)) {
  5816. const style = group[styleName];
  5817. styles[styleName] = {
  5818. open: `\u001B[${style[0]}m`,
  5819. close: `\u001B[${style[1]}m`
  5820. };
  5821. group[styleName] = styles[styleName];
  5822. codes.set(style[0], style[1]);
  5823. }
  5824. Object.defineProperty(styles, groupName, {
  5825. value: group,
  5826. enumerable: false
  5827. });
  5828. Object.defineProperty(styles, 'codes', {
  5829. value: codes,
  5830. enumerable: false
  5831. });
  5832. }
  5833. const ansi2ansi = n => n;
  5834. const rgb2rgb = (r, g, b) => [r, g, b];
  5835. styles.color.close = '\u001B[39m';
  5836. styles.bgColor.close = '\u001B[49m';
  5837. styles.color.ansi = {
  5838. ansi: wrapAnsi16(ansi2ansi, 0)
  5839. };
  5840. styles.color.ansi256 = {
  5841. ansi256: wrapAnsi256(ansi2ansi, 0)
  5842. };
  5843. styles.color.ansi16m = {
  5844. rgb: wrapAnsi16m(rgb2rgb, 0)
  5845. };
  5846. styles.bgColor.ansi = {
  5847. ansi: wrapAnsi16(ansi2ansi, 10)
  5848. };
  5849. styles.bgColor.ansi256 = {
  5850. ansi256: wrapAnsi256(ansi2ansi, 10)
  5851. };
  5852. styles.bgColor.ansi16m = {
  5853. rgb: wrapAnsi16m(rgb2rgb, 10)
  5854. };
  5855. for (let key of Object.keys(colorConvert)) {
  5856. if (typeof colorConvert[key] !== 'object') {
  5857. continue;
  5858. }
  5859. const suite = colorConvert[key];
  5860. if (key === 'ansi16') {
  5861. key = 'ansi';
  5862. }
  5863. if ('ansi16' in suite) {
  5864. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  5865. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  5866. }
  5867. if ('ansi256' in suite) {
  5868. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  5869. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  5870. }
  5871. if ('rgb' in suite) {
  5872. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  5873. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  5874. }
  5875. }
  5876. return styles;
  5877. } // Make the export immutable
  5878. Object.defineProperty(module, 'exports', {
  5879. enumerable: true,
  5880. get: assembleStyles
  5881. });
  5882. });
  5883. var hasFlag = (flag, argv) => {
  5884. argv = argv || process.argv;
  5885. const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  5886. const pos = argv.indexOf(prefix + flag);
  5887. const terminatorPos = argv.indexOf('--');
  5888. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  5889. };
  5890. const env = process.env;
  5891. let forceColor;
  5892. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  5893. forceColor = false;
  5894. } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  5895. forceColor = true;
  5896. }
  5897. if ('FORCE_COLOR' in env) {
  5898. forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
  5899. }
  5900. function translateLevel(level) {
  5901. if (level === 0) {
  5902. return false;
  5903. }
  5904. return {
  5905. level,
  5906. hasBasic: true,
  5907. has256: level >= 2,
  5908. has16m: level >= 3
  5909. };
  5910. }
  5911. function supportsColor(stream) {
  5912. if (forceColor === false) {
  5913. return 0;
  5914. }
  5915. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  5916. return 3;
  5917. }
  5918. if (hasFlag('color=256')) {
  5919. return 2;
  5920. }
  5921. if (stream && !stream.isTTY && forceColor !== true) {
  5922. return 0;
  5923. }
  5924. const min = forceColor ? 1 : 0;
  5925. if (process.platform === 'win32') {
  5926. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  5927. // libuv that enables 256 color output on Windows. Anything earlier and it
  5928. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  5929. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  5930. // release that supports 256 colors. Windows 10 build 14931 is the first release
  5931. // that supports 16m/TrueColor.
  5932. const osRelease = os__default['default'].release().split('.');
  5933. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  5934. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  5935. }
  5936. return 1;
  5937. }
  5938. if ('CI' in env) {
  5939. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
  5940. return 1;
  5941. }
  5942. return min;
  5943. }
  5944. if ('TEAMCITY_VERSION' in env) {
  5945. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  5946. }
  5947. if (env.COLORTERM === 'truecolor') {
  5948. return 3;
  5949. }
  5950. if ('TERM_PROGRAM' in env) {
  5951. const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  5952. switch (env.TERM_PROGRAM) {
  5953. case 'iTerm.app':
  5954. return version >= 3 ? 3 : 2;
  5955. case 'Apple_Terminal':
  5956. return 2;
  5957. // No default
  5958. }
  5959. }
  5960. if (/-256(color)?$/i.test(env.TERM)) {
  5961. return 2;
  5962. }
  5963. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  5964. return 1;
  5965. }
  5966. if ('COLORTERM' in env) {
  5967. return 1;
  5968. }
  5969. if (env.TERM === 'dumb') {
  5970. return min;
  5971. }
  5972. return min;
  5973. }
  5974. function getSupportLevel(stream) {
  5975. const level = supportsColor(stream);
  5976. return translateLevel(level);
  5977. }
  5978. var supportsColor_1 = {
  5979. supportsColor: getSupportLevel,
  5980. stdout: getSupportLevel(process.stdout),
  5981. stderr: getSupportLevel(process.stderr)
  5982. };
  5983. const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  5984. const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  5985. const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  5986. const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  5987. const ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  5988. function unescape(c) {
  5989. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  5990. return String.fromCharCode(parseInt(c.slice(1), 16));
  5991. }
  5992. return ESCAPES.get(c) || c;
  5993. }
  5994. function parseArguments(name, args) {
  5995. const results = [];
  5996. const chunks = args.trim().split(/\s*,\s*/g);
  5997. let matches;
  5998. for (const chunk of chunks) {
  5999. if (!isNaN(chunk)) {
  6000. results.push(Number(chunk));
  6001. } else if (matches = chunk.match(STRING_REGEX)) {
  6002. results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr));
  6003. } else {
  6004. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  6005. }
  6006. }
  6007. return results;
  6008. }
  6009. function parseStyle(style) {
  6010. STYLE_REGEX.lastIndex = 0;
  6011. const results = [];
  6012. let matches;
  6013. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  6014. const name = matches[1];
  6015. if (matches[2]) {
  6016. const args = parseArguments(name, matches[2]);
  6017. results.push([name].concat(args));
  6018. } else {
  6019. results.push([name]);
  6020. }
  6021. }
  6022. return results;
  6023. }
  6024. function buildStyle(chalk, styles) {
  6025. const enabled = {};
  6026. for (const layer of styles) {
  6027. for (const style of layer.styles) {
  6028. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  6029. }
  6030. }
  6031. let current = chalk;
  6032. for (const styleName of Object.keys(enabled)) {
  6033. if (Array.isArray(enabled[styleName])) {
  6034. if (!(styleName in current)) {
  6035. throw new Error(`Unknown Chalk style: ${styleName}`);
  6036. }
  6037. if (enabled[styleName].length > 0) {
  6038. current = current[styleName].apply(current, enabled[styleName]);
  6039. } else {
  6040. current = current[styleName];
  6041. }
  6042. }
  6043. }
  6044. return current;
  6045. }
  6046. var templates = (chalk, tmp) => {
  6047. const styles = [];
  6048. const chunks = [];
  6049. let chunk = []; // eslint-disable-next-line max-params
  6050. tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => {
  6051. if (escapeChar) {
  6052. chunk.push(unescape(escapeChar));
  6053. } else if (style) {
  6054. const str = chunk.join('');
  6055. chunk = [];
  6056. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  6057. styles.push({
  6058. inverse,
  6059. styles: parseStyle(style)
  6060. });
  6061. } else if (close) {
  6062. if (styles.length === 0) {
  6063. throw new Error('Found extraneous } in Chalk template literal');
  6064. }
  6065. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  6066. chunk = [];
  6067. styles.pop();
  6068. } else {
  6069. chunk.push(chr);
  6070. }
  6071. });
  6072. chunks.push(chunk.join(''));
  6073. if (styles.length > 0) {
  6074. const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  6075. throw new Error(errMsg);
  6076. }
  6077. return chunks.join('');
  6078. };
  6079. var chalk = createCommonjsModule(function (module) {
  6080. const stdoutColor = supportsColor_1.stdout;
  6081. const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  6082. const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  6083. const skipModels = new Set(['gray']);
  6084. const styles = Object.create(null);
  6085. function applyOptions(obj, options) {
  6086. options = options || {}; // Detect level if not set manually
  6087. const scLevel = stdoutColor ? stdoutColor.level : 0;
  6088. obj.level = options.level === undefined ? scLevel : options.level;
  6089. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  6090. }
  6091. function Chalk(options) {
  6092. // We check for this.template here since calling `chalk.constructor()`
  6093. // by itself will have a `this` of a previously constructed chalk object
  6094. if (!this || !(this instanceof Chalk) || this.template) {
  6095. const chalk = {};
  6096. applyOptions(chalk, options);
  6097. chalk.template = function () {
  6098. const args = [].slice.call(arguments);
  6099. return chalkTag.apply(null, [chalk.template].concat(args));
  6100. };
  6101. Object.setPrototypeOf(chalk, Chalk.prototype);
  6102. Object.setPrototypeOf(chalk.template, chalk);
  6103. chalk.template.constructor = Chalk;
  6104. return chalk.template;
  6105. }
  6106. applyOptions(this, options);
  6107. } // Use bright blue on Windows as the normal blue color is illegible
  6108. if (isSimpleWindowsTerm) {
  6109. ansiStyles.blue.open = '\u001B[94m';
  6110. }
  6111. for (const key of Object.keys(ansiStyles)) {
  6112. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp$1(ansiStyles[key].close), 'g');
  6113. styles[key] = {
  6114. get() {
  6115. const codes = ansiStyles[key];
  6116. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  6117. }
  6118. };
  6119. }
  6120. styles.visible = {
  6121. get() {
  6122. return build.call(this, this._styles || [], true, 'visible');
  6123. }
  6124. };
  6125. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp$1(ansiStyles.color.close), 'g');
  6126. for (const model of Object.keys(ansiStyles.color.ansi)) {
  6127. if (skipModels.has(model)) {
  6128. continue;
  6129. }
  6130. styles[model] = {
  6131. get() {
  6132. const level = this.level;
  6133. return function () {
  6134. const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  6135. const codes = {
  6136. open,
  6137. close: ansiStyles.color.close,
  6138. closeRe: ansiStyles.color.closeRe
  6139. };
  6140. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  6141. };
  6142. }
  6143. };
  6144. }
  6145. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp$1(ansiStyles.bgColor.close), 'g');
  6146. for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
  6147. if (skipModels.has(model)) {
  6148. continue;
  6149. }
  6150. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  6151. styles[bgModel] = {
  6152. get() {
  6153. const level = this.level;
  6154. return function () {
  6155. const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  6156. const codes = {
  6157. open,
  6158. close: ansiStyles.bgColor.close,
  6159. closeRe: ansiStyles.bgColor.closeRe
  6160. };
  6161. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  6162. };
  6163. }
  6164. };
  6165. }
  6166. const proto = Object.defineProperties(() => {}, styles);
  6167. function build(_styles, _empty, key) {
  6168. const builder = function () {
  6169. return applyStyle.apply(builder, arguments);
  6170. };
  6171. builder._styles = _styles;
  6172. builder._empty = _empty;
  6173. const self = this;
  6174. Object.defineProperty(builder, 'level', {
  6175. enumerable: true,
  6176. get() {
  6177. return self.level;
  6178. },
  6179. set(level) {
  6180. self.level = level;
  6181. }
  6182. });
  6183. Object.defineProperty(builder, 'enabled', {
  6184. enumerable: true,
  6185. get() {
  6186. return self.enabled;
  6187. },
  6188. set(enabled) {
  6189. self.enabled = enabled;
  6190. }
  6191. }); // See below for fix regarding invisible grey/dim combination on Windows
  6192. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  6193. // no way to create a function with a different prototype
  6194. builder.__proto__ = proto; // eslint-disable-line no-proto
  6195. return builder;
  6196. }
  6197. function applyStyle() {
  6198. // Support varags, but simply cast to string in case there's only one arg
  6199. const args = arguments;
  6200. const argsLen = args.length;
  6201. let str = String(arguments[0]);
  6202. if (argsLen === 0) {
  6203. return '';
  6204. }
  6205. if (argsLen > 1) {
  6206. // Don't slice `arguments`, it prevents V8 optimizations
  6207. for (let a = 1; a < argsLen; a++) {
  6208. str += ' ' + args[a];
  6209. }
  6210. }
  6211. if (!this.enabled || this.level <= 0 || !str) {
  6212. return this._empty ? '' : str;
  6213. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  6214. // see https://github.com/chalk/chalk/issues/58
  6215. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  6216. const originalDim = ansiStyles.dim.open;
  6217. if (isSimpleWindowsTerm && this.hasGrey) {
  6218. ansiStyles.dim.open = '';
  6219. }
  6220. for (const code of this._styles.slice().reverse()) {
  6221. // Replace any instances already present with a re-opening code
  6222. // otherwise only the part of the string until said closing code
  6223. // will be colored, and the rest will simply be 'plain'.
  6224. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  6225. // after next line to fix a bleed issue on macOS
  6226. // https://github.com/chalk/chalk/pull/92
  6227. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  6228. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  6229. ansiStyles.dim.open = originalDim;
  6230. return str;
  6231. }
  6232. function chalkTag(chalk, strings) {
  6233. if (!Array.isArray(strings)) {
  6234. // If chalk() was called by itself or with a string,
  6235. // return the string itself as a string.
  6236. return [].slice.call(arguments, 1).join(' ');
  6237. }
  6238. const args = [].slice.call(arguments, 2);
  6239. const parts = [strings.raw[0]];
  6240. for (let i = 1; i < strings.length; i++) {
  6241. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  6242. parts.push(String(strings.raw[i]));
  6243. }
  6244. return templates(chalk, parts.join(''));
  6245. }
  6246. Object.defineProperties(Chalk.prototype, styles);
  6247. module.exports = Chalk(); // eslint-disable-line new-cap
  6248. module.exports.supportsColor = stdoutColor;
  6249. module.exports.default = module.exports; // For TypeScript
  6250. });
  6251. var common = createCommonjsModule(function (module, exports) {
  6252. Object.defineProperty(exports, "__esModule", {
  6253. value: true
  6254. });
  6255. exports.commonDeprecatedHandler = (keyOrPair, redirectTo, {
  6256. descriptor
  6257. }) => {
  6258. const messages = [`${chalk.default.yellow(typeof keyOrPair === 'string' ? descriptor.key(keyOrPair) : descriptor.pair(keyOrPair))} is deprecated`];
  6259. if (redirectTo) {
  6260. messages.push(`we now treat it as ${chalk.default.blue(typeof redirectTo === 'string' ? descriptor.key(redirectTo) : descriptor.pair(redirectTo))}`);
  6261. }
  6262. return messages.join('; ') + '.';
  6263. };
  6264. });
  6265. var deprecated = createCommonjsModule(function (module, exports) {
  6266. Object.defineProperty(exports, "__esModule", {
  6267. value: true
  6268. });
  6269. tslib_es6.__exportStar(common, exports);
  6270. });
  6271. var common$1 = createCommonjsModule(function (module, exports) {
  6272. Object.defineProperty(exports, "__esModule", {
  6273. value: true
  6274. });
  6275. exports.commonInvalidHandler = (key, value, utils) => [`Invalid ${chalk.default.red(utils.descriptor.key(key))} value.`, `Expected ${chalk.default.blue(utils.schemas[key].expected(utils))},`, `but received ${chalk.default.red(utils.descriptor.value(value))}.`].join(' ');
  6276. });
  6277. var invalid = createCommonjsModule(function (module, exports) {
  6278. Object.defineProperty(exports, "__esModule", {
  6279. value: true
  6280. });
  6281. tslib_es6.__exportStar(common$1, exports);
  6282. });
  6283. /* eslint-disable no-nested-ternary */
  6284. var arr = [];
  6285. var charCodeCache = [];
  6286. var leven = function (a, b) {
  6287. if (a === b) {
  6288. return 0;
  6289. }
  6290. var swap = a; // Swapping the strings if `a` is longer than `b` so we know which one is the
  6291. // shortest & which one is the longest
  6292. if (a.length > b.length) {
  6293. a = b;
  6294. b = swap;
  6295. }
  6296. var aLen = a.length;
  6297. var bLen = b.length;
  6298. if (aLen === 0) {
  6299. return bLen;
  6300. }
  6301. if (bLen === 0) {
  6302. return aLen;
  6303. } // Performing suffix trimming:
  6304. // We can linearly drop suffix common to both strings since they
  6305. // don't increase distance at all
  6306. // Note: `~-` is the bitwise way to perform a `- 1` operation
  6307. while (aLen > 0 && a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen)) {
  6308. aLen--;
  6309. bLen--;
  6310. }
  6311. if (aLen === 0) {
  6312. return bLen;
  6313. } // Performing prefix trimming
  6314. // We can linearly drop prefix common to both strings since they
  6315. // don't increase distance at all
  6316. var start = 0;
  6317. while (start < aLen && a.charCodeAt(start) === b.charCodeAt(start)) {
  6318. start++;
  6319. }
  6320. aLen -= start;
  6321. bLen -= start;
  6322. if (aLen === 0) {
  6323. return bLen;
  6324. }
  6325. var bCharCode;
  6326. var ret;
  6327. var tmp;
  6328. var tmp2;
  6329. var i = 0;
  6330. var j = 0;
  6331. while (i < aLen) {
  6332. charCodeCache[start + i] = a.charCodeAt(start + i);
  6333. arr[i] = ++i;
  6334. }
  6335. while (j < bLen) {
  6336. bCharCode = b.charCodeAt(start + j);
  6337. tmp = j++;
  6338. ret = j;
  6339. for (i = 0; i < aLen; i++) {
  6340. tmp2 = bCharCode === charCodeCache[start + i] ? tmp : tmp + 1;
  6341. tmp = arr[i];
  6342. ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;
  6343. }
  6344. }
  6345. return ret;
  6346. };
  6347. var leven_1 = createCommonjsModule(function (module, exports) {
  6348. Object.defineProperty(exports, "__esModule", {
  6349. value: true
  6350. });
  6351. exports.levenUnknownHandler = (key, value, {
  6352. descriptor,
  6353. logger,
  6354. schemas
  6355. }) => {
  6356. const messages = [`Ignored unknown option ${chalk.default.yellow(descriptor.pair({
  6357. key,
  6358. value
  6359. }))}.`];
  6360. const suggestion = Object.keys(schemas).sort().find(knownKey => leven(key, knownKey) < 3);
  6361. if (suggestion) {
  6362. messages.push(`Did you mean ${chalk.default.blue(descriptor.key(suggestion))}?`);
  6363. }
  6364. logger.warn(messages.join(' '));
  6365. };
  6366. });
  6367. var unknown = createCommonjsModule(function (module, exports) {
  6368. Object.defineProperty(exports, "__esModule", {
  6369. value: true
  6370. });
  6371. tslib_es6.__exportStar(leven_1, exports);
  6372. });
  6373. var handlers = createCommonjsModule(function (module, exports) {
  6374. Object.defineProperty(exports, "__esModule", {
  6375. value: true
  6376. });
  6377. tslib_es6.__exportStar(deprecated, exports);
  6378. tslib_es6.__exportStar(invalid, exports);
  6379. tslib_es6.__exportStar(unknown, exports);
  6380. });
  6381. var schema = createCommonjsModule(function (module, exports) {
  6382. Object.defineProperty(exports, "__esModule", {
  6383. value: true
  6384. });
  6385. const HANDLER_KEYS = ['default', 'expected', 'validate', 'deprecated', 'forward', 'redirect', 'overlap', 'preprocess', 'postprocess'];
  6386. function createSchema(SchemaConstructor, parameters) {
  6387. const schema = new SchemaConstructor(parameters);
  6388. const subSchema = Object.create(schema);
  6389. for (const handlerKey of HANDLER_KEYS) {
  6390. if (handlerKey in parameters) {
  6391. subSchema[handlerKey] = normalizeHandler(parameters[handlerKey], schema, Schema.prototype[handlerKey].length);
  6392. }
  6393. }
  6394. return subSchema;
  6395. }
  6396. exports.createSchema = createSchema;
  6397. class Schema {
  6398. constructor(parameters) {
  6399. this.name = parameters.name;
  6400. }
  6401. static create(parameters) {
  6402. // @ts-ignore: https://github.com/Microsoft/TypeScript/issues/5863
  6403. return createSchema(this, parameters);
  6404. }
  6405. default(_utils) {
  6406. return undefined;
  6407. } // istanbul ignore next: this is actually an abstract method but we need a placeholder to get `function.length`
  6408. expected(_utils) {
  6409. return 'nothing';
  6410. } // istanbul ignore next: this is actually an abstract method but we need a placeholder to get `function.length`
  6411. validate(_value, _utils) {
  6412. return false;
  6413. }
  6414. deprecated(_value, _utils) {
  6415. return false;
  6416. }
  6417. forward(_value, _utils) {
  6418. return undefined;
  6419. }
  6420. redirect(_value, _utils) {
  6421. return undefined;
  6422. }
  6423. overlap(currentValue, _newValue, _utils) {
  6424. return currentValue;
  6425. }
  6426. preprocess(value, _utils) {
  6427. return value;
  6428. }
  6429. postprocess(value, _utils) {
  6430. return value;
  6431. }
  6432. }
  6433. exports.Schema = Schema;
  6434. function normalizeHandler(handler, superSchema, handlerArgumentsLength) {
  6435. return typeof handler === 'function' ? (...args) => handler(...args.slice(0, handlerArgumentsLength - 1), superSchema, ...args.slice(handlerArgumentsLength - 1)) : () => handler;
  6436. }
  6437. });
  6438. var alias = createCommonjsModule(function (module, exports) {
  6439. Object.defineProperty(exports, "__esModule", {
  6440. value: true
  6441. });
  6442. class AliasSchema extends schema.Schema {
  6443. constructor(parameters) {
  6444. super(parameters);
  6445. this._sourceName = parameters.sourceName;
  6446. }
  6447. expected(utils) {
  6448. return utils.schemas[this._sourceName].expected(utils);
  6449. }
  6450. validate(value, utils) {
  6451. return utils.schemas[this._sourceName].validate(value, utils);
  6452. }
  6453. redirect(_value, _utils) {
  6454. return this._sourceName;
  6455. }
  6456. }
  6457. exports.AliasSchema = AliasSchema;
  6458. });
  6459. var any = createCommonjsModule(function (module, exports) {
  6460. Object.defineProperty(exports, "__esModule", {
  6461. value: true
  6462. });
  6463. class AnySchema extends schema.Schema {
  6464. expected() {
  6465. return 'anything';
  6466. }
  6467. validate() {
  6468. return true;
  6469. }
  6470. }
  6471. exports.AnySchema = AnySchema;
  6472. });
  6473. var array = createCommonjsModule(function (module, exports) {
  6474. Object.defineProperty(exports, "__esModule", {
  6475. value: true
  6476. });
  6477. class ArraySchema extends schema.Schema {
  6478. constructor(_a) {
  6479. var {
  6480. valueSchema,
  6481. name = valueSchema.name
  6482. } = _a,
  6483. handlers = tslib_es6.__rest(_a, ["valueSchema", "name"]);
  6484. super(Object.assign({}, handlers, {
  6485. name
  6486. }));
  6487. this._valueSchema = valueSchema;
  6488. }
  6489. expected(utils) {
  6490. return `an array of ${this._valueSchema.expected(utils)}`;
  6491. }
  6492. validate(value, utils) {
  6493. if (!Array.isArray(value)) {
  6494. return false;
  6495. }
  6496. const invalidValues = [];
  6497. for (const subValue of value) {
  6498. const subValidateResult = utils.normalizeValidateResult(this._valueSchema.validate(subValue, utils), subValue);
  6499. if (subValidateResult !== true) {
  6500. invalidValues.push(subValidateResult.value);
  6501. }
  6502. }
  6503. return invalidValues.length === 0 ? true : {
  6504. value: invalidValues
  6505. };
  6506. }
  6507. deprecated(value, utils) {
  6508. const deprecatedResult = [];
  6509. for (const subValue of value) {
  6510. const subDeprecatedResult = utils.normalizeDeprecatedResult(this._valueSchema.deprecated(subValue, utils), subValue);
  6511. if (subDeprecatedResult !== false) {
  6512. deprecatedResult.push(...subDeprecatedResult.map(({
  6513. value: deprecatedValue
  6514. }) => ({
  6515. value: [deprecatedValue]
  6516. })));
  6517. }
  6518. }
  6519. return deprecatedResult;
  6520. }
  6521. forward(value, utils) {
  6522. const forwardResult = [];
  6523. for (const subValue of value) {
  6524. const subForwardResult = utils.normalizeForwardResult(this._valueSchema.forward(subValue, utils), subValue);
  6525. forwardResult.push(...subForwardResult.map(wrapTransferResult));
  6526. }
  6527. return forwardResult;
  6528. }
  6529. redirect(value, utils) {
  6530. const remain = [];
  6531. const redirect = [];
  6532. for (const subValue of value) {
  6533. const subRedirectResult = utils.normalizeRedirectResult(this._valueSchema.redirect(subValue, utils), subValue);
  6534. if ('remain' in subRedirectResult) {
  6535. remain.push(subRedirectResult.remain);
  6536. }
  6537. redirect.push(...subRedirectResult.redirect.map(wrapTransferResult));
  6538. }
  6539. return remain.length === 0 ? {
  6540. redirect
  6541. } : {
  6542. redirect,
  6543. remain
  6544. };
  6545. }
  6546. overlap(currentValue, newValue) {
  6547. return currentValue.concat(newValue);
  6548. }
  6549. }
  6550. exports.ArraySchema = ArraySchema;
  6551. function wrapTransferResult({
  6552. from,
  6553. to
  6554. }) {
  6555. return {
  6556. from: [from],
  6557. to
  6558. };
  6559. }
  6560. });
  6561. var boolean_1 = createCommonjsModule(function (module, exports) {
  6562. Object.defineProperty(exports, "__esModule", {
  6563. value: true
  6564. });
  6565. class BooleanSchema extends schema.Schema {
  6566. expected() {
  6567. return 'true or false';
  6568. }
  6569. validate(value) {
  6570. return typeof value === 'boolean';
  6571. }
  6572. }
  6573. exports.BooleanSchema = BooleanSchema;
  6574. });
  6575. var utils = createCommonjsModule(function (module, exports) {
  6576. Object.defineProperty(exports, "__esModule", {
  6577. value: true
  6578. });
  6579. function recordFromArray(array, mainKey) {
  6580. const record = Object.create(null);
  6581. for (const value of array) {
  6582. const key = value[mainKey]; // istanbul ignore next
  6583. if (record[key]) {
  6584. throw new Error(`Duplicate ${mainKey} ${JSON.stringify(key)}`);
  6585. } // @ts-ignore
  6586. record[key] = value;
  6587. }
  6588. return record;
  6589. }
  6590. exports.recordFromArray = recordFromArray;
  6591. function mapFromArray(array, mainKey) {
  6592. const map = new Map();
  6593. for (const value of array) {
  6594. const key = value[mainKey]; // istanbul ignore next
  6595. if (map.has(key)) {
  6596. throw new Error(`Duplicate ${mainKey} ${JSON.stringify(key)}`);
  6597. }
  6598. map.set(key, value);
  6599. }
  6600. return map;
  6601. }
  6602. exports.mapFromArray = mapFromArray;
  6603. function createAutoChecklist() {
  6604. const map = Object.create(null);
  6605. return id => {
  6606. const idString = JSON.stringify(id);
  6607. if (map[idString]) {
  6608. return true;
  6609. }
  6610. map[idString] = true;
  6611. return false;
  6612. };
  6613. }
  6614. exports.createAutoChecklist = createAutoChecklist;
  6615. function partition(array, predicate) {
  6616. const trueArray = [];
  6617. const falseArray = [];
  6618. for (const value of array) {
  6619. if (predicate(value)) {
  6620. trueArray.push(value);
  6621. } else {
  6622. falseArray.push(value);
  6623. }
  6624. }
  6625. return [trueArray, falseArray];
  6626. }
  6627. exports.partition = partition;
  6628. function isInt(value) {
  6629. return value === Math.floor(value);
  6630. }
  6631. exports.isInt = isInt;
  6632. function comparePrimitive(a, b) {
  6633. if (a === b) {
  6634. return 0;
  6635. }
  6636. const typeofA = typeof a;
  6637. const typeofB = typeof b;
  6638. const orders = ['undefined', 'object', 'boolean', 'number', 'string'];
  6639. if (typeofA !== typeofB) {
  6640. return orders.indexOf(typeofA) - orders.indexOf(typeofB);
  6641. }
  6642. if (typeofA !== 'string') {
  6643. return Number(a) - Number(b);
  6644. }
  6645. return a.localeCompare(b);
  6646. }
  6647. exports.comparePrimitive = comparePrimitive;
  6648. function normalizeDefaultResult(result) {
  6649. return result === undefined ? {} : result;
  6650. }
  6651. exports.normalizeDefaultResult = normalizeDefaultResult;
  6652. function normalizeValidateResult(result, value) {
  6653. return result === true ? true : result === false ? {
  6654. value
  6655. } : result;
  6656. }
  6657. exports.normalizeValidateResult = normalizeValidateResult;
  6658. function normalizeDeprecatedResult(result, value, doNotNormalizeTrue = false) {
  6659. return result === false ? false : result === true ? doNotNormalizeTrue ? true : [{
  6660. value
  6661. }] : 'value' in result ? [result] : result.length === 0 ? false : result;
  6662. }
  6663. exports.normalizeDeprecatedResult = normalizeDeprecatedResult;
  6664. function normalizeTransferResult(result, value) {
  6665. return typeof result === 'string' || 'key' in result ? {
  6666. from: value,
  6667. to: result
  6668. } : 'from' in result ? {
  6669. from: result.from,
  6670. to: result.to
  6671. } : {
  6672. from: value,
  6673. to: result.to
  6674. };
  6675. }
  6676. exports.normalizeTransferResult = normalizeTransferResult;
  6677. function normalizeForwardResult(result, value) {
  6678. return result === undefined ? [] : Array.isArray(result) ? result.map(transferResult => normalizeTransferResult(transferResult, value)) : [normalizeTransferResult(result, value)];
  6679. }
  6680. exports.normalizeForwardResult = normalizeForwardResult;
  6681. function normalizeRedirectResult(result, value) {
  6682. const redirect = normalizeForwardResult(typeof result === 'object' && 'redirect' in result ? result.redirect : result, value);
  6683. return redirect.length === 0 ? {
  6684. remain: value,
  6685. redirect
  6686. } : typeof result === 'object' && 'remain' in result ? {
  6687. remain: result.remain,
  6688. redirect
  6689. } : {
  6690. redirect
  6691. };
  6692. }
  6693. exports.normalizeRedirectResult = normalizeRedirectResult;
  6694. });
  6695. var choice = createCommonjsModule(function (module, exports) {
  6696. Object.defineProperty(exports, "__esModule", {
  6697. value: true
  6698. });
  6699. class ChoiceSchema extends schema.Schema {
  6700. constructor(parameters) {
  6701. super(parameters);
  6702. this._choices = utils.mapFromArray(parameters.choices.map(choice => choice && typeof choice === 'object' ? choice : {
  6703. value: choice
  6704. }), 'value');
  6705. }
  6706. expected({
  6707. descriptor
  6708. }) {
  6709. const choiceValues = Array.from(this._choices.keys()).map(value => this._choices.get(value)).filter(choiceInfo => !choiceInfo.deprecated).map(choiceInfo => choiceInfo.value).sort(utils.comparePrimitive).map(descriptor.value);
  6710. const head = choiceValues.slice(0, -2);
  6711. const tail = choiceValues.slice(-2);
  6712. return head.concat(tail.join(' or ')).join(', ');
  6713. }
  6714. validate(value) {
  6715. return this._choices.has(value);
  6716. }
  6717. deprecated(value) {
  6718. const choiceInfo = this._choices.get(value);
  6719. return choiceInfo && choiceInfo.deprecated ? {
  6720. value
  6721. } : false;
  6722. }
  6723. forward(value) {
  6724. const choiceInfo = this._choices.get(value);
  6725. return choiceInfo ? choiceInfo.forward : undefined;
  6726. }
  6727. redirect(value) {
  6728. const choiceInfo = this._choices.get(value);
  6729. return choiceInfo ? choiceInfo.redirect : undefined;
  6730. }
  6731. }
  6732. exports.ChoiceSchema = ChoiceSchema;
  6733. });
  6734. var number = createCommonjsModule(function (module, exports) {
  6735. Object.defineProperty(exports, "__esModule", {
  6736. value: true
  6737. });
  6738. class NumberSchema extends schema.Schema {
  6739. expected() {
  6740. return 'a number';
  6741. }
  6742. validate(value, _utils) {
  6743. return typeof value === 'number';
  6744. }
  6745. }
  6746. exports.NumberSchema = NumberSchema;
  6747. });
  6748. var integer = createCommonjsModule(function (module, exports) {
  6749. Object.defineProperty(exports, "__esModule", {
  6750. value: true
  6751. });
  6752. class IntegerSchema extends number.NumberSchema {
  6753. expected() {
  6754. return 'an integer';
  6755. }
  6756. validate(value, utils$1) {
  6757. return utils$1.normalizeValidateResult(super.validate(value, utils$1), value) === true && utils.isInt(value);
  6758. }
  6759. }
  6760. exports.IntegerSchema = IntegerSchema;
  6761. });
  6762. var string = createCommonjsModule(function (module, exports) {
  6763. Object.defineProperty(exports, "__esModule", {
  6764. value: true
  6765. });
  6766. class StringSchema extends schema.Schema {
  6767. expected() {
  6768. return 'a string';
  6769. }
  6770. validate(value) {
  6771. return typeof value === 'string';
  6772. }
  6773. }
  6774. exports.StringSchema = StringSchema;
  6775. });
  6776. var schemas = createCommonjsModule(function (module, exports) {
  6777. Object.defineProperty(exports, "__esModule", {
  6778. value: true
  6779. });
  6780. tslib_es6.__exportStar(alias, exports);
  6781. tslib_es6.__exportStar(any, exports);
  6782. tslib_es6.__exportStar(array, exports);
  6783. tslib_es6.__exportStar(boolean_1, exports);
  6784. tslib_es6.__exportStar(choice, exports);
  6785. tslib_es6.__exportStar(integer, exports);
  6786. tslib_es6.__exportStar(number, exports);
  6787. tslib_es6.__exportStar(string, exports);
  6788. });
  6789. var defaults = createCommonjsModule(function (module, exports) {
  6790. Object.defineProperty(exports, "__esModule", {
  6791. value: true
  6792. });
  6793. exports.defaultDescriptor = api.apiDescriptor;
  6794. exports.defaultUnknownHandler = leven_1.levenUnknownHandler;
  6795. exports.defaultInvalidHandler = invalid.commonInvalidHandler;
  6796. exports.defaultDeprecatedHandler = common.commonDeprecatedHandler;
  6797. });
  6798. var normalize = createCommonjsModule(function (module, exports) {
  6799. Object.defineProperty(exports, "__esModule", {
  6800. value: true
  6801. });
  6802. exports.normalize = (options, schemas, opts) => new Normalizer(schemas, opts).normalize(options);
  6803. class Normalizer {
  6804. constructor(schemas, opts) {
  6805. // istanbul ignore next
  6806. const {
  6807. logger = console,
  6808. descriptor = defaults.defaultDescriptor,
  6809. unknown = defaults.defaultUnknownHandler,
  6810. invalid = defaults.defaultInvalidHandler,
  6811. deprecated = defaults.defaultDeprecatedHandler
  6812. } = opts || {};
  6813. this._utils = {
  6814. descriptor,
  6815. logger:
  6816. /* istanbul ignore next */
  6817. logger || {
  6818. warn: () => {}
  6819. },
  6820. schemas: utils.recordFromArray(schemas, 'name'),
  6821. normalizeDefaultResult: utils.normalizeDefaultResult,
  6822. normalizeDeprecatedResult: utils.normalizeDeprecatedResult,
  6823. normalizeForwardResult: utils.normalizeForwardResult,
  6824. normalizeRedirectResult: utils.normalizeRedirectResult,
  6825. normalizeValidateResult: utils.normalizeValidateResult
  6826. };
  6827. this._unknownHandler = unknown;
  6828. this._invalidHandler = invalid;
  6829. this._deprecatedHandler = deprecated;
  6830. this.cleanHistory();
  6831. }
  6832. cleanHistory() {
  6833. this._hasDeprecationWarned = utils.createAutoChecklist();
  6834. }
  6835. normalize(options) {
  6836. const normalized = {};
  6837. const restOptionsArray = [options];
  6838. const applyNormalization = () => {
  6839. while (restOptionsArray.length !== 0) {
  6840. const currentOptions = restOptionsArray.shift();
  6841. const transferredOptionsArray = this._applyNormalization(currentOptions, normalized);
  6842. restOptionsArray.push(...transferredOptionsArray);
  6843. }
  6844. };
  6845. applyNormalization();
  6846. for (const key of Object.keys(this._utils.schemas)) {
  6847. const schema = this._utils.schemas[key];
  6848. if (!(key in normalized)) {
  6849. const defaultResult = utils.normalizeDefaultResult(schema.default(this._utils));
  6850. if ('value' in defaultResult) {
  6851. restOptionsArray.push({
  6852. [key]: defaultResult.value
  6853. });
  6854. }
  6855. }
  6856. }
  6857. applyNormalization();
  6858. for (const key of Object.keys(this._utils.schemas)) {
  6859. const schema = this._utils.schemas[key];
  6860. if (key in normalized) {
  6861. normalized[key] = schema.postprocess(normalized[key], this._utils);
  6862. }
  6863. }
  6864. return normalized;
  6865. }
  6866. _applyNormalization(options, normalized) {
  6867. const transferredOptionsArray = [];
  6868. const [knownOptionNames, unknownOptionNames] = utils.partition(Object.keys(options), key => key in this._utils.schemas);
  6869. for (const key of knownOptionNames) {
  6870. const schema = this._utils.schemas[key];
  6871. const value = schema.preprocess(options[key], this._utils);
  6872. const validateResult = utils.normalizeValidateResult(schema.validate(value, this._utils), value);
  6873. if (validateResult !== true) {
  6874. const {
  6875. value: invalidValue
  6876. } = validateResult;
  6877. const errorMessageOrError = this._invalidHandler(key, invalidValue, this._utils);
  6878. throw typeof errorMessageOrError === 'string' ? new Error(errorMessageOrError) :
  6879. /* istanbul ignore next*/
  6880. errorMessageOrError;
  6881. }
  6882. const appendTransferredOptions = ({
  6883. from,
  6884. to
  6885. }) => {
  6886. transferredOptionsArray.push(typeof to === 'string' ? {
  6887. [to]: from
  6888. } : {
  6889. [to.key]: to.value
  6890. });
  6891. };
  6892. const warnDeprecated = ({
  6893. value: currentValue,
  6894. redirectTo
  6895. }) => {
  6896. const deprecatedResult = utils.normalizeDeprecatedResult(schema.deprecated(currentValue, this._utils), value,
  6897. /* doNotNormalizeTrue */
  6898. true);
  6899. if (deprecatedResult === false) {
  6900. return;
  6901. }
  6902. if (deprecatedResult === true) {
  6903. if (!this._hasDeprecationWarned(key)) {
  6904. this._utils.logger.warn(this._deprecatedHandler(key, redirectTo, this._utils));
  6905. }
  6906. } else {
  6907. for (const {
  6908. value: deprecatedValue
  6909. } of deprecatedResult) {
  6910. const pair = {
  6911. key,
  6912. value: deprecatedValue
  6913. };
  6914. if (!this._hasDeprecationWarned(pair)) {
  6915. const redirectToPair = typeof redirectTo === 'string' ? {
  6916. key: redirectTo,
  6917. value: deprecatedValue
  6918. } : redirectTo;
  6919. this._utils.logger.warn(this._deprecatedHandler(pair, redirectToPair, this._utils));
  6920. }
  6921. }
  6922. }
  6923. };
  6924. const forwardResult = utils.normalizeForwardResult(schema.forward(value, this._utils), value);
  6925. forwardResult.forEach(appendTransferredOptions);
  6926. const redirectResult = utils.normalizeRedirectResult(schema.redirect(value, this._utils), value);
  6927. redirectResult.redirect.forEach(appendTransferredOptions);
  6928. if ('remain' in redirectResult) {
  6929. const remainingValue = redirectResult.remain;
  6930. normalized[key] = key in normalized ? schema.overlap(normalized[key], remainingValue, this._utils) : remainingValue;
  6931. warnDeprecated({
  6932. value: remainingValue
  6933. });
  6934. }
  6935. for (const {
  6936. from,
  6937. to
  6938. } of redirectResult.redirect) {
  6939. warnDeprecated({
  6940. value: from,
  6941. redirectTo: to
  6942. });
  6943. }
  6944. }
  6945. for (const key of unknownOptionNames) {
  6946. const value = options[key];
  6947. const unknownResult = this._unknownHandler(key, value, this._utils);
  6948. if (unknownResult) {
  6949. for (const unknownKey of Object.keys(unknownResult)) {
  6950. const unknownOption = {
  6951. [unknownKey]: unknownResult[unknownKey]
  6952. };
  6953. if (unknownKey in this._utils.schemas) {
  6954. transferredOptionsArray.push(unknownOption);
  6955. } else {
  6956. Object.assign(normalized, unknownOption);
  6957. }
  6958. }
  6959. }
  6960. }
  6961. return transferredOptionsArray;
  6962. }
  6963. }
  6964. exports.Normalizer = Normalizer;
  6965. });
  6966. var lib$1 = createCommonjsModule(function (module, exports) {
  6967. Object.defineProperty(exports, "__esModule", {
  6968. value: true
  6969. });
  6970. tslib_es6.__exportStar(descriptors, exports);
  6971. tslib_es6.__exportStar(handlers, exports);
  6972. tslib_es6.__exportStar(schemas, exports);
  6973. tslib_es6.__exportStar(normalize, exports);
  6974. tslib_es6.__exportStar(schema, exports);
  6975. });
  6976. const array$1 = [];
  6977. const charCodeCache$1 = [];
  6978. const leven$1 = (left, right) => {
  6979. if (left === right) {
  6980. return 0;
  6981. }
  6982. const swap = left; // Swapping the strings if `a` is longer than `b` so we know which one is the
  6983. // shortest & which one is the longest
  6984. if (left.length > right.length) {
  6985. left = right;
  6986. right = swap;
  6987. }
  6988. let leftLength = left.length;
  6989. let rightLength = right.length; // Performing suffix trimming:
  6990. // We can linearly drop suffix common to both strings since they
  6991. // don't increase distance at all
  6992. // Note: `~-` is the bitwise way to perform a `- 1` operation
  6993. while (leftLength > 0 && left.charCodeAt(~-leftLength) === right.charCodeAt(~-rightLength)) {
  6994. leftLength--;
  6995. rightLength--;
  6996. } // Performing prefix trimming
  6997. // We can linearly drop prefix common to both strings since they
  6998. // don't increase distance at all
  6999. let start = 0;
  7000. while (start < leftLength && left.charCodeAt(start) === right.charCodeAt(start)) {
  7001. start++;
  7002. }
  7003. leftLength -= start;
  7004. rightLength -= start;
  7005. if (leftLength === 0) {
  7006. return rightLength;
  7007. }
  7008. let bCharCode;
  7009. let result;
  7010. let temp;
  7011. let temp2;
  7012. let i = 0;
  7013. let j = 0;
  7014. while (i < leftLength) {
  7015. charCodeCache$1[i] = left.charCodeAt(start + i);
  7016. array$1[i] = ++i;
  7017. }
  7018. while (j < rightLength) {
  7019. bCharCode = right.charCodeAt(start + j);
  7020. temp = j++;
  7021. result = j;
  7022. for (i = 0; i < leftLength; i++) {
  7023. temp2 = bCharCode === charCodeCache$1[i] ? temp : temp + 1;
  7024. temp = array$1[i]; // eslint-disable-next-line no-multi-assign
  7025. result = array$1[i] = temp > result ? temp2 > result ? result + 1 : temp2 : temp2 > temp ? temp + 1 : temp2;
  7026. }
  7027. }
  7028. return result;
  7029. };
  7030. var leven_1$1 = leven$1; // TODO: Remove this for the next major release
  7031. var _default$2 = leven$1;
  7032. leven_1$1.default = _default$2;
  7033. var colorName$1 = {
  7034. "aliceblue": [240, 248, 255],
  7035. "antiquewhite": [250, 235, 215],
  7036. "aqua": [0, 255, 255],
  7037. "aquamarine": [127, 255, 212],
  7038. "azure": [240, 255, 255],
  7039. "beige": [245, 245, 220],
  7040. "bisque": [255, 228, 196],
  7041. "black": [0, 0, 0],
  7042. "blanchedalmond": [255, 235, 205],
  7043. "blue": [0, 0, 255],
  7044. "blueviolet": [138, 43, 226],
  7045. "brown": [165, 42, 42],
  7046. "burlywood": [222, 184, 135],
  7047. "cadetblue": [95, 158, 160],
  7048. "chartreuse": [127, 255, 0],
  7049. "chocolate": [210, 105, 30],
  7050. "coral": [255, 127, 80],
  7051. "cornflowerblue": [100, 149, 237],
  7052. "cornsilk": [255, 248, 220],
  7053. "crimson": [220, 20, 60],
  7054. "cyan": [0, 255, 255],
  7055. "darkblue": [0, 0, 139],
  7056. "darkcyan": [0, 139, 139],
  7057. "darkgoldenrod": [184, 134, 11],
  7058. "darkgray": [169, 169, 169],
  7059. "darkgreen": [0, 100, 0],
  7060. "darkgrey": [169, 169, 169],
  7061. "darkkhaki": [189, 183, 107],
  7062. "darkmagenta": [139, 0, 139],
  7063. "darkolivegreen": [85, 107, 47],
  7064. "darkorange": [255, 140, 0],
  7065. "darkorchid": [153, 50, 204],
  7066. "darkred": [139, 0, 0],
  7067. "darksalmon": [233, 150, 122],
  7068. "darkseagreen": [143, 188, 143],
  7069. "darkslateblue": [72, 61, 139],
  7070. "darkslategray": [47, 79, 79],
  7071. "darkslategrey": [47, 79, 79],
  7072. "darkturquoise": [0, 206, 209],
  7073. "darkviolet": [148, 0, 211],
  7074. "deeppink": [255, 20, 147],
  7075. "deepskyblue": [0, 191, 255],
  7076. "dimgray": [105, 105, 105],
  7077. "dimgrey": [105, 105, 105],
  7078. "dodgerblue": [30, 144, 255],
  7079. "firebrick": [178, 34, 34],
  7080. "floralwhite": [255, 250, 240],
  7081. "forestgreen": [34, 139, 34],
  7082. "fuchsia": [255, 0, 255],
  7083. "gainsboro": [220, 220, 220],
  7084. "ghostwhite": [248, 248, 255],
  7085. "gold": [255, 215, 0],
  7086. "goldenrod": [218, 165, 32],
  7087. "gray": [128, 128, 128],
  7088. "green": [0, 128, 0],
  7089. "greenyellow": [173, 255, 47],
  7090. "grey": [128, 128, 128],
  7091. "honeydew": [240, 255, 240],
  7092. "hotpink": [255, 105, 180],
  7093. "indianred": [205, 92, 92],
  7094. "indigo": [75, 0, 130],
  7095. "ivory": [255, 255, 240],
  7096. "khaki": [240, 230, 140],
  7097. "lavender": [230, 230, 250],
  7098. "lavenderblush": [255, 240, 245],
  7099. "lawngreen": [124, 252, 0],
  7100. "lemonchiffon": [255, 250, 205],
  7101. "lightblue": [173, 216, 230],
  7102. "lightcoral": [240, 128, 128],
  7103. "lightcyan": [224, 255, 255],
  7104. "lightgoldenrodyellow": [250, 250, 210],
  7105. "lightgray": [211, 211, 211],
  7106. "lightgreen": [144, 238, 144],
  7107. "lightgrey": [211, 211, 211],
  7108. "lightpink": [255, 182, 193],
  7109. "lightsalmon": [255, 160, 122],
  7110. "lightseagreen": [32, 178, 170],
  7111. "lightskyblue": [135, 206, 250],
  7112. "lightslategray": [119, 136, 153],
  7113. "lightslategrey": [119, 136, 153],
  7114. "lightsteelblue": [176, 196, 222],
  7115. "lightyellow": [255, 255, 224],
  7116. "lime": [0, 255, 0],
  7117. "limegreen": [50, 205, 50],
  7118. "linen": [250, 240, 230],
  7119. "magenta": [255, 0, 255],
  7120. "maroon": [128, 0, 0],
  7121. "mediumaquamarine": [102, 205, 170],
  7122. "mediumblue": [0, 0, 205],
  7123. "mediumorchid": [186, 85, 211],
  7124. "mediumpurple": [147, 112, 219],
  7125. "mediumseagreen": [60, 179, 113],
  7126. "mediumslateblue": [123, 104, 238],
  7127. "mediumspringgreen": [0, 250, 154],
  7128. "mediumturquoise": [72, 209, 204],
  7129. "mediumvioletred": [199, 21, 133],
  7130. "midnightblue": [25, 25, 112],
  7131. "mintcream": [245, 255, 250],
  7132. "mistyrose": [255, 228, 225],
  7133. "moccasin": [255, 228, 181],
  7134. "navajowhite": [255, 222, 173],
  7135. "navy": [0, 0, 128],
  7136. "oldlace": [253, 245, 230],
  7137. "olive": [128, 128, 0],
  7138. "olivedrab": [107, 142, 35],
  7139. "orange": [255, 165, 0],
  7140. "orangered": [255, 69, 0],
  7141. "orchid": [218, 112, 214],
  7142. "palegoldenrod": [238, 232, 170],
  7143. "palegreen": [152, 251, 152],
  7144. "paleturquoise": [175, 238, 238],
  7145. "palevioletred": [219, 112, 147],
  7146. "papayawhip": [255, 239, 213],
  7147. "peachpuff": [255, 218, 185],
  7148. "peru": [205, 133, 63],
  7149. "pink": [255, 192, 203],
  7150. "plum": [221, 160, 221],
  7151. "powderblue": [176, 224, 230],
  7152. "purple": [128, 0, 128],
  7153. "rebeccapurple": [102, 51, 153],
  7154. "red": [255, 0, 0],
  7155. "rosybrown": [188, 143, 143],
  7156. "royalblue": [65, 105, 225],
  7157. "saddlebrown": [139, 69, 19],
  7158. "salmon": [250, 128, 114],
  7159. "sandybrown": [244, 164, 96],
  7160. "seagreen": [46, 139, 87],
  7161. "seashell": [255, 245, 238],
  7162. "sienna": [160, 82, 45],
  7163. "silver": [192, 192, 192],
  7164. "skyblue": [135, 206, 235],
  7165. "slateblue": [106, 90, 205],
  7166. "slategray": [112, 128, 144],
  7167. "slategrey": [112, 128, 144],
  7168. "snow": [255, 250, 250],
  7169. "springgreen": [0, 255, 127],
  7170. "steelblue": [70, 130, 180],
  7171. "tan": [210, 180, 140],
  7172. "teal": [0, 128, 128],
  7173. "thistle": [216, 191, 216],
  7174. "tomato": [255, 99, 71],
  7175. "turquoise": [64, 224, 208],
  7176. "violet": [238, 130, 238],
  7177. "wheat": [245, 222, 179],
  7178. "white": [255, 255, 255],
  7179. "whitesmoke": [245, 245, 245],
  7180. "yellow": [255, 255, 0],
  7181. "yellowgreen": [154, 205, 50]
  7182. };
  7183. /* MIT license */
  7184. /* eslint-disable no-mixed-operators */
  7185. // NOTE: conversions should only return primitive values (i.e. arrays, or
  7186. // values that give correct `typeof` results).
  7187. // do not use box values types (i.e. Number(), String(), etc.)
  7188. const reverseKeywords = {};
  7189. for (const key of Object.keys(colorName$1)) {
  7190. reverseKeywords[colorName$1[key]] = key;
  7191. }
  7192. const convert$1 = {
  7193. rgb: {
  7194. channels: 3,
  7195. labels: 'rgb'
  7196. },
  7197. hsl: {
  7198. channels: 3,
  7199. labels: 'hsl'
  7200. },
  7201. hsv: {
  7202. channels: 3,
  7203. labels: 'hsv'
  7204. },
  7205. hwb: {
  7206. channels: 3,
  7207. labels: 'hwb'
  7208. },
  7209. cmyk: {
  7210. channels: 4,
  7211. labels: 'cmyk'
  7212. },
  7213. xyz: {
  7214. channels: 3,
  7215. labels: 'xyz'
  7216. },
  7217. lab: {
  7218. channels: 3,
  7219. labels: 'lab'
  7220. },
  7221. lch: {
  7222. channels: 3,
  7223. labels: 'lch'
  7224. },
  7225. hex: {
  7226. channels: 1,
  7227. labels: ['hex']
  7228. },
  7229. keyword: {
  7230. channels: 1,
  7231. labels: ['keyword']
  7232. },
  7233. ansi16: {
  7234. channels: 1,
  7235. labels: ['ansi16']
  7236. },
  7237. ansi256: {
  7238. channels: 1,
  7239. labels: ['ansi256']
  7240. },
  7241. hcg: {
  7242. channels: 3,
  7243. labels: ['h', 'c', 'g']
  7244. },
  7245. apple: {
  7246. channels: 3,
  7247. labels: ['r16', 'g16', 'b16']
  7248. },
  7249. gray: {
  7250. channels: 1,
  7251. labels: ['gray']
  7252. }
  7253. };
  7254. var conversions$1 = convert$1; // Hide .channels and .labels properties
  7255. for (const model of Object.keys(convert$1)) {
  7256. if (!('channels' in convert$1[model])) {
  7257. throw new Error('missing channels property: ' + model);
  7258. }
  7259. if (!('labels' in convert$1[model])) {
  7260. throw new Error('missing channel labels property: ' + model);
  7261. }
  7262. if (convert$1[model].labels.length !== convert$1[model].channels) {
  7263. throw new Error('channel and label counts mismatch: ' + model);
  7264. }
  7265. const {
  7266. channels,
  7267. labels
  7268. } = convert$1[model];
  7269. delete convert$1[model].channels;
  7270. delete convert$1[model].labels;
  7271. Object.defineProperty(convert$1[model], 'channels', {
  7272. value: channels
  7273. });
  7274. Object.defineProperty(convert$1[model], 'labels', {
  7275. value: labels
  7276. });
  7277. }
  7278. convert$1.rgb.hsl = function (rgb) {
  7279. const r = rgb[0] / 255;
  7280. const g = rgb[1] / 255;
  7281. const b = rgb[2] / 255;
  7282. const min = Math.min(r, g, b);
  7283. const max = Math.max(r, g, b);
  7284. const delta = max - min;
  7285. let h;
  7286. let s;
  7287. if (max === min) {
  7288. h = 0;
  7289. } else if (r === max) {
  7290. h = (g - b) / delta;
  7291. } else if (g === max) {
  7292. h = 2 + (b - r) / delta;
  7293. } else if (b === max) {
  7294. h = 4 + (r - g) / delta;
  7295. }
  7296. h = Math.min(h * 60, 360);
  7297. if (h < 0) {
  7298. h += 360;
  7299. }
  7300. const l = (min + max) / 2;
  7301. if (max === min) {
  7302. s = 0;
  7303. } else if (l <= 0.5) {
  7304. s = delta / (max + min);
  7305. } else {
  7306. s = delta / (2 - max - min);
  7307. }
  7308. return [h, s * 100, l * 100];
  7309. };
  7310. convert$1.rgb.hsv = function (rgb) {
  7311. let rdif;
  7312. let gdif;
  7313. let bdif;
  7314. let h;
  7315. let s;
  7316. const r = rgb[0] / 255;
  7317. const g = rgb[1] / 255;
  7318. const b = rgb[2] / 255;
  7319. const v = Math.max(r, g, b);
  7320. const diff = v - Math.min(r, g, b);
  7321. const diffc = function (c) {
  7322. return (v - c) / 6 / diff + 1 / 2;
  7323. };
  7324. if (diff === 0) {
  7325. h = 0;
  7326. s = 0;
  7327. } else {
  7328. s = diff / v;
  7329. rdif = diffc(r);
  7330. gdif = diffc(g);
  7331. bdif = diffc(b);
  7332. if (r === v) {
  7333. h = bdif - gdif;
  7334. } else if (g === v) {
  7335. h = 1 / 3 + rdif - bdif;
  7336. } else if (b === v) {
  7337. h = 2 / 3 + gdif - rdif;
  7338. }
  7339. if (h < 0) {
  7340. h += 1;
  7341. } else if (h > 1) {
  7342. h -= 1;
  7343. }
  7344. }
  7345. return [h * 360, s * 100, v * 100];
  7346. };
  7347. convert$1.rgb.hwb = function (rgb) {
  7348. const r = rgb[0];
  7349. const g = rgb[1];
  7350. let b = rgb[2];
  7351. const h = convert$1.rgb.hsl(rgb)[0];
  7352. const w = 1 / 255 * Math.min(r, Math.min(g, b));
  7353. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  7354. return [h, w * 100, b * 100];
  7355. };
  7356. convert$1.rgb.cmyk = function (rgb) {
  7357. const r = rgb[0] / 255;
  7358. const g = rgb[1] / 255;
  7359. const b = rgb[2] / 255;
  7360. const k = Math.min(1 - r, 1 - g, 1 - b);
  7361. const c = (1 - r - k) / (1 - k) || 0;
  7362. const m = (1 - g - k) / (1 - k) || 0;
  7363. const y = (1 - b - k) / (1 - k) || 0;
  7364. return [c * 100, m * 100, y * 100, k * 100];
  7365. };
  7366. function comparativeDistance(x, y) {
  7367. /*
  7368. See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  7369. */
  7370. return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
  7371. }
  7372. convert$1.rgb.keyword = function (rgb) {
  7373. const reversed = reverseKeywords[rgb];
  7374. if (reversed) {
  7375. return reversed;
  7376. }
  7377. let currentClosestDistance = Infinity;
  7378. let currentClosestKeyword;
  7379. for (const keyword of Object.keys(colorName$1)) {
  7380. const value = colorName$1[keyword]; // Compute comparative distance
  7381. const distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  7382. if (distance < currentClosestDistance) {
  7383. currentClosestDistance = distance;
  7384. currentClosestKeyword = keyword;
  7385. }
  7386. }
  7387. return currentClosestKeyword;
  7388. };
  7389. convert$1.keyword.rgb = function (keyword) {
  7390. return colorName$1[keyword];
  7391. };
  7392. convert$1.rgb.xyz = function (rgb) {
  7393. let r = rgb[0] / 255;
  7394. let g = rgb[1] / 255;
  7395. let b = rgb[2] / 255; // Assume sRGB
  7396. r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
  7397. g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
  7398. b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
  7399. const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  7400. const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  7401. const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  7402. return [x * 100, y * 100, z * 100];
  7403. };
  7404. convert$1.rgb.lab = function (rgb) {
  7405. const xyz = convert$1.rgb.xyz(rgb);
  7406. let x = xyz[0];
  7407. let y = xyz[1];
  7408. let z = xyz[2];
  7409. x /= 95.047;
  7410. y /= 100;
  7411. z /= 108.883;
  7412. x = x > 0.008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
  7413. y = y > 0.008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
  7414. z = z > 0.008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
  7415. const l = 116 * y - 16;
  7416. const a = 500 * (x - y);
  7417. const b = 200 * (y - z);
  7418. return [l, a, b];
  7419. };
  7420. convert$1.hsl.rgb = function (hsl) {
  7421. const h = hsl[0] / 360;
  7422. const s = hsl[1] / 100;
  7423. const l = hsl[2] / 100;
  7424. let t2;
  7425. let t3;
  7426. let val;
  7427. if (s === 0) {
  7428. val = l * 255;
  7429. return [val, val, val];
  7430. }
  7431. if (l < 0.5) {
  7432. t2 = l * (1 + s);
  7433. } else {
  7434. t2 = l + s - l * s;
  7435. }
  7436. const t1 = 2 * l - t2;
  7437. const rgb = [0, 0, 0];
  7438. for (let i = 0; i < 3; i++) {
  7439. t3 = h + 1 / 3 * -(i - 1);
  7440. if (t3 < 0) {
  7441. t3++;
  7442. }
  7443. if (t3 > 1) {
  7444. t3--;
  7445. }
  7446. if (6 * t3 < 1) {
  7447. val = t1 + (t2 - t1) * 6 * t3;
  7448. } else if (2 * t3 < 1) {
  7449. val = t2;
  7450. } else if (3 * t3 < 2) {
  7451. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  7452. } else {
  7453. val = t1;
  7454. }
  7455. rgb[i] = val * 255;
  7456. }
  7457. return rgb;
  7458. };
  7459. convert$1.hsl.hsv = function (hsl) {
  7460. const h = hsl[0];
  7461. let s = hsl[1] / 100;
  7462. let l = hsl[2] / 100;
  7463. let smin = s;
  7464. const lmin = Math.max(l, 0.01);
  7465. l *= 2;
  7466. s *= l <= 1 ? l : 2 - l;
  7467. smin *= lmin <= 1 ? lmin : 2 - lmin;
  7468. const v = (l + s) / 2;
  7469. const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  7470. return [h, sv * 100, v * 100];
  7471. };
  7472. convert$1.hsv.rgb = function (hsv) {
  7473. const h = hsv[0] / 60;
  7474. const s = hsv[1] / 100;
  7475. let v = hsv[2] / 100;
  7476. const hi = Math.floor(h) % 6;
  7477. const f = h - Math.floor(h);
  7478. const p = 255 * v * (1 - s);
  7479. const q = 255 * v * (1 - s * f);
  7480. const t = 255 * v * (1 - s * (1 - f));
  7481. v *= 255;
  7482. switch (hi) {
  7483. case 0:
  7484. return [v, t, p];
  7485. case 1:
  7486. return [q, v, p];
  7487. case 2:
  7488. return [p, v, t];
  7489. case 3:
  7490. return [p, q, v];
  7491. case 4:
  7492. return [t, p, v];
  7493. case 5:
  7494. return [v, p, q];
  7495. }
  7496. };
  7497. convert$1.hsv.hsl = function (hsv) {
  7498. const h = hsv[0];
  7499. const s = hsv[1] / 100;
  7500. const v = hsv[2] / 100;
  7501. const vmin = Math.max(v, 0.01);
  7502. let sl;
  7503. let l;
  7504. l = (2 - s) * v;
  7505. const lmin = (2 - s) * vmin;
  7506. sl = s * vmin;
  7507. sl /= lmin <= 1 ? lmin : 2 - lmin;
  7508. sl = sl || 0;
  7509. l /= 2;
  7510. return [h, sl * 100, l * 100];
  7511. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  7512. convert$1.hwb.rgb = function (hwb) {
  7513. const h = hwb[0] / 360;
  7514. let wh = hwb[1] / 100;
  7515. let bl = hwb[2] / 100;
  7516. const ratio = wh + bl;
  7517. let f; // Wh + bl cant be > 1
  7518. if (ratio > 1) {
  7519. wh /= ratio;
  7520. bl /= ratio;
  7521. }
  7522. const i = Math.floor(6 * h);
  7523. const v = 1 - bl;
  7524. f = 6 * h - i;
  7525. if ((i & 0x01) !== 0) {
  7526. f = 1 - f;
  7527. }
  7528. const n = wh + f * (v - wh); // Linear interpolation
  7529. let r;
  7530. let g;
  7531. let b;
  7532. /* eslint-disable max-statements-per-line,no-multi-spaces */
  7533. switch (i) {
  7534. default:
  7535. case 6:
  7536. case 0:
  7537. r = v;
  7538. g = n;
  7539. b = wh;
  7540. break;
  7541. case 1:
  7542. r = n;
  7543. g = v;
  7544. b = wh;
  7545. break;
  7546. case 2:
  7547. r = wh;
  7548. g = v;
  7549. b = n;
  7550. break;
  7551. case 3:
  7552. r = wh;
  7553. g = n;
  7554. b = v;
  7555. break;
  7556. case 4:
  7557. r = n;
  7558. g = wh;
  7559. b = v;
  7560. break;
  7561. case 5:
  7562. r = v;
  7563. g = wh;
  7564. b = n;
  7565. break;
  7566. }
  7567. /* eslint-enable max-statements-per-line,no-multi-spaces */
  7568. return [r * 255, g * 255, b * 255];
  7569. };
  7570. convert$1.cmyk.rgb = function (cmyk) {
  7571. const c = cmyk[0] / 100;
  7572. const m = cmyk[1] / 100;
  7573. const y = cmyk[2] / 100;
  7574. const k = cmyk[3] / 100;
  7575. const r = 1 - Math.min(1, c * (1 - k) + k);
  7576. const g = 1 - Math.min(1, m * (1 - k) + k);
  7577. const b = 1 - Math.min(1, y * (1 - k) + k);
  7578. return [r * 255, g * 255, b * 255];
  7579. };
  7580. convert$1.xyz.rgb = function (xyz) {
  7581. const x = xyz[0] / 100;
  7582. const y = xyz[1] / 100;
  7583. const z = xyz[2] / 100;
  7584. let r;
  7585. let g;
  7586. let b;
  7587. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  7588. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  7589. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // Assume sRGB
  7590. r = r > 0.0031308 ? 1.055 * r ** (1.0 / 2.4) - 0.055 : r * 12.92;
  7591. g = g > 0.0031308 ? 1.055 * g ** (1.0 / 2.4) - 0.055 : g * 12.92;
  7592. b = b > 0.0031308 ? 1.055 * b ** (1.0 / 2.4) - 0.055 : b * 12.92;
  7593. r = Math.min(Math.max(0, r), 1);
  7594. g = Math.min(Math.max(0, g), 1);
  7595. b = Math.min(Math.max(0, b), 1);
  7596. return [r * 255, g * 255, b * 255];
  7597. };
  7598. convert$1.xyz.lab = function (xyz) {
  7599. let x = xyz[0];
  7600. let y = xyz[1];
  7601. let z = xyz[2];
  7602. x /= 95.047;
  7603. y /= 100;
  7604. z /= 108.883;
  7605. x = x > 0.008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
  7606. y = y > 0.008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
  7607. z = z > 0.008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
  7608. const l = 116 * y - 16;
  7609. const a = 500 * (x - y);
  7610. const b = 200 * (y - z);
  7611. return [l, a, b];
  7612. };
  7613. convert$1.lab.xyz = function (lab) {
  7614. const l = lab[0];
  7615. const a = lab[1];
  7616. const b = lab[2];
  7617. let x;
  7618. let y;
  7619. let z;
  7620. y = (l + 16) / 116;
  7621. x = a / 500 + y;
  7622. z = y - b / 200;
  7623. const y2 = y ** 3;
  7624. const x2 = x ** 3;
  7625. const z2 = z ** 3;
  7626. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  7627. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  7628. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  7629. x *= 95.047;
  7630. y *= 100;
  7631. z *= 108.883;
  7632. return [x, y, z];
  7633. };
  7634. convert$1.lab.lch = function (lab) {
  7635. const l = lab[0];
  7636. const a = lab[1];
  7637. const b = lab[2];
  7638. let h;
  7639. const hr = Math.atan2(b, a);
  7640. h = hr * 360 / 2 / Math.PI;
  7641. if (h < 0) {
  7642. h += 360;
  7643. }
  7644. const c = Math.sqrt(a * a + b * b);
  7645. return [l, c, h];
  7646. };
  7647. convert$1.lch.lab = function (lch) {
  7648. const l = lch[0];
  7649. const c = lch[1];
  7650. const h = lch[2];
  7651. const hr = h / 360 * 2 * Math.PI;
  7652. const a = c * Math.cos(hr);
  7653. const b = c * Math.sin(hr);
  7654. return [l, a, b];
  7655. };
  7656. convert$1.rgb.ansi16 = function (args, saturation = null) {
  7657. const [r, g, b] = args;
  7658. let value = saturation === null ? convert$1.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
  7659. value = Math.round(value / 50);
  7660. if (value === 0) {
  7661. return 30;
  7662. }
  7663. let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  7664. if (value === 2) {
  7665. ansi += 60;
  7666. }
  7667. return ansi;
  7668. };
  7669. convert$1.hsv.ansi16 = function (args) {
  7670. // Optimization here; we already know the value and don't need to get
  7671. // it converted for us.
  7672. return convert$1.rgb.ansi16(convert$1.hsv.rgb(args), args[2]);
  7673. };
  7674. convert$1.rgb.ansi256 = function (args) {
  7675. const r = args[0];
  7676. const g = args[1];
  7677. const b = args[2]; // We use the extended greyscale palette here, with the exception of
  7678. // black and white. normal palette only has 4 greyscale shades.
  7679. if (r === g && g === b) {
  7680. if (r < 8) {
  7681. return 16;
  7682. }
  7683. if (r > 248) {
  7684. return 231;
  7685. }
  7686. return Math.round((r - 8) / 247 * 24) + 232;
  7687. }
  7688. const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  7689. return ansi;
  7690. };
  7691. convert$1.ansi16.rgb = function (args) {
  7692. let color = args % 10; // Handle greyscale
  7693. if (color === 0 || color === 7) {
  7694. if (args > 50) {
  7695. color += 3.5;
  7696. }
  7697. color = color / 10.5 * 255;
  7698. return [color, color, color];
  7699. }
  7700. const mult = (~~(args > 50) + 1) * 0.5;
  7701. const r = (color & 1) * mult * 255;
  7702. const g = (color >> 1 & 1) * mult * 255;
  7703. const b = (color >> 2 & 1) * mult * 255;
  7704. return [r, g, b];
  7705. };
  7706. convert$1.ansi256.rgb = function (args) {
  7707. // Handle greyscale
  7708. if (args >= 232) {
  7709. const c = (args - 232) * 10 + 8;
  7710. return [c, c, c];
  7711. }
  7712. args -= 16;
  7713. let rem;
  7714. const r = Math.floor(args / 36) / 5 * 255;
  7715. const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  7716. const b = rem % 6 / 5 * 255;
  7717. return [r, g, b];
  7718. };
  7719. convert$1.rgb.hex = function (args) {
  7720. const integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  7721. const string = integer.toString(16).toUpperCase();
  7722. return '000000'.substring(string.length) + string;
  7723. };
  7724. convert$1.hex.rgb = function (args) {
  7725. const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  7726. if (!match) {
  7727. return [0, 0, 0];
  7728. }
  7729. let colorString = match[0];
  7730. if (match[0].length === 3) {
  7731. colorString = colorString.split('').map(char => {
  7732. return char + char;
  7733. }).join('');
  7734. }
  7735. const integer = parseInt(colorString, 16);
  7736. const r = integer >> 16 & 0xFF;
  7737. const g = integer >> 8 & 0xFF;
  7738. const b = integer & 0xFF;
  7739. return [r, g, b];
  7740. };
  7741. convert$1.rgb.hcg = function (rgb) {
  7742. const r = rgb[0] / 255;
  7743. const g = rgb[1] / 255;
  7744. const b = rgb[2] / 255;
  7745. const max = Math.max(Math.max(r, g), b);
  7746. const min = Math.min(Math.min(r, g), b);
  7747. const chroma = max - min;
  7748. let grayscale;
  7749. let hue;
  7750. if (chroma < 1) {
  7751. grayscale = min / (1 - chroma);
  7752. } else {
  7753. grayscale = 0;
  7754. }
  7755. if (chroma <= 0) {
  7756. hue = 0;
  7757. } else if (max === r) {
  7758. hue = (g - b) / chroma % 6;
  7759. } else if (max === g) {
  7760. hue = 2 + (b - r) / chroma;
  7761. } else {
  7762. hue = 4 + (r - g) / chroma;
  7763. }
  7764. hue /= 6;
  7765. hue %= 1;
  7766. return [hue * 360, chroma * 100, grayscale * 100];
  7767. };
  7768. convert$1.hsl.hcg = function (hsl) {
  7769. const s = hsl[1] / 100;
  7770. const l = hsl[2] / 100;
  7771. const c = l < 0.5 ? 2.0 * s * l : 2.0 * s * (1.0 - l);
  7772. let f = 0;
  7773. if (c < 1.0) {
  7774. f = (l - 0.5 * c) / (1.0 - c);
  7775. }
  7776. return [hsl[0], c * 100, f * 100];
  7777. };
  7778. convert$1.hsv.hcg = function (hsv) {
  7779. const s = hsv[1] / 100;
  7780. const v = hsv[2] / 100;
  7781. const c = s * v;
  7782. let f = 0;
  7783. if (c < 1.0) {
  7784. f = (v - c) / (1 - c);
  7785. }
  7786. return [hsv[0], c * 100, f * 100];
  7787. };
  7788. convert$1.hcg.rgb = function (hcg) {
  7789. const h = hcg[0] / 360;
  7790. const c = hcg[1] / 100;
  7791. const g = hcg[2] / 100;
  7792. if (c === 0.0) {
  7793. return [g * 255, g * 255, g * 255];
  7794. }
  7795. const pure = [0, 0, 0];
  7796. const hi = h % 1 * 6;
  7797. const v = hi % 1;
  7798. const w = 1 - v;
  7799. let mg = 0;
  7800. /* eslint-disable max-statements-per-line */
  7801. switch (Math.floor(hi)) {
  7802. case 0:
  7803. pure[0] = 1;
  7804. pure[1] = v;
  7805. pure[2] = 0;
  7806. break;
  7807. case 1:
  7808. pure[0] = w;
  7809. pure[1] = 1;
  7810. pure[2] = 0;
  7811. break;
  7812. case 2:
  7813. pure[0] = 0;
  7814. pure[1] = 1;
  7815. pure[2] = v;
  7816. break;
  7817. case 3:
  7818. pure[0] = 0;
  7819. pure[1] = w;
  7820. pure[2] = 1;
  7821. break;
  7822. case 4:
  7823. pure[0] = v;
  7824. pure[1] = 0;
  7825. pure[2] = 1;
  7826. break;
  7827. default:
  7828. pure[0] = 1;
  7829. pure[1] = 0;
  7830. pure[2] = w;
  7831. }
  7832. /* eslint-enable max-statements-per-line */
  7833. mg = (1.0 - c) * g;
  7834. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  7835. };
  7836. convert$1.hcg.hsv = function (hcg) {
  7837. const c = hcg[1] / 100;
  7838. const g = hcg[2] / 100;
  7839. const v = c + g * (1.0 - c);
  7840. let f = 0;
  7841. if (v > 0.0) {
  7842. f = c / v;
  7843. }
  7844. return [hcg[0], f * 100, v * 100];
  7845. };
  7846. convert$1.hcg.hsl = function (hcg) {
  7847. const c = hcg[1] / 100;
  7848. const g = hcg[2] / 100;
  7849. const l = g * (1.0 - c) + 0.5 * c;
  7850. let s = 0;
  7851. if (l > 0.0 && l < 0.5) {
  7852. s = c / (2 * l);
  7853. } else if (l >= 0.5 && l < 1.0) {
  7854. s = c / (2 * (1 - l));
  7855. }
  7856. return [hcg[0], s * 100, l * 100];
  7857. };
  7858. convert$1.hcg.hwb = function (hcg) {
  7859. const c = hcg[1] / 100;
  7860. const g = hcg[2] / 100;
  7861. const v = c + g * (1.0 - c);
  7862. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  7863. };
  7864. convert$1.hwb.hcg = function (hwb) {
  7865. const w = hwb[1] / 100;
  7866. const b = hwb[2] / 100;
  7867. const v = 1 - b;
  7868. const c = v - w;
  7869. let g = 0;
  7870. if (c < 1) {
  7871. g = (v - c) / (1 - c);
  7872. }
  7873. return [hwb[0], c * 100, g * 100];
  7874. };
  7875. convert$1.apple.rgb = function (apple) {
  7876. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  7877. };
  7878. convert$1.rgb.apple = function (rgb) {
  7879. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  7880. };
  7881. convert$1.gray.rgb = function (args) {
  7882. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  7883. };
  7884. convert$1.gray.hsl = function (args) {
  7885. return [0, 0, args[0]];
  7886. };
  7887. convert$1.gray.hsv = convert$1.gray.hsl;
  7888. convert$1.gray.hwb = function (gray) {
  7889. return [0, 100, gray[0]];
  7890. };
  7891. convert$1.gray.cmyk = function (gray) {
  7892. return [0, 0, 0, gray[0]];
  7893. };
  7894. convert$1.gray.lab = function (gray) {
  7895. return [gray[0], 0, 0];
  7896. };
  7897. convert$1.gray.hex = function (gray) {
  7898. const val = Math.round(gray[0] / 100 * 255) & 0xFF;
  7899. const integer = (val << 16) + (val << 8) + val;
  7900. const string = integer.toString(16).toUpperCase();
  7901. return '000000'.substring(string.length) + string;
  7902. };
  7903. convert$1.rgb.gray = function (rgb) {
  7904. const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  7905. return [val / 255 * 100];
  7906. };
  7907. /*
  7908. This function routes a model to all other models.
  7909. all functions that are routed have a property `.conversion` attached
  7910. to the returned synthetic function. This property is an array
  7911. of strings, each with the steps in between the 'from' and 'to'
  7912. color models (inclusive).
  7913. conversions that are not possible simply are not included.
  7914. */
  7915. function buildGraph$1() {
  7916. const graph = {}; // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  7917. const models = Object.keys(conversions$1);
  7918. for (let len = models.length, i = 0; i < len; i++) {
  7919. graph[models[i]] = {
  7920. // http://jsperf.com/1-vs-infinity
  7921. // micro-opt, but this is simple.
  7922. distance: -1,
  7923. parent: null
  7924. };
  7925. }
  7926. return graph;
  7927. } // https://en.wikipedia.org/wiki/Breadth-first_search
  7928. function deriveBFS$1(fromModel) {
  7929. const graph = buildGraph$1();
  7930. const queue = [fromModel]; // Unshift -> queue -> pop
  7931. graph[fromModel].distance = 0;
  7932. while (queue.length) {
  7933. const current = queue.pop();
  7934. const adjacents = Object.keys(conversions$1[current]);
  7935. for (let len = adjacents.length, i = 0; i < len; i++) {
  7936. const adjacent = adjacents[i];
  7937. const node = graph[adjacent];
  7938. if (node.distance === -1) {
  7939. node.distance = graph[current].distance + 1;
  7940. node.parent = current;
  7941. queue.unshift(adjacent);
  7942. }
  7943. }
  7944. }
  7945. return graph;
  7946. }
  7947. function link$1(from, to) {
  7948. return function (args) {
  7949. return to(from(args));
  7950. };
  7951. }
  7952. function wrapConversion$1(toModel, graph) {
  7953. const path = [graph[toModel].parent, toModel];
  7954. let fn = conversions$1[graph[toModel].parent][toModel];
  7955. let cur = graph[toModel].parent;
  7956. while (graph[cur].parent) {
  7957. path.unshift(graph[cur].parent);
  7958. fn = link$1(conversions$1[graph[cur].parent][cur], fn);
  7959. cur = graph[cur].parent;
  7960. }
  7961. fn.conversion = path;
  7962. return fn;
  7963. }
  7964. var route$1 = function (fromModel) {
  7965. const graph = deriveBFS$1(fromModel);
  7966. const conversion = {};
  7967. const models = Object.keys(graph);
  7968. for (let len = models.length, i = 0; i < len; i++) {
  7969. const toModel = models[i];
  7970. const node = graph[toModel];
  7971. if (node.parent === null) {
  7972. // No possible conversion, or this node is the source model.
  7973. continue;
  7974. }
  7975. conversion[toModel] = wrapConversion$1(toModel, graph);
  7976. }
  7977. return conversion;
  7978. };
  7979. const convert$2 = {};
  7980. const models$1 = Object.keys(conversions$1);
  7981. function wrapRaw$1(fn) {
  7982. const wrappedFn = function (...args) {
  7983. const arg0 = args[0];
  7984. if (arg0 === undefined || arg0 === null) {
  7985. return arg0;
  7986. }
  7987. if (arg0.length > 1) {
  7988. args = arg0;
  7989. }
  7990. return fn(args);
  7991. }; // Preserve .conversion property if there is one
  7992. if ('conversion' in fn) {
  7993. wrappedFn.conversion = fn.conversion;
  7994. }
  7995. return wrappedFn;
  7996. }
  7997. function wrapRounded$1(fn) {
  7998. const wrappedFn = function (...args) {
  7999. const arg0 = args[0];
  8000. if (arg0 === undefined || arg0 === null) {
  8001. return arg0;
  8002. }
  8003. if (arg0.length > 1) {
  8004. args = arg0;
  8005. }
  8006. const result = fn(args); // We're assuming the result is an array here.
  8007. // see notice in conversions.js; don't use box types
  8008. // in conversion functions.
  8009. if (typeof result === 'object') {
  8010. for (let len = result.length, i = 0; i < len; i++) {
  8011. result[i] = Math.round(result[i]);
  8012. }
  8013. }
  8014. return result;
  8015. }; // Preserve .conversion property if there is one
  8016. if ('conversion' in fn) {
  8017. wrappedFn.conversion = fn.conversion;
  8018. }
  8019. return wrappedFn;
  8020. }
  8021. models$1.forEach(fromModel => {
  8022. convert$2[fromModel] = {};
  8023. Object.defineProperty(convert$2[fromModel], 'channels', {
  8024. value: conversions$1[fromModel].channels
  8025. });
  8026. Object.defineProperty(convert$2[fromModel], 'labels', {
  8027. value: conversions$1[fromModel].labels
  8028. });
  8029. const routes = route$1(fromModel);
  8030. const routeModels = Object.keys(routes);
  8031. routeModels.forEach(toModel => {
  8032. const fn = routes[toModel];
  8033. convert$2[fromModel][toModel] = wrapRounded$1(fn);
  8034. convert$2[fromModel][toModel].raw = wrapRaw$1(fn);
  8035. });
  8036. });
  8037. var colorConvert$1 = convert$2;
  8038. var ansiStyles$1 = createCommonjsModule(function (module) {
  8039. const wrapAnsi16 = (fn, offset) => (...args) => {
  8040. const code = fn(...args);
  8041. return `\u001B[${code + offset}m`;
  8042. };
  8043. const wrapAnsi256 = (fn, offset) => (...args) => {
  8044. const code = fn(...args);
  8045. return `\u001B[${38 + offset};5;${code}m`;
  8046. };
  8047. const wrapAnsi16m = (fn, offset) => (...args) => {
  8048. const rgb = fn(...args);
  8049. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  8050. };
  8051. const ansi2ansi = n => n;
  8052. const rgb2rgb = (r, g, b) => [r, g, b];
  8053. const setLazyProperty = (object, property, get) => {
  8054. Object.defineProperty(object, property, {
  8055. get: () => {
  8056. const value = get();
  8057. Object.defineProperty(object, property, {
  8058. value,
  8059. enumerable: true,
  8060. configurable: true
  8061. });
  8062. return value;
  8063. },
  8064. enumerable: true,
  8065. configurable: true
  8066. });
  8067. };
  8068. /** @type {typeof import('color-convert')} */
  8069. let colorConvert;
  8070. const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
  8071. if (colorConvert === undefined) {
  8072. colorConvert = colorConvert$1;
  8073. }
  8074. const offset = isBackground ? 10 : 0;
  8075. const styles = {};
  8076. for (const [sourceSpace, suite] of Object.entries(colorConvert)) {
  8077. const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
  8078. if (sourceSpace === targetSpace) {
  8079. styles[name] = wrap(identity, offset);
  8080. } else if (typeof suite === 'object') {
  8081. styles[name] = wrap(suite[targetSpace], offset);
  8082. }
  8083. }
  8084. return styles;
  8085. };
  8086. function assembleStyles() {
  8087. const codes = new Map();
  8088. const styles = {
  8089. modifier: {
  8090. reset: [0, 0],
  8091. // 21 isn't widely supported and 22 does the same thing
  8092. bold: [1, 22],
  8093. dim: [2, 22],
  8094. italic: [3, 23],
  8095. underline: [4, 24],
  8096. inverse: [7, 27],
  8097. hidden: [8, 28],
  8098. strikethrough: [9, 29]
  8099. },
  8100. color: {
  8101. black: [30, 39],
  8102. red: [31, 39],
  8103. green: [32, 39],
  8104. yellow: [33, 39],
  8105. blue: [34, 39],
  8106. magenta: [35, 39],
  8107. cyan: [36, 39],
  8108. white: [37, 39],
  8109. // Bright color
  8110. blackBright: [90, 39],
  8111. redBright: [91, 39],
  8112. greenBright: [92, 39],
  8113. yellowBright: [93, 39],
  8114. blueBright: [94, 39],
  8115. magentaBright: [95, 39],
  8116. cyanBright: [96, 39],
  8117. whiteBright: [97, 39]
  8118. },
  8119. bgColor: {
  8120. bgBlack: [40, 49],
  8121. bgRed: [41, 49],
  8122. bgGreen: [42, 49],
  8123. bgYellow: [43, 49],
  8124. bgBlue: [44, 49],
  8125. bgMagenta: [45, 49],
  8126. bgCyan: [46, 49],
  8127. bgWhite: [47, 49],
  8128. // Bright color
  8129. bgBlackBright: [100, 49],
  8130. bgRedBright: [101, 49],
  8131. bgGreenBright: [102, 49],
  8132. bgYellowBright: [103, 49],
  8133. bgBlueBright: [104, 49],
  8134. bgMagentaBright: [105, 49],
  8135. bgCyanBright: [106, 49],
  8136. bgWhiteBright: [107, 49]
  8137. }
  8138. }; // Alias bright black as gray (and grey)
  8139. styles.color.gray = styles.color.blackBright;
  8140. styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
  8141. styles.color.grey = styles.color.blackBright;
  8142. styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
  8143. for (const [groupName, group] of Object.entries(styles)) {
  8144. for (const [styleName, style] of Object.entries(group)) {
  8145. styles[styleName] = {
  8146. open: `\u001B[${style[0]}m`,
  8147. close: `\u001B[${style[1]}m`
  8148. };
  8149. group[styleName] = styles[styleName];
  8150. codes.set(style[0], style[1]);
  8151. }
  8152. Object.defineProperty(styles, groupName, {
  8153. value: group,
  8154. enumerable: false
  8155. });
  8156. }
  8157. Object.defineProperty(styles, 'codes', {
  8158. value: codes,
  8159. enumerable: false
  8160. });
  8161. styles.color.close = '\u001B[39m';
  8162. styles.bgColor.close = '\u001B[49m';
  8163. setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
  8164. setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
  8165. setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
  8166. setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
  8167. setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
  8168. setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
  8169. return styles;
  8170. } // Make the export immutable
  8171. Object.defineProperty(module, 'exports', {
  8172. enumerable: true,
  8173. get: assembleStyles
  8174. });
  8175. });
  8176. var hasFlag$1 = (flag, argv = process.argv) => {
  8177. const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  8178. const position = argv.indexOf(prefix + flag);
  8179. const terminatorPosition = argv.indexOf('--');
  8180. return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
  8181. };
  8182. const {
  8183. env: env$1
  8184. } = process;
  8185. let forceColor$1;
  8186. if (hasFlag$1('no-color') || hasFlag$1('no-colors') || hasFlag$1('color=false') || hasFlag$1('color=never')) {
  8187. forceColor$1 = 0;
  8188. } else if (hasFlag$1('color') || hasFlag$1('colors') || hasFlag$1('color=true') || hasFlag$1('color=always')) {
  8189. forceColor$1 = 1;
  8190. }
  8191. if ('FORCE_COLOR' in env$1) {
  8192. if (env$1.FORCE_COLOR === 'true') {
  8193. forceColor$1 = 1;
  8194. } else if (env$1.FORCE_COLOR === 'false') {
  8195. forceColor$1 = 0;
  8196. } else {
  8197. forceColor$1 = env$1.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env$1.FORCE_COLOR, 10), 3);
  8198. }
  8199. }
  8200. function translateLevel$1(level) {
  8201. if (level === 0) {
  8202. return false;
  8203. }
  8204. return {
  8205. level,
  8206. hasBasic: true,
  8207. has256: level >= 2,
  8208. has16m: level >= 3
  8209. };
  8210. }
  8211. function supportsColor$1(haveStream, streamIsTTY) {
  8212. if (forceColor$1 === 0) {
  8213. return 0;
  8214. }
  8215. if (hasFlag$1('color=16m') || hasFlag$1('color=full') || hasFlag$1('color=truecolor')) {
  8216. return 3;
  8217. }
  8218. if (hasFlag$1('color=256')) {
  8219. return 2;
  8220. }
  8221. if (haveStream && !streamIsTTY && forceColor$1 === undefined) {
  8222. return 0;
  8223. }
  8224. const min = forceColor$1 || 0;
  8225. if (env$1.TERM === 'dumb') {
  8226. return min;
  8227. }
  8228. if (process.platform === 'win32') {
  8229. // Windows 10 build 10586 is the first Windows release that supports 256 colors.
  8230. // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
  8231. const osRelease = os__default['default'].release().split('.');
  8232. if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  8233. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  8234. }
  8235. return 1;
  8236. }
  8237. if ('CI' in env$1) {
  8238. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env$1) || env$1.CI_NAME === 'codeship') {
  8239. return 1;
  8240. }
  8241. return min;
  8242. }
  8243. if ('TEAMCITY_VERSION' in env$1) {
  8244. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env$1.TEAMCITY_VERSION) ? 1 : 0;
  8245. }
  8246. if ('GITHUB_ACTIONS' in env$1) {
  8247. return 1;
  8248. }
  8249. if (env$1.COLORTERM === 'truecolor') {
  8250. return 3;
  8251. }
  8252. if ('TERM_PROGRAM' in env$1) {
  8253. const version = parseInt((env$1.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  8254. switch (env$1.TERM_PROGRAM) {
  8255. case 'iTerm.app':
  8256. return version >= 3 ? 3 : 2;
  8257. case 'Apple_Terminal':
  8258. return 2;
  8259. // No default
  8260. }
  8261. }
  8262. if (/-256(color)?$/i.test(env$1.TERM)) {
  8263. return 2;
  8264. }
  8265. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env$1.TERM)) {
  8266. return 1;
  8267. }
  8268. if ('COLORTERM' in env$1) {
  8269. return 1;
  8270. }
  8271. return min;
  8272. }
  8273. function getSupportLevel$1(stream) {
  8274. const level = supportsColor$1(stream, stream && stream.isTTY);
  8275. return translateLevel$1(level);
  8276. }
  8277. var supportsColor_1$1 = {
  8278. supportsColor: getSupportLevel$1,
  8279. stdout: translateLevel$1(supportsColor$1(true, tty__default['default'].isatty(1))),
  8280. stderr: translateLevel$1(supportsColor$1(true, tty__default['default'].isatty(2)))
  8281. };
  8282. const stringReplaceAll = (string, substring, replacer) => {
  8283. let index = string.indexOf(substring);
  8284. if (index === -1) {
  8285. return string;
  8286. }
  8287. const substringLength = substring.length;
  8288. let endIndex = 0;
  8289. let returnValue = '';
  8290. do {
  8291. returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
  8292. endIndex = index + substringLength;
  8293. index = string.indexOf(substring, endIndex);
  8294. } while (index !== -1);
  8295. returnValue += string.substr(endIndex);
  8296. return returnValue;
  8297. };
  8298. const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
  8299. let endIndex = 0;
  8300. let returnValue = '';
  8301. do {
  8302. const gotCR = string[index - 1] === '\r';
  8303. returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
  8304. endIndex = index + 1;
  8305. index = string.indexOf('\n', endIndex);
  8306. } while (index !== -1);
  8307. returnValue += string.substr(endIndex);
  8308. return returnValue;
  8309. };
  8310. var util$1 = {
  8311. stringReplaceAll,
  8312. stringEncaseCRLFWithFirstIndex
  8313. };
  8314. const TEMPLATE_REGEX$1 = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  8315. const STYLE_REGEX$1 = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  8316. const STRING_REGEX$1 = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  8317. const ESCAPE_REGEX$1 = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
  8318. const ESCAPES$1 = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  8319. function unescape$1(c) {
  8320. const u = c[0] === 'u';
  8321. const bracket = c[1] === '{';
  8322. if (u && !bracket && c.length === 5 || c[0] === 'x' && c.length === 3) {
  8323. return String.fromCharCode(parseInt(c.slice(1), 16));
  8324. }
  8325. if (u && bracket) {
  8326. return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
  8327. }
  8328. return ESCAPES$1.get(c) || c;
  8329. }
  8330. function parseArguments$1(name, arguments_) {
  8331. const results = [];
  8332. const chunks = arguments_.trim().split(/\s*,\s*/g);
  8333. let matches;
  8334. for (const chunk of chunks) {
  8335. const number = Number(chunk);
  8336. if (!Number.isNaN(number)) {
  8337. results.push(number);
  8338. } else if (matches = chunk.match(STRING_REGEX$1)) {
  8339. results.push(matches[2].replace(ESCAPE_REGEX$1, (m, escape, character) => escape ? unescape$1(escape) : character));
  8340. } else {
  8341. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  8342. }
  8343. }
  8344. return results;
  8345. }
  8346. function parseStyle$1(style) {
  8347. STYLE_REGEX$1.lastIndex = 0;
  8348. const results = [];
  8349. let matches;
  8350. while ((matches = STYLE_REGEX$1.exec(style)) !== null) {
  8351. const name = matches[1];
  8352. if (matches[2]) {
  8353. const args = parseArguments$1(name, matches[2]);
  8354. results.push([name].concat(args));
  8355. } else {
  8356. results.push([name]);
  8357. }
  8358. }
  8359. return results;
  8360. }
  8361. function buildStyle$1(chalk, styles) {
  8362. const enabled = {};
  8363. for (const layer of styles) {
  8364. for (const style of layer.styles) {
  8365. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  8366. }
  8367. }
  8368. let current = chalk;
  8369. for (const [styleName, styles] of Object.entries(enabled)) {
  8370. if (!Array.isArray(styles)) {
  8371. continue;
  8372. }
  8373. if (!(styleName in current)) {
  8374. throw new Error(`Unknown Chalk style: ${styleName}`);
  8375. }
  8376. current = styles.length > 0 ? current[styleName](...styles) : current[styleName];
  8377. }
  8378. return current;
  8379. }
  8380. var templates$1 = (chalk, temporary) => {
  8381. const styles = [];
  8382. const chunks = [];
  8383. let chunk = []; // eslint-disable-next-line max-params
  8384. temporary.replace(TEMPLATE_REGEX$1, (m, escapeCharacter, inverse, style, close, character) => {
  8385. if (escapeCharacter) {
  8386. chunk.push(unescape$1(escapeCharacter));
  8387. } else if (style) {
  8388. const string = chunk.join('');
  8389. chunk = [];
  8390. chunks.push(styles.length === 0 ? string : buildStyle$1(chalk, styles)(string));
  8391. styles.push({
  8392. inverse,
  8393. styles: parseStyle$1(style)
  8394. });
  8395. } else if (close) {
  8396. if (styles.length === 0) {
  8397. throw new Error('Found extraneous } in Chalk template literal');
  8398. }
  8399. chunks.push(buildStyle$1(chalk, styles)(chunk.join('')));
  8400. chunk = [];
  8401. styles.pop();
  8402. } else {
  8403. chunk.push(character);
  8404. }
  8405. });
  8406. chunks.push(chunk.join(''));
  8407. if (styles.length > 0) {
  8408. const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  8409. throw new Error(errMessage);
  8410. }
  8411. return chunks.join('');
  8412. };
  8413. const {
  8414. stdout: stdoutColor,
  8415. stderr: stderrColor
  8416. } = supportsColor_1$1;
  8417. const {
  8418. stringReplaceAll: stringReplaceAll$1,
  8419. stringEncaseCRLFWithFirstIndex: stringEncaseCRLFWithFirstIndex$1
  8420. } = util$1;
  8421. const {
  8422. isArray
  8423. } = Array; // `supportsColor.level` → `ansiStyles.color[name]` mapping
  8424. const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
  8425. const styles = Object.create(null);
  8426. const applyOptions = (object, options = {}) => {
  8427. if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
  8428. throw new Error('The `level` option should be an integer from 0 to 3');
  8429. } // Detect level if not set manually
  8430. const colorLevel = stdoutColor ? stdoutColor.level : 0;
  8431. object.level = options.level === undefined ? colorLevel : options.level;
  8432. };
  8433. class ChalkClass {
  8434. constructor(options) {
  8435. // eslint-disable-next-line no-constructor-return
  8436. return chalkFactory(options);
  8437. }
  8438. }
  8439. const chalkFactory = options => {
  8440. const chalk = {};
  8441. applyOptions(chalk, options);
  8442. chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_);
  8443. Object.setPrototypeOf(chalk, Chalk.prototype);
  8444. Object.setPrototypeOf(chalk.template, chalk);
  8445. chalk.template.constructor = () => {
  8446. throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
  8447. };
  8448. chalk.template.Instance = ChalkClass;
  8449. return chalk.template;
  8450. };
  8451. function Chalk(options) {
  8452. return chalkFactory(options);
  8453. }
  8454. for (const [styleName, style] of Object.entries(ansiStyles$1)) {
  8455. styles[styleName] = {
  8456. get() {
  8457. const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
  8458. Object.defineProperty(this, styleName, {
  8459. value: builder
  8460. });
  8461. return builder;
  8462. }
  8463. };
  8464. }
  8465. styles.visible = {
  8466. get() {
  8467. const builder = createBuilder(this, this._styler, true);
  8468. Object.defineProperty(this, 'visible', {
  8469. value: builder
  8470. });
  8471. return builder;
  8472. }
  8473. };
  8474. const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256'];
  8475. for (const model of usedModels) {
  8476. styles[model] = {
  8477. get() {
  8478. const {
  8479. level
  8480. } = this;
  8481. return function (...arguments_) {
  8482. const styler = createStyler(ansiStyles$1.color[levelMapping[level]][model](...arguments_), ansiStyles$1.color.close, this._styler);
  8483. return createBuilder(this, styler, this._isEmpty);
  8484. };
  8485. }
  8486. };
  8487. }
  8488. for (const model of usedModels) {
  8489. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  8490. styles[bgModel] = {
  8491. get() {
  8492. const {
  8493. level
  8494. } = this;
  8495. return function (...arguments_) {
  8496. const styler = createStyler(ansiStyles$1.bgColor[levelMapping[level]][model](...arguments_), ansiStyles$1.bgColor.close, this._styler);
  8497. return createBuilder(this, styler, this._isEmpty);
  8498. };
  8499. }
  8500. };
  8501. }
  8502. const proto = Object.defineProperties(() => {}, Object.assign({}, styles, {
  8503. level: {
  8504. enumerable: true,
  8505. get() {
  8506. return this._generator.level;
  8507. },
  8508. set(level) {
  8509. this._generator.level = level;
  8510. }
  8511. }
  8512. }));
  8513. const createStyler = (open, close, parent) => {
  8514. let openAll;
  8515. let closeAll;
  8516. if (parent === undefined) {
  8517. openAll = open;
  8518. closeAll = close;
  8519. } else {
  8520. openAll = parent.openAll + open;
  8521. closeAll = close + parent.closeAll;
  8522. }
  8523. return {
  8524. open,
  8525. close,
  8526. openAll,
  8527. closeAll,
  8528. parent
  8529. };
  8530. };
  8531. const createBuilder = (self, _styler, _isEmpty) => {
  8532. const builder = (...arguments_) => {
  8533. if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
  8534. // Called as a template literal, for example: chalk.red`2 + 3 = {bold ${2+3}}`
  8535. return applyStyle(builder, chalkTag(builder, ...arguments_));
  8536. } // Single argument is hot path, implicit coercion is faster than anything
  8537. // eslint-disable-next-line no-implicit-coercion
  8538. return applyStyle(builder, arguments_.length === 1 ? '' + arguments_[0] : arguments_.join(' '));
  8539. }; // We alter the prototype because we must return a function, but there is
  8540. // no way to create a function with a different prototype
  8541. Object.setPrototypeOf(builder, proto);
  8542. builder._generator = self;
  8543. builder._styler = _styler;
  8544. builder._isEmpty = _isEmpty;
  8545. return builder;
  8546. };
  8547. const applyStyle = (self, string) => {
  8548. if (self.level <= 0 || !string) {
  8549. return self._isEmpty ? '' : string;
  8550. }
  8551. let styler = self._styler;
  8552. if (styler === undefined) {
  8553. return string;
  8554. }
  8555. const {
  8556. openAll,
  8557. closeAll
  8558. } = styler;
  8559. if (string.indexOf('\u001B') !== -1) {
  8560. while (styler !== undefined) {
  8561. // Replace any instances already present with a re-opening code
  8562. // otherwise only the part of the string until said closing code
  8563. // will be colored, and the rest will simply be 'plain'.
  8564. string = stringReplaceAll$1(string, styler.close, styler.open);
  8565. styler = styler.parent;
  8566. }
  8567. } // We can move both next actions out of loop, because remaining actions in loop won't have
  8568. // any/visible effect on parts we add here. Close the styling before a linebreak and reopen
  8569. // after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
  8570. const lfIndex = string.indexOf('\n');
  8571. if (lfIndex !== -1) {
  8572. string = stringEncaseCRLFWithFirstIndex$1(string, closeAll, openAll, lfIndex);
  8573. }
  8574. return openAll + string + closeAll;
  8575. };
  8576. let template;
  8577. const chalkTag = (chalk, ...strings) => {
  8578. const [firstString] = strings;
  8579. if (!isArray(firstString) || !isArray(firstString.raw)) {
  8580. // If chalk() was called by itself or with a string,
  8581. // return the string itself as a string.
  8582. return strings.join(' ');
  8583. }
  8584. const arguments_ = strings.slice(1);
  8585. const parts = [firstString.raw[0]];
  8586. for (let i = 1; i < firstString.length; i++) {
  8587. parts.push(String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'), String(firstString.raw[i]));
  8588. }
  8589. if (template === undefined) {
  8590. template = templates$1;
  8591. }
  8592. return template(chalk, parts.join(''));
  8593. };
  8594. Object.defineProperties(Chalk.prototype, styles);
  8595. const chalk$1 = Chalk(); // eslint-disable-line new-cap
  8596. chalk$1.supportsColor = stdoutColor;
  8597. chalk$1.stderr = Chalk({
  8598. level: stderrColor ? stderrColor.level : 0
  8599. }); // eslint-disable-line new-cap
  8600. chalk$1.stderr.supportsColor = stderrColor;
  8601. var source = chalk$1;
  8602. /**
  8603. * Appends the elements of `values` to `array`.
  8604. *
  8605. * @private
  8606. * @param {Array} array The array to modify.
  8607. * @param {Array} values The values to append.
  8608. * @returns {Array} Returns `array`.
  8609. */
  8610. function arrayPush(array, values) {
  8611. var index = -1,
  8612. length = values.length,
  8613. offset = array.length;
  8614. while (++index < length) {
  8615. array[offset + index] = values[index];
  8616. }
  8617. return array;
  8618. }
  8619. var _arrayPush = arrayPush;
  8620. /** Detect free variable `global` from Node.js. */
  8621. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  8622. var _freeGlobal = freeGlobal;
  8623. /** Detect free variable `self`. */
  8624. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  8625. /** Used as a reference to the global object. */
  8626. var root = _freeGlobal || freeSelf || Function('return this')();
  8627. var _root = root;
  8628. /** Built-in value references. */
  8629. var Symbol$1 = _root.Symbol;
  8630. var _Symbol = Symbol$1;
  8631. /** Used for built-in method references. */
  8632. var objectProto = Object.prototype;
  8633. /** Used to check objects for own properties. */
  8634. var hasOwnProperty = objectProto.hasOwnProperty;
  8635. /**
  8636. * Used to resolve the
  8637. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  8638. * of values.
  8639. */
  8640. var nativeObjectToString = objectProto.toString;
  8641. /** Built-in value references. */
  8642. var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
  8643. /**
  8644. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  8645. *
  8646. * @private
  8647. * @param {*} value The value to query.
  8648. * @returns {string} Returns the raw `toStringTag`.
  8649. */
  8650. function getRawTag(value) {
  8651. var isOwn = hasOwnProperty.call(value, symToStringTag),
  8652. tag = value[symToStringTag];
  8653. try {
  8654. value[symToStringTag] = undefined;
  8655. var unmasked = true;
  8656. } catch (e) {}
  8657. var result = nativeObjectToString.call(value);
  8658. if (unmasked) {
  8659. if (isOwn) {
  8660. value[symToStringTag] = tag;
  8661. } else {
  8662. delete value[symToStringTag];
  8663. }
  8664. }
  8665. return result;
  8666. }
  8667. var _getRawTag = getRawTag;
  8668. /** Used for built-in method references. */
  8669. var objectProto$1 = Object.prototype;
  8670. /**
  8671. * Used to resolve the
  8672. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  8673. * of values.
  8674. */
  8675. var nativeObjectToString$1 = objectProto$1.toString;
  8676. /**
  8677. * Converts `value` to a string using `Object.prototype.toString`.
  8678. *
  8679. * @private
  8680. * @param {*} value The value to convert.
  8681. * @returns {string} Returns the converted string.
  8682. */
  8683. function objectToString(value) {
  8684. return nativeObjectToString$1.call(value);
  8685. }
  8686. var _objectToString = objectToString;
  8687. /** `Object#toString` result references. */
  8688. var nullTag = '[object Null]',
  8689. undefinedTag = '[object Undefined]';
  8690. /** Built-in value references. */
  8691. var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined;
  8692. /**
  8693. * The base implementation of `getTag` without fallbacks for buggy environments.
  8694. *
  8695. * @private
  8696. * @param {*} value The value to query.
  8697. * @returns {string} Returns the `toStringTag`.
  8698. */
  8699. function baseGetTag(value) {
  8700. if (value == null) {
  8701. return value === undefined ? undefinedTag : nullTag;
  8702. }
  8703. return symToStringTag$1 && symToStringTag$1 in Object(value) ? _getRawTag(value) : _objectToString(value);
  8704. }
  8705. var _baseGetTag = baseGetTag;
  8706. /**
  8707. * Checks if `value` is object-like. A value is object-like if it's not `null`
  8708. * and has a `typeof` result of "object".
  8709. *
  8710. * @static
  8711. * @memberOf _
  8712. * @since 4.0.0
  8713. * @category Lang
  8714. * @param {*} value The value to check.
  8715. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  8716. * @example
  8717. *
  8718. * _.isObjectLike({});
  8719. * // => true
  8720. *
  8721. * _.isObjectLike([1, 2, 3]);
  8722. * // => true
  8723. *
  8724. * _.isObjectLike(_.noop);
  8725. * // => false
  8726. *
  8727. * _.isObjectLike(null);
  8728. * // => false
  8729. */
  8730. function isObjectLike(value) {
  8731. return value != null && typeof value == 'object';
  8732. }
  8733. var isObjectLike_1 = isObjectLike;
  8734. /** `Object#toString` result references. */
  8735. var argsTag = '[object Arguments]';
  8736. /**
  8737. * The base implementation of `_.isArguments`.
  8738. *
  8739. * @private
  8740. * @param {*} value The value to check.
  8741. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  8742. */
  8743. function baseIsArguments(value) {
  8744. return isObjectLike_1(value) && _baseGetTag(value) == argsTag;
  8745. }
  8746. var _baseIsArguments = baseIsArguments;
  8747. /** Used for built-in method references. */
  8748. var objectProto$2 = Object.prototype;
  8749. /** Used to check objects for own properties. */
  8750. var hasOwnProperty$1 = objectProto$2.hasOwnProperty;
  8751. /** Built-in value references. */
  8752. var propertyIsEnumerable = objectProto$2.propertyIsEnumerable;
  8753. /**
  8754. * Checks if `value` is likely an `arguments` object.
  8755. *
  8756. * @static
  8757. * @memberOf _
  8758. * @since 0.1.0
  8759. * @category Lang
  8760. * @param {*} value The value to check.
  8761. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  8762. * else `false`.
  8763. * @example
  8764. *
  8765. * _.isArguments(function() { return arguments; }());
  8766. * // => true
  8767. *
  8768. * _.isArguments([1, 2, 3]);
  8769. * // => false
  8770. */
  8771. var isArguments = _baseIsArguments(function () {
  8772. return arguments;
  8773. }()) ? _baseIsArguments : function (value) {
  8774. return isObjectLike_1(value) && hasOwnProperty$1.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
  8775. };
  8776. var isArguments_1 = isArguments;
  8777. /**
  8778. * Checks if `value` is classified as an `Array` object.
  8779. *
  8780. * @static
  8781. * @memberOf _
  8782. * @since 0.1.0
  8783. * @category Lang
  8784. * @param {*} value The value to check.
  8785. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  8786. * @example
  8787. *
  8788. * _.isArray([1, 2, 3]);
  8789. * // => true
  8790. *
  8791. * _.isArray(document.body.children);
  8792. * // => false
  8793. *
  8794. * _.isArray('abc');
  8795. * // => false
  8796. *
  8797. * _.isArray(_.noop);
  8798. * // => false
  8799. */
  8800. var isArray$1 = Array.isArray;
  8801. var isArray_1 = isArray$1;
  8802. /** Built-in value references. */
  8803. var spreadableSymbol = _Symbol ? _Symbol.isConcatSpreadable : undefined;
  8804. /**
  8805. * Checks if `value` is a flattenable `arguments` object or array.
  8806. *
  8807. * @private
  8808. * @param {*} value The value to check.
  8809. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  8810. */
  8811. function isFlattenable(value) {
  8812. return isArray_1(value) || isArguments_1(value) || !!(spreadableSymbol && value && value[spreadableSymbol]);
  8813. }
  8814. var _isFlattenable = isFlattenable;
  8815. /**
  8816. * The base implementation of `_.flatten` with support for restricting flattening.
  8817. *
  8818. * @private
  8819. * @param {Array} array The array to flatten.
  8820. * @param {number} depth The maximum recursion depth.
  8821. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  8822. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  8823. * @param {Array} [result=[]] The initial result value.
  8824. * @returns {Array} Returns the new flattened array.
  8825. */
  8826. function baseFlatten(array, depth, predicate, isStrict, result) {
  8827. var index = -1,
  8828. length = array.length;
  8829. predicate || (predicate = _isFlattenable);
  8830. result || (result = []);
  8831. while (++index < length) {
  8832. var value = array[index];
  8833. if (depth > 0 && predicate(value)) {
  8834. if (depth > 1) {
  8835. // Recursively flatten arrays (susceptible to call stack limits).
  8836. baseFlatten(value, depth - 1, predicate, isStrict, result);
  8837. } else {
  8838. _arrayPush(result, value);
  8839. }
  8840. } else if (!isStrict) {
  8841. result[result.length] = value;
  8842. }
  8843. }
  8844. return result;
  8845. }
  8846. var _baseFlatten = baseFlatten;
  8847. /**
  8848. * Flattens `array` a single level deep.
  8849. *
  8850. * @static
  8851. * @memberOf _
  8852. * @since 0.1.0
  8853. * @category Array
  8854. * @param {Array} array The array to flatten.
  8855. * @returns {Array} Returns the new flattened array.
  8856. * @example
  8857. *
  8858. * _.flatten([1, [2, [3, [4]], 5]]);
  8859. * // => [1, 2, [3, [4]], 5]
  8860. */
  8861. function flatten(array) {
  8862. var length = array == null ? 0 : array.length;
  8863. return length ? _baseFlatten(array, 1) : [];
  8864. }
  8865. var flatten_1 = flatten;
  8866. const cliDescriptor = {
  8867. key: key => key.length === 1 ? `-${key}` : `--${key}`,
  8868. value: value => lib$1.apiDescriptor.value(value),
  8869. pair: ({
  8870. key,
  8871. value
  8872. }) => value === false ? `--no-${key}` : value === true ? cliDescriptor.key(key) : value === "" ? `${cliDescriptor.key(key)} without an argument` : `${cliDescriptor.key(key)}=${value}`
  8873. };
  8874. class FlagSchema extends lib$1.ChoiceSchema {
  8875. constructor({
  8876. name,
  8877. flags
  8878. }) {
  8879. super({
  8880. name,
  8881. choices: flags
  8882. });
  8883. this._flags = flags.slice().sort();
  8884. }
  8885. preprocess(value, utils) {
  8886. if (typeof value === "string" && value.length !== 0 && !this._flags.includes(value)) {
  8887. const suggestion = this._flags.find(flag => leven_1$1(flag, value) < 3);
  8888. if (suggestion) {
  8889. utils.logger.warn([`Unknown flag ${source.yellow(utils.descriptor.value(value))},`, `did you mean ${source.blue(utils.descriptor.value(suggestion))}?`].join(" "));
  8890. return suggestion;
  8891. }
  8892. }
  8893. return value;
  8894. }
  8895. expected() {
  8896. return "a flag";
  8897. }
  8898. }
  8899. let hasDeprecationWarned;
  8900. function normalizeOptions(options, optionInfos, {
  8901. logger,
  8902. isCLI = false,
  8903. passThrough = false
  8904. } = {}) {
  8905. const unknown = !passThrough ? (key, value, options) => {
  8906. // Don't suggest `_` for unknown flags
  8907. const _options$schemas = options.schemas,
  8908. schemas = _objectWithoutPropertiesLoose(_options$schemas, ["_"]);
  8909. return lib$1.levenUnknownHandler(key, value, Object.assign({}, options, {
  8910. schemas
  8911. }));
  8912. } : Array.isArray(passThrough) ? (key, value) => !passThrough.includes(key) ? undefined : {
  8913. [key]: value
  8914. } : (key, value) => ({
  8915. [key]: value
  8916. });
  8917. const descriptor = isCLI ? cliDescriptor : lib$1.apiDescriptor;
  8918. const schemas = optionInfosToSchemas(optionInfos, {
  8919. isCLI
  8920. });
  8921. const normalizer = new lib$1.Normalizer(schemas, {
  8922. logger,
  8923. unknown,
  8924. descriptor
  8925. });
  8926. const shouldSuppressDuplicateDeprecationWarnings = logger !== false;
  8927. if (shouldSuppressDuplicateDeprecationWarnings && hasDeprecationWarned) {
  8928. normalizer._hasDeprecationWarned = hasDeprecationWarned;
  8929. }
  8930. const normalized = normalizer.normalize(options);
  8931. if (shouldSuppressDuplicateDeprecationWarnings) {
  8932. hasDeprecationWarned = normalizer._hasDeprecationWarned;
  8933. }
  8934. return normalized;
  8935. }
  8936. function optionInfosToSchemas(optionInfos, {
  8937. isCLI
  8938. }) {
  8939. const schemas = [];
  8940. if (isCLI) {
  8941. schemas.push(lib$1.AnySchema.create({
  8942. name: "_"
  8943. }));
  8944. }
  8945. for (const optionInfo of optionInfos) {
  8946. schemas.push(optionInfoToSchema(optionInfo, {
  8947. isCLI,
  8948. optionInfos
  8949. }));
  8950. if (optionInfo.alias && isCLI) {
  8951. schemas.push(lib$1.AliasSchema.create({
  8952. name: optionInfo.alias,
  8953. sourceName: optionInfo.name
  8954. }));
  8955. }
  8956. }
  8957. return schemas;
  8958. }
  8959. function optionInfoToSchema(optionInfo, {
  8960. isCLI,
  8961. optionInfos
  8962. }) {
  8963. let SchemaConstructor;
  8964. const parameters = {
  8965. name: optionInfo.name
  8966. };
  8967. const handlers = {};
  8968. switch (optionInfo.type) {
  8969. case "int":
  8970. SchemaConstructor = lib$1.IntegerSchema;
  8971. if (isCLI) {
  8972. parameters.preprocess = value => Number(value);
  8973. }
  8974. break;
  8975. case "string":
  8976. SchemaConstructor = lib$1.StringSchema;
  8977. break;
  8978. case "choice":
  8979. SchemaConstructor = lib$1.ChoiceSchema;
  8980. parameters.choices = optionInfo.choices.map(choiceInfo => typeof choiceInfo === "object" && choiceInfo.redirect ? Object.assign({}, choiceInfo, {
  8981. redirect: {
  8982. to: {
  8983. key: optionInfo.name,
  8984. value: choiceInfo.redirect
  8985. }
  8986. }
  8987. }) : choiceInfo);
  8988. break;
  8989. case "boolean":
  8990. SchemaConstructor = lib$1.BooleanSchema;
  8991. break;
  8992. case "flag":
  8993. SchemaConstructor = FlagSchema;
  8994. parameters.flags = flatten_1(optionInfos.map(optionInfo => [optionInfo.alias, optionInfo.description && optionInfo.name, optionInfo.oppositeDescription && `no-${optionInfo.name}`].filter(Boolean)));
  8995. break;
  8996. case "path":
  8997. SchemaConstructor = lib$1.StringSchema;
  8998. break;
  8999. default:
  9000. /* istanbul ignore next */
  9001. throw new Error(`Unexpected type ${optionInfo.type}`);
  9002. }
  9003. if (optionInfo.exception) {
  9004. parameters.validate = (value, schema, utils) => {
  9005. return optionInfo.exception(value) || schema.validate(value, utils);
  9006. };
  9007. } else {
  9008. parameters.validate = (value, schema, utils) => {
  9009. return value === undefined || schema.validate(value, utils);
  9010. };
  9011. }
  9012. /* istanbul ignore next */
  9013. if (optionInfo.redirect) {
  9014. handlers.redirect = value => !value ? undefined : {
  9015. to: {
  9016. key: optionInfo.redirect.option,
  9017. value: optionInfo.redirect.value
  9018. }
  9019. };
  9020. }
  9021. /* istanbul ignore next */
  9022. if (optionInfo.deprecated) {
  9023. handlers.deprecated = true;
  9024. } // allow CLI overriding, e.g., prettier package.json --tab-width 1 --tab-width 2
  9025. if (isCLI && !optionInfo.array) {
  9026. const originalPreprocess = parameters.preprocess || (x => x);
  9027. parameters.preprocess = (value, schema, utils) => schema.preprocess(originalPreprocess(Array.isArray(value) ? value[value.length - 1] : value), utils);
  9028. }
  9029. return optionInfo.array ? lib$1.ArraySchema.create(Object.assign({}, isCLI ? {
  9030. preprocess: v => [].concat(v)
  9031. } : {}, handlers, {
  9032. valueSchema: SchemaConstructor.create(parameters)
  9033. })) : SchemaConstructor.create(Object.assign({}, parameters, handlers));
  9034. }
  9035. function normalizeApiOptions(options, optionInfos, opts) {
  9036. return normalizeOptions(options, optionInfos, opts);
  9037. }
  9038. function normalizeCliOptions(options, optionInfos, opts) {
  9039. return normalizeOptions(options, optionInfos, Object.assign({
  9040. isCLI: true
  9041. }, opts));
  9042. }
  9043. var optionsNormalizer = {
  9044. normalizeApiOptions,
  9045. normalizeCliOptions
  9046. };
  9047. function locStart(node, opts) {
  9048. const {
  9049. ignoreDecorators
  9050. } = opts || {}; // Handle nodes with decorators. They should start at the first decorator
  9051. if (!ignoreDecorators) {
  9052. const decorators = node.declaration && node.declaration.decorators || node.decorators;
  9053. if (decorators && decorators.length > 0) {
  9054. return locStart(decorators[0]);
  9055. }
  9056. }
  9057. return node.range ? node.range[0] : node.start;
  9058. }
  9059. function locEnd(node) {
  9060. const end = node.range ? node.range[1] : node.end;
  9061. return node.typeAnnotation ? Math.max(end, locEnd(node.typeAnnotation)) : end;
  9062. }
  9063. function composeLoc(startNode, endNodeOrLength = startNode) {
  9064. const start = locStart(startNode);
  9065. const end = typeof endNodeOrLength === "number" ? start + endNodeOrLength : locEnd(endNodeOrLength);
  9066. return [start, end];
  9067. }
  9068. var loc = {
  9069. locStart,
  9070. locEnd,
  9071. composeLoc
  9072. };
  9073. var jsTokens = createCommonjsModule(function (module, exports) {
  9074. // Copyright 2014, 2015, 2016, 2017, 2018 Simon Lydell
  9075. // License: MIT. (See LICENSE.)
  9076. Object.defineProperty(exports, "__esModule", {
  9077. value: true
  9078. }); // This regex comes from regex.coffee, and is inserted here by generate-index.js
  9079. // (run `npm run build`).
  9080. exports.default = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyus]{1,6}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g;
  9081. exports.matchToToken = function (match) {
  9082. var token = {
  9083. type: "invalid",
  9084. value: match[0],
  9085. closed: undefined
  9086. };
  9087. if (match[1]) token.type = "string", token.closed = !!(match[3] || match[4]);else if (match[5]) token.type = "comment";else if (match[6]) token.type = "comment", token.closed = !!match[7];else if (match[8]) token.type = "regex";else if (match[9]) token.type = "number";else if (match[10]) token.type = "name";else if (match[11]) token.type = "punctuator";else if (match[12]) token.type = "whitespace";
  9088. return token;
  9089. };
  9090. });
  9091. var identifier = createCommonjsModule(function (module, exports) {
  9092. Object.defineProperty(exports, "__esModule", {
  9093. value: true
  9094. });
  9095. exports.isIdentifierStart = isIdentifierStart;
  9096. exports.isIdentifierChar = isIdentifierChar;
  9097. exports.isIdentifierName = isIdentifierName;
  9098. let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\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\u0860-\u086a\u08a0-\u08b4\u08b6-\u08c7\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\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\u0af9\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-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\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-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\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\u2118-\u211d\u2124\u2126\u2128\u212a-\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\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\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";
  9099. let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\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\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf\u1ac0\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
  9100. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  9101. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  9102. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  9103. const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 28, 11, 0, 9, 21, 107, 20, 28, 22, 13, 52, 76, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 230, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 35, 56, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 190, 0, 80, 921, 103, 110, 18, 195, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8952, 286, 50, 2, 18, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 2357, 44, 11, 6, 17, 0, 370, 43, 1301, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42717, 35, 4148, 12, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938];
  9104. const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 154, 10, 176, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 135, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 262, 6, 10, 9, 419, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  9105. function isInAstralSet(code, set) {
  9106. let pos = 0x10000;
  9107. for (let i = 0, length = set.length; i < length; i += 2) {
  9108. pos += set[i];
  9109. if (pos > code) return false;
  9110. pos += set[i + 1];
  9111. if (pos >= code) return true;
  9112. }
  9113. return false;
  9114. }
  9115. function isIdentifierStart(code) {
  9116. if (code < 65) return code === 36;
  9117. if (code <= 90) return true;
  9118. if (code < 97) return code === 95;
  9119. if (code <= 122) return true;
  9120. if (code <= 0xffff) {
  9121. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  9122. }
  9123. return isInAstralSet(code, astralIdentifierStartCodes);
  9124. }
  9125. function isIdentifierChar(code) {
  9126. if (code < 48) return code === 36;
  9127. if (code < 58) return true;
  9128. if (code < 65) return false;
  9129. if (code <= 90) return true;
  9130. if (code < 97) return code === 95;
  9131. if (code <= 122) return true;
  9132. if (code <= 0xffff) {
  9133. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  9134. }
  9135. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  9136. }
  9137. function isIdentifierName(name) {
  9138. let isFirst = true;
  9139. for (let _i = 0, _Array$from = Array.from(name); _i < _Array$from.length; _i++) {
  9140. const char = _Array$from[_i];
  9141. const cp = char.codePointAt(0);
  9142. if (isFirst) {
  9143. if (!isIdentifierStart(cp)) {
  9144. return false;
  9145. }
  9146. isFirst = false;
  9147. } else if (!isIdentifierChar(cp)) {
  9148. return false;
  9149. }
  9150. }
  9151. return !isFirst;
  9152. }
  9153. });
  9154. var keyword = createCommonjsModule(function (module, exports) {
  9155. Object.defineProperty(exports, "__esModule", {
  9156. value: true
  9157. });
  9158. exports.isReservedWord = isReservedWord;
  9159. exports.isStrictReservedWord = isStrictReservedWord;
  9160. exports.isStrictBindOnlyReservedWord = isStrictBindOnlyReservedWord;
  9161. exports.isStrictBindReservedWord = isStrictBindReservedWord;
  9162. exports.isKeyword = isKeyword;
  9163. const reservedWords = {
  9164. keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"],
  9165. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  9166. strictBind: ["eval", "arguments"]
  9167. };
  9168. const keywords = new Set(reservedWords.keyword);
  9169. const reservedWordsStrictSet = new Set(reservedWords.strict);
  9170. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  9171. function isReservedWord(word, inModule) {
  9172. return inModule && word === "await" || word === "enum";
  9173. }
  9174. function isStrictReservedWord(word, inModule) {
  9175. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  9176. }
  9177. function isStrictBindOnlyReservedWord(word) {
  9178. return reservedWordsStrictBindSet.has(word);
  9179. }
  9180. function isStrictBindReservedWord(word, inModule) {
  9181. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  9182. }
  9183. function isKeyword(word) {
  9184. return keywords.has(word);
  9185. }
  9186. });
  9187. var lib$2 = createCommonjsModule(function (module, exports) {
  9188. Object.defineProperty(exports, "__esModule", {
  9189. value: true
  9190. });
  9191. Object.defineProperty(exports, "isIdentifierName", {
  9192. enumerable: true,
  9193. get: function () {
  9194. return identifier.isIdentifierName;
  9195. }
  9196. });
  9197. Object.defineProperty(exports, "isIdentifierChar", {
  9198. enumerable: true,
  9199. get: function () {
  9200. return identifier.isIdentifierChar;
  9201. }
  9202. });
  9203. Object.defineProperty(exports, "isIdentifierStart", {
  9204. enumerable: true,
  9205. get: function () {
  9206. return identifier.isIdentifierStart;
  9207. }
  9208. });
  9209. Object.defineProperty(exports, "isReservedWord", {
  9210. enumerable: true,
  9211. get: function () {
  9212. return keyword.isReservedWord;
  9213. }
  9214. });
  9215. Object.defineProperty(exports, "isStrictBindOnlyReservedWord", {
  9216. enumerable: true,
  9217. get: function () {
  9218. return keyword.isStrictBindOnlyReservedWord;
  9219. }
  9220. });
  9221. Object.defineProperty(exports, "isStrictBindReservedWord", {
  9222. enumerable: true,
  9223. get: function () {
  9224. return keyword.isStrictBindReservedWord;
  9225. }
  9226. });
  9227. Object.defineProperty(exports, "isStrictReservedWord", {
  9228. enumerable: true,
  9229. get: function () {
  9230. return keyword.isStrictReservedWord;
  9231. }
  9232. });
  9233. Object.defineProperty(exports, "isKeyword", {
  9234. enumerable: true,
  9235. get: function () {
  9236. return keyword.isKeyword;
  9237. }
  9238. });
  9239. });
  9240. var matchOperatorsRe$1 = /[|\\{}()[\]^$+*?.]/g;
  9241. var escapeStringRegexp$2 = function (str) {
  9242. if (typeof str !== 'string') {
  9243. throw new TypeError('Expected a string');
  9244. }
  9245. return str.replace(matchOperatorsRe$1, '\\$&');
  9246. };
  9247. var colorName$2 = {
  9248. "aliceblue": [240, 248, 255],
  9249. "antiquewhite": [250, 235, 215],
  9250. "aqua": [0, 255, 255],
  9251. "aquamarine": [127, 255, 212],
  9252. "azure": [240, 255, 255],
  9253. "beige": [245, 245, 220],
  9254. "bisque": [255, 228, 196],
  9255. "black": [0, 0, 0],
  9256. "blanchedalmond": [255, 235, 205],
  9257. "blue": [0, 0, 255],
  9258. "blueviolet": [138, 43, 226],
  9259. "brown": [165, 42, 42],
  9260. "burlywood": [222, 184, 135],
  9261. "cadetblue": [95, 158, 160],
  9262. "chartreuse": [127, 255, 0],
  9263. "chocolate": [210, 105, 30],
  9264. "coral": [255, 127, 80],
  9265. "cornflowerblue": [100, 149, 237],
  9266. "cornsilk": [255, 248, 220],
  9267. "crimson": [220, 20, 60],
  9268. "cyan": [0, 255, 255],
  9269. "darkblue": [0, 0, 139],
  9270. "darkcyan": [0, 139, 139],
  9271. "darkgoldenrod": [184, 134, 11],
  9272. "darkgray": [169, 169, 169],
  9273. "darkgreen": [0, 100, 0],
  9274. "darkgrey": [169, 169, 169],
  9275. "darkkhaki": [189, 183, 107],
  9276. "darkmagenta": [139, 0, 139],
  9277. "darkolivegreen": [85, 107, 47],
  9278. "darkorange": [255, 140, 0],
  9279. "darkorchid": [153, 50, 204],
  9280. "darkred": [139, 0, 0],
  9281. "darksalmon": [233, 150, 122],
  9282. "darkseagreen": [143, 188, 143],
  9283. "darkslateblue": [72, 61, 139],
  9284. "darkslategray": [47, 79, 79],
  9285. "darkslategrey": [47, 79, 79],
  9286. "darkturquoise": [0, 206, 209],
  9287. "darkviolet": [148, 0, 211],
  9288. "deeppink": [255, 20, 147],
  9289. "deepskyblue": [0, 191, 255],
  9290. "dimgray": [105, 105, 105],
  9291. "dimgrey": [105, 105, 105],
  9292. "dodgerblue": [30, 144, 255],
  9293. "firebrick": [178, 34, 34],
  9294. "floralwhite": [255, 250, 240],
  9295. "forestgreen": [34, 139, 34],
  9296. "fuchsia": [255, 0, 255],
  9297. "gainsboro": [220, 220, 220],
  9298. "ghostwhite": [248, 248, 255],
  9299. "gold": [255, 215, 0],
  9300. "goldenrod": [218, 165, 32],
  9301. "gray": [128, 128, 128],
  9302. "green": [0, 128, 0],
  9303. "greenyellow": [173, 255, 47],
  9304. "grey": [128, 128, 128],
  9305. "honeydew": [240, 255, 240],
  9306. "hotpink": [255, 105, 180],
  9307. "indianred": [205, 92, 92],
  9308. "indigo": [75, 0, 130],
  9309. "ivory": [255, 255, 240],
  9310. "khaki": [240, 230, 140],
  9311. "lavender": [230, 230, 250],
  9312. "lavenderblush": [255, 240, 245],
  9313. "lawngreen": [124, 252, 0],
  9314. "lemonchiffon": [255, 250, 205],
  9315. "lightblue": [173, 216, 230],
  9316. "lightcoral": [240, 128, 128],
  9317. "lightcyan": [224, 255, 255],
  9318. "lightgoldenrodyellow": [250, 250, 210],
  9319. "lightgray": [211, 211, 211],
  9320. "lightgreen": [144, 238, 144],
  9321. "lightgrey": [211, 211, 211],
  9322. "lightpink": [255, 182, 193],
  9323. "lightsalmon": [255, 160, 122],
  9324. "lightseagreen": [32, 178, 170],
  9325. "lightskyblue": [135, 206, 250],
  9326. "lightslategray": [119, 136, 153],
  9327. "lightslategrey": [119, 136, 153],
  9328. "lightsteelblue": [176, 196, 222],
  9329. "lightyellow": [255, 255, 224],
  9330. "lime": [0, 255, 0],
  9331. "limegreen": [50, 205, 50],
  9332. "linen": [250, 240, 230],
  9333. "magenta": [255, 0, 255],
  9334. "maroon": [128, 0, 0],
  9335. "mediumaquamarine": [102, 205, 170],
  9336. "mediumblue": [0, 0, 205],
  9337. "mediumorchid": [186, 85, 211],
  9338. "mediumpurple": [147, 112, 219],
  9339. "mediumseagreen": [60, 179, 113],
  9340. "mediumslateblue": [123, 104, 238],
  9341. "mediumspringgreen": [0, 250, 154],
  9342. "mediumturquoise": [72, 209, 204],
  9343. "mediumvioletred": [199, 21, 133],
  9344. "midnightblue": [25, 25, 112],
  9345. "mintcream": [245, 255, 250],
  9346. "mistyrose": [255, 228, 225],
  9347. "moccasin": [255, 228, 181],
  9348. "navajowhite": [255, 222, 173],
  9349. "navy": [0, 0, 128],
  9350. "oldlace": [253, 245, 230],
  9351. "olive": [128, 128, 0],
  9352. "olivedrab": [107, 142, 35],
  9353. "orange": [255, 165, 0],
  9354. "orangered": [255, 69, 0],
  9355. "orchid": [218, 112, 214],
  9356. "palegoldenrod": [238, 232, 170],
  9357. "palegreen": [152, 251, 152],
  9358. "paleturquoise": [175, 238, 238],
  9359. "palevioletred": [219, 112, 147],
  9360. "papayawhip": [255, 239, 213],
  9361. "peachpuff": [255, 218, 185],
  9362. "peru": [205, 133, 63],
  9363. "pink": [255, 192, 203],
  9364. "plum": [221, 160, 221],
  9365. "powderblue": [176, 224, 230],
  9366. "purple": [128, 0, 128],
  9367. "rebeccapurple": [102, 51, 153],
  9368. "red": [255, 0, 0],
  9369. "rosybrown": [188, 143, 143],
  9370. "royalblue": [65, 105, 225],
  9371. "saddlebrown": [139, 69, 19],
  9372. "salmon": [250, 128, 114],
  9373. "sandybrown": [244, 164, 96],
  9374. "seagreen": [46, 139, 87],
  9375. "seashell": [255, 245, 238],
  9376. "sienna": [160, 82, 45],
  9377. "silver": [192, 192, 192],
  9378. "skyblue": [135, 206, 235],
  9379. "slateblue": [106, 90, 205],
  9380. "slategray": [112, 128, 144],
  9381. "slategrey": [112, 128, 144],
  9382. "snow": [255, 250, 250],
  9383. "springgreen": [0, 255, 127],
  9384. "steelblue": [70, 130, 180],
  9385. "tan": [210, 180, 140],
  9386. "teal": [0, 128, 128],
  9387. "thistle": [216, 191, 216],
  9388. "tomato": [255, 99, 71],
  9389. "turquoise": [64, 224, 208],
  9390. "violet": [238, 130, 238],
  9391. "wheat": [245, 222, 179],
  9392. "white": [255, 255, 255],
  9393. "whitesmoke": [245, 245, 245],
  9394. "yellow": [255, 255, 0],
  9395. "yellowgreen": [154, 205, 50]
  9396. };
  9397. var conversions$2 = createCommonjsModule(function (module) {
  9398. /* MIT license */
  9399. // NOTE: conversions should only return primitive values (i.e. arrays, or
  9400. // values that give correct `typeof` results).
  9401. // do not use box values types (i.e. Number(), String(), etc.)
  9402. var reverseKeywords = {};
  9403. for (var key in colorName$2) {
  9404. if (colorName$2.hasOwnProperty(key)) {
  9405. reverseKeywords[colorName$2[key]] = key;
  9406. }
  9407. }
  9408. var convert = module.exports = {
  9409. rgb: {
  9410. channels: 3,
  9411. labels: 'rgb'
  9412. },
  9413. hsl: {
  9414. channels: 3,
  9415. labels: 'hsl'
  9416. },
  9417. hsv: {
  9418. channels: 3,
  9419. labels: 'hsv'
  9420. },
  9421. hwb: {
  9422. channels: 3,
  9423. labels: 'hwb'
  9424. },
  9425. cmyk: {
  9426. channels: 4,
  9427. labels: 'cmyk'
  9428. },
  9429. xyz: {
  9430. channels: 3,
  9431. labels: 'xyz'
  9432. },
  9433. lab: {
  9434. channels: 3,
  9435. labels: 'lab'
  9436. },
  9437. lch: {
  9438. channels: 3,
  9439. labels: 'lch'
  9440. },
  9441. hex: {
  9442. channels: 1,
  9443. labels: ['hex']
  9444. },
  9445. keyword: {
  9446. channels: 1,
  9447. labels: ['keyword']
  9448. },
  9449. ansi16: {
  9450. channels: 1,
  9451. labels: ['ansi16']
  9452. },
  9453. ansi256: {
  9454. channels: 1,
  9455. labels: ['ansi256']
  9456. },
  9457. hcg: {
  9458. channels: 3,
  9459. labels: ['h', 'c', 'g']
  9460. },
  9461. apple: {
  9462. channels: 3,
  9463. labels: ['r16', 'g16', 'b16']
  9464. },
  9465. gray: {
  9466. channels: 1,
  9467. labels: ['gray']
  9468. }
  9469. }; // hide .channels and .labels properties
  9470. for (var model in convert) {
  9471. if (convert.hasOwnProperty(model)) {
  9472. if (!('channels' in convert[model])) {
  9473. throw new Error('missing channels property: ' + model);
  9474. }
  9475. if (!('labels' in convert[model])) {
  9476. throw new Error('missing channel labels property: ' + model);
  9477. }
  9478. if (convert[model].labels.length !== convert[model].channels) {
  9479. throw new Error('channel and label counts mismatch: ' + model);
  9480. }
  9481. var channels = convert[model].channels;
  9482. var labels = convert[model].labels;
  9483. delete convert[model].channels;
  9484. delete convert[model].labels;
  9485. Object.defineProperty(convert[model], 'channels', {
  9486. value: channels
  9487. });
  9488. Object.defineProperty(convert[model], 'labels', {
  9489. value: labels
  9490. });
  9491. }
  9492. }
  9493. convert.rgb.hsl = function (rgb) {
  9494. var r = rgb[0] / 255;
  9495. var g = rgb[1] / 255;
  9496. var b = rgb[2] / 255;
  9497. var min = Math.min(r, g, b);
  9498. var max = Math.max(r, g, b);
  9499. var delta = max - min;
  9500. var h;
  9501. var s;
  9502. var l;
  9503. if (max === min) {
  9504. h = 0;
  9505. } else if (r === max) {
  9506. h = (g - b) / delta;
  9507. } else if (g === max) {
  9508. h = 2 + (b - r) / delta;
  9509. } else if (b === max) {
  9510. h = 4 + (r - g) / delta;
  9511. }
  9512. h = Math.min(h * 60, 360);
  9513. if (h < 0) {
  9514. h += 360;
  9515. }
  9516. l = (min + max) / 2;
  9517. if (max === min) {
  9518. s = 0;
  9519. } else if (l <= 0.5) {
  9520. s = delta / (max + min);
  9521. } else {
  9522. s = delta / (2 - max - min);
  9523. }
  9524. return [h, s * 100, l * 100];
  9525. };
  9526. convert.rgb.hsv = function (rgb) {
  9527. var rdif;
  9528. var gdif;
  9529. var bdif;
  9530. var h;
  9531. var s;
  9532. var r = rgb[0] / 255;
  9533. var g = rgb[1] / 255;
  9534. var b = rgb[2] / 255;
  9535. var v = Math.max(r, g, b);
  9536. var diff = v - Math.min(r, g, b);
  9537. var diffc = function (c) {
  9538. return (v - c) / 6 / diff + 1 / 2;
  9539. };
  9540. if (diff === 0) {
  9541. h = s = 0;
  9542. } else {
  9543. s = diff / v;
  9544. rdif = diffc(r);
  9545. gdif = diffc(g);
  9546. bdif = diffc(b);
  9547. if (r === v) {
  9548. h = bdif - gdif;
  9549. } else if (g === v) {
  9550. h = 1 / 3 + rdif - bdif;
  9551. } else if (b === v) {
  9552. h = 2 / 3 + gdif - rdif;
  9553. }
  9554. if (h < 0) {
  9555. h += 1;
  9556. } else if (h > 1) {
  9557. h -= 1;
  9558. }
  9559. }
  9560. return [h * 360, s * 100, v * 100];
  9561. };
  9562. convert.rgb.hwb = function (rgb) {
  9563. var r = rgb[0];
  9564. var g = rgb[1];
  9565. var b = rgb[2];
  9566. var h = convert.rgb.hsl(rgb)[0];
  9567. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  9568. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  9569. return [h, w * 100, b * 100];
  9570. };
  9571. convert.rgb.cmyk = function (rgb) {
  9572. var r = rgb[0] / 255;
  9573. var g = rgb[1] / 255;
  9574. var b = rgb[2] / 255;
  9575. var c;
  9576. var m;
  9577. var y;
  9578. var k;
  9579. k = Math.min(1 - r, 1 - g, 1 - b);
  9580. c = (1 - r - k) / (1 - k) || 0;
  9581. m = (1 - g - k) / (1 - k) || 0;
  9582. y = (1 - b - k) / (1 - k) || 0;
  9583. return [c * 100, m * 100, y * 100, k * 100];
  9584. };
  9585. /**
  9586. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  9587. * */
  9588. function comparativeDistance(x, y) {
  9589. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  9590. }
  9591. convert.rgb.keyword = function (rgb) {
  9592. var reversed = reverseKeywords[rgb];
  9593. if (reversed) {
  9594. return reversed;
  9595. }
  9596. var currentClosestDistance = Infinity;
  9597. var currentClosestKeyword;
  9598. for (var keyword in colorName$2) {
  9599. if (colorName$2.hasOwnProperty(keyword)) {
  9600. var value = colorName$2[keyword]; // Compute comparative distance
  9601. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  9602. if (distance < currentClosestDistance) {
  9603. currentClosestDistance = distance;
  9604. currentClosestKeyword = keyword;
  9605. }
  9606. }
  9607. }
  9608. return currentClosestKeyword;
  9609. };
  9610. convert.keyword.rgb = function (keyword) {
  9611. return colorName$2[keyword];
  9612. };
  9613. convert.rgb.xyz = function (rgb) {
  9614. var r = rgb[0] / 255;
  9615. var g = rgb[1] / 255;
  9616. var b = rgb[2] / 255; // assume sRGB
  9617. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  9618. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  9619. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  9620. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  9621. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  9622. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  9623. return [x * 100, y * 100, z * 100];
  9624. };
  9625. convert.rgb.lab = function (rgb) {
  9626. var xyz = convert.rgb.xyz(rgb);
  9627. var x = xyz[0];
  9628. var y = xyz[1];
  9629. var z = xyz[2];
  9630. var l;
  9631. var a;
  9632. var b;
  9633. x /= 95.047;
  9634. y /= 100;
  9635. z /= 108.883;
  9636. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  9637. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  9638. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  9639. l = 116 * y - 16;
  9640. a = 500 * (x - y);
  9641. b = 200 * (y - z);
  9642. return [l, a, b];
  9643. };
  9644. convert.hsl.rgb = function (hsl) {
  9645. var h = hsl[0] / 360;
  9646. var s = hsl[1] / 100;
  9647. var l = hsl[2] / 100;
  9648. var t1;
  9649. var t2;
  9650. var t3;
  9651. var rgb;
  9652. var val;
  9653. if (s === 0) {
  9654. val = l * 255;
  9655. return [val, val, val];
  9656. }
  9657. if (l < 0.5) {
  9658. t2 = l * (1 + s);
  9659. } else {
  9660. t2 = l + s - l * s;
  9661. }
  9662. t1 = 2 * l - t2;
  9663. rgb = [0, 0, 0];
  9664. for (var i = 0; i < 3; i++) {
  9665. t3 = h + 1 / 3 * -(i - 1);
  9666. if (t3 < 0) {
  9667. t3++;
  9668. }
  9669. if (t3 > 1) {
  9670. t3--;
  9671. }
  9672. if (6 * t3 < 1) {
  9673. val = t1 + (t2 - t1) * 6 * t3;
  9674. } else if (2 * t3 < 1) {
  9675. val = t2;
  9676. } else if (3 * t3 < 2) {
  9677. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  9678. } else {
  9679. val = t1;
  9680. }
  9681. rgb[i] = val * 255;
  9682. }
  9683. return rgb;
  9684. };
  9685. convert.hsl.hsv = function (hsl) {
  9686. var h = hsl[0];
  9687. var s = hsl[1] / 100;
  9688. var l = hsl[2] / 100;
  9689. var smin = s;
  9690. var lmin = Math.max(l, 0.01);
  9691. var sv;
  9692. var v;
  9693. l *= 2;
  9694. s *= l <= 1 ? l : 2 - l;
  9695. smin *= lmin <= 1 ? lmin : 2 - lmin;
  9696. v = (l + s) / 2;
  9697. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  9698. return [h, sv * 100, v * 100];
  9699. };
  9700. convert.hsv.rgb = function (hsv) {
  9701. var h = hsv[0] / 60;
  9702. var s = hsv[1] / 100;
  9703. var v = hsv[2] / 100;
  9704. var hi = Math.floor(h) % 6;
  9705. var f = h - Math.floor(h);
  9706. var p = 255 * v * (1 - s);
  9707. var q = 255 * v * (1 - s * f);
  9708. var t = 255 * v * (1 - s * (1 - f));
  9709. v *= 255;
  9710. switch (hi) {
  9711. case 0:
  9712. return [v, t, p];
  9713. case 1:
  9714. return [q, v, p];
  9715. case 2:
  9716. return [p, v, t];
  9717. case 3:
  9718. return [p, q, v];
  9719. case 4:
  9720. return [t, p, v];
  9721. case 5:
  9722. return [v, p, q];
  9723. }
  9724. };
  9725. convert.hsv.hsl = function (hsv) {
  9726. var h = hsv[0];
  9727. var s = hsv[1] / 100;
  9728. var v = hsv[2] / 100;
  9729. var vmin = Math.max(v, 0.01);
  9730. var lmin;
  9731. var sl;
  9732. var l;
  9733. l = (2 - s) * v;
  9734. lmin = (2 - s) * vmin;
  9735. sl = s * vmin;
  9736. sl /= lmin <= 1 ? lmin : 2 - lmin;
  9737. sl = sl || 0;
  9738. l /= 2;
  9739. return [h, sl * 100, l * 100];
  9740. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  9741. convert.hwb.rgb = function (hwb) {
  9742. var h = hwb[0] / 360;
  9743. var wh = hwb[1] / 100;
  9744. var bl = hwb[2] / 100;
  9745. var ratio = wh + bl;
  9746. var i;
  9747. var v;
  9748. var f;
  9749. var n; // wh + bl cant be > 1
  9750. if (ratio > 1) {
  9751. wh /= ratio;
  9752. bl /= ratio;
  9753. }
  9754. i = Math.floor(6 * h);
  9755. v = 1 - bl;
  9756. f = 6 * h - i;
  9757. if ((i & 0x01) !== 0) {
  9758. f = 1 - f;
  9759. }
  9760. n = wh + f * (v - wh); // linear interpolation
  9761. var r;
  9762. var g;
  9763. var b;
  9764. switch (i) {
  9765. default:
  9766. case 6:
  9767. case 0:
  9768. r = v;
  9769. g = n;
  9770. b = wh;
  9771. break;
  9772. case 1:
  9773. r = n;
  9774. g = v;
  9775. b = wh;
  9776. break;
  9777. case 2:
  9778. r = wh;
  9779. g = v;
  9780. b = n;
  9781. break;
  9782. case 3:
  9783. r = wh;
  9784. g = n;
  9785. b = v;
  9786. break;
  9787. case 4:
  9788. r = n;
  9789. g = wh;
  9790. b = v;
  9791. break;
  9792. case 5:
  9793. r = v;
  9794. g = wh;
  9795. b = n;
  9796. break;
  9797. }
  9798. return [r * 255, g * 255, b * 255];
  9799. };
  9800. convert.cmyk.rgb = function (cmyk) {
  9801. var c = cmyk[0] / 100;
  9802. var m = cmyk[1] / 100;
  9803. var y = cmyk[2] / 100;
  9804. var k = cmyk[3] / 100;
  9805. var r;
  9806. var g;
  9807. var b;
  9808. r = 1 - Math.min(1, c * (1 - k) + k);
  9809. g = 1 - Math.min(1, m * (1 - k) + k);
  9810. b = 1 - Math.min(1, y * (1 - k) + k);
  9811. return [r * 255, g * 255, b * 255];
  9812. };
  9813. convert.xyz.rgb = function (xyz) {
  9814. var x = xyz[0] / 100;
  9815. var y = xyz[1] / 100;
  9816. var z = xyz[2] / 100;
  9817. var r;
  9818. var g;
  9819. var b;
  9820. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  9821. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  9822. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  9823. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  9824. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  9825. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  9826. r = Math.min(Math.max(0, r), 1);
  9827. g = Math.min(Math.max(0, g), 1);
  9828. b = Math.min(Math.max(0, b), 1);
  9829. return [r * 255, g * 255, b * 255];
  9830. };
  9831. convert.xyz.lab = function (xyz) {
  9832. var x = xyz[0];
  9833. var y = xyz[1];
  9834. var z = xyz[2];
  9835. var l;
  9836. var a;
  9837. var b;
  9838. x /= 95.047;
  9839. y /= 100;
  9840. z /= 108.883;
  9841. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  9842. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  9843. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  9844. l = 116 * y - 16;
  9845. a = 500 * (x - y);
  9846. b = 200 * (y - z);
  9847. return [l, a, b];
  9848. };
  9849. convert.lab.xyz = function (lab) {
  9850. var l = lab[0];
  9851. var a = lab[1];
  9852. var b = lab[2];
  9853. var x;
  9854. var y;
  9855. var z;
  9856. y = (l + 16) / 116;
  9857. x = a / 500 + y;
  9858. z = y - b / 200;
  9859. var y2 = Math.pow(y, 3);
  9860. var x2 = Math.pow(x, 3);
  9861. var z2 = Math.pow(z, 3);
  9862. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  9863. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  9864. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  9865. x *= 95.047;
  9866. y *= 100;
  9867. z *= 108.883;
  9868. return [x, y, z];
  9869. };
  9870. convert.lab.lch = function (lab) {
  9871. var l = lab[0];
  9872. var a = lab[1];
  9873. var b = lab[2];
  9874. var hr;
  9875. var h;
  9876. var c;
  9877. hr = Math.atan2(b, a);
  9878. h = hr * 360 / 2 / Math.PI;
  9879. if (h < 0) {
  9880. h += 360;
  9881. }
  9882. c = Math.sqrt(a * a + b * b);
  9883. return [l, c, h];
  9884. };
  9885. convert.lch.lab = function (lch) {
  9886. var l = lch[0];
  9887. var c = lch[1];
  9888. var h = lch[2];
  9889. var a;
  9890. var b;
  9891. var hr;
  9892. hr = h / 360 * 2 * Math.PI;
  9893. a = c * Math.cos(hr);
  9894. b = c * Math.sin(hr);
  9895. return [l, a, b];
  9896. };
  9897. convert.rgb.ansi16 = function (args) {
  9898. var r = args[0];
  9899. var g = args[1];
  9900. var b = args[2];
  9901. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  9902. value = Math.round(value / 50);
  9903. if (value === 0) {
  9904. return 30;
  9905. }
  9906. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  9907. if (value === 2) {
  9908. ansi += 60;
  9909. }
  9910. return ansi;
  9911. };
  9912. convert.hsv.ansi16 = function (args) {
  9913. // optimization here; we already know the value and don't need to get
  9914. // it converted for us.
  9915. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  9916. };
  9917. convert.rgb.ansi256 = function (args) {
  9918. var r = args[0];
  9919. var g = args[1];
  9920. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  9921. // black and white. normal palette only has 4 greyscale shades.
  9922. if (r === g && g === b) {
  9923. if (r < 8) {
  9924. return 16;
  9925. }
  9926. if (r > 248) {
  9927. return 231;
  9928. }
  9929. return Math.round((r - 8) / 247 * 24) + 232;
  9930. }
  9931. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  9932. return ansi;
  9933. };
  9934. convert.ansi16.rgb = function (args) {
  9935. var color = args % 10; // handle greyscale
  9936. if (color === 0 || color === 7) {
  9937. if (args > 50) {
  9938. color += 3.5;
  9939. }
  9940. color = color / 10.5 * 255;
  9941. return [color, color, color];
  9942. }
  9943. var mult = (~~(args > 50) + 1) * 0.5;
  9944. var r = (color & 1) * mult * 255;
  9945. var g = (color >> 1 & 1) * mult * 255;
  9946. var b = (color >> 2 & 1) * mult * 255;
  9947. return [r, g, b];
  9948. };
  9949. convert.ansi256.rgb = function (args) {
  9950. // handle greyscale
  9951. if (args >= 232) {
  9952. var c = (args - 232) * 10 + 8;
  9953. return [c, c, c];
  9954. }
  9955. args -= 16;
  9956. var rem;
  9957. var r = Math.floor(args / 36) / 5 * 255;
  9958. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  9959. var b = rem % 6 / 5 * 255;
  9960. return [r, g, b];
  9961. };
  9962. convert.rgb.hex = function (args) {
  9963. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  9964. var string = integer.toString(16).toUpperCase();
  9965. return '000000'.substring(string.length) + string;
  9966. };
  9967. convert.hex.rgb = function (args) {
  9968. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  9969. if (!match) {
  9970. return [0, 0, 0];
  9971. }
  9972. var colorString = match[0];
  9973. if (match[0].length === 3) {
  9974. colorString = colorString.split('').map(function (char) {
  9975. return char + char;
  9976. }).join('');
  9977. }
  9978. var integer = parseInt(colorString, 16);
  9979. var r = integer >> 16 & 0xFF;
  9980. var g = integer >> 8 & 0xFF;
  9981. var b = integer & 0xFF;
  9982. return [r, g, b];
  9983. };
  9984. convert.rgb.hcg = function (rgb) {
  9985. var r = rgb[0] / 255;
  9986. var g = rgb[1] / 255;
  9987. var b = rgb[2] / 255;
  9988. var max = Math.max(Math.max(r, g), b);
  9989. var min = Math.min(Math.min(r, g), b);
  9990. var chroma = max - min;
  9991. var grayscale;
  9992. var hue;
  9993. if (chroma < 1) {
  9994. grayscale = min / (1 - chroma);
  9995. } else {
  9996. grayscale = 0;
  9997. }
  9998. if (chroma <= 0) {
  9999. hue = 0;
  10000. } else if (max === r) {
  10001. hue = (g - b) / chroma % 6;
  10002. } else if (max === g) {
  10003. hue = 2 + (b - r) / chroma;
  10004. } else {
  10005. hue = 4 + (r - g) / chroma + 4;
  10006. }
  10007. hue /= 6;
  10008. hue %= 1;
  10009. return [hue * 360, chroma * 100, grayscale * 100];
  10010. };
  10011. convert.hsl.hcg = function (hsl) {
  10012. var s = hsl[1] / 100;
  10013. var l = hsl[2] / 100;
  10014. var c = 1;
  10015. var f = 0;
  10016. if (l < 0.5) {
  10017. c = 2.0 * s * l;
  10018. } else {
  10019. c = 2.0 * s * (1.0 - l);
  10020. }
  10021. if (c < 1.0) {
  10022. f = (l - 0.5 * c) / (1.0 - c);
  10023. }
  10024. return [hsl[0], c * 100, f * 100];
  10025. };
  10026. convert.hsv.hcg = function (hsv) {
  10027. var s = hsv[1] / 100;
  10028. var v = hsv[2] / 100;
  10029. var c = s * v;
  10030. var f = 0;
  10031. if (c < 1.0) {
  10032. f = (v - c) / (1 - c);
  10033. }
  10034. return [hsv[0], c * 100, f * 100];
  10035. };
  10036. convert.hcg.rgb = function (hcg) {
  10037. var h = hcg[0] / 360;
  10038. var c = hcg[1] / 100;
  10039. var g = hcg[2] / 100;
  10040. if (c === 0.0) {
  10041. return [g * 255, g * 255, g * 255];
  10042. }
  10043. var pure = [0, 0, 0];
  10044. var hi = h % 1 * 6;
  10045. var v = hi % 1;
  10046. var w = 1 - v;
  10047. var mg = 0;
  10048. switch (Math.floor(hi)) {
  10049. case 0:
  10050. pure[0] = 1;
  10051. pure[1] = v;
  10052. pure[2] = 0;
  10053. break;
  10054. case 1:
  10055. pure[0] = w;
  10056. pure[1] = 1;
  10057. pure[2] = 0;
  10058. break;
  10059. case 2:
  10060. pure[0] = 0;
  10061. pure[1] = 1;
  10062. pure[2] = v;
  10063. break;
  10064. case 3:
  10065. pure[0] = 0;
  10066. pure[1] = w;
  10067. pure[2] = 1;
  10068. break;
  10069. case 4:
  10070. pure[0] = v;
  10071. pure[1] = 0;
  10072. pure[2] = 1;
  10073. break;
  10074. default:
  10075. pure[0] = 1;
  10076. pure[1] = 0;
  10077. pure[2] = w;
  10078. }
  10079. mg = (1.0 - c) * g;
  10080. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  10081. };
  10082. convert.hcg.hsv = function (hcg) {
  10083. var c = hcg[1] / 100;
  10084. var g = hcg[2] / 100;
  10085. var v = c + g * (1.0 - c);
  10086. var f = 0;
  10087. if (v > 0.0) {
  10088. f = c / v;
  10089. }
  10090. return [hcg[0], f * 100, v * 100];
  10091. };
  10092. convert.hcg.hsl = function (hcg) {
  10093. var c = hcg[1] / 100;
  10094. var g = hcg[2] / 100;
  10095. var l = g * (1.0 - c) + 0.5 * c;
  10096. var s = 0;
  10097. if (l > 0.0 && l < 0.5) {
  10098. s = c / (2 * l);
  10099. } else if (l >= 0.5 && l < 1.0) {
  10100. s = c / (2 * (1 - l));
  10101. }
  10102. return [hcg[0], s * 100, l * 100];
  10103. };
  10104. convert.hcg.hwb = function (hcg) {
  10105. var c = hcg[1] / 100;
  10106. var g = hcg[2] / 100;
  10107. var v = c + g * (1.0 - c);
  10108. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  10109. };
  10110. convert.hwb.hcg = function (hwb) {
  10111. var w = hwb[1] / 100;
  10112. var b = hwb[2] / 100;
  10113. var v = 1 - b;
  10114. var c = v - w;
  10115. var g = 0;
  10116. if (c < 1) {
  10117. g = (v - c) / (1 - c);
  10118. }
  10119. return [hwb[0], c * 100, g * 100];
  10120. };
  10121. convert.apple.rgb = function (apple) {
  10122. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  10123. };
  10124. convert.rgb.apple = function (rgb) {
  10125. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  10126. };
  10127. convert.gray.rgb = function (args) {
  10128. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  10129. };
  10130. convert.gray.hsl = convert.gray.hsv = function (args) {
  10131. return [0, 0, args[0]];
  10132. };
  10133. convert.gray.hwb = function (gray) {
  10134. return [0, 100, gray[0]];
  10135. };
  10136. convert.gray.cmyk = function (gray) {
  10137. return [0, 0, 0, gray[0]];
  10138. };
  10139. convert.gray.lab = function (gray) {
  10140. return [gray[0], 0, 0];
  10141. };
  10142. convert.gray.hex = function (gray) {
  10143. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  10144. var integer = (val << 16) + (val << 8) + val;
  10145. var string = integer.toString(16).toUpperCase();
  10146. return '000000'.substring(string.length) + string;
  10147. };
  10148. convert.rgb.gray = function (rgb) {
  10149. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  10150. return [val / 255 * 100];
  10151. };
  10152. });
  10153. /*
  10154. this function routes a model to all other models.
  10155. all functions that are routed have a property `.conversion` attached
  10156. to the returned synthetic function. This property is an array
  10157. of strings, each with the steps in between the 'from' and 'to'
  10158. color models (inclusive).
  10159. conversions that are not possible simply are not included.
  10160. */
  10161. function buildGraph$2() {
  10162. var graph = {}; // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  10163. var models = Object.keys(conversions$2);
  10164. for (var len = models.length, i = 0; i < len; i++) {
  10165. graph[models[i]] = {
  10166. // http://jsperf.com/1-vs-infinity
  10167. // micro-opt, but this is simple.
  10168. distance: -1,
  10169. parent: null
  10170. };
  10171. }
  10172. return graph;
  10173. } // https://en.wikipedia.org/wiki/Breadth-first_search
  10174. function deriveBFS$2(fromModel) {
  10175. var graph = buildGraph$2();
  10176. var queue = [fromModel]; // unshift -> queue -> pop
  10177. graph[fromModel].distance = 0;
  10178. while (queue.length) {
  10179. var current = queue.pop();
  10180. var adjacents = Object.keys(conversions$2[current]);
  10181. for (var len = adjacents.length, i = 0; i < len; i++) {
  10182. var adjacent = adjacents[i];
  10183. var node = graph[adjacent];
  10184. if (node.distance === -1) {
  10185. node.distance = graph[current].distance + 1;
  10186. node.parent = current;
  10187. queue.unshift(adjacent);
  10188. }
  10189. }
  10190. }
  10191. return graph;
  10192. }
  10193. function link$2(from, to) {
  10194. return function (args) {
  10195. return to(from(args));
  10196. };
  10197. }
  10198. function wrapConversion$2(toModel, graph) {
  10199. var path = [graph[toModel].parent, toModel];
  10200. var fn = conversions$2[graph[toModel].parent][toModel];
  10201. var cur = graph[toModel].parent;
  10202. while (graph[cur].parent) {
  10203. path.unshift(graph[cur].parent);
  10204. fn = link$2(conversions$2[graph[cur].parent][cur], fn);
  10205. cur = graph[cur].parent;
  10206. }
  10207. fn.conversion = path;
  10208. return fn;
  10209. }
  10210. var route$2 = function (fromModel) {
  10211. var graph = deriveBFS$2(fromModel);
  10212. var conversion = {};
  10213. var models = Object.keys(graph);
  10214. for (var len = models.length, i = 0; i < len; i++) {
  10215. var toModel = models[i];
  10216. var node = graph[toModel];
  10217. if (node.parent === null) {
  10218. // no possible conversion, or this node is the source model.
  10219. continue;
  10220. }
  10221. conversion[toModel] = wrapConversion$2(toModel, graph);
  10222. }
  10223. return conversion;
  10224. };
  10225. var convert$3 = {};
  10226. var models$2 = Object.keys(conversions$2);
  10227. function wrapRaw$2(fn) {
  10228. var wrappedFn = function (args) {
  10229. if (args === undefined || args === null) {
  10230. return args;
  10231. }
  10232. if (arguments.length > 1) {
  10233. args = Array.prototype.slice.call(arguments);
  10234. }
  10235. return fn(args);
  10236. }; // preserve .conversion property if there is one
  10237. if ('conversion' in fn) {
  10238. wrappedFn.conversion = fn.conversion;
  10239. }
  10240. return wrappedFn;
  10241. }
  10242. function wrapRounded$2(fn) {
  10243. var wrappedFn = function (args) {
  10244. if (args === undefined || args === null) {
  10245. return args;
  10246. }
  10247. if (arguments.length > 1) {
  10248. args = Array.prototype.slice.call(arguments);
  10249. }
  10250. var result = fn(args); // we're assuming the result is an array here.
  10251. // see notice in conversions.js; don't use box types
  10252. // in conversion functions.
  10253. if (typeof result === 'object') {
  10254. for (var len = result.length, i = 0; i < len; i++) {
  10255. result[i] = Math.round(result[i]);
  10256. }
  10257. }
  10258. return result;
  10259. }; // preserve .conversion property if there is one
  10260. if ('conversion' in fn) {
  10261. wrappedFn.conversion = fn.conversion;
  10262. }
  10263. return wrappedFn;
  10264. }
  10265. models$2.forEach(function (fromModel) {
  10266. convert$3[fromModel] = {};
  10267. Object.defineProperty(convert$3[fromModel], 'channels', {
  10268. value: conversions$2[fromModel].channels
  10269. });
  10270. Object.defineProperty(convert$3[fromModel], 'labels', {
  10271. value: conversions$2[fromModel].labels
  10272. });
  10273. var routes = route$2(fromModel);
  10274. var routeModels = Object.keys(routes);
  10275. routeModels.forEach(function (toModel) {
  10276. var fn = routes[toModel];
  10277. convert$3[fromModel][toModel] = wrapRounded$2(fn);
  10278. convert$3[fromModel][toModel].raw = wrapRaw$2(fn);
  10279. });
  10280. });
  10281. var colorConvert$2 = convert$3;
  10282. var ansiStyles$2 = createCommonjsModule(function (module) {
  10283. const wrapAnsi16 = (fn, offset) => function () {
  10284. const code = fn.apply(colorConvert$2, arguments);
  10285. return `\u001B[${code + offset}m`;
  10286. };
  10287. const wrapAnsi256 = (fn, offset) => function () {
  10288. const code = fn.apply(colorConvert$2, arguments);
  10289. return `\u001B[${38 + offset};5;${code}m`;
  10290. };
  10291. const wrapAnsi16m = (fn, offset) => function () {
  10292. const rgb = fn.apply(colorConvert$2, arguments);
  10293. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  10294. };
  10295. function assembleStyles() {
  10296. const codes = new Map();
  10297. const styles = {
  10298. modifier: {
  10299. reset: [0, 0],
  10300. // 21 isn't widely supported and 22 does the same thing
  10301. bold: [1, 22],
  10302. dim: [2, 22],
  10303. italic: [3, 23],
  10304. underline: [4, 24],
  10305. inverse: [7, 27],
  10306. hidden: [8, 28],
  10307. strikethrough: [9, 29]
  10308. },
  10309. color: {
  10310. black: [30, 39],
  10311. red: [31, 39],
  10312. green: [32, 39],
  10313. yellow: [33, 39],
  10314. blue: [34, 39],
  10315. magenta: [35, 39],
  10316. cyan: [36, 39],
  10317. white: [37, 39],
  10318. gray: [90, 39],
  10319. // Bright color
  10320. redBright: [91, 39],
  10321. greenBright: [92, 39],
  10322. yellowBright: [93, 39],
  10323. blueBright: [94, 39],
  10324. magentaBright: [95, 39],
  10325. cyanBright: [96, 39],
  10326. whiteBright: [97, 39]
  10327. },
  10328. bgColor: {
  10329. bgBlack: [40, 49],
  10330. bgRed: [41, 49],
  10331. bgGreen: [42, 49],
  10332. bgYellow: [43, 49],
  10333. bgBlue: [44, 49],
  10334. bgMagenta: [45, 49],
  10335. bgCyan: [46, 49],
  10336. bgWhite: [47, 49],
  10337. // Bright color
  10338. bgBlackBright: [100, 49],
  10339. bgRedBright: [101, 49],
  10340. bgGreenBright: [102, 49],
  10341. bgYellowBright: [103, 49],
  10342. bgBlueBright: [104, 49],
  10343. bgMagentaBright: [105, 49],
  10344. bgCyanBright: [106, 49],
  10345. bgWhiteBright: [107, 49]
  10346. }
  10347. }; // Fix humans
  10348. styles.color.grey = styles.color.gray;
  10349. for (const groupName of Object.keys(styles)) {
  10350. const group = styles[groupName];
  10351. for (const styleName of Object.keys(group)) {
  10352. const style = group[styleName];
  10353. styles[styleName] = {
  10354. open: `\u001B[${style[0]}m`,
  10355. close: `\u001B[${style[1]}m`
  10356. };
  10357. group[styleName] = styles[styleName];
  10358. codes.set(style[0], style[1]);
  10359. }
  10360. Object.defineProperty(styles, groupName, {
  10361. value: group,
  10362. enumerable: false
  10363. });
  10364. Object.defineProperty(styles, 'codes', {
  10365. value: codes,
  10366. enumerable: false
  10367. });
  10368. }
  10369. const ansi2ansi = n => n;
  10370. const rgb2rgb = (r, g, b) => [r, g, b];
  10371. styles.color.close = '\u001B[39m';
  10372. styles.bgColor.close = '\u001B[49m';
  10373. styles.color.ansi = {
  10374. ansi: wrapAnsi16(ansi2ansi, 0)
  10375. };
  10376. styles.color.ansi256 = {
  10377. ansi256: wrapAnsi256(ansi2ansi, 0)
  10378. };
  10379. styles.color.ansi16m = {
  10380. rgb: wrapAnsi16m(rgb2rgb, 0)
  10381. };
  10382. styles.bgColor.ansi = {
  10383. ansi: wrapAnsi16(ansi2ansi, 10)
  10384. };
  10385. styles.bgColor.ansi256 = {
  10386. ansi256: wrapAnsi256(ansi2ansi, 10)
  10387. };
  10388. styles.bgColor.ansi16m = {
  10389. rgb: wrapAnsi16m(rgb2rgb, 10)
  10390. };
  10391. for (let key of Object.keys(colorConvert$2)) {
  10392. if (typeof colorConvert$2[key] !== 'object') {
  10393. continue;
  10394. }
  10395. const suite = colorConvert$2[key];
  10396. if (key === 'ansi16') {
  10397. key = 'ansi';
  10398. }
  10399. if ('ansi16' in suite) {
  10400. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  10401. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  10402. }
  10403. if ('ansi256' in suite) {
  10404. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  10405. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  10406. }
  10407. if ('rgb' in suite) {
  10408. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  10409. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  10410. }
  10411. }
  10412. return styles;
  10413. } // Make the export immutable
  10414. Object.defineProperty(module, 'exports', {
  10415. enumerable: true,
  10416. get: assembleStyles
  10417. });
  10418. });
  10419. const env$2 = process.env;
  10420. let forceColor$2;
  10421. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  10422. forceColor$2 = false;
  10423. } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  10424. forceColor$2 = true;
  10425. }
  10426. if ('FORCE_COLOR' in env$2) {
  10427. forceColor$2 = env$2.FORCE_COLOR.length === 0 || parseInt(env$2.FORCE_COLOR, 10) !== 0;
  10428. }
  10429. function translateLevel$2(level) {
  10430. if (level === 0) {
  10431. return false;
  10432. }
  10433. return {
  10434. level,
  10435. hasBasic: true,
  10436. has256: level >= 2,
  10437. has16m: level >= 3
  10438. };
  10439. }
  10440. function supportsColor$2(stream) {
  10441. if (forceColor$2 === false) {
  10442. return 0;
  10443. }
  10444. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  10445. return 3;
  10446. }
  10447. if (hasFlag('color=256')) {
  10448. return 2;
  10449. }
  10450. if (stream && !stream.isTTY && forceColor$2 !== true) {
  10451. return 0;
  10452. }
  10453. const min = forceColor$2 ? 1 : 0;
  10454. if (process.platform === 'win32') {
  10455. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  10456. // libuv that enables 256 color output on Windows. Anything earlier and it
  10457. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  10458. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  10459. // release that supports 256 colors. Windows 10 build 14931 is the first release
  10460. // that supports 16m/TrueColor.
  10461. const osRelease = os__default['default'].release().split('.');
  10462. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  10463. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  10464. }
  10465. return 1;
  10466. }
  10467. if ('CI' in env$2) {
  10468. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env$2) || env$2.CI_NAME === 'codeship') {
  10469. return 1;
  10470. }
  10471. return min;
  10472. }
  10473. if ('TEAMCITY_VERSION' in env$2) {
  10474. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env$2.TEAMCITY_VERSION) ? 1 : 0;
  10475. }
  10476. if (env$2.COLORTERM === 'truecolor') {
  10477. return 3;
  10478. }
  10479. if ('TERM_PROGRAM' in env$2) {
  10480. const version = parseInt((env$2.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  10481. switch (env$2.TERM_PROGRAM) {
  10482. case 'iTerm.app':
  10483. return version >= 3 ? 3 : 2;
  10484. case 'Apple_Terminal':
  10485. return 2;
  10486. // No default
  10487. }
  10488. }
  10489. if (/-256(color)?$/i.test(env$2.TERM)) {
  10490. return 2;
  10491. }
  10492. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env$2.TERM)) {
  10493. return 1;
  10494. }
  10495. if ('COLORTERM' in env$2) {
  10496. return 1;
  10497. }
  10498. if (env$2.TERM === 'dumb') {
  10499. return min;
  10500. }
  10501. return min;
  10502. }
  10503. function getSupportLevel$2(stream) {
  10504. const level = supportsColor$2(stream);
  10505. return translateLevel$2(level);
  10506. }
  10507. var supportsColor_1$2 = {
  10508. supportsColor: getSupportLevel$2,
  10509. stdout: getSupportLevel$2(process.stdout),
  10510. stderr: getSupportLevel$2(process.stderr)
  10511. };
  10512. const TEMPLATE_REGEX$2 = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  10513. const STYLE_REGEX$2 = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  10514. const STRING_REGEX$2 = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  10515. const ESCAPE_REGEX$2 = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  10516. const ESCAPES$2 = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  10517. function unescape$2(c) {
  10518. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  10519. return String.fromCharCode(parseInt(c.slice(1), 16));
  10520. }
  10521. return ESCAPES$2.get(c) || c;
  10522. }
  10523. function parseArguments$2(name, args) {
  10524. const results = [];
  10525. const chunks = args.trim().split(/\s*,\s*/g);
  10526. let matches;
  10527. for (const chunk of chunks) {
  10528. if (!isNaN(chunk)) {
  10529. results.push(Number(chunk));
  10530. } else if (matches = chunk.match(STRING_REGEX$2)) {
  10531. results.push(matches[2].replace(ESCAPE_REGEX$2, (m, escape, chr) => escape ? unescape$2(escape) : chr));
  10532. } else {
  10533. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  10534. }
  10535. }
  10536. return results;
  10537. }
  10538. function parseStyle$2(style) {
  10539. STYLE_REGEX$2.lastIndex = 0;
  10540. const results = [];
  10541. let matches;
  10542. while ((matches = STYLE_REGEX$2.exec(style)) !== null) {
  10543. const name = matches[1];
  10544. if (matches[2]) {
  10545. const args = parseArguments$2(name, matches[2]);
  10546. results.push([name].concat(args));
  10547. } else {
  10548. results.push([name]);
  10549. }
  10550. }
  10551. return results;
  10552. }
  10553. function buildStyle$2(chalk, styles) {
  10554. const enabled = {};
  10555. for (const layer of styles) {
  10556. for (const style of layer.styles) {
  10557. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  10558. }
  10559. }
  10560. let current = chalk;
  10561. for (const styleName of Object.keys(enabled)) {
  10562. if (Array.isArray(enabled[styleName])) {
  10563. if (!(styleName in current)) {
  10564. throw new Error(`Unknown Chalk style: ${styleName}`);
  10565. }
  10566. if (enabled[styleName].length > 0) {
  10567. current = current[styleName].apply(current, enabled[styleName]);
  10568. } else {
  10569. current = current[styleName];
  10570. }
  10571. }
  10572. }
  10573. return current;
  10574. }
  10575. var templates$2 = (chalk, tmp) => {
  10576. const styles = [];
  10577. const chunks = [];
  10578. let chunk = []; // eslint-disable-next-line max-params
  10579. tmp.replace(TEMPLATE_REGEX$2, (m, escapeChar, inverse, style, close, chr) => {
  10580. if (escapeChar) {
  10581. chunk.push(unescape$2(escapeChar));
  10582. } else if (style) {
  10583. const str = chunk.join('');
  10584. chunk = [];
  10585. chunks.push(styles.length === 0 ? str : buildStyle$2(chalk, styles)(str));
  10586. styles.push({
  10587. inverse,
  10588. styles: parseStyle$2(style)
  10589. });
  10590. } else if (close) {
  10591. if (styles.length === 0) {
  10592. throw new Error('Found extraneous } in Chalk template literal');
  10593. }
  10594. chunks.push(buildStyle$2(chalk, styles)(chunk.join('')));
  10595. chunk = [];
  10596. styles.pop();
  10597. } else {
  10598. chunk.push(chr);
  10599. }
  10600. });
  10601. chunks.push(chunk.join(''));
  10602. if (styles.length > 0) {
  10603. const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  10604. throw new Error(errMsg);
  10605. }
  10606. return chunks.join('');
  10607. };
  10608. var chalk$2 = createCommonjsModule(function (module) {
  10609. const stdoutColor = supportsColor_1$2.stdout;
  10610. const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  10611. const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  10612. const skipModels = new Set(['gray']);
  10613. const styles = Object.create(null);
  10614. function applyOptions(obj, options) {
  10615. options = options || {}; // Detect level if not set manually
  10616. const scLevel = stdoutColor ? stdoutColor.level : 0;
  10617. obj.level = options.level === undefined ? scLevel : options.level;
  10618. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  10619. }
  10620. function Chalk(options) {
  10621. // We check for this.template here since calling `chalk.constructor()`
  10622. // by itself will have a `this` of a previously constructed chalk object
  10623. if (!this || !(this instanceof Chalk) || this.template) {
  10624. const chalk = {};
  10625. applyOptions(chalk, options);
  10626. chalk.template = function () {
  10627. const args = [].slice.call(arguments);
  10628. return chalkTag.apply(null, [chalk.template].concat(args));
  10629. };
  10630. Object.setPrototypeOf(chalk, Chalk.prototype);
  10631. Object.setPrototypeOf(chalk.template, chalk);
  10632. chalk.template.constructor = Chalk;
  10633. return chalk.template;
  10634. }
  10635. applyOptions(this, options);
  10636. } // Use bright blue on Windows as the normal blue color is illegible
  10637. if (isSimpleWindowsTerm) {
  10638. ansiStyles$2.blue.open = '\u001B[94m';
  10639. }
  10640. for (const key of Object.keys(ansiStyles$2)) {
  10641. ansiStyles$2[key].closeRe = new RegExp(escapeStringRegexp$2(ansiStyles$2[key].close), 'g');
  10642. styles[key] = {
  10643. get() {
  10644. const codes = ansiStyles$2[key];
  10645. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  10646. }
  10647. };
  10648. }
  10649. styles.visible = {
  10650. get() {
  10651. return build.call(this, this._styles || [], true, 'visible');
  10652. }
  10653. };
  10654. ansiStyles$2.color.closeRe = new RegExp(escapeStringRegexp$2(ansiStyles$2.color.close), 'g');
  10655. for (const model of Object.keys(ansiStyles$2.color.ansi)) {
  10656. if (skipModels.has(model)) {
  10657. continue;
  10658. }
  10659. styles[model] = {
  10660. get() {
  10661. const level = this.level;
  10662. return function () {
  10663. const open = ansiStyles$2.color[levelMapping[level]][model].apply(null, arguments);
  10664. const codes = {
  10665. open,
  10666. close: ansiStyles$2.color.close,
  10667. closeRe: ansiStyles$2.color.closeRe
  10668. };
  10669. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  10670. };
  10671. }
  10672. };
  10673. }
  10674. ansiStyles$2.bgColor.closeRe = new RegExp(escapeStringRegexp$2(ansiStyles$2.bgColor.close), 'g');
  10675. for (const model of Object.keys(ansiStyles$2.bgColor.ansi)) {
  10676. if (skipModels.has(model)) {
  10677. continue;
  10678. }
  10679. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  10680. styles[bgModel] = {
  10681. get() {
  10682. const level = this.level;
  10683. return function () {
  10684. const open = ansiStyles$2.bgColor[levelMapping[level]][model].apply(null, arguments);
  10685. const codes = {
  10686. open,
  10687. close: ansiStyles$2.bgColor.close,
  10688. closeRe: ansiStyles$2.bgColor.closeRe
  10689. };
  10690. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  10691. };
  10692. }
  10693. };
  10694. }
  10695. const proto = Object.defineProperties(() => {}, styles);
  10696. function build(_styles, _empty, key) {
  10697. const builder = function () {
  10698. return applyStyle.apply(builder, arguments);
  10699. };
  10700. builder._styles = _styles;
  10701. builder._empty = _empty;
  10702. const self = this;
  10703. Object.defineProperty(builder, 'level', {
  10704. enumerable: true,
  10705. get() {
  10706. return self.level;
  10707. },
  10708. set(level) {
  10709. self.level = level;
  10710. }
  10711. });
  10712. Object.defineProperty(builder, 'enabled', {
  10713. enumerable: true,
  10714. get() {
  10715. return self.enabled;
  10716. },
  10717. set(enabled) {
  10718. self.enabled = enabled;
  10719. }
  10720. }); // See below for fix regarding invisible grey/dim combination on Windows
  10721. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  10722. // no way to create a function with a different prototype
  10723. builder.__proto__ = proto; // eslint-disable-line no-proto
  10724. return builder;
  10725. }
  10726. function applyStyle() {
  10727. // Support varags, but simply cast to string in case there's only one arg
  10728. const args = arguments;
  10729. const argsLen = args.length;
  10730. let str = String(arguments[0]);
  10731. if (argsLen === 0) {
  10732. return '';
  10733. }
  10734. if (argsLen > 1) {
  10735. // Don't slice `arguments`, it prevents V8 optimizations
  10736. for (let a = 1; a < argsLen; a++) {
  10737. str += ' ' + args[a];
  10738. }
  10739. }
  10740. if (!this.enabled || this.level <= 0 || !str) {
  10741. return this._empty ? '' : str;
  10742. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  10743. // see https://github.com/chalk/chalk/issues/58
  10744. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  10745. const originalDim = ansiStyles$2.dim.open;
  10746. if (isSimpleWindowsTerm && this.hasGrey) {
  10747. ansiStyles$2.dim.open = '';
  10748. }
  10749. for (const code of this._styles.slice().reverse()) {
  10750. // Replace any instances already present with a re-opening code
  10751. // otherwise only the part of the string until said closing code
  10752. // will be colored, and the rest will simply be 'plain'.
  10753. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  10754. // after next line to fix a bleed issue on macOS
  10755. // https://github.com/chalk/chalk/pull/92
  10756. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  10757. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  10758. ansiStyles$2.dim.open = originalDim;
  10759. return str;
  10760. }
  10761. function chalkTag(chalk, strings) {
  10762. if (!Array.isArray(strings)) {
  10763. // If chalk() was called by itself or with a string,
  10764. // return the string itself as a string.
  10765. return [].slice.call(arguments, 1).join(' ');
  10766. }
  10767. const args = [].slice.call(arguments, 2);
  10768. const parts = [strings.raw[0]];
  10769. for (let i = 1; i < strings.length; i++) {
  10770. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  10771. parts.push(String(strings.raw[i]));
  10772. }
  10773. return templates$2(chalk, parts.join(''));
  10774. }
  10775. Object.defineProperties(Chalk.prototype, styles);
  10776. module.exports = Chalk(); // eslint-disable-line new-cap
  10777. module.exports.supportsColor = stdoutColor;
  10778. module.exports.default = module.exports; // For TypeScript
  10779. });
  10780. var lib$3 = createCommonjsModule(function (module, exports) {
  10781. Object.defineProperty(exports, "__esModule", {
  10782. value: true
  10783. });
  10784. exports.shouldHighlight = shouldHighlight;
  10785. exports.getChalk = getChalk;
  10786. exports.default = highlight;
  10787. var _jsTokens = _interopRequireWildcard(jsTokens);
  10788. var _chalk = _interopRequireDefault(chalk$2);
  10789. function _interopRequireDefault(obj) {
  10790. return obj && obj.__esModule ? obj : {
  10791. default: obj
  10792. };
  10793. }
  10794. function _getRequireWildcardCache() {
  10795. if (typeof WeakMap !== "function") return null;
  10796. var cache = new WeakMap();
  10797. _getRequireWildcardCache = function () {
  10798. return cache;
  10799. };
  10800. return cache;
  10801. }
  10802. function _interopRequireWildcard(obj) {
  10803. if (obj && obj.__esModule) {
  10804. return obj;
  10805. }
  10806. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  10807. return {
  10808. default: obj
  10809. };
  10810. }
  10811. var cache = _getRequireWildcardCache();
  10812. if (cache && cache.has(obj)) {
  10813. return cache.get(obj);
  10814. }
  10815. var newObj = {};
  10816. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  10817. for (var key in obj) {
  10818. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  10819. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  10820. if (desc && (desc.get || desc.set)) {
  10821. Object.defineProperty(newObj, key, desc);
  10822. } else {
  10823. newObj[key] = obj[key];
  10824. }
  10825. }
  10826. }
  10827. newObj.default = obj;
  10828. if (cache) {
  10829. cache.set(obj, newObj);
  10830. }
  10831. return newObj;
  10832. }
  10833. function getDefs(chalk) {
  10834. return {
  10835. keyword: chalk.cyan,
  10836. capitalized: chalk.yellow,
  10837. jsx_tag: chalk.yellow,
  10838. punctuator: chalk.yellow,
  10839. number: chalk.magenta,
  10840. string: chalk.green,
  10841. regex: chalk.magenta,
  10842. comment: chalk.grey,
  10843. invalid: chalk.white.bgRed.bold
  10844. };
  10845. }
  10846. const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  10847. const JSX_TAG = /^[a-z][\w-]*$/i;
  10848. const BRACKET = /^[()[\]{}]$/;
  10849. function getTokenType(match) {
  10850. const [offset, text] = match.slice(-2);
  10851. const token = (0, _jsTokens.matchToToken)(match);
  10852. if (token.type === "name") {
  10853. if ((0, lib$2.isKeyword)(token.value) || (0, lib$2.isReservedWord)(token.value)) {
  10854. return "keyword";
  10855. }
  10856. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  10857. return "jsx_tag";
  10858. }
  10859. if (token.value[0] !== token.value[0].toLowerCase()) {
  10860. return "capitalized";
  10861. }
  10862. }
  10863. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  10864. return "bracket";
  10865. }
  10866. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  10867. return "punctuator";
  10868. }
  10869. return token.type;
  10870. }
  10871. function highlightTokens(defs, text) {
  10872. return text.replace(_jsTokens.default, function (...args) {
  10873. const type = getTokenType(args);
  10874. const colorize = defs[type];
  10875. if (colorize) {
  10876. return args[0].split(NEWLINE).map(str => colorize(str)).join("\n");
  10877. } else {
  10878. return args[0];
  10879. }
  10880. });
  10881. }
  10882. function shouldHighlight(options) {
  10883. return _chalk.default.supportsColor || options.forceColor;
  10884. }
  10885. function getChalk(options) {
  10886. let chalk = _chalk.default;
  10887. if (options.forceColor) {
  10888. chalk = new _chalk.default.constructor({
  10889. enabled: true,
  10890. level: 1
  10891. });
  10892. }
  10893. return chalk;
  10894. }
  10895. function highlight(code, options = {}) {
  10896. if (shouldHighlight(options)) {
  10897. const chalk = getChalk(options);
  10898. const defs = getDefs(chalk);
  10899. return highlightTokens(defs, code);
  10900. } else {
  10901. return code;
  10902. }
  10903. }
  10904. });
  10905. var lib$4 = createCommonjsModule(function (module, exports) {
  10906. Object.defineProperty(exports, "__esModule", {
  10907. value: true
  10908. });
  10909. exports.codeFrameColumns = codeFrameColumns;
  10910. exports.default = _default;
  10911. var _highlight = _interopRequireWildcard(lib$3);
  10912. function _getRequireWildcardCache() {
  10913. if (typeof WeakMap !== "function") return null;
  10914. var cache = new WeakMap();
  10915. _getRequireWildcardCache = function () {
  10916. return cache;
  10917. };
  10918. return cache;
  10919. }
  10920. function _interopRequireWildcard(obj) {
  10921. if (obj && obj.__esModule) {
  10922. return obj;
  10923. }
  10924. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  10925. return {
  10926. default: obj
  10927. };
  10928. }
  10929. var cache = _getRequireWildcardCache();
  10930. if (cache && cache.has(obj)) {
  10931. return cache.get(obj);
  10932. }
  10933. var newObj = {};
  10934. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  10935. for (var key in obj) {
  10936. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  10937. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  10938. if (desc && (desc.get || desc.set)) {
  10939. Object.defineProperty(newObj, key, desc);
  10940. } else {
  10941. newObj[key] = obj[key];
  10942. }
  10943. }
  10944. }
  10945. newObj.default = obj;
  10946. if (cache) {
  10947. cache.set(obj, newObj);
  10948. }
  10949. return newObj;
  10950. }
  10951. let deprecationWarningShown = false;
  10952. function getDefs(chalk) {
  10953. return {
  10954. gutter: chalk.grey,
  10955. marker: chalk.red.bold,
  10956. message: chalk.red.bold
  10957. };
  10958. }
  10959. const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  10960. function getMarkerLines(loc, source, opts) {
  10961. const startLoc = Object.assign({
  10962. column: 0,
  10963. line: -1
  10964. }, loc.start);
  10965. const endLoc = Object.assign({}, startLoc, loc.end);
  10966. const {
  10967. linesAbove = 2,
  10968. linesBelow = 3
  10969. } = opts || {};
  10970. const startLine = startLoc.line;
  10971. const startColumn = startLoc.column;
  10972. const endLine = endLoc.line;
  10973. const endColumn = endLoc.column;
  10974. let start = Math.max(startLine - (linesAbove + 1), 0);
  10975. let end = Math.min(source.length, endLine + linesBelow);
  10976. if (startLine === -1) {
  10977. start = 0;
  10978. }
  10979. if (endLine === -1) {
  10980. end = source.length;
  10981. }
  10982. const lineDiff = endLine - startLine;
  10983. const markerLines = {};
  10984. if (lineDiff) {
  10985. for (let i = 0; i <= lineDiff; i++) {
  10986. const lineNumber = i + startLine;
  10987. if (!startColumn) {
  10988. markerLines[lineNumber] = true;
  10989. } else if (i === 0) {
  10990. const sourceLength = source[lineNumber - 1].length;
  10991. markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
  10992. } else if (i === lineDiff) {
  10993. markerLines[lineNumber] = [0, endColumn];
  10994. } else {
  10995. const sourceLength = source[lineNumber - i].length;
  10996. markerLines[lineNumber] = [0, sourceLength];
  10997. }
  10998. }
  10999. } else {
  11000. if (startColumn === endColumn) {
  11001. if (startColumn) {
  11002. markerLines[startLine] = [startColumn, 0];
  11003. } else {
  11004. markerLines[startLine] = true;
  11005. }
  11006. } else {
  11007. markerLines[startLine] = [startColumn, endColumn - startColumn];
  11008. }
  11009. }
  11010. return {
  11011. start,
  11012. end,
  11013. markerLines
  11014. };
  11015. }
  11016. function codeFrameColumns(rawLines, loc, opts = {}) {
  11017. const highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight.shouldHighlight)(opts);
  11018. const chalk = (0, _highlight.getChalk)(opts);
  11019. const defs = getDefs(chalk);
  11020. const maybeHighlight = (chalkFn, string) => {
  11021. return highlighted ? chalkFn(string) : string;
  11022. };
  11023. const lines = rawLines.split(NEWLINE);
  11024. const {
  11025. start,
  11026. end,
  11027. markerLines
  11028. } = getMarkerLines(loc, lines, opts);
  11029. const hasColumns = loc.start && typeof loc.start.column === "number";
  11030. const numberMaxWidth = String(end).length;
  11031. const highlightedLines = highlighted ? (0, _highlight.default)(rawLines, opts) : rawLines;
  11032. let frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => {
  11033. const number = start + 1 + index;
  11034. const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
  11035. const gutter = ` ${paddedNumber} | `;
  11036. const hasMarker = markerLines[number];
  11037. const lastMarkerLine = !markerLines[number + 1];
  11038. if (hasMarker) {
  11039. let markerLine = "";
  11040. if (Array.isArray(hasMarker)) {
  11041. const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  11042. const numberOfMarkers = hasMarker[1] || 1;
  11043. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  11044. if (lastMarkerLine && opts.message) {
  11045. markerLine += " " + maybeHighlight(defs.message, opts.message);
  11046. }
  11047. }
  11048. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  11049. } else {
  11050. return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
  11051. }
  11052. }).join("\n");
  11053. if (opts.message && !hasColumns) {
  11054. frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
  11055. }
  11056. if (highlighted) {
  11057. return chalk.reset(frame);
  11058. } else {
  11059. return frame;
  11060. }
  11061. }
  11062. function _default(rawLines, lineNumber, colNumber, opts = {}) {
  11063. if (!deprecationWarningShown) {
  11064. deprecationWarningShown = true;
  11065. const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  11066. if (process.emitWarning) {
  11067. process.emitWarning(message, "DeprecationWarning");
  11068. } else {
  11069. const deprecationError = new Error(message);
  11070. deprecationError.name = "DeprecationWarning";
  11071. console.warn(new Error(message));
  11072. }
  11073. }
  11074. colNumber = Math.max(colNumber, 0);
  11075. const location = {
  11076. start: {
  11077. column: colNumber,
  11078. line: lineNumber
  11079. }
  11080. };
  11081. return codeFrameColumns(rawLines, location, opts);
  11082. }
  11083. });
  11084. const {
  11085. ConfigError: ConfigError$1
  11086. } = errors;
  11087. const {
  11088. locStart: locStart$1,
  11089. locEnd: locEnd$1
  11090. } = loc; // Use defineProperties()/getOwnPropertyDescriptor() to prevent
  11091. // triggering the parsers getters.
  11092. const ownNames = Object.getOwnPropertyNames;
  11093. const ownDescriptor = Object.getOwnPropertyDescriptor;
  11094. function getParsers(options) {
  11095. const parsers = {};
  11096. for (const plugin of options.plugins) {
  11097. // TODO: test this with plugins
  11098. /* istanbul ignore next */
  11099. if (!plugin.parsers) {
  11100. continue;
  11101. }
  11102. for (const name of ownNames(plugin.parsers)) {
  11103. Object.defineProperty(parsers, name, ownDescriptor(plugin.parsers, name));
  11104. }
  11105. }
  11106. return parsers;
  11107. }
  11108. function resolveParser(opts, parsers) {
  11109. parsers = parsers || getParsers(opts);
  11110. if (typeof opts.parser === "function") {
  11111. // Custom parser API always works with JavaScript.
  11112. return {
  11113. parse: opts.parser,
  11114. astFormat: "estree",
  11115. locStart: locStart$1,
  11116. locEnd: locEnd$1
  11117. };
  11118. }
  11119. if (typeof opts.parser === "string") {
  11120. if (Object.prototype.hasOwnProperty.call(parsers, opts.parser)) {
  11121. return parsers[opts.parser];
  11122. }
  11123. try {
  11124. return {
  11125. parse: require(path__default['default'].resolve(process.cwd(), opts.parser)),
  11126. astFormat: "estree",
  11127. locStart: locStart$1,
  11128. locEnd: locEnd$1
  11129. };
  11130. } catch (err) {
  11131. /* istanbul ignore next */
  11132. throw new ConfigError$1(`Couldn't resolve parser "${opts.parser}"`);
  11133. }
  11134. }
  11135. }
  11136. function parse(text, opts) {
  11137. const parsers = getParsers(opts); // Create a new object {parserName: parseFn}. Uses defineProperty() to only call
  11138. // the parsers getters when actually calling the parser `parse` function.
  11139. const parsersForCustomParserApi = Object.keys(parsers).reduce((object, parserName) => Object.defineProperty(object, parserName, {
  11140. enumerable: true,
  11141. get() {
  11142. return parsers[parserName].parse;
  11143. }
  11144. }), {});
  11145. const parser = resolveParser(opts, parsers);
  11146. try {
  11147. if (parser.preprocess) {
  11148. text = parser.preprocess(text, opts);
  11149. }
  11150. return {
  11151. text,
  11152. ast: parser.parse(text, parsersForCustomParserApi, opts)
  11153. };
  11154. } catch (error) {
  11155. const {
  11156. loc
  11157. } = error;
  11158. if (loc) {
  11159. const codeFrame = lib$4;
  11160. error.codeFrame = codeFrame.codeFrameColumns(text, loc, {
  11161. highlightCode: true
  11162. });
  11163. error.message += "\n" + error.codeFrame;
  11164. throw error;
  11165. }
  11166. /* istanbul ignore next */
  11167. throw error.stack;
  11168. }
  11169. }
  11170. var parser = {
  11171. parse,
  11172. resolveParser
  11173. };
  11174. const {
  11175. UndefinedParserError: UndefinedParserError$1
  11176. } = errors;
  11177. const {
  11178. getSupportInfo: getSupportInfo$1
  11179. } = support;
  11180. const {
  11181. resolveParser: resolveParser$1
  11182. } = parser;
  11183. const hiddenDefaults = {
  11184. astFormat: "estree",
  11185. printer: {},
  11186. originalText: undefined,
  11187. locStart: null,
  11188. locEnd: null
  11189. }; // Copy options and fill in default values.
  11190. function normalize$1(options, opts) {
  11191. opts = opts || {};
  11192. const rawOptions = Object.assign({}, options);
  11193. const supportOptions = getSupportInfo$1({
  11194. plugins: options.plugins,
  11195. showUnreleased: true,
  11196. showDeprecated: true
  11197. }).options;
  11198. const defaults = Object.assign({}, hiddenDefaults, fromPairs_1(supportOptions.filter(optionInfo => optionInfo.default !== undefined).map(option => [option.name, option.default])));
  11199. if (!rawOptions.parser) {
  11200. if (!rawOptions.filepath) {
  11201. const logger = opts.logger || console;
  11202. logger.warn("No parser and no filepath given, using 'babel' the parser now " + "but this will throw an error in the future. " + "Please specify a parser or a filepath so one can be inferred.");
  11203. rawOptions.parser = "babel";
  11204. } else {
  11205. rawOptions.parser = inferParser(rawOptions.filepath, rawOptions.plugins);
  11206. if (!rawOptions.parser) {
  11207. throw new UndefinedParserError$1(`No parser could be inferred for file: ${rawOptions.filepath}`);
  11208. }
  11209. }
  11210. }
  11211. const parser = resolveParser$1(optionsNormalizer.normalizeApiOptions(rawOptions, [supportOptions.find(x => x.name === "parser")], {
  11212. passThrough: true,
  11213. logger: false
  11214. }));
  11215. rawOptions.astFormat = parser.astFormat;
  11216. rawOptions.locEnd = parser.locEnd;
  11217. rawOptions.locStart = parser.locStart;
  11218. const plugin = getPlugin(rawOptions);
  11219. rawOptions.printer = plugin.printers[rawOptions.astFormat];
  11220. const pluginDefaults = supportOptions.filter(optionInfo => optionInfo.pluginDefaults && optionInfo.pluginDefaults[plugin.name] !== undefined).reduce((reduced, optionInfo) => Object.assign(reduced, {
  11221. [optionInfo.name]: optionInfo.pluginDefaults[plugin.name]
  11222. }), {});
  11223. const mixedDefaults = Object.assign({}, defaults, pluginDefaults);
  11224. Object.keys(mixedDefaults).forEach(k => {
  11225. if (rawOptions[k] == null) {
  11226. rawOptions[k] = mixedDefaults[k];
  11227. }
  11228. });
  11229. if (rawOptions.parser === "json") {
  11230. rawOptions.trailingComma = "none";
  11231. }
  11232. return optionsNormalizer.normalizeApiOptions(rawOptions, supportOptions, Object.assign({
  11233. passThrough: Object.keys(hiddenDefaults)
  11234. }, opts));
  11235. }
  11236. function getPlugin(options) {
  11237. const {
  11238. astFormat
  11239. } = options; // TODO: test this with plugins
  11240. /* istanbul ignore next */
  11241. if (!astFormat) {
  11242. throw new Error("getPlugin() requires astFormat to be set");
  11243. }
  11244. const printerPlugin = options.plugins.find(plugin => plugin.printers && plugin.printers[astFormat]); // TODO: test this with plugins
  11245. /* istanbul ignore next */
  11246. if (!printerPlugin) {
  11247. throw new Error(`Couldn't find plugin for AST format "${astFormat}"`);
  11248. }
  11249. return printerPlugin;
  11250. }
  11251. function getInterpreter(filepath) {
  11252. /* istanbul ignore next */
  11253. if (typeof filepath !== "string") {
  11254. return "";
  11255. }
  11256. let fd;
  11257. try {
  11258. fd = fs__default['default'].openSync(filepath, "r");
  11259. } catch (err) {
  11260. // istanbul ignore next
  11261. return "";
  11262. }
  11263. try {
  11264. const liner = new readlines(fd);
  11265. const firstLine = liner.next().toString("utf8"); // #!/bin/env node, #!/usr/bin/env node
  11266. const m1 = firstLine.match(/^#!\/(?:usr\/)?bin\/env\s+(\S+)/);
  11267. if (m1) {
  11268. return m1[1];
  11269. } // #!/bin/node, #!/usr/bin/node, #!/usr/local/bin/node
  11270. const m2 = firstLine.match(/^#!\/(?:usr\/(?:local\/)?)?bin\/(\S+)/);
  11271. if (m2) {
  11272. return m2[1];
  11273. }
  11274. return "";
  11275. } catch (err) {
  11276. // There are some weird cases where paths are missing, causing Jest
  11277. // failures. It's unclear what these correspond to in the real world.
  11278. /* istanbul ignore next */
  11279. return "";
  11280. } finally {
  11281. try {
  11282. // There are some weird cases where paths are missing, causing Jest
  11283. // failures. It's unclear what these correspond to in the real world.
  11284. fs__default['default'].closeSync(fd);
  11285. } catch (err) {// nop
  11286. }
  11287. }
  11288. }
  11289. function inferParser(filepath, plugins) {
  11290. const filename = path__default['default'].basename(filepath).toLowerCase();
  11291. const languages = getSupportInfo$1({
  11292. plugins
  11293. }).languages.filter(language => language.since !== null); // If the file has no extension, we can try to infer the language from the
  11294. // interpreter in the shebang line, if any; but since this requires FS access,
  11295. // do it last.
  11296. let language = languages.find(language => language.extensions && language.extensions.some(extension => filename.endsWith(extension)) || language.filenames && language.filenames.some(name => name.toLowerCase() === filename));
  11297. if (!language && !filename.includes(".")) {
  11298. const interpreter = getInterpreter(filepath);
  11299. language = languages.find(language => language.interpreters && language.interpreters.includes(interpreter));
  11300. }
  11301. return language && language.parsers[0];
  11302. }
  11303. var options$1 = {
  11304. normalize: normalize$1,
  11305. hiddenDefaults,
  11306. inferParser
  11307. };
  11308. function massageAST(ast, options, parent) {
  11309. if (Array.isArray(ast)) {
  11310. return ast.map(e => massageAST(e, options, parent)).filter(Boolean);
  11311. }
  11312. if (!ast || typeof ast !== "object") {
  11313. return ast;
  11314. }
  11315. const newObj = {};
  11316. for (const key of Object.keys(ast)) {
  11317. if (typeof ast[key] !== "function") {
  11318. newObj[key] = massageAST(ast[key], options, ast);
  11319. }
  11320. }
  11321. if (options.printer.massageAstNode) {
  11322. const result = options.printer.massageAstNode(ast, newObj, parent);
  11323. if (result === null) {
  11324. return;
  11325. }
  11326. if (result) {
  11327. return result;
  11328. }
  11329. }
  11330. return newObj;
  11331. }
  11332. var massageAst = massageAST;
  11333. /** @type {import("assert")} */
  11334. const {
  11335. concat: concat$3,
  11336. line: line$1,
  11337. hardline: hardline$1,
  11338. breakParent: breakParent$1,
  11339. indent: indent$1,
  11340. lineSuffix: lineSuffix$1,
  11341. join: join$1,
  11342. cursor: cursor$2
  11343. } = document.builders;
  11344. const {
  11345. hasNewline: hasNewline$1,
  11346. skipNewline: skipNewline$1,
  11347. skipSpaces: skipSpaces$1,
  11348. isPreviousLineEmpty: isPreviousLineEmpty$1,
  11349. addLeadingComment: addLeadingComment$1,
  11350. addDanglingComment: addDanglingComment$1,
  11351. addTrailingComment: addTrailingComment$1
  11352. } = util;
  11353. const childNodesCacheKey = Symbol("child-nodes");
  11354. function getSortedChildNodes(node, options, resultArray) {
  11355. if (!node) {
  11356. return;
  11357. }
  11358. const {
  11359. printer,
  11360. locStart,
  11361. locEnd
  11362. } = options;
  11363. if (resultArray) {
  11364. if (printer.canAttachComment && printer.canAttachComment(node)) {
  11365. // This reverse insertion sort almost always takes constant
  11366. // time because we almost always (maybe always?) append the
  11367. // nodes in order anyway.
  11368. let i;
  11369. for (i = resultArray.length - 1; i >= 0; --i) {
  11370. if (locStart(resultArray[i]) <= locStart(node) && locEnd(resultArray[i]) <= locEnd(node)) {
  11371. break;
  11372. }
  11373. }
  11374. resultArray.splice(i + 1, 0, node);
  11375. return;
  11376. }
  11377. } else if (node[childNodesCacheKey]) {
  11378. return node[childNodesCacheKey];
  11379. }
  11380. const childNodes = printer.getCommentChildNodes && printer.getCommentChildNodes(node, options) || typeof node === "object" && Object.keys(node).filter(n => n !== "enclosingNode" && n !== "precedingNode" && n !== "followingNode" && n !== "tokens" && n !== "comments").map(n => node[n]);
  11381. if (!childNodes) {
  11382. return;
  11383. }
  11384. if (!resultArray) {
  11385. Object.defineProperty(node, childNodesCacheKey, {
  11386. value: resultArray = [],
  11387. enumerable: false
  11388. });
  11389. }
  11390. childNodes.forEach(childNode => {
  11391. getSortedChildNodes(childNode, options, resultArray);
  11392. });
  11393. return resultArray;
  11394. } // As efficiently as possible, decorate the comment object with
  11395. // .precedingNode, .enclosingNode, and/or .followingNode properties, at
  11396. // least one of which is guaranteed to be defined.
  11397. function decorateComment(node, comment, options) {
  11398. const {
  11399. locStart,
  11400. locEnd
  11401. } = options;
  11402. const childNodes = getSortedChildNodes(node, options);
  11403. let precedingNode;
  11404. let followingNode; // Time to dust off the old binary search robes and wizard hat.
  11405. let left = 0;
  11406. let right = childNodes.length;
  11407. while (left < right) {
  11408. const middle = left + right >> 1;
  11409. const child = childNodes[middle];
  11410. if (locStart(child) - locStart(comment) <= 0 && locEnd(comment) - locEnd(child) <= 0) {
  11411. // The comment is completely contained by this child node.
  11412. comment.enclosingNode = child;
  11413. decorateComment(child, comment, options);
  11414. return; // Abandon the binary search at this level.
  11415. }
  11416. if (locEnd(child) - locStart(comment) <= 0) {
  11417. // This child node falls completely before the comment.
  11418. // Because we will never consider this node or any nodes
  11419. // before it again, this node must be the closest preceding
  11420. // node we have encountered so far.
  11421. precedingNode = child;
  11422. left = middle + 1;
  11423. continue;
  11424. }
  11425. if (locEnd(comment) - locStart(child) <= 0) {
  11426. // This child node falls completely after the comment.
  11427. // Because we will never consider this node or any nodes after
  11428. // it again, this node must be the closest following node we
  11429. // have encountered so far.
  11430. followingNode = child;
  11431. right = middle;
  11432. continue;
  11433. }
  11434. /* istanbul ignore next */
  11435. throw new Error("Comment location overlaps with node location");
  11436. } // We don't want comments inside of different expressions inside of the same
  11437. // template literal to move to another expression.
  11438. if (comment.enclosingNode && comment.enclosingNode.type === "TemplateLiteral") {
  11439. const {
  11440. quasis
  11441. } = comment.enclosingNode;
  11442. const commentIndex = findExpressionIndexForComment(quasis, comment, options);
  11443. if (precedingNode && findExpressionIndexForComment(quasis, precedingNode, options) !== commentIndex) {
  11444. precedingNode = null;
  11445. }
  11446. if (followingNode && findExpressionIndexForComment(quasis, followingNode, options) !== commentIndex) {
  11447. followingNode = null;
  11448. }
  11449. }
  11450. if (precedingNode) {
  11451. comment.precedingNode = precedingNode;
  11452. }
  11453. if (followingNode) {
  11454. comment.followingNode = followingNode;
  11455. }
  11456. }
  11457. function attach(comments, ast, text, options) {
  11458. if (!Array.isArray(comments)) {
  11459. return;
  11460. }
  11461. const tiesToBreak = [];
  11462. const {
  11463. locStart,
  11464. locEnd
  11465. } = options;
  11466. comments.forEach((comment, i) => {
  11467. if (options.parser === "json" || options.parser === "json5" || options.parser === "__js_expression" || options.parser === "__vue_expression") {
  11468. if (locStart(comment) - locStart(ast) <= 0) {
  11469. addLeadingComment$1(ast, comment);
  11470. return;
  11471. }
  11472. if (locEnd(comment) - locEnd(ast) >= 0) {
  11473. addTrailingComment$1(ast, comment);
  11474. return;
  11475. }
  11476. }
  11477. decorateComment(ast, comment, options);
  11478. const {
  11479. precedingNode,
  11480. enclosingNode,
  11481. followingNode
  11482. } = comment;
  11483. const pluginHandleOwnLineComment = options.printer.handleComments && options.printer.handleComments.ownLine ? options.printer.handleComments.ownLine : () => false;
  11484. const pluginHandleEndOfLineComment = options.printer.handleComments && options.printer.handleComments.endOfLine ? options.printer.handleComments.endOfLine : () => false;
  11485. const pluginHandleRemainingComment = options.printer.handleComments && options.printer.handleComments.remaining ? options.printer.handleComments.remaining : () => false;
  11486. const isLastComment = comments.length - 1 === i;
  11487. if (hasNewline$1(text, locStart(comment), {
  11488. backwards: true
  11489. })) {
  11490. // If a comment exists on its own line, prefer a leading comment.
  11491. // We also need to check if it's the first line of the file.
  11492. if (pluginHandleOwnLineComment(comment, text, options, ast, isLastComment)) ; else if (followingNode) {
  11493. // Always a leading comment.
  11494. addLeadingComment$1(followingNode, comment);
  11495. } else if (precedingNode) {
  11496. addTrailingComment$1(precedingNode, comment);
  11497. } else if (enclosingNode) {
  11498. addDanglingComment$1(enclosingNode, comment);
  11499. } else {
  11500. // There are no nodes, let's attach it to the root of the ast
  11501. /* istanbul ignore next */
  11502. addDanglingComment$1(ast, comment);
  11503. }
  11504. } else if (hasNewline$1(text, locEnd(comment))) {
  11505. if (pluginHandleEndOfLineComment(comment, text, options, ast, isLastComment)) ; else if (precedingNode) {
  11506. // There is content before this comment on the same line, but
  11507. // none after it, so prefer a trailing comment of the previous node.
  11508. addTrailingComment$1(precedingNode, comment);
  11509. } else if (followingNode) {
  11510. addLeadingComment$1(followingNode, comment);
  11511. } else if (enclosingNode) {
  11512. addDanglingComment$1(enclosingNode, comment);
  11513. } else {
  11514. // There are no nodes, let's attach it to the root of the ast
  11515. /* istanbul ignore next */
  11516. addDanglingComment$1(ast, comment);
  11517. }
  11518. } else {
  11519. if (pluginHandleRemainingComment(comment, text, options, ast, isLastComment)) ; else if (precedingNode && followingNode) {
  11520. // Otherwise, text exists both before and after the comment on
  11521. // the same line. If there is both a preceding and following
  11522. // node, use a tie-breaking algorithm to determine if it should
  11523. // be attached to the next or previous node. In the last case,
  11524. // simply attach the right node;
  11525. const tieCount = tiesToBreak.length;
  11526. if (tieCount > 0) {
  11527. const lastTie = tiesToBreak[tieCount - 1];
  11528. if (lastTie.followingNode !== comment.followingNode) {
  11529. breakTies(tiesToBreak, text, options);
  11530. }
  11531. }
  11532. tiesToBreak.push(comment);
  11533. } else if (precedingNode) {
  11534. addTrailingComment$1(precedingNode, comment);
  11535. } else if (followingNode) {
  11536. addLeadingComment$1(followingNode, comment);
  11537. } else if (enclosingNode) {
  11538. addDanglingComment$1(enclosingNode, comment);
  11539. } else {
  11540. // There are no nodes, let's attach it to the root of the ast
  11541. /* istanbul ignore next */
  11542. addDanglingComment$1(ast, comment);
  11543. }
  11544. }
  11545. });
  11546. breakTies(tiesToBreak, text, options);
  11547. comments.forEach(comment => {
  11548. // These node references were useful for breaking ties, but we
  11549. // don't need them anymore, and they create cycles in the AST that
  11550. // may lead to infinite recursion if we don't delete them here.
  11551. delete comment.precedingNode;
  11552. delete comment.enclosingNode;
  11553. delete comment.followingNode;
  11554. });
  11555. }
  11556. function breakTies(tiesToBreak, text, options) {
  11557. const tieCount = tiesToBreak.length;
  11558. if (tieCount === 0) {
  11559. return;
  11560. }
  11561. const {
  11562. precedingNode,
  11563. followingNode,
  11564. enclosingNode
  11565. } = tiesToBreak[0];
  11566. const gapRegExp = options.printer.getGapRegex && options.printer.getGapRegex(enclosingNode) || /^[\s(]*$/;
  11567. let gapEndPos = options.locStart(followingNode); // Iterate backwards through tiesToBreak, examining the gaps
  11568. // between the tied comments. In order to qualify as leading, a
  11569. // comment must be separated from followingNode by an unbroken series of
  11570. // gaps (or other comments). Gaps should only contain whitespace or open
  11571. // parentheses.
  11572. let indexOfFirstLeadingComment;
  11573. for (indexOfFirstLeadingComment = tieCount; indexOfFirstLeadingComment > 0; --indexOfFirstLeadingComment) {
  11574. const comment = tiesToBreak[indexOfFirstLeadingComment - 1];
  11575. assert__default['default'].strictEqual(comment.precedingNode, precedingNode);
  11576. assert__default['default'].strictEqual(comment.followingNode, followingNode);
  11577. const gap = text.slice(options.locEnd(comment), gapEndPos);
  11578. if (gapRegExp.test(gap)) {
  11579. gapEndPos = options.locStart(comment);
  11580. } else {
  11581. // The gap string contained something other than whitespace or open
  11582. // parentheses.
  11583. break;
  11584. }
  11585. }
  11586. tiesToBreak.forEach((comment, i) => {
  11587. if (i < indexOfFirstLeadingComment) {
  11588. addTrailingComment$1(precedingNode, comment);
  11589. } else {
  11590. addLeadingComment$1(followingNode, comment);
  11591. }
  11592. });
  11593. for (const node of [precedingNode, followingNode]) {
  11594. if (node.comments && node.comments.length > 1) {
  11595. node.comments.sort((a, b) => options.locStart(a) - options.locStart(b));
  11596. }
  11597. }
  11598. tiesToBreak.length = 0;
  11599. }
  11600. function printComment(commentPath, options) {
  11601. const comment = commentPath.getValue();
  11602. comment.printed = true;
  11603. return options.printer.printComment(commentPath, options);
  11604. }
  11605. function findExpressionIndexForComment(quasis, comment, options) {
  11606. const startPos = options.locStart(comment) - 1;
  11607. for (let i = 1; i < quasis.length; ++i) {
  11608. if (startPos < options.locStart(quasis[i])) {
  11609. return i - 1;
  11610. }
  11611. } // We haven't found it, it probably means that some of the locations are off.
  11612. // Let's just return the first one.
  11613. /* istanbul ignore next */
  11614. return 0;
  11615. }
  11616. function printLeadingComment(commentPath, options) {
  11617. const comment = commentPath.getValue();
  11618. const contents = printComment(commentPath, options);
  11619. /* istanbul ignore next */
  11620. if (!contents) {
  11621. return "";
  11622. }
  11623. const isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // Leading block comments should see if they need to stay on the
  11624. // same line or not.
  11625. if (isBlock) {
  11626. const lineBreak = hasNewline$1(options.originalText, options.locEnd(comment)) ? hasNewline$1(options.originalText, options.locStart(comment), {
  11627. backwards: true
  11628. }) ? hardline$1 : line$1 : " ";
  11629. return concat$3([contents, lineBreak]);
  11630. }
  11631. return concat$3([contents, hardline$1]);
  11632. }
  11633. function printTrailingComment(commentPath, options) {
  11634. const comment = commentPath.getValue();
  11635. const contents = printComment(commentPath, options);
  11636. /* istanbul ignore next */
  11637. if (!contents) {
  11638. return "";
  11639. }
  11640. const {
  11641. printer,
  11642. originalText,
  11643. locStart
  11644. } = options;
  11645. const isBlock = printer.isBlockComment && printer.isBlockComment(comment);
  11646. if (hasNewline$1(originalText, locStart(comment), {
  11647. backwards: true
  11648. })) {
  11649. // This allows comments at the end of nested structures:
  11650. // {
  11651. // x: 1,
  11652. // y: 2
  11653. // // A comment
  11654. // }
  11655. // Those kinds of comments are almost always leading comments, but
  11656. // here it doesn't go "outside" the block and turns it into a
  11657. // trailing comment for `2`. We can simulate the above by checking
  11658. // if this a comment on its own line; normal trailing comments are
  11659. // always at the end of another expression.
  11660. const isLineBeforeEmpty = isPreviousLineEmpty$1(originalText, comment, locStart);
  11661. return lineSuffix$1(concat$3([hardline$1, isLineBeforeEmpty ? hardline$1 : "", contents]));
  11662. }
  11663. let printed = concat$3([" ", contents]); // Trailing block comments never need a newline
  11664. if (!isBlock) {
  11665. printed = concat$3([lineSuffix$1(printed), breakParent$1]);
  11666. }
  11667. return printed;
  11668. }
  11669. function printDanglingComments(path, options, sameIndent, filter) {
  11670. const parts = [];
  11671. const node = path.getValue();
  11672. if (!node || !node.comments) {
  11673. return "";
  11674. }
  11675. path.each(commentPath => {
  11676. const comment = commentPath.getValue();
  11677. if (comment && !comment.leading && !comment.trailing && (!filter || filter(comment))) {
  11678. parts.push(printComment(commentPath, options));
  11679. }
  11680. }, "comments");
  11681. if (parts.length === 0) {
  11682. return "";
  11683. }
  11684. if (sameIndent) {
  11685. return join$1(hardline$1, parts);
  11686. }
  11687. return indent$1(concat$3([hardline$1, join$1(hardline$1, parts)]));
  11688. }
  11689. function prependCursorPlaceholder(path, options, printed) {
  11690. if (path.getNode() === options.cursorNode && path.getValue()) {
  11691. return concat$3([cursor$2, printed, cursor$2]);
  11692. }
  11693. return printed;
  11694. }
  11695. function printComments(path, print, options, needsSemi) {
  11696. const value = path.getValue();
  11697. const printed = print(path);
  11698. const comments = value && value.comments;
  11699. if (!comments || comments.length === 0) {
  11700. return prependCursorPlaceholder(path, options, printed);
  11701. }
  11702. const leadingParts = [];
  11703. const trailingParts = [needsSemi ? ";" : "", printed];
  11704. path.each(commentPath => {
  11705. const comment = commentPath.getValue();
  11706. const {
  11707. leading,
  11708. trailing
  11709. } = comment;
  11710. if (leading) {
  11711. const contents = printLeadingComment(commentPath, options);
  11712. /* istanbul ignore next */
  11713. if (!contents) {
  11714. return;
  11715. }
  11716. leadingParts.push(contents);
  11717. const text = options.originalText;
  11718. const index = skipNewline$1(text, skipSpaces$1(text, options.locEnd(comment)));
  11719. if (index !== false && hasNewline$1(text, index)) {
  11720. leadingParts.push(hardline$1);
  11721. }
  11722. } else if (trailing) {
  11723. trailingParts.push(printTrailingComment(commentPath, options));
  11724. }
  11725. }, "comments");
  11726. return prependCursorPlaceholder(path, options, concat$3(leadingParts.concat(trailingParts)));
  11727. }
  11728. function ensureAllCommentsPrinted(astComments) {
  11729. if (!astComments) {
  11730. return;
  11731. }
  11732. astComments.forEach(comment => {
  11733. if (!comment.printed) {
  11734. throw new Error('Comment "' + comment.value.trim() + '" was not printed. Please report this error!');
  11735. }
  11736. delete comment.printed;
  11737. });
  11738. }
  11739. var comments = {
  11740. attach,
  11741. printComments,
  11742. printDanglingComments,
  11743. getSortedChildNodes,
  11744. ensureAllCommentsPrinted
  11745. };
  11746. function getNodeHelper(path, count) {
  11747. const stackIndex = getNodeStackIndexHelper(path.stack, count);
  11748. return stackIndex === -1 ? null : path.stack[stackIndex];
  11749. }
  11750. function getNodeStackIndexHelper(stack, count) {
  11751. for (let i = stack.length - 1; i >= 0; i -= 2) {
  11752. const value = stack[i];
  11753. if (value && !Array.isArray(value) && --count < 0) {
  11754. return i;
  11755. }
  11756. }
  11757. return -1;
  11758. }
  11759. class FastPath {
  11760. constructor(value) {
  11761. this.stack = [value];
  11762. } // The name of the current property is always the penultimate element of
  11763. // this.stack, and always a String.
  11764. getName() {
  11765. const {
  11766. stack
  11767. } = this;
  11768. const {
  11769. length
  11770. } = stack;
  11771. if (length > 1) {
  11772. return stack[length - 2];
  11773. } // Since the name is always a string, null is a safe sentinel value to
  11774. // return if we do not know the name of the (root) value.
  11775. /* istanbul ignore next */
  11776. return null;
  11777. } // The value of the current property is always the final element of
  11778. // this.stack.
  11779. getValue() {
  11780. return getLast(this.stack);
  11781. }
  11782. getNode(count = 0) {
  11783. return getNodeHelper(this, count);
  11784. }
  11785. getParentNode(count = 0) {
  11786. return getNodeHelper(this, count + 1);
  11787. } // Temporarily push properties named by string arguments given after the
  11788. // callback function onto this.stack, then call the callback with a
  11789. // reference to this (modified) FastPath object. Note that the stack will
  11790. // be restored to its original state after the callback is finished, so it
  11791. // is probably a mistake to retain a reference to the path.
  11792. call(callback, ...names) {
  11793. const {
  11794. stack
  11795. } = this;
  11796. const {
  11797. length
  11798. } = stack;
  11799. let value = getLast(stack);
  11800. for (const name of names) {
  11801. value = value[name];
  11802. stack.push(name, value);
  11803. }
  11804. const result = callback(this);
  11805. stack.length = length;
  11806. return result;
  11807. }
  11808. callParent(callback, count = 0) {
  11809. const stackIndex = getNodeStackIndexHelper(this.stack, count + 1);
  11810. const parentValues = this.stack.splice(stackIndex + 1);
  11811. const result = callback(this);
  11812. this.stack.push(...parentValues);
  11813. return result;
  11814. } // Similar to FastPath.prototype.call, except that the value obtained by
  11815. // accessing this.getValue()[name1][name2]... should be array-like. The
  11816. // callback will be called with a reference to this path object for each
  11817. // element of the array.
  11818. each(callback, ...names) {
  11819. const {
  11820. stack
  11821. } = this;
  11822. const {
  11823. length
  11824. } = stack;
  11825. let value = getLast(stack);
  11826. for (const name of names) {
  11827. value = value[name];
  11828. stack.push(name, value);
  11829. }
  11830. for (let i = 0; i < value.length; ++i) {
  11831. if (i in value) {
  11832. stack.push(i, value[i]); // If the callback needs to know the value of i, call
  11833. // path.getName(), assuming path is the parameter name.
  11834. callback(this);
  11835. stack.length -= 2;
  11836. }
  11837. }
  11838. stack.length = length;
  11839. } // Similar to FastPath.prototype.each, except that the results of the
  11840. // callback function invocations are stored in an array and returned at
  11841. // the end of the iteration.
  11842. map(callback, ...names) {
  11843. const {
  11844. stack
  11845. } = this;
  11846. const {
  11847. length
  11848. } = stack;
  11849. let value = getLast(stack);
  11850. for (const name of names) {
  11851. value = value[name];
  11852. stack.push(name, value);
  11853. }
  11854. const result = new Array(value.length);
  11855. for (let i = 0; i < value.length; ++i) {
  11856. if (i in value) {
  11857. stack.push(i, value[i]);
  11858. result[i] = callback(this, i);
  11859. stack.length -= 2;
  11860. }
  11861. }
  11862. stack.length = length;
  11863. return result;
  11864. }
  11865. /**
  11866. * @param {...(
  11867. * | ((node: any, name: string | null, number: number | null) => boolean)
  11868. * | undefined
  11869. * )} predicates
  11870. */
  11871. match(...predicates) {
  11872. let stackPointer = this.stack.length - 1;
  11873. let name = null;
  11874. let node = this.stack[stackPointer--];
  11875. for (const predicate of predicates) {
  11876. /* istanbul ignore next */
  11877. if (node === undefined) {
  11878. return false;
  11879. } // skip index/array
  11880. let number = null;
  11881. if (typeof name === "number") {
  11882. number = name;
  11883. name = this.stack[stackPointer--];
  11884. node = this.stack[stackPointer--];
  11885. }
  11886. if (predicate && !predicate(node, name, number)) {
  11887. return false;
  11888. }
  11889. name = this.stack[stackPointer--];
  11890. node = this.stack[stackPointer--];
  11891. }
  11892. return true;
  11893. }
  11894. }
  11895. var fastPath = FastPath;
  11896. const {
  11897. utils: {
  11898. stripTrailingHardline: stripTrailingHardline$1
  11899. }
  11900. } = document;
  11901. const {
  11902. normalize: normalize$2
  11903. } = options$1;
  11904. function printSubtree(path, print, options, printAstToDoc) {
  11905. if (options.printer.embed && options.embeddedLanguageFormatting === "auto") {
  11906. return options.printer.embed(path, print, (text, partialNextOptions, textToDocOptions) => textToDoc(text, partialNextOptions, options, printAstToDoc, textToDocOptions), options);
  11907. }
  11908. }
  11909. function textToDoc(text, partialNextOptions, parentOptions, printAstToDoc, // TODO: remove `stripTrailingHardline` in v3.0.0
  11910. {
  11911. stripTrailingHardline: shouldStripTrailingHardline = false
  11912. } = {}) {
  11913. const nextOptions = normalize$2(Object.assign({}, parentOptions, partialNextOptions, {
  11914. parentParser: parentOptions.parser,
  11915. embeddedInHtml: !!(parentOptions.embeddedInHtml || parentOptions.parser === "html" || parentOptions.parser === "vue" || parentOptions.parser === "angular" || parentOptions.parser === "lwc"),
  11916. originalText: text
  11917. }), {
  11918. passThrough: true
  11919. });
  11920. const result = parser.parse(text, nextOptions);
  11921. const {
  11922. ast
  11923. } = result;
  11924. text = result.text;
  11925. const astComments = ast.comments;
  11926. delete ast.comments;
  11927. comments.attach(astComments, ast, text, nextOptions);
  11928. nextOptions[Symbol.for("comments")] = astComments || [];
  11929. nextOptions[Symbol.for("tokens")] = ast.tokens || [];
  11930. const doc = printAstToDoc(ast, nextOptions);
  11931. comments.ensureAllCommentsPrinted(astComments);
  11932. if (shouldStripTrailingHardline) {
  11933. // TODO: move this to `stripTrailingHardline` function in `/src/document/doc-utils.js`
  11934. if (typeof doc === "string") {
  11935. return doc.replace(/(?:\r?\n)*$/, "");
  11936. }
  11937. return stripTrailingHardline$1(doc, true);
  11938. }
  11939. /* istanbul ignore next */
  11940. return doc;
  11941. }
  11942. var multiparser = {
  11943. printSubtree
  11944. };
  11945. const doc = document;
  11946. const docBuilders$1 = doc.builders;
  11947. const {
  11948. concat: concat$4,
  11949. hardline: hardline$2,
  11950. addAlignmentToDoc: addAlignmentToDoc$1
  11951. } = docBuilders$1;
  11952. const docUtils$1 = doc.utils;
  11953. /**
  11954. * Takes an abstract syntax tree (AST) and recursively converts it to a
  11955. * document (series of printing primitives).
  11956. *
  11957. * This is done by descending down the AST recursively. The recursion
  11958. * involves two functions that call each other:
  11959. *
  11960. * 1. printGenerically(), which is defined as an inner function here.
  11961. * It basically takes care of node caching.
  11962. * 2. callPluginPrintFunction(), which checks for some options, and
  11963. * ultimately calls the print() function provided by the plugin.
  11964. *
  11965. * The plugin function will call printGenerically() again for child nodes
  11966. * of the current node, which will do its housekeeping, then call the
  11967. * plugin function again, and so on.
  11968. *
  11969. * All the while, these functions pass a "path" variable around, which
  11970. * is a stack-like data structure (FastPath) that maintains the current
  11971. * state of the recursion. It is called "path", because it represents
  11972. * the path to the current node through the Abstract Syntax Tree.
  11973. */
  11974. function printAstToDoc(ast, options, alignmentSize = 0) {
  11975. const {
  11976. printer
  11977. } = options;
  11978. if (printer.preprocess) {
  11979. ast = printer.preprocess(ast, options);
  11980. }
  11981. const cache = new Map();
  11982. function printGenerically(path, args) {
  11983. const node = path.getValue();
  11984. const shouldCache = node && typeof node === "object" && args === undefined;
  11985. if (shouldCache && cache.has(node)) {
  11986. return cache.get(node);
  11987. } // We let JSXElement print its comments itself because it adds () around
  11988. // UnionTypeAnnotation has to align the child without the comments
  11989. let res;
  11990. if (printer.willPrintOwnComments && printer.willPrintOwnComments(path, options)) {
  11991. res = callPluginPrintFunction(path, options, printGenerically, args);
  11992. } else {
  11993. // printComments will call the plugin print function and check for
  11994. // comments to print
  11995. res = comments.printComments(path, p => callPluginPrintFunction(p, options, printGenerically, args), options, args && args.needsSemi);
  11996. }
  11997. if (shouldCache) {
  11998. cache.set(node, res);
  11999. }
  12000. return res;
  12001. }
  12002. let doc = printGenerically(new fastPath(ast));
  12003. if (alignmentSize > 0) {
  12004. // Add a hardline to make the indents take effect
  12005. // It should be removed in index.js format()
  12006. doc = addAlignmentToDoc$1(concat$4([hardline$2, doc]), alignmentSize, options.tabWidth);
  12007. }
  12008. docUtils$1.propagateBreaks(doc);
  12009. return doc;
  12010. }
  12011. function printPrettierIgnoredNode(node, options) {
  12012. const {
  12013. originalText,
  12014. [Symbol.for("comments")]: comments,
  12015. locStart,
  12016. locEnd
  12017. } = options;
  12018. const start = locStart(node);
  12019. const end = locEnd(node);
  12020. for (const comment of comments) {
  12021. if (locStart(comment) >= start && locEnd(comment) <= end) {
  12022. comment.printed = true;
  12023. }
  12024. }
  12025. return originalText.slice(start, end);
  12026. }
  12027. function callPluginPrintFunction(path, options, printPath, args) {
  12028. assert__default['default'].ok(path instanceof fastPath);
  12029. const node = path.getValue();
  12030. const {
  12031. printer
  12032. } = options; // Escape hatch
  12033. if (printer.hasPrettierIgnore && printer.hasPrettierIgnore(path)) {
  12034. return printPrettierIgnoredNode(node, options);
  12035. }
  12036. if (node) {
  12037. try {
  12038. // Potentially switch to a different parser
  12039. const sub = multiparser.printSubtree(path, printPath, options, printAstToDoc);
  12040. if (sub) {
  12041. return sub;
  12042. }
  12043. } catch (error) {
  12044. /* istanbul ignore if */
  12045. if (process.env.PRETTIER_DEBUG) {
  12046. throw error;
  12047. } // Continue with current parser
  12048. }
  12049. }
  12050. return printer.print(path, options, printPath, args);
  12051. }
  12052. var astToDoc = printAstToDoc;
  12053. function findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts) {
  12054. let resultStartNode = startNodeAndParents.node;
  12055. let resultEndNode = endNodeAndParents.node;
  12056. if (resultStartNode === resultEndNode) {
  12057. return {
  12058. startNode: resultStartNode,
  12059. endNode: resultEndNode
  12060. };
  12061. }
  12062. for (const endParent of endNodeAndParents.parentNodes) {
  12063. if (endParent.type !== "Program" && endParent.type !== "File" && opts.locStart(endParent) >= opts.locStart(startNodeAndParents.node)) {
  12064. resultEndNode = endParent;
  12065. } else {
  12066. break;
  12067. }
  12068. }
  12069. for (const startParent of startNodeAndParents.parentNodes) {
  12070. if (startParent.type !== "Program" && startParent.type !== "File" && opts.locEnd(startParent) <= opts.locEnd(endNodeAndParents.node)) {
  12071. resultStartNode = startParent;
  12072. } else {
  12073. break;
  12074. }
  12075. }
  12076. return {
  12077. startNode: resultStartNode,
  12078. endNode: resultEndNode
  12079. };
  12080. }
  12081. function findNodeAtOffset(node, offset, options, predicate, parentNodes = []) {
  12082. if (offset < options.locStart(node) || offset > options.locEnd(node)) {
  12083. return;
  12084. }
  12085. for (const childNode of comments.getSortedChildNodes(node, options)) {
  12086. const childResult = findNodeAtOffset(childNode, offset, options, predicate, [node, ...parentNodes]);
  12087. if (childResult) {
  12088. return childResult;
  12089. }
  12090. }
  12091. if (!predicate || predicate(node)) {
  12092. return {
  12093. node,
  12094. parentNodes
  12095. };
  12096. }
  12097. } // See https://www.ecma-international.org/ecma-262/5.1/#sec-A.5
  12098. function isJsSourceElement(type) {
  12099. return type === "Directive" || type === "TypeAlias" || type === "TSExportAssignment" || type.startsWith("Declare") || type.startsWith("TSDeclare") || type.endsWith("Statement") || type.endsWith("Declaration");
  12100. }
  12101. const jsonSourceElements = new Set(["ObjectExpression", "ArrayExpression", "StringLiteral", "NumericLiteral", "BooleanLiteral", "NullLiteral"]);
  12102. const graphqlSourceElements = new Set(["OperationDefinition", "FragmentDefinition", "VariableDefinition", "TypeExtensionDefinition", "ObjectTypeDefinition", "FieldDefinition", "DirectiveDefinition", "EnumTypeDefinition", "EnumValueDefinition", "InputValueDefinition", "InputObjectTypeDefinition", "SchemaDefinition", "OperationTypeDefinition", "InterfaceTypeDefinition", "UnionTypeDefinition", "ScalarTypeDefinition"]);
  12103. function isSourceElement(opts, node) {
  12104. /* istanbul ignore next */
  12105. if (node == null) {
  12106. return false;
  12107. }
  12108. switch (opts.parser) {
  12109. case "flow":
  12110. case "babel":
  12111. case "babel-flow":
  12112. case "babel-ts":
  12113. case "typescript":
  12114. return isJsSourceElement(node.type);
  12115. case "json":
  12116. return jsonSourceElements.has(node.type);
  12117. case "graphql":
  12118. return graphqlSourceElements.has(node.kind);
  12119. case "vue":
  12120. return node.tag !== "root";
  12121. }
  12122. return false;
  12123. }
  12124. function calculateRange(text, opts, ast) {
  12125. // Contract the range so that it has non-whitespace characters at its endpoints.
  12126. // This ensures we can format a range that doesn't end on a node.
  12127. const rangeStringOrig = text.slice(opts.rangeStart, opts.rangeEnd);
  12128. const startNonWhitespace = Math.max(opts.rangeStart + rangeStringOrig.search(/\S/), opts.rangeStart);
  12129. let endNonWhitespace;
  12130. for (endNonWhitespace = opts.rangeEnd; endNonWhitespace > opts.rangeStart; --endNonWhitespace) {
  12131. if (/\S/.test(text[endNonWhitespace - 1])) {
  12132. break;
  12133. }
  12134. }
  12135. const startNodeAndParents = findNodeAtOffset(ast, startNonWhitespace, opts, node => isSourceElement(opts, node));
  12136. const endNodeAndParents = findNodeAtOffset(ast, endNonWhitespace, opts, node => isSourceElement(opts, node));
  12137. if (!startNodeAndParents || !endNodeAndParents) {
  12138. return {
  12139. rangeStart: 0,
  12140. rangeEnd: 0
  12141. };
  12142. }
  12143. const {
  12144. startNode,
  12145. endNode
  12146. } = findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts);
  12147. return {
  12148. rangeStart: Math.min(opts.locStart(startNode), opts.locStart(endNode)),
  12149. rangeEnd: Math.max(opts.locEnd(startNode), opts.locEnd(endNode))
  12150. };
  12151. }
  12152. var rangeUtil = {
  12153. calculateRange,
  12154. findNodeAtOffset
  12155. };
  12156. const {
  12157. printer: {
  12158. printDocToString: printDocToString$1
  12159. },
  12160. debug: {
  12161. printDocToDebug
  12162. }
  12163. } = document;
  12164. const {
  12165. getAlignmentSize: getAlignmentSize$1
  12166. } = util;
  12167. const {
  12168. guessEndOfLine: guessEndOfLine$1,
  12169. convertEndOfLineToChars: convertEndOfLineToChars$2,
  12170. countEndOfLineChars: countEndOfLineChars$1,
  12171. normalizeEndOfLine: normalizeEndOfLine$1
  12172. } = endOfLine;
  12173. const normalizeOptions$1 = options$1.normalize;
  12174. const BOM = "\uFEFF";
  12175. const CURSOR = Symbol("cursor");
  12176. function attachComments(text, ast, opts) {
  12177. const astComments = ast.comments;
  12178. if (astComments) {
  12179. delete ast.comments;
  12180. comments.attach(astComments, ast, text, opts);
  12181. }
  12182. opts[Symbol.for("comments")] = astComments || [];
  12183. opts[Symbol.for("tokens")] = ast.tokens || [];
  12184. opts.originalText = text;
  12185. return astComments;
  12186. }
  12187. function coreFormat(text, opts, addAlignmentSize) {
  12188. if (!text || !text.trim().length) {
  12189. return {
  12190. formatted: "",
  12191. cursorOffset: -1
  12192. };
  12193. }
  12194. addAlignmentSize = addAlignmentSize || 0;
  12195. const parsed = parser.parse(text, opts);
  12196. const {
  12197. ast
  12198. } = parsed;
  12199. text = parsed.text;
  12200. if (opts.cursorOffset >= 0) {
  12201. const nodeResult = rangeUtil.findNodeAtOffset(ast, opts.cursorOffset, opts);
  12202. if (nodeResult && nodeResult.node) {
  12203. opts.cursorNode = nodeResult.node;
  12204. }
  12205. }
  12206. const astComments = attachComments(text, ast, opts);
  12207. const doc = astToDoc(ast, opts, addAlignmentSize);
  12208. const result = printDocToString$1(doc, opts);
  12209. comments.ensureAllCommentsPrinted(astComments); // Remove extra leading indentation as well as the added indentation after last newline
  12210. if (addAlignmentSize > 0) {
  12211. const trimmed = result.formatted.trim();
  12212. if (result.cursorNodeStart !== undefined) {
  12213. result.cursorNodeStart -= result.formatted.indexOf(trimmed);
  12214. }
  12215. result.formatted = trimmed + convertEndOfLineToChars$2(opts.endOfLine);
  12216. }
  12217. if (opts.cursorOffset >= 0) {
  12218. let oldCursorNodeStart;
  12219. let oldCursorNodeText;
  12220. let cursorOffsetRelativeToOldCursorNode;
  12221. let newCursorNodeStart;
  12222. let newCursorNodeText;
  12223. if (opts.cursorNode && result.cursorNodeText) {
  12224. oldCursorNodeStart = opts.locStart(opts.cursorNode);
  12225. oldCursorNodeText = text.slice(oldCursorNodeStart, opts.locEnd(opts.cursorNode));
  12226. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset - oldCursorNodeStart;
  12227. newCursorNodeStart = result.cursorNodeStart;
  12228. newCursorNodeText = result.cursorNodeText;
  12229. } else {
  12230. oldCursorNodeStart = 0;
  12231. oldCursorNodeText = text;
  12232. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset;
  12233. newCursorNodeStart = 0;
  12234. newCursorNodeText = result.formatted;
  12235. }
  12236. if (oldCursorNodeText === newCursorNodeText) {
  12237. return {
  12238. formatted: result.formatted,
  12239. cursorOffset: newCursorNodeStart + cursorOffsetRelativeToOldCursorNode
  12240. };
  12241. } // diff old and new cursor node texts, with a special cursor
  12242. // symbol inserted to find out where it moves to
  12243. const oldCursorNodeCharArray = oldCursorNodeText.split("");
  12244. oldCursorNodeCharArray.splice(cursorOffsetRelativeToOldCursorNode, 0, CURSOR);
  12245. const newCursorNodeCharArray = newCursorNodeText.split("");
  12246. const cursorNodeDiff = index_es6.diffArrays(oldCursorNodeCharArray, newCursorNodeCharArray);
  12247. let cursorOffset = newCursorNodeStart;
  12248. for (const entry of cursorNodeDiff) {
  12249. if (entry.removed) {
  12250. if (entry.value.includes(CURSOR)) {
  12251. break;
  12252. }
  12253. } else {
  12254. cursorOffset += entry.count;
  12255. }
  12256. }
  12257. return {
  12258. formatted: result.formatted,
  12259. cursorOffset
  12260. };
  12261. }
  12262. return {
  12263. formatted: result.formatted,
  12264. cursorOffset: -1
  12265. };
  12266. }
  12267. function formatRange(text, opts) {
  12268. const parsed = parser.parse(text, opts);
  12269. const {
  12270. ast
  12271. } = parsed;
  12272. text = parsed.text;
  12273. const {
  12274. rangeStart,
  12275. rangeEnd
  12276. } = rangeUtil.calculateRange(text, opts, ast);
  12277. const rangeString = text.slice(rangeStart, rangeEnd); // Try to extend the range backwards to the beginning of the line.
  12278. // This is so we can detect indentation correctly and restore it.
  12279. // Use `Math.min` since `lastIndexOf` returns 0 when `rangeStart` is 0
  12280. const rangeStart2 = Math.min(rangeStart, text.lastIndexOf("\n", rangeStart) + 1);
  12281. const indentString = text.slice(rangeStart2, rangeStart).match(/^\s*/)[0];
  12282. const alignmentSize = getAlignmentSize$1(indentString, opts.tabWidth);
  12283. const rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
  12284. rangeStart: 0,
  12285. rangeEnd: Infinity,
  12286. // Track the cursor offset only if it's within our range
  12287. cursorOffset: opts.cursorOffset > rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1,
  12288. // Always use `lf` to format, we'll replace it later
  12289. endOfLine: "lf"
  12290. }), alignmentSize); // Since the range contracts to avoid trailing whitespace,
  12291. // we need to remove the newline that was inserted by the `format` call.
  12292. const rangeTrimmed = rangeResult.formatted.trimEnd();
  12293. let {
  12294. cursorOffset
  12295. } = opts;
  12296. if (cursorOffset >= rangeEnd) {
  12297. // handle the case where the cursor was past the end of the range
  12298. cursorOffset = opts.cursorOffset + (rangeTrimmed.length - rangeString.length);
  12299. } else if (rangeResult.cursorOffset >= 0) {
  12300. // handle the case where the cursor was in the range
  12301. cursorOffset = rangeResult.cursorOffset + rangeStart;
  12302. } // keep the cursor as it was if it was before the start of the range
  12303. let formatted = text.slice(0, rangeStart) + rangeTrimmed + text.slice(rangeEnd);
  12304. if (opts.endOfLine !== "lf") {
  12305. const eol = convertEndOfLineToChars$2(opts.endOfLine);
  12306. if (cursorOffset >= 0 && eol === "\r\n") {
  12307. cursorOffset += countEndOfLineChars$1(formatted.slice(0, cursorOffset), "\n");
  12308. }
  12309. formatted = formatted.replace(/\n/g, eol);
  12310. }
  12311. return {
  12312. formatted,
  12313. cursorOffset
  12314. };
  12315. }
  12316. function format(originalText, opts) {
  12317. const selectedParser = parser.resolveParser(opts);
  12318. const hasBOM = originalText.charAt(0) === BOM;
  12319. let text = hasBOM ? originalText.slice(1) : originalText;
  12320. const hasCursor = opts.cursorOffset >= 0;
  12321. if (!hasCursor) {
  12322. opts.cursorOffset = -1;
  12323. }
  12324. const hasPragma = !selectedParser.hasPragma || selectedParser.hasPragma(text);
  12325. if (opts.requirePragma && !hasPragma) {
  12326. return {
  12327. formatted: originalText,
  12328. cursorOffset: opts.cursorOffset
  12329. };
  12330. }
  12331. if (opts.endOfLine === "auto") {
  12332. opts.endOfLine = guessEndOfLine$1(text);
  12333. }
  12334. const hasRangeStart = opts.rangeStart > 0;
  12335. const hasRangeEnd = opts.rangeEnd < text.length;
  12336. if (hasBOM) {
  12337. if (hasCursor) {
  12338. opts.cursorOffset--;
  12339. }
  12340. if (hasRangeStart) {
  12341. opts.rangeStart--;
  12342. }
  12343. if (hasRangeEnd) {
  12344. opts.rangeEnd--;
  12345. }
  12346. } // get rid of CR/CRLF parsing
  12347. if (text.includes("\r")) {
  12348. const countCrlfBefore = position => countEndOfLineChars$1(text.slice(0, position), "\r\n");
  12349. if (hasCursor) {
  12350. opts.cursorOffset -= countCrlfBefore(opts.cursorOffset);
  12351. }
  12352. if (hasRangeStart) {
  12353. opts.rangeStart -= countCrlfBefore(opts.rangeStart);
  12354. }
  12355. if (hasRangeEnd) {
  12356. opts.rangeEnd -= countCrlfBefore(opts.rangeEnd);
  12357. }
  12358. text = normalizeEndOfLine$1(text);
  12359. }
  12360. if (opts.rangeStart < 0) {
  12361. opts.rangeStart = 0;
  12362. }
  12363. if (opts.rangeEnd > text.length) {
  12364. opts.rangeEnd = text.length;
  12365. }
  12366. let result;
  12367. if (hasRangeStart || hasRangeEnd) {
  12368. result = formatRange(text, opts);
  12369. } else {
  12370. if (!hasPragma && opts.insertPragma && opts.printer.insertPragma) {
  12371. text = opts.printer.insertPragma(text);
  12372. }
  12373. result = coreFormat(text, opts);
  12374. }
  12375. if (hasBOM) {
  12376. result.formatted = BOM + result.formatted;
  12377. if (hasCursor && result.cursorOffset >= 0) {
  12378. result.cursorOffset++;
  12379. }
  12380. }
  12381. return result;
  12382. }
  12383. var core = {
  12384. formatWithCursor(text, opts) {
  12385. opts = normalizeOptions$1(opts);
  12386. return format(text, opts);
  12387. },
  12388. parse(text, opts, massage) {
  12389. opts = normalizeOptions$1(opts);
  12390. text = normalizeEndOfLine$1(text.charAt(0) === BOM ? text.slice(1) : text);
  12391. const parsed = parser.parse(text, opts);
  12392. if (massage) {
  12393. parsed.ast = massageAst(parsed.ast, opts);
  12394. }
  12395. return parsed;
  12396. },
  12397. formatAST(ast, opts) {
  12398. opts = normalizeOptions$1(opts);
  12399. const doc = astToDoc(ast, opts);
  12400. return printDocToString$1(doc, opts);
  12401. },
  12402. // Doesn't handle shebang for now
  12403. formatDoc(doc, opts) {
  12404. opts = normalizeOptions$1(Object.assign({}, opts, {
  12405. parser: "babel"
  12406. }));
  12407. const debug = printDocToDebug(doc);
  12408. return format(debug, opts).formatted;
  12409. },
  12410. printToDoc(originalText, opts) {
  12411. opts = normalizeOptions$1(opts);
  12412. const parsed = parser.parse(originalText, opts);
  12413. const {
  12414. ast,
  12415. text
  12416. } = parsed;
  12417. attachComments(text, ast, opts);
  12418. return astToDoc(ast, opts);
  12419. },
  12420. printDocToString(doc, opts) {
  12421. return printDocToString$1(doc, normalizeOptions$1(opts));
  12422. }
  12423. };
  12424. var concatMap = function (xs, fn) {
  12425. var res = [];
  12426. for (var i = 0; i < xs.length; i++) {
  12427. var x = fn(xs[i], i);
  12428. if (isArray$2(x)) res.push.apply(res, x);else res.push(x);
  12429. }
  12430. return res;
  12431. };
  12432. var isArray$2 = Array.isArray || function (xs) {
  12433. return Object.prototype.toString.call(xs) === '[object Array]';
  12434. };
  12435. var balancedMatch = balanced;
  12436. function balanced(a, b, str) {
  12437. if (a instanceof RegExp) a = maybeMatch(a, str);
  12438. if (b instanceof RegExp) b = maybeMatch(b, str);
  12439. var r = range(a, b, str);
  12440. return r && {
  12441. start: r[0],
  12442. end: r[1],
  12443. pre: str.slice(0, r[0]),
  12444. body: str.slice(r[0] + a.length, r[1]),
  12445. post: str.slice(r[1] + b.length)
  12446. };
  12447. }
  12448. function maybeMatch(reg, str) {
  12449. var m = str.match(reg);
  12450. return m ? m[0] : null;
  12451. }
  12452. balanced.range = range;
  12453. function range(a, b, str) {
  12454. var begs, beg, left, right, result;
  12455. var ai = str.indexOf(a);
  12456. var bi = str.indexOf(b, ai + 1);
  12457. var i = ai;
  12458. if (ai >= 0 && bi > 0) {
  12459. begs = [];
  12460. left = str.length;
  12461. while (i >= 0 && !result) {
  12462. if (i == ai) {
  12463. begs.push(i);
  12464. ai = str.indexOf(a, i + 1);
  12465. } else if (begs.length == 1) {
  12466. result = [begs.pop(), bi];
  12467. } else {
  12468. beg = begs.pop();
  12469. if (beg < left) {
  12470. left = beg;
  12471. right = bi;
  12472. }
  12473. bi = str.indexOf(b, i + 1);
  12474. }
  12475. i = ai < bi && ai >= 0 ? ai : bi;
  12476. }
  12477. if (begs.length) {
  12478. result = [left, right];
  12479. }
  12480. }
  12481. return result;
  12482. }
  12483. var braceExpansion = expandTop;
  12484. var escSlash = '\0SLASH' + Math.random() + '\0';
  12485. var escOpen = '\0OPEN' + Math.random() + '\0';
  12486. var escClose = '\0CLOSE' + Math.random() + '\0';
  12487. var escComma = '\0COMMA' + Math.random() + '\0';
  12488. var escPeriod = '\0PERIOD' + Math.random() + '\0';
  12489. function numeric$1(str) {
  12490. return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
  12491. }
  12492. function escapeBraces(str) {
  12493. return str.split('\\\\').join(escSlash).split('\\{').join(escOpen).split('\\}').join(escClose).split('\\,').join(escComma).split('\\.').join(escPeriod);
  12494. }
  12495. function unescapeBraces(str) {
  12496. return str.split(escSlash).join('\\').split(escOpen).join('{').split(escClose).join('}').split(escComma).join(',').split(escPeriod).join('.');
  12497. } // Basically just str.split(","), but handling cases
  12498. // where we have nested braced sections, which should be
  12499. // treated as individual members, like {a,{b,c},d}
  12500. function parseCommaParts(str) {
  12501. if (!str) return [''];
  12502. var parts = [];
  12503. var m = balancedMatch('{', '}', str);
  12504. if (!m) return str.split(',');
  12505. var pre = m.pre;
  12506. var body = m.body;
  12507. var post = m.post;
  12508. var p = pre.split(',');
  12509. p[p.length - 1] += '{' + body + '}';
  12510. var postParts = parseCommaParts(post);
  12511. if (post.length) {
  12512. p[p.length - 1] += postParts.shift();
  12513. p.push.apply(p, postParts);
  12514. }
  12515. parts.push.apply(parts, p);
  12516. return parts;
  12517. }
  12518. function expandTop(str) {
  12519. if (!str) return []; // I don't know why Bash 4.3 does this, but it does.
  12520. // Anything starting with {} will have the first two bytes preserved
  12521. // but *only* at the top level, so {},a}b will not expand to anything,
  12522. // but a{},b}c will be expanded to [a}c,abc].
  12523. // One could argue that this is a bug in Bash, but since the goal of
  12524. // this module is to match Bash's rules, we escape a leading {}
  12525. if (str.substr(0, 2) === '{}') {
  12526. str = '\\{\\}' + str.substr(2);
  12527. }
  12528. return expand(escapeBraces(str), true).map(unescapeBraces);
  12529. }
  12530. function embrace(str) {
  12531. return '{' + str + '}';
  12532. }
  12533. function isPadded(el) {
  12534. return /^-?0\d/.test(el);
  12535. }
  12536. function lte(i, y) {
  12537. return i <= y;
  12538. }
  12539. function gte$1(i, y) {
  12540. return i >= y;
  12541. }
  12542. function expand(str, isTop) {
  12543. var expansions = [];
  12544. var m = balancedMatch('{', '}', str);
  12545. if (!m || /\$$/.test(m.pre)) return [str];
  12546. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  12547. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  12548. var isSequence = isNumericSequence || isAlphaSequence;
  12549. var isOptions = m.body.indexOf(',') >= 0;
  12550. if (!isSequence && !isOptions) {
  12551. // {a},b}
  12552. if (m.post.match(/,.*\}/)) {
  12553. str = m.pre + '{' + m.body + escClose + m.post;
  12554. return expand(str);
  12555. }
  12556. return [str];
  12557. }
  12558. var n;
  12559. if (isSequence) {
  12560. n = m.body.split(/\.\./);
  12561. } else {
  12562. n = parseCommaParts(m.body);
  12563. if (n.length === 1) {
  12564. // x{{a,b}}y ==> x{a}y x{b}y
  12565. n = expand(n[0], false).map(embrace);
  12566. if (n.length === 1) {
  12567. var post = m.post.length ? expand(m.post, false) : [''];
  12568. return post.map(function (p) {
  12569. return m.pre + n[0] + p;
  12570. });
  12571. }
  12572. }
  12573. } // at this point, n is the parts, and we know it's not a comma set
  12574. // with a single entry.
  12575. // no need to expand pre, since it is guaranteed to be free of brace-sets
  12576. var pre = m.pre;
  12577. var post = m.post.length ? expand(m.post, false) : [''];
  12578. var N;
  12579. if (isSequence) {
  12580. var x = numeric$1(n[0]);
  12581. var y = numeric$1(n[1]);
  12582. var width = Math.max(n[0].length, n[1].length);
  12583. var incr = n.length == 3 ? Math.abs(numeric$1(n[2])) : 1;
  12584. var test = lte;
  12585. var reverse = y < x;
  12586. if (reverse) {
  12587. incr *= -1;
  12588. test = gte$1;
  12589. }
  12590. var pad = n.some(isPadded);
  12591. N = [];
  12592. for (var i = x; test(i, y); i += incr) {
  12593. var c;
  12594. if (isAlphaSequence) {
  12595. c = String.fromCharCode(i);
  12596. if (c === '\\') c = '';
  12597. } else {
  12598. c = String(i);
  12599. if (pad) {
  12600. var need = width - c.length;
  12601. if (need > 0) {
  12602. var z = new Array(need + 1).join('0');
  12603. if (i < 0) c = '-' + z + c.slice(1);else c = z + c;
  12604. }
  12605. }
  12606. }
  12607. N.push(c);
  12608. }
  12609. } else {
  12610. N = concatMap(n, function (el) {
  12611. return expand(el, false);
  12612. });
  12613. }
  12614. for (var j = 0; j < N.length; j++) {
  12615. for (var k = 0; k < post.length; k++) {
  12616. var expansion = pre + N[j] + post[k];
  12617. if (!isTop || isSequence || expansion) expansions.push(expansion);
  12618. }
  12619. }
  12620. return expansions;
  12621. }
  12622. var minimatch_1 = minimatch;
  12623. minimatch.Minimatch = Minimatch;
  12624. var path = {
  12625. sep: '/'
  12626. };
  12627. try {
  12628. path = path__default['default'];
  12629. } catch (er) {}
  12630. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  12631. var plTypes = {
  12632. '!': {
  12633. open: '(?:(?!(?:',
  12634. close: '))[^/]*?)'
  12635. },
  12636. '?': {
  12637. open: '(?:',
  12638. close: ')?'
  12639. },
  12640. '+': {
  12641. open: '(?:',
  12642. close: ')+'
  12643. },
  12644. '*': {
  12645. open: '(?:',
  12646. close: ')*'
  12647. },
  12648. '@': {
  12649. open: '(?:',
  12650. close: ')'
  12651. }
  12652. }; // any single thing other than /
  12653. // don't need to escape / when using new RegExp()
  12654. var qmark = '[^/]'; // * => any number of characters
  12655. var star = qmark + '*?'; // ** when dots are allowed. Anything goes, except .. and .
  12656. // not (^ or / followed by one or two dots followed by $ or /),
  12657. // followed by anything, any number of times.
  12658. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'; // not a ^ or / followed by a dot,
  12659. // followed by anything, any number of times.
  12660. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'; // characters that need to be escaped in RegExp.
  12661. var reSpecials = charSet('().*{}+?[]^$\\!'); // "abc" -> { a:true, b:true, c:true }
  12662. function charSet(s) {
  12663. return s.split('').reduce(function (set, c) {
  12664. set[c] = true;
  12665. return set;
  12666. }, {});
  12667. } // normalizes slashes.
  12668. var slashSplit = /\/+/;
  12669. minimatch.filter = filter;
  12670. function filter(pattern, options) {
  12671. options = options || {};
  12672. return function (p, i, list) {
  12673. return minimatch(p, pattern, options);
  12674. };
  12675. }
  12676. function ext(a, b) {
  12677. a = a || {};
  12678. b = b || {};
  12679. var t = {};
  12680. Object.keys(b).forEach(function (k) {
  12681. t[k] = b[k];
  12682. });
  12683. Object.keys(a).forEach(function (k) {
  12684. t[k] = a[k];
  12685. });
  12686. return t;
  12687. }
  12688. minimatch.defaults = function (def) {
  12689. if (!def || !Object.keys(def).length) return minimatch;
  12690. var orig = minimatch;
  12691. var m = function minimatch(p, pattern, options) {
  12692. return orig.minimatch(p, pattern, ext(def, options));
  12693. };
  12694. m.Minimatch = function Minimatch(pattern, options) {
  12695. return new orig.Minimatch(pattern, ext(def, options));
  12696. };
  12697. return m;
  12698. };
  12699. Minimatch.defaults = function (def) {
  12700. if (!def || !Object.keys(def).length) return Minimatch;
  12701. return minimatch.defaults(def).Minimatch;
  12702. };
  12703. function minimatch(p, pattern, options) {
  12704. if (typeof pattern !== 'string') {
  12705. throw new TypeError('glob pattern string required');
  12706. }
  12707. if (!options) options = {}; // shortcut: comments match nothing.
  12708. if (!options.nocomment && pattern.charAt(0) === '#') {
  12709. return false;
  12710. } // "" only matches ""
  12711. if (pattern.trim() === '') return p === '';
  12712. return new Minimatch(pattern, options).match(p);
  12713. }
  12714. function Minimatch(pattern, options) {
  12715. if (!(this instanceof Minimatch)) {
  12716. return new Minimatch(pattern, options);
  12717. }
  12718. if (typeof pattern !== 'string') {
  12719. throw new TypeError('glob pattern string required');
  12720. }
  12721. if (!options) options = {};
  12722. pattern = pattern.trim(); // windows support: need to use /, not \
  12723. if (path.sep !== '/') {
  12724. pattern = pattern.split(path.sep).join('/');
  12725. }
  12726. this.options = options;
  12727. this.set = [];
  12728. this.pattern = pattern;
  12729. this.regexp = null;
  12730. this.negate = false;
  12731. this.comment = false;
  12732. this.empty = false; // make the set of regexps etc.
  12733. this.make();
  12734. }
  12735. Minimatch.prototype.debug = function () {};
  12736. Minimatch.prototype.make = make;
  12737. function make() {
  12738. // don't do it more than once.
  12739. if (this._made) return;
  12740. var pattern = this.pattern;
  12741. var options = this.options; // empty patterns and comments match nothing.
  12742. if (!options.nocomment && pattern.charAt(0) === '#') {
  12743. this.comment = true;
  12744. return;
  12745. }
  12746. if (!pattern) {
  12747. this.empty = true;
  12748. return;
  12749. } // step 1: figure out negation, etc.
  12750. this.parseNegate(); // step 2: expand braces
  12751. var set = this.globSet = this.braceExpand();
  12752. if (options.debug) this.debug = console.error;
  12753. this.debug(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
  12754. // matching patterns.
  12755. // These will be regexps, except in the case of "**", which is
  12756. // set to the GLOBSTAR object for globstar behavior,
  12757. // and will not contain any / characters
  12758. set = this.globParts = set.map(function (s) {
  12759. return s.split(slashSplit);
  12760. });
  12761. this.debug(this.pattern, set); // glob --> regexps
  12762. set = set.map(function (s, si, set) {
  12763. return s.map(this.parse, this);
  12764. }, this);
  12765. this.debug(this.pattern, set); // filter out everything that didn't compile properly.
  12766. set = set.filter(function (s) {
  12767. return s.indexOf(false) === -1;
  12768. });
  12769. this.debug(this.pattern, set);
  12770. this.set = set;
  12771. }
  12772. Minimatch.prototype.parseNegate = parseNegate;
  12773. function parseNegate() {
  12774. var pattern = this.pattern;
  12775. var negate = false;
  12776. var options = this.options;
  12777. var negateOffset = 0;
  12778. if (options.nonegate) return;
  12779. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === '!'; i++) {
  12780. negate = !negate;
  12781. negateOffset++;
  12782. }
  12783. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  12784. this.negate = negate;
  12785. } // Brace expansion:
  12786. // a{b,c}d -> abd acd
  12787. // a{b,}c -> abc ac
  12788. // a{0..3}d -> a0d a1d a2d a3d
  12789. // a{b,c{d,e}f}g -> abg acdfg acefg
  12790. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  12791. //
  12792. // Invalid sets are not expanded.
  12793. // a{2..}b -> a{2..}b
  12794. // a{b}c -> a{b}c
  12795. minimatch.braceExpand = function (pattern, options) {
  12796. return braceExpand(pattern, options);
  12797. };
  12798. Minimatch.prototype.braceExpand = braceExpand;
  12799. function braceExpand(pattern, options) {
  12800. if (!options) {
  12801. if (this instanceof Minimatch) {
  12802. options = this.options;
  12803. } else {
  12804. options = {};
  12805. }
  12806. }
  12807. pattern = typeof pattern === 'undefined' ? this.pattern : pattern;
  12808. if (typeof pattern === 'undefined') {
  12809. throw new TypeError('undefined pattern');
  12810. }
  12811. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  12812. // shortcut. no need to expand.
  12813. return [pattern];
  12814. }
  12815. return braceExpansion(pattern);
  12816. } // parse a component of the expanded set.
  12817. // At this point, no pattern may contain "/" in it
  12818. // so we're going to return a 2d array, where each entry is the full
  12819. // pattern, split on '/', and then turned into a regular expression.
  12820. // A regexp is made at the end which joins each array with an
  12821. // escaped /, and another full one which joins each regexp with |.
  12822. //
  12823. // Following the lead of Bash 4.1, note that "**" only has special meaning
  12824. // when it is the *only* thing in a path portion. Otherwise, any series
  12825. // of * is equivalent to a single *. Globstar behavior is enabled by
  12826. // default, and can be disabled by setting options.noglobstar.
  12827. Minimatch.prototype.parse = parse$1;
  12828. var SUBPARSE = {};
  12829. function parse$1(pattern, isSub) {
  12830. if (pattern.length > 1024 * 64) {
  12831. throw new TypeError('pattern is too long');
  12832. }
  12833. var options = this.options; // shortcuts
  12834. if (!options.noglobstar && pattern === '**') return GLOBSTAR;
  12835. if (pattern === '') return '';
  12836. var re = '';
  12837. var hasMagic = !!options.nocase;
  12838. var escaping = false; // ? => one single character
  12839. var patternListStack = [];
  12840. var negativeLists = [];
  12841. var stateChar;
  12842. var inClass = false;
  12843. var reClassStart = -1;
  12844. var classStart = -1; // . and .. never match anything that doesn't start with .,
  12845. // even when options.dot is set.
  12846. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  12847. // not (start or / followed by . or .. followed by / or end)
  12848. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' : '(?!\\.)';
  12849. var self = this;
  12850. function clearStateChar() {
  12851. if (stateChar) {
  12852. // we had some state-tracking character
  12853. // that wasn't consumed by this pass.
  12854. switch (stateChar) {
  12855. case '*':
  12856. re += star;
  12857. hasMagic = true;
  12858. break;
  12859. case '?':
  12860. re += qmark;
  12861. hasMagic = true;
  12862. break;
  12863. default:
  12864. re += '\\' + stateChar;
  12865. break;
  12866. }
  12867. self.debug('clearStateChar %j %j', stateChar, re);
  12868. stateChar = false;
  12869. }
  12870. }
  12871. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  12872. this.debug('%s\t%s %s %j', pattern, i, re, c); // skip over any that are escaped.
  12873. if (escaping && reSpecials[c]) {
  12874. re += '\\' + c;
  12875. escaping = false;
  12876. continue;
  12877. }
  12878. switch (c) {
  12879. case '/':
  12880. // completely not allowed, even escaped.
  12881. // Should already be path-split by now.
  12882. return false;
  12883. case '\\':
  12884. clearStateChar();
  12885. escaping = true;
  12886. continue;
  12887. // the various stateChar values
  12888. // for the "extglob" stuff.
  12889. case '?':
  12890. case '*':
  12891. case '+':
  12892. case '@':
  12893. case '!':
  12894. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c); // all of those are literals inside a class, except that
  12895. // the glob [!a] means [^a] in regexp
  12896. if (inClass) {
  12897. this.debug(' in class');
  12898. if (c === '!' && i === classStart + 1) c = '^';
  12899. re += c;
  12900. continue;
  12901. } // if we already have a stateChar, then it means
  12902. // that there was something like ** or +? in there.
  12903. // Handle the stateChar, then proceed with this one.
  12904. self.debug('call clearStateChar %j', stateChar);
  12905. clearStateChar();
  12906. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  12907. // just clear the statechar *now*, rather than even diving into
  12908. // the patternList stuff.
  12909. if (options.noext) clearStateChar();
  12910. continue;
  12911. case '(':
  12912. if (inClass) {
  12913. re += '(';
  12914. continue;
  12915. }
  12916. if (!stateChar) {
  12917. re += '\\(';
  12918. continue;
  12919. }
  12920. patternListStack.push({
  12921. type: stateChar,
  12922. start: i - 1,
  12923. reStart: re.length,
  12924. open: plTypes[stateChar].open,
  12925. close: plTypes[stateChar].close
  12926. }); // negation is (?:(?!js)[^/]*)
  12927. re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
  12928. this.debug('plType %j %j', stateChar, re);
  12929. stateChar = false;
  12930. continue;
  12931. case ')':
  12932. if (inClass || !patternListStack.length) {
  12933. re += '\\)';
  12934. continue;
  12935. }
  12936. clearStateChar();
  12937. hasMagic = true;
  12938. var pl = patternListStack.pop(); // negation is (?:(?!js)[^/]*)
  12939. // The others are (?:<pattern>)<type>
  12940. re += pl.close;
  12941. if (pl.type === '!') {
  12942. negativeLists.push(pl);
  12943. }
  12944. pl.reEnd = re.length;
  12945. continue;
  12946. case '|':
  12947. if (inClass || !patternListStack.length || escaping) {
  12948. re += '\\|';
  12949. escaping = false;
  12950. continue;
  12951. }
  12952. clearStateChar();
  12953. re += '|';
  12954. continue;
  12955. // these are mostly the same in regexp and glob
  12956. case '[':
  12957. // swallow any state-tracking char before the [
  12958. clearStateChar();
  12959. if (inClass) {
  12960. re += '\\' + c;
  12961. continue;
  12962. }
  12963. inClass = true;
  12964. classStart = i;
  12965. reClassStart = re.length;
  12966. re += c;
  12967. continue;
  12968. case ']':
  12969. // a right bracket shall lose its special
  12970. // meaning and represent itself in
  12971. // a bracket expression if it occurs
  12972. // first in the list. -- POSIX.2 2.8.3.2
  12973. if (i === classStart + 1 || !inClass) {
  12974. re += '\\' + c;
  12975. escaping = false;
  12976. continue;
  12977. } // handle the case where we left a class open.
  12978. // "[z-a]" is valid, equivalent to "\[z-a\]"
  12979. if (inClass) {
  12980. // split where the last [ was, make sure we don't have
  12981. // an invalid re. if so, re-walk the contents of the
  12982. // would-be class to re-translate any characters that
  12983. // were passed through as-is
  12984. // TODO: It would probably be faster to determine this
  12985. // without a try/catch and a new RegExp, but it's tricky
  12986. // to do safely. For now, this is safe and works.
  12987. var cs = pattern.substring(classStart + 1, i);
  12988. try {
  12989. RegExp('[' + cs + ']');
  12990. } catch (er) {
  12991. // not a valid class!
  12992. var sp = this.parse(cs, SUBPARSE);
  12993. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
  12994. hasMagic = hasMagic || sp[1];
  12995. inClass = false;
  12996. continue;
  12997. }
  12998. } // finish up the class.
  12999. hasMagic = true;
  13000. inClass = false;
  13001. re += c;
  13002. continue;
  13003. default:
  13004. // swallow any state char that wasn't consumed
  13005. clearStateChar();
  13006. if (escaping) {
  13007. // no need
  13008. escaping = false;
  13009. } else if (reSpecials[c] && !(c === '^' && inClass)) {
  13010. re += '\\';
  13011. }
  13012. re += c;
  13013. } // switch
  13014. } // for
  13015. // handle the case where we left a class open.
  13016. // "[abc" is valid, equivalent to "\[abc"
  13017. if (inClass) {
  13018. // split where the last [ was, and escape it
  13019. // this is a huge pita. We now have to re-walk
  13020. // the contents of the would-be class to re-translate
  13021. // any characters that were passed through as-is
  13022. cs = pattern.substr(classStart + 1);
  13023. sp = this.parse(cs, SUBPARSE);
  13024. re = re.substr(0, reClassStart) + '\\[' + sp[0];
  13025. hasMagic = hasMagic || sp[1];
  13026. } // handle the case where we had a +( thing at the *end*
  13027. // of the pattern.
  13028. // each pattern list stack adds 3 chars, and we need to go through
  13029. // and escape any | chars that were passed through as-is for the regexp.
  13030. // Go through and escape them, taking care not to double-escape any
  13031. // | chars that were already escaped.
  13032. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  13033. var tail = re.slice(pl.reStart + pl.open.length);
  13034. this.debug('setting tail', re, pl); // maybe some even number of \, then maybe 1 \, followed by a |
  13035. tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
  13036. if (!$2) {
  13037. // the | isn't already escaped, so escape it.
  13038. $2 = '\\';
  13039. } // need to escape all those slashes *again*, without escaping the
  13040. // one that we need for escaping the | character. As it works out,
  13041. // escaping an even number of slashes can be done by simply repeating
  13042. // it exactly after itself. That's why this trick works.
  13043. //
  13044. // I am sorry that you have to see this.
  13045. return $1 + $1 + $2 + '|';
  13046. });
  13047. this.debug('tail=%j\n %s', tail, tail, pl, re);
  13048. var t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
  13049. hasMagic = true;
  13050. re = re.slice(0, pl.reStart) + t + '\\(' + tail;
  13051. } // handle trailing things that only matter at the very end.
  13052. clearStateChar();
  13053. if (escaping) {
  13054. // trailing \\
  13055. re += '\\\\';
  13056. } // only need to apply the nodot start if the re starts with
  13057. // something that could conceivably capture a dot
  13058. var addPatternStart = false;
  13059. switch (re.charAt(0)) {
  13060. case '.':
  13061. case '[':
  13062. case '(':
  13063. addPatternStart = true;
  13064. } // Hack to work around lack of negative lookbehind in JS
  13065. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  13066. // like 'a.xyz.yz' doesn't match. So, the first negative
  13067. // lookahead, has to look ALL the way ahead, to the end of
  13068. // the pattern.
  13069. for (var n = negativeLists.length - 1; n > -1; n--) {
  13070. var nl = negativeLists[n];
  13071. var nlBefore = re.slice(0, nl.reStart);
  13072. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
  13073. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
  13074. var nlAfter = re.slice(nl.reEnd);
  13075. nlLast += nlAfter; // Handle nested stuff like *(*.js|!(*.json)), where open parens
  13076. // mean that we should *not* include the ) in the bit that is considered
  13077. // "after" the negated section.
  13078. var openParensBefore = nlBefore.split('(').length - 1;
  13079. var cleanAfter = nlAfter;
  13080. for (i = 0; i < openParensBefore; i++) {
  13081. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
  13082. }
  13083. nlAfter = cleanAfter;
  13084. var dollar = '';
  13085. if (nlAfter === '' && isSub !== SUBPARSE) {
  13086. dollar = '$';
  13087. }
  13088. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
  13089. re = newRe;
  13090. } // if the re is not "" at this point, then we need to make sure
  13091. // it doesn't match against an empty path part.
  13092. // Otherwise a/* will match a/, which it should not.
  13093. if (re !== '' && hasMagic) {
  13094. re = '(?=.)' + re;
  13095. }
  13096. if (addPatternStart) {
  13097. re = patternStart + re;
  13098. } // parsing just a piece of a larger pattern.
  13099. if (isSub === SUBPARSE) {
  13100. return [re, hasMagic];
  13101. } // skip the regexp for non-magical patterns
  13102. // unescape anything in it, though, so that it'll be
  13103. // an exact match against a file etc.
  13104. if (!hasMagic) {
  13105. return globUnescape(pattern);
  13106. }
  13107. var flags = options.nocase ? 'i' : '';
  13108. try {
  13109. var regExp = new RegExp('^' + re + '$', flags);
  13110. } catch (er) {
  13111. // If it was an invalid regular expression, then it can't match
  13112. // anything. This trick looks for a character after the end of
  13113. // the string, which is of course impossible, except in multi-line
  13114. // mode, but it's not a /m regex.
  13115. return new RegExp('$.');
  13116. }
  13117. regExp._glob = pattern;
  13118. regExp._src = re;
  13119. return regExp;
  13120. }
  13121. minimatch.makeRe = function (pattern, options) {
  13122. return new Minimatch(pattern, options || {}).makeRe();
  13123. };
  13124. Minimatch.prototype.makeRe = makeRe;
  13125. function makeRe() {
  13126. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  13127. // pattern strings, or "**".
  13128. //
  13129. // It's better to use .match(). This function shouldn't
  13130. // be used, really, but it's pretty convenient sometimes,
  13131. // when you just want to work with a regex.
  13132. var set = this.set;
  13133. if (!set.length) {
  13134. this.regexp = false;
  13135. return this.regexp;
  13136. }
  13137. var options = this.options;
  13138. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
  13139. var flags = options.nocase ? 'i' : '';
  13140. var re = set.map(function (pattern) {
  13141. return pattern.map(function (p) {
  13142. return p === GLOBSTAR ? twoStar : typeof p === 'string' ? regExpEscape(p) : p._src;
  13143. }).join('\\\/');
  13144. }).join('|'); // must match entire pattern
  13145. // ending in a * or ** will make it less strict.
  13146. re = '^(?:' + re + ')$'; // can match anything, as long as it's not this.
  13147. if (this.negate) re = '^(?!' + re + ').*$';
  13148. try {
  13149. this.regexp = new RegExp(re, flags);
  13150. } catch (ex) {
  13151. this.regexp = false;
  13152. }
  13153. return this.regexp;
  13154. }
  13155. minimatch.match = function (list, pattern, options) {
  13156. options = options || {};
  13157. var mm = new Minimatch(pattern, options);
  13158. list = list.filter(function (f) {
  13159. return mm.match(f);
  13160. });
  13161. if (mm.options.nonull && !list.length) {
  13162. list.push(pattern);
  13163. }
  13164. return list;
  13165. };
  13166. Minimatch.prototype.match = match;
  13167. function match(f, partial) {
  13168. this.debug('match', f, this.pattern); // short-circuit in the case of busted things.
  13169. // comments, etc.
  13170. if (this.comment) return false;
  13171. if (this.empty) return f === '';
  13172. if (f === '/' && partial) return true;
  13173. var options = this.options; // windows: need to use /, not \
  13174. if (path.sep !== '/') {
  13175. f = f.split(path.sep).join('/');
  13176. } // treat the test path as a set of pathparts.
  13177. f = f.split(slashSplit);
  13178. this.debug(this.pattern, 'split', f); // just ONE of the pattern sets in this.set needs to match
  13179. // in order for it to be valid. If negating, then just one
  13180. // match means that we have failed.
  13181. // Either way, return on the first hit.
  13182. var set = this.set;
  13183. this.debug(this.pattern, 'set', set); // Find the basename of the path by looking for the last non-empty segment
  13184. var filename;
  13185. var i;
  13186. for (i = f.length - 1; i >= 0; i--) {
  13187. filename = f[i];
  13188. if (filename) break;
  13189. }
  13190. for (i = 0; i < set.length; i++) {
  13191. var pattern = set[i];
  13192. var file = f;
  13193. if (options.matchBase && pattern.length === 1) {
  13194. file = [filename];
  13195. }
  13196. var hit = this.matchOne(file, pattern, partial);
  13197. if (hit) {
  13198. if (options.flipNegate) return true;
  13199. return !this.negate;
  13200. }
  13201. } // didn't get any hits. this is success if it's a negative
  13202. // pattern, failure otherwise.
  13203. if (options.flipNegate) return false;
  13204. return this.negate;
  13205. } // set partial to true to test if, for example,
  13206. // "/a/b" matches the start of "/*/b/*/d"
  13207. // Partial means, if you run out of file before you run
  13208. // out of pattern, then that's fine, as long as all
  13209. // the parts match.
  13210. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  13211. var options = this.options;
  13212. this.debug('matchOne', {
  13213. 'this': this,
  13214. file: file,
  13215. pattern: pattern
  13216. });
  13217. this.debug('matchOne', file.length, pattern.length);
  13218. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  13219. this.debug('matchOne loop');
  13220. var p = pattern[pi];
  13221. var f = file[fi];
  13222. this.debug(pattern, p, f); // should be impossible.
  13223. // some invalid regexp stuff in the set.
  13224. if (p === false) return false;
  13225. if (p === GLOBSTAR) {
  13226. this.debug('GLOBSTAR', [pattern, p, f]); // "**"
  13227. // a/**/b/**/c would match the following:
  13228. // a/b/x/y/z/c
  13229. // a/x/y/z/b/c
  13230. // a/b/x/b/x/c
  13231. // a/b/c
  13232. // To do this, take the rest of the pattern after
  13233. // the **, and see if it would match the file remainder.
  13234. // If so, return success.
  13235. // If not, the ** "swallows" a segment, and try again.
  13236. // This is recursively awful.
  13237. //
  13238. // a/**/b/**/c matching a/b/x/y/z/c
  13239. // - a matches a
  13240. // - doublestar
  13241. // - matchOne(b/x/y/z/c, b/**/c)
  13242. // - b matches b
  13243. // - doublestar
  13244. // - matchOne(x/y/z/c, c) -> no
  13245. // - matchOne(y/z/c, c) -> no
  13246. // - matchOne(z/c, c) -> no
  13247. // - matchOne(c, c) yes, hit
  13248. var fr = fi;
  13249. var pr = pi + 1;
  13250. if (pr === pl) {
  13251. this.debug('** at the end'); // a ** at the end will just swallow the rest.
  13252. // We have found a match.
  13253. // however, it will not swallow /.x, unless
  13254. // options.dot is set.
  13255. // . and .. are *never* matched by **, for explosively
  13256. // exponential reasons.
  13257. for (; fi < fl; fi++) {
  13258. if (file[fi] === '.' || file[fi] === '..' || !options.dot && file[fi].charAt(0) === '.') return false;
  13259. }
  13260. return true;
  13261. } // ok, let's see if we can swallow whatever we can.
  13262. while (fr < fl) {
  13263. var swallowee = file[fr];
  13264. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee); // XXX remove this slice. Just pass the start index.
  13265. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  13266. this.debug('globstar found match!', fr, fl, swallowee); // found a match.
  13267. return true;
  13268. } else {
  13269. // can't swallow "." or ".." ever.
  13270. // can only swallow ".foo" when explicitly asked.
  13271. if (swallowee === '.' || swallowee === '..' || !options.dot && swallowee.charAt(0) === '.') {
  13272. this.debug('dot detected!', file, fr, pattern, pr);
  13273. break;
  13274. } // ** swallows a segment, and continue.
  13275. this.debug('globstar swallow a segment, and continue');
  13276. fr++;
  13277. }
  13278. } // no match was found.
  13279. // However, in partial mode, we can't say this is necessarily over.
  13280. // If there's more *pattern* left, then
  13281. if (partial) {
  13282. // ran out of file
  13283. this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
  13284. if (fr === fl) return true;
  13285. }
  13286. return false;
  13287. } // something other than **
  13288. // non-magic patterns just have to match exactly
  13289. // patterns with magic have been turned into regexps.
  13290. var hit;
  13291. if (typeof p === 'string') {
  13292. if (options.nocase) {
  13293. hit = f.toLowerCase() === p.toLowerCase();
  13294. } else {
  13295. hit = f === p;
  13296. }
  13297. this.debug('string match', p, f, hit);
  13298. } else {
  13299. hit = f.match(p);
  13300. this.debug('pattern match', p, f, hit);
  13301. }
  13302. if (!hit) return false;
  13303. } // Note: ending in / means that we'll get a final ""
  13304. // at the end of the pattern. This can only match a
  13305. // corresponding "" at the end of the file.
  13306. // If the file ends in /, then it can only match a
  13307. // a pattern that ends in /, unless the pattern just
  13308. // doesn't have any more for it. But, a/b/ should *not*
  13309. // match "a/b/*", even though "" matches against the
  13310. // [^/]*? pattern, except in partial mode, where it might
  13311. // simply not be reached yet.
  13312. // However, a/b/ should still satisfy a/*
  13313. // now either we fell off the end of the pattern, or we're done.
  13314. if (fi === fl && pi === pl) {
  13315. // ran out of pattern and filename at the same time.
  13316. // an exact hit!
  13317. return true;
  13318. } else if (fi === fl) {
  13319. // ran out of file, but still had pattern left.
  13320. // this is ok if we're doing the match as part of
  13321. // a glob fs traversal.
  13322. return partial;
  13323. } else if (pi === pl) {
  13324. // ran out of pattern, still have file left.
  13325. // this is only acceptable if we're on the very last
  13326. // empty segment of a file with a trailing slash.
  13327. // a/* should match a/b/
  13328. var emptyFileEnd = fi === fl - 1 && file[fi] === '';
  13329. return emptyFileEnd;
  13330. } // should be unreachable.
  13331. throw new Error('wtf?');
  13332. }; // replace stuff like \* with *
  13333. function globUnescape(s) {
  13334. return s.replace(/\\(.)/g, '$1');
  13335. }
  13336. function regExpEscape(s) {
  13337. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
  13338. }
  13339. const copyProperty = (to, from, property, ignoreNonConfigurable) => {
  13340. // `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
  13341. // `Function#prototype` is non-writable and non-configurable so can never be modified.
  13342. if (property === 'length' || property === 'prototype') {
  13343. return;
  13344. }
  13345. const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
  13346. const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
  13347. if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
  13348. return;
  13349. }
  13350. Object.defineProperty(to, property, fromDescriptor);
  13351. }; // `Object.defineProperty()` throws if the property exists, is not configurable and either:
  13352. // - one its descriptors is changed
  13353. // - it is non-writable and its value is changed
  13354. const canCopyProperty = function (toDescriptor, fromDescriptor) {
  13355. return toDescriptor === undefined || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value);
  13356. };
  13357. const changePrototype = (to, from) => {
  13358. const fromPrototype = Object.getPrototypeOf(from);
  13359. if (fromPrototype === Object.getPrototypeOf(to)) {
  13360. return;
  13361. }
  13362. Object.setPrototypeOf(to, fromPrototype);
  13363. };
  13364. const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`;
  13365. const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString');
  13366. const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name'); // We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected.
  13367. // We use `bind()` instead of a closure for the same reason.
  13368. // Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times.
  13369. const changeToString = (to, from, name) => {
  13370. const withName = name === '' ? '' : `with ${name.trim()}() `;
  13371. const newToString = wrappedToString.bind(null, withName, from.toString()); // Ensure `to.toString.toString` is non-enumerable and has the same `same`
  13372. Object.defineProperty(newToString, 'name', toStringName);
  13373. Object.defineProperty(to, 'toString', Object.assign({}, toStringDescriptor, {
  13374. value: newToString
  13375. }));
  13376. };
  13377. const mimicFn = (to, from, {
  13378. ignoreNonConfigurable = false
  13379. } = {}) => {
  13380. const {
  13381. name
  13382. } = to;
  13383. for (const property of Reflect.ownKeys(from)) {
  13384. copyProperty(to, from, property, ignoreNonConfigurable);
  13385. }
  13386. changePrototype(to, from);
  13387. changeToString(to, from, name);
  13388. return to;
  13389. };
  13390. var mimicFn_1 = mimicFn;
  13391. var pDefer = () => {
  13392. const ret = {};
  13393. ret.promise = new Promise((resolve, reject) => {
  13394. ret.resolve = resolve;
  13395. ret.reject = reject;
  13396. });
  13397. return ret;
  13398. };
  13399. var dist = createCommonjsModule(function (module, exports) {
  13400. var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
  13401. return new (P || (P = Promise))(function (resolve, reject) {
  13402. function fulfilled(value) {
  13403. try {
  13404. step(generator.next(value));
  13405. } catch (e) {
  13406. reject(e);
  13407. }
  13408. }
  13409. function rejected(value) {
  13410. try {
  13411. step(generator["throw"](value));
  13412. } catch (e) {
  13413. reject(e);
  13414. }
  13415. }
  13416. function step(result) {
  13417. result.done ? resolve(result.value) : new P(function (resolve) {
  13418. resolve(result.value);
  13419. }).then(fulfilled, rejected);
  13420. }
  13421. step((generator = generator.apply(thisArg, _arguments || [])).next());
  13422. });
  13423. };
  13424. var __importDefault = this && this.__importDefault || function (mod) {
  13425. return mod && mod.__esModule ? mod : {
  13426. "default": mod
  13427. };
  13428. };
  13429. Object.defineProperty(exports, "__esModule", {
  13430. value: true
  13431. });
  13432. const p_defer_1 = __importDefault(pDefer);
  13433. function mapAgeCleaner(map, property = 'maxAge') {
  13434. let processingKey;
  13435. let processingTimer;
  13436. let processingDeferred;
  13437. const cleanup = () => __awaiter(this, void 0, void 0, function* () {
  13438. if (processingKey !== undefined) {
  13439. // If we are already processing an item, we can safely exit
  13440. return;
  13441. }
  13442. const setupTimer = item => __awaiter(this, void 0, void 0, function* () {
  13443. processingDeferred = p_defer_1.default();
  13444. const delay = item[1][property] - Date.now();
  13445. if (delay <= 0) {
  13446. // Remove the item immediately if the delay is equal to or below 0
  13447. map.delete(item[0]);
  13448. processingDeferred.resolve();
  13449. return;
  13450. } // Keep track of the current processed key
  13451. processingKey = item[0];
  13452. processingTimer = setTimeout(() => {
  13453. // Remove the item when the timeout fires
  13454. map.delete(item[0]);
  13455. if (processingDeferred) {
  13456. processingDeferred.resolve();
  13457. }
  13458. }, delay); // tslint:disable-next-line:strict-type-predicates
  13459. if (typeof processingTimer.unref === 'function') {
  13460. // Don't hold up the process from exiting
  13461. processingTimer.unref();
  13462. }
  13463. return processingDeferred.promise;
  13464. });
  13465. try {
  13466. for (const entry of map) {
  13467. yield setupTimer(entry);
  13468. }
  13469. } catch (_a) {// Do nothing if an error occurs, this means the timer was cleaned up and we should stop processing
  13470. }
  13471. processingKey = undefined;
  13472. });
  13473. const reset = () => {
  13474. processingKey = undefined;
  13475. if (processingTimer !== undefined) {
  13476. clearTimeout(processingTimer);
  13477. processingTimer = undefined;
  13478. }
  13479. if (processingDeferred !== undefined) {
  13480. // tslint:disable-line:early-exit
  13481. processingDeferred.reject(undefined);
  13482. processingDeferred = undefined;
  13483. }
  13484. };
  13485. const originalSet = map.set.bind(map);
  13486. map.set = (key, value) => {
  13487. if (map.has(key)) {
  13488. // If the key already exist, remove it so we can add it back at the end of the map.
  13489. map.delete(key);
  13490. } // Call the original `map.set`
  13491. const result = originalSet(key, value); // If we are already processing a key and the key added is the current processed key, stop processing it
  13492. if (processingKey && processingKey === key) {
  13493. reset();
  13494. } // Always run the cleanup method in case it wasn't started yet
  13495. cleanup(); // tslint:disable-line:no-floating-promises
  13496. return result;
  13497. };
  13498. cleanup(); // tslint:disable-line:no-floating-promises
  13499. return map;
  13500. }
  13501. exports.default = mapAgeCleaner; // Add support for CJS
  13502. module.exports = mapAgeCleaner;
  13503. module.exports.default = mapAgeCleaner;
  13504. });
  13505. const cacheStore = new WeakMap();
  13506. const mem = (fn, options = {}) => {
  13507. // Automatically use WeakMap unless the user provided their own cache
  13508. const weakCache = options.cache || new WeakMap();
  13509. const {
  13510. cacheKey = ([firstArgument]) => firstArgument,
  13511. cache = new Map(),
  13512. maxAge
  13513. } = options;
  13514. if (typeof maxAge === 'number') {
  13515. dist(cache);
  13516. }
  13517. const memoized = function (...arguments_) {
  13518. const key = cacheKey(arguments_); // Prefer WeakMap if the key allows it
  13519. const bestCache = key && (typeof key === 'object' || typeof key === 'function') ? weakCache : cache;
  13520. if (bestCache.has(key)) {
  13521. return bestCache.get(key).data;
  13522. }
  13523. const cacheItem = fn.apply(this, arguments_);
  13524. bestCache.set(key, {
  13525. data: cacheItem,
  13526. maxAge: maxAge ? Date.now() + maxAge : Infinity
  13527. });
  13528. return cacheItem;
  13529. };
  13530. try {
  13531. // The below call will throw in some host environments
  13532. // See https://github.com/sindresorhus/mimic-fn/issues/10
  13533. mimicFn_1(memoized, fn);
  13534. } catch (_) {}
  13535. cacheStore.set(memoized, cache);
  13536. return memoized;
  13537. };
  13538. var mem_1 = mem;
  13539. var clear = fn => {
  13540. if (!cacheStore.has(fn)) {
  13541. throw new Error('Can\'t clear a function that was not memoized!');
  13542. }
  13543. const cache = cacheStore.get(fn);
  13544. if (typeof cache.clear === 'function') {
  13545. cache.clear();
  13546. }
  13547. };
  13548. mem_1.clear = clear;
  13549. var thirdParty = require("./third-party");
  13550. const ParserEND = 0x110000;
  13551. class ParserError extends Error {
  13552. /* istanbul ignore next */
  13553. constructor(msg, filename, linenumber) {
  13554. super('[ParserError] ' + msg, filename, linenumber);
  13555. this.name = 'ParserError';
  13556. this.code = 'ParserError';
  13557. if (Error.captureStackTrace) Error.captureStackTrace(this, ParserError);
  13558. }
  13559. }
  13560. class State {
  13561. constructor(parser) {
  13562. this.parser = parser;
  13563. this.buf = '';
  13564. this.returned = null;
  13565. this.result = null;
  13566. this.resultTable = null;
  13567. this.resultArr = null;
  13568. }
  13569. }
  13570. class Parser {
  13571. constructor() {
  13572. this.pos = 0;
  13573. this.col = 0;
  13574. this.line = 0;
  13575. this.obj = {};
  13576. this.ctx = this.obj;
  13577. this.stack = [];
  13578. this._buf = '';
  13579. this.char = null;
  13580. this.ii = 0;
  13581. this.state = new State(this.parseStart);
  13582. }
  13583. parse(str) {
  13584. /* istanbul ignore next */
  13585. if (str.length === 0 || str.length == null) return;
  13586. this._buf = String(str);
  13587. this.ii = -1;
  13588. this.char = -1;
  13589. let getNext;
  13590. while (getNext === false || this.nextChar()) {
  13591. getNext = this.runOne();
  13592. }
  13593. this._buf = null;
  13594. }
  13595. nextChar() {
  13596. if (this.char === 0x0A) {
  13597. ++this.line;
  13598. this.col = -1;
  13599. }
  13600. ++this.ii;
  13601. this.char = this._buf.codePointAt(this.ii);
  13602. ++this.pos;
  13603. ++this.col;
  13604. return this.haveBuffer();
  13605. }
  13606. haveBuffer() {
  13607. return this.ii < this._buf.length;
  13608. }
  13609. runOne() {
  13610. return this.state.parser.call(this, this.state.returned);
  13611. }
  13612. finish() {
  13613. this.char = ParserEND;
  13614. let last;
  13615. do {
  13616. last = this.state.parser;
  13617. this.runOne();
  13618. } while (this.state.parser !== last);
  13619. this.ctx = null;
  13620. this.state = null;
  13621. this._buf = null;
  13622. return this.obj;
  13623. }
  13624. next(fn) {
  13625. /* istanbul ignore next */
  13626. if (typeof fn !== 'function') throw new ParserError('Tried to set state to non-existent state: ' + JSON.stringify(fn));
  13627. this.state.parser = fn;
  13628. }
  13629. goto(fn) {
  13630. this.next(fn);
  13631. return this.runOne();
  13632. }
  13633. call(fn, returnWith) {
  13634. if (returnWith) this.next(returnWith);
  13635. this.stack.push(this.state);
  13636. this.state = new State(fn);
  13637. }
  13638. callNow(fn, returnWith) {
  13639. this.call(fn, returnWith);
  13640. return this.runOne();
  13641. }
  13642. return(value) {
  13643. /* istanbul ignore next */
  13644. if (this.stack.length === 0) throw this.error(new ParserError('Stack underflow'));
  13645. if (value === undefined) value = this.state.buf;
  13646. this.state = this.stack.pop();
  13647. this.state.returned = value;
  13648. }
  13649. returnNow(value) {
  13650. this.return(value);
  13651. return this.runOne();
  13652. }
  13653. consume() {
  13654. /* istanbul ignore next */
  13655. if (this.char === ParserEND) throw this.error(new ParserError('Unexpected end-of-buffer'));
  13656. this.state.buf += this._buf[this.ii];
  13657. }
  13658. error(err) {
  13659. err.line = this.line;
  13660. err.col = this.col;
  13661. err.pos = this.pos;
  13662. return err;
  13663. }
  13664. /* istanbul ignore next */
  13665. parseStart() {
  13666. throw new ParserError('Must declare a parseStart method');
  13667. }
  13668. }
  13669. Parser.END = ParserEND;
  13670. Parser.Error = ParserError;
  13671. var parser$1 = Parser;
  13672. var createDatetime = value => {
  13673. const date = new Date(value);
  13674. /* istanbul ignore if */
  13675. if (isNaN(date)) {
  13676. throw new TypeError('Invalid Datetime');
  13677. } else {
  13678. return date;
  13679. }
  13680. };
  13681. var formatNum = (d, num) => {
  13682. num = String(num);
  13683. while (num.length < d) num = '0' + num;
  13684. return num;
  13685. };
  13686. class FloatingDateTime extends Date {
  13687. constructor(value) {
  13688. super(value + 'Z');
  13689. this.isFloating = true;
  13690. }
  13691. toISOString() {
  13692. const date = `${this.getUTCFullYear()}-${formatNum(2, this.getUTCMonth() + 1)}-${formatNum(2, this.getUTCDate())}`;
  13693. const time = `${formatNum(2, this.getUTCHours())}:${formatNum(2, this.getUTCMinutes())}:${formatNum(2, this.getUTCSeconds())}.${formatNum(3, this.getUTCMilliseconds())}`;
  13694. return `${date}T${time}`;
  13695. }
  13696. }
  13697. var createDatetimeFloat = value => {
  13698. const date = new FloatingDateTime(value);
  13699. /* istanbul ignore if */
  13700. if (isNaN(date)) {
  13701. throw new TypeError('Invalid Datetime');
  13702. } else {
  13703. return date;
  13704. }
  13705. };
  13706. const DateTime = global.Date;
  13707. class Date$1 extends DateTime {
  13708. constructor(value) {
  13709. super(value);
  13710. this.isDate = true;
  13711. }
  13712. toISOString() {
  13713. return `${this.getUTCFullYear()}-${formatNum(2, this.getUTCMonth() + 1)}-${formatNum(2, this.getUTCDate())}`;
  13714. }
  13715. }
  13716. var createDate = value => {
  13717. const date = new Date$1(value);
  13718. /* istanbul ignore if */
  13719. if (isNaN(date)) {
  13720. throw new TypeError('Invalid Datetime');
  13721. } else {
  13722. return date;
  13723. }
  13724. };
  13725. class Time extends Date {
  13726. constructor(value) {
  13727. super(`0000-01-01T${value}Z`);
  13728. this.isTime = true;
  13729. }
  13730. toISOString() {
  13731. return `${formatNum(2, this.getUTCHours())}:${formatNum(2, this.getUTCMinutes())}:${formatNum(2, this.getUTCSeconds())}.${formatNum(3, this.getUTCMilliseconds())}`;
  13732. }
  13733. }
  13734. var createTime = value => {
  13735. const date = new Time(value);
  13736. /* istanbul ignore if */
  13737. if (isNaN(date)) {
  13738. throw new TypeError('Invalid Datetime');
  13739. } else {
  13740. return date;
  13741. }
  13742. };
  13743. /* eslint-disable no-new-wrappers, no-eval, camelcase, operator-linebreak */
  13744. var tomlParser = makeParserClass(parser$1);
  13745. var makeParserClass_1 = makeParserClass;
  13746. class TomlError extends Error {
  13747. constructor(msg) {
  13748. super(msg);
  13749. this.name = 'TomlError';
  13750. /* istanbul ignore next */
  13751. if (Error.captureStackTrace) Error.captureStackTrace(this, TomlError);
  13752. this.fromTOML = true;
  13753. this.wrapped = null;
  13754. }
  13755. }
  13756. TomlError.wrap = err => {
  13757. const terr = new TomlError(err.message);
  13758. terr.code = err.code;
  13759. terr.wrapped = err;
  13760. return terr;
  13761. };
  13762. var TomlError_1 = TomlError;
  13763. const CTRL_I = 0x09;
  13764. const CTRL_J = 0x0A;
  13765. const CTRL_M = 0x0D;
  13766. const CTRL_CHAR_BOUNDARY = 0x1F; // the last non-character in the latin1 region of unicode, except DEL
  13767. const CHAR_SP = 0x20;
  13768. const CHAR_QUOT = 0x22;
  13769. const CHAR_NUM = 0x23;
  13770. const CHAR_APOS = 0x27;
  13771. const CHAR_PLUS = 0x2B;
  13772. const CHAR_COMMA = 0x2C;
  13773. const CHAR_HYPHEN = 0x2D;
  13774. const CHAR_PERIOD = 0x2E;
  13775. const CHAR_0 = 0x30;
  13776. const CHAR_1 = 0x31;
  13777. const CHAR_7 = 0x37;
  13778. const CHAR_9 = 0x39;
  13779. const CHAR_COLON = 0x3A;
  13780. const CHAR_EQUALS = 0x3D;
  13781. const CHAR_A = 0x41;
  13782. const CHAR_E = 0x45;
  13783. const CHAR_F = 0x46;
  13784. const CHAR_T = 0x54;
  13785. const CHAR_U = 0x55;
  13786. const CHAR_Z = 0x5A;
  13787. const CHAR_LOWBAR = 0x5F;
  13788. const CHAR_a = 0x61;
  13789. const CHAR_b = 0x62;
  13790. const CHAR_e = 0x65;
  13791. const CHAR_f = 0x66;
  13792. const CHAR_i = 0x69;
  13793. const CHAR_l = 0x6C;
  13794. const CHAR_n = 0x6E;
  13795. const CHAR_o = 0x6F;
  13796. const CHAR_r = 0x72;
  13797. const CHAR_s = 0x73;
  13798. const CHAR_t = 0x74;
  13799. const CHAR_u = 0x75;
  13800. const CHAR_x = 0x78;
  13801. const CHAR_z = 0x7A;
  13802. const CHAR_LCUB = 0x7B;
  13803. const CHAR_RCUB = 0x7D;
  13804. const CHAR_LSQB = 0x5B;
  13805. const CHAR_BSOL = 0x5C;
  13806. const CHAR_RSQB = 0x5D;
  13807. const CHAR_DEL = 0x7F;
  13808. const SURROGATE_FIRST = 0xD800;
  13809. const SURROGATE_LAST = 0xDFFF;
  13810. const escapes = {
  13811. [CHAR_b]: '\u0008',
  13812. [CHAR_t]: '\u0009',
  13813. [CHAR_n]: '\u000A',
  13814. [CHAR_f]: '\u000C',
  13815. [CHAR_r]: '\u000D',
  13816. [CHAR_QUOT]: '\u0022',
  13817. [CHAR_BSOL]: '\u005C'
  13818. };
  13819. function isDigit(cp) {
  13820. return cp >= CHAR_0 && cp <= CHAR_9;
  13821. }
  13822. function isHexit(cp) {
  13823. return cp >= CHAR_A && cp <= CHAR_F || cp >= CHAR_a && cp <= CHAR_f || cp >= CHAR_0 && cp <= CHAR_9;
  13824. }
  13825. function isBit(cp) {
  13826. return cp === CHAR_1 || cp === CHAR_0;
  13827. }
  13828. function isOctit(cp) {
  13829. return cp >= CHAR_0 && cp <= CHAR_7;
  13830. }
  13831. function isAlphaNumQuoteHyphen(cp) {
  13832. return cp >= CHAR_A && cp <= CHAR_Z || cp >= CHAR_a && cp <= CHAR_z || cp >= CHAR_0 && cp <= CHAR_9 || cp === CHAR_APOS || cp === CHAR_QUOT || cp === CHAR_LOWBAR || cp === CHAR_HYPHEN;
  13833. }
  13834. function isAlphaNumHyphen(cp) {
  13835. return cp >= CHAR_A && cp <= CHAR_Z || cp >= CHAR_a && cp <= CHAR_z || cp >= CHAR_0 && cp <= CHAR_9 || cp === CHAR_LOWBAR || cp === CHAR_HYPHEN;
  13836. }
  13837. const _type = Symbol('type');
  13838. const _declared = Symbol('declared');
  13839. const hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  13840. const defineProperty = Object.defineProperty;
  13841. const descriptor = {
  13842. configurable: true,
  13843. enumerable: true,
  13844. writable: true,
  13845. value: undefined
  13846. };
  13847. function hasKey(obj, key) {
  13848. if (hasOwnProperty$2.call(obj, key)) return true;
  13849. if (key === '__proto__') defineProperty(obj, '__proto__', descriptor);
  13850. return false;
  13851. }
  13852. const INLINE_TABLE = Symbol('inline-table');
  13853. function InlineTable() {
  13854. return Object.defineProperties({}, {
  13855. [_type]: {
  13856. value: INLINE_TABLE
  13857. }
  13858. });
  13859. }
  13860. function isInlineTable(obj) {
  13861. if (obj === null || typeof obj !== 'object') return false;
  13862. return obj[_type] === INLINE_TABLE;
  13863. }
  13864. const TABLE = Symbol('table');
  13865. function Table() {
  13866. return Object.defineProperties({}, {
  13867. [_type]: {
  13868. value: TABLE
  13869. },
  13870. [_declared]: {
  13871. value: false,
  13872. writable: true
  13873. }
  13874. });
  13875. }
  13876. function isTable(obj) {
  13877. if (obj === null || typeof obj !== 'object') return false;
  13878. return obj[_type] === TABLE;
  13879. }
  13880. const _contentType = Symbol('content-type');
  13881. const INLINE_LIST = Symbol('inline-list');
  13882. function InlineList(type) {
  13883. return Object.defineProperties([], {
  13884. [_type]: {
  13885. value: INLINE_LIST
  13886. },
  13887. [_contentType]: {
  13888. value: type
  13889. }
  13890. });
  13891. }
  13892. function isInlineList(obj) {
  13893. if (obj === null || typeof obj !== 'object') return false;
  13894. return obj[_type] === INLINE_LIST;
  13895. }
  13896. const LIST = Symbol('list');
  13897. function List() {
  13898. return Object.defineProperties([], {
  13899. [_type]: {
  13900. value: LIST
  13901. }
  13902. });
  13903. }
  13904. function isList(obj) {
  13905. if (obj === null || typeof obj !== 'object') return false;
  13906. return obj[_type] === LIST;
  13907. } // in an eval, to let bundlers not slurp in a util proxy
  13908. let _custom;
  13909. try {
  13910. const utilInspect = util__default['default'].inspect;
  13911. _custom = utilInspect.custom;
  13912. } catch (_) {
  13913. /* eval require not available in transpiled bundle */
  13914. }
  13915. /* istanbul ignore next */
  13916. const _inspect = _custom || 'inspect';
  13917. class BoxedBigInt {
  13918. constructor(value) {
  13919. try {
  13920. this.value = global.BigInt.asIntN(64, value);
  13921. } catch (_) {
  13922. /* istanbul ignore next */
  13923. this.value = null;
  13924. }
  13925. Object.defineProperty(this, _type, {
  13926. value: INTEGER
  13927. });
  13928. }
  13929. isNaN() {
  13930. return this.value === null;
  13931. }
  13932. /* istanbul ignore next */
  13933. toString() {
  13934. return String(this.value);
  13935. }
  13936. /* istanbul ignore next */
  13937. [_inspect]() {
  13938. return `[BigInt: ${this.toString()}]}`;
  13939. }
  13940. valueOf() {
  13941. return this.value;
  13942. }
  13943. }
  13944. const INTEGER = Symbol('integer');
  13945. function Integer(value) {
  13946. let num = Number(value); // -0 is a float thing, not an int thing
  13947. if (Object.is(num, -0)) num = 0;
  13948. /* istanbul ignore else */
  13949. if (global.BigInt && !Number.isSafeInteger(num)) {
  13950. return new BoxedBigInt(value);
  13951. } else {
  13952. /* istanbul ignore next */
  13953. return Object.defineProperties(new Number(num), {
  13954. isNaN: {
  13955. value: function () {
  13956. return isNaN(this);
  13957. }
  13958. },
  13959. [_type]: {
  13960. value: INTEGER
  13961. },
  13962. [_inspect]: {
  13963. value: () => `[Integer: ${value}]`
  13964. }
  13965. });
  13966. }
  13967. }
  13968. function isInteger(obj) {
  13969. if (obj === null || typeof obj !== 'object') return false;
  13970. return obj[_type] === INTEGER;
  13971. }
  13972. const FLOAT = Symbol('float');
  13973. function Float(value) {
  13974. /* istanbul ignore next */
  13975. return Object.defineProperties(new Number(value), {
  13976. [_type]: {
  13977. value: FLOAT
  13978. },
  13979. [_inspect]: {
  13980. value: () => `[Float: ${value}]`
  13981. }
  13982. });
  13983. }
  13984. function isFloat(obj) {
  13985. if (obj === null || typeof obj !== 'object') return false;
  13986. return obj[_type] === FLOAT;
  13987. }
  13988. function tomlType(value) {
  13989. const type = typeof value;
  13990. if (type === 'object') {
  13991. /* istanbul ignore if */
  13992. if (value === null) return 'null';
  13993. if (value instanceof Date) return 'datetime';
  13994. /* istanbul ignore else */
  13995. if (_type in value) {
  13996. switch (value[_type]) {
  13997. case INLINE_TABLE:
  13998. return 'inline-table';
  13999. case INLINE_LIST:
  14000. return 'inline-list';
  14001. /* istanbul ignore next */
  14002. case TABLE:
  14003. return 'table';
  14004. /* istanbul ignore next */
  14005. case LIST:
  14006. return 'list';
  14007. case FLOAT:
  14008. return 'float';
  14009. case INTEGER:
  14010. return 'integer';
  14011. }
  14012. }
  14013. }
  14014. return type;
  14015. }
  14016. function makeParserClass(Parser) {
  14017. class TOMLParser extends Parser {
  14018. constructor() {
  14019. super();
  14020. this.ctx = this.obj = Table();
  14021. }
  14022. /* MATCH HELPER */
  14023. atEndOfWord() {
  14024. return this.char === CHAR_NUM || this.char === CTRL_I || this.char === CHAR_SP || this.atEndOfLine();
  14025. }
  14026. atEndOfLine() {
  14027. return this.char === Parser.END || this.char === CTRL_J || this.char === CTRL_M;
  14028. }
  14029. parseStart() {
  14030. if (this.char === Parser.END) {
  14031. return null;
  14032. } else if (this.char === CHAR_LSQB) {
  14033. return this.call(this.parseTableOrList);
  14034. } else if (this.char === CHAR_NUM) {
  14035. return this.call(this.parseComment);
  14036. } else if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  14037. return null;
  14038. } else if (isAlphaNumQuoteHyphen(this.char)) {
  14039. return this.callNow(this.parseAssignStatement);
  14040. } else {
  14041. throw this.error(new TomlError(`Unknown character "${this.char}"`));
  14042. }
  14043. } // HELPER, this strips any whitespace and comments to the end of the line
  14044. // then RETURNS. Last state in a production.
  14045. parseWhitespaceToEOL() {
  14046. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  14047. return null;
  14048. } else if (this.char === CHAR_NUM) {
  14049. return this.goto(this.parseComment);
  14050. } else if (this.char === Parser.END || this.char === CTRL_J) {
  14051. return this.return();
  14052. } else {
  14053. throw this.error(new TomlError('Unexpected character, expected only whitespace or comments till end of line'));
  14054. }
  14055. }
  14056. /* ASSIGNMENT: key = value */
  14057. parseAssignStatement() {
  14058. return this.callNow(this.parseAssign, this.recordAssignStatement);
  14059. }
  14060. recordAssignStatement(kv) {
  14061. let target = this.ctx;
  14062. let finalKey = kv.key.pop();
  14063. for (let kw of kv.key) {
  14064. if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
  14065. throw this.error(new TomlError("Can't redefine existing key"));
  14066. }
  14067. target = target[kw] = target[kw] || Table();
  14068. }
  14069. if (hasKey(target, finalKey)) {
  14070. throw this.error(new TomlError("Can't redefine existing key"));
  14071. } // unbox our numbers
  14072. if (isInteger(kv.value) || isFloat(kv.value)) {
  14073. target[finalKey] = kv.value.valueOf();
  14074. } else {
  14075. target[finalKey] = kv.value;
  14076. }
  14077. return this.goto(this.parseWhitespaceToEOL);
  14078. }
  14079. /* ASSSIGNMENT expression, key = value possibly inside an inline table */
  14080. parseAssign() {
  14081. return this.callNow(this.parseKeyword, this.recordAssignKeyword);
  14082. }
  14083. recordAssignKeyword(key) {
  14084. if (this.state.resultTable) {
  14085. this.state.resultTable.push(key);
  14086. } else {
  14087. this.state.resultTable = [key];
  14088. }
  14089. return this.goto(this.parseAssignKeywordPreDot);
  14090. }
  14091. parseAssignKeywordPreDot() {
  14092. if (this.char === CHAR_PERIOD) {
  14093. return this.next(this.parseAssignKeywordPostDot);
  14094. } else if (this.char !== CHAR_SP && this.char !== CTRL_I) {
  14095. return this.goto(this.parseAssignEqual);
  14096. }
  14097. }
  14098. parseAssignKeywordPostDot() {
  14099. if (this.char !== CHAR_SP && this.char !== CTRL_I) {
  14100. return this.callNow(this.parseKeyword, this.recordAssignKeyword);
  14101. }
  14102. }
  14103. parseAssignEqual() {
  14104. if (this.char === CHAR_EQUALS) {
  14105. return this.next(this.parseAssignPreValue);
  14106. } else {
  14107. throw this.error(new TomlError('Invalid character, expected "="'));
  14108. }
  14109. }
  14110. parseAssignPreValue() {
  14111. if (this.char === CHAR_SP || this.char === CTRL_I) {
  14112. return null;
  14113. } else {
  14114. return this.callNow(this.parseValue, this.recordAssignValue);
  14115. }
  14116. }
  14117. recordAssignValue(value) {
  14118. return this.returnNow({
  14119. key: this.state.resultTable,
  14120. value: value
  14121. });
  14122. }
  14123. /* COMMENTS: #...eol */
  14124. parseComment() {
  14125. do {
  14126. if (this.char === Parser.END || this.char === CTRL_J) {
  14127. return this.return();
  14128. }
  14129. } while (this.nextChar());
  14130. }
  14131. /* TABLES AND LISTS, [foo] and [[foo]] */
  14132. parseTableOrList() {
  14133. if (this.char === CHAR_LSQB) {
  14134. this.next(this.parseList);
  14135. } else {
  14136. return this.goto(this.parseTable);
  14137. }
  14138. }
  14139. /* TABLE [foo.bar.baz] */
  14140. parseTable() {
  14141. this.ctx = this.obj;
  14142. return this.goto(this.parseTableNext);
  14143. }
  14144. parseTableNext() {
  14145. if (this.char === CHAR_SP || this.char === CTRL_I) {
  14146. return null;
  14147. } else {
  14148. return this.callNow(this.parseKeyword, this.parseTableMore);
  14149. }
  14150. }
  14151. parseTableMore(keyword) {
  14152. if (this.char === CHAR_SP || this.char === CTRL_I) {
  14153. return null;
  14154. } else if (this.char === CHAR_RSQB) {
  14155. if (hasKey(this.ctx, keyword) && (!isTable(this.ctx[keyword]) || this.ctx[keyword][_declared])) {
  14156. throw this.error(new TomlError("Can't redefine existing key"));
  14157. } else {
  14158. this.ctx = this.ctx[keyword] = this.ctx[keyword] || Table();
  14159. this.ctx[_declared] = true;
  14160. }
  14161. return this.next(this.parseWhitespaceToEOL);
  14162. } else if (this.char === CHAR_PERIOD) {
  14163. if (!hasKey(this.ctx, keyword)) {
  14164. this.ctx = this.ctx[keyword] = Table();
  14165. } else if (isTable(this.ctx[keyword])) {
  14166. this.ctx = this.ctx[keyword];
  14167. } else if (isList(this.ctx[keyword])) {
  14168. this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
  14169. } else {
  14170. throw this.error(new TomlError("Can't redefine existing key"));
  14171. }
  14172. return this.next(this.parseTableNext);
  14173. } else {
  14174. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  14175. }
  14176. }
  14177. /* LIST [[a.b.c]] */
  14178. parseList() {
  14179. this.ctx = this.obj;
  14180. return this.goto(this.parseListNext);
  14181. }
  14182. parseListNext() {
  14183. if (this.char === CHAR_SP || this.char === CTRL_I) {
  14184. return null;
  14185. } else {
  14186. return this.callNow(this.parseKeyword, this.parseListMore);
  14187. }
  14188. }
  14189. parseListMore(keyword) {
  14190. if (this.char === CHAR_SP || this.char === CTRL_I) {
  14191. return null;
  14192. } else if (this.char === CHAR_RSQB) {
  14193. if (!hasKey(this.ctx, keyword)) {
  14194. this.ctx[keyword] = List();
  14195. }
  14196. if (isInlineList(this.ctx[keyword])) {
  14197. throw this.error(new TomlError("Can't extend an inline array"));
  14198. } else if (isList(this.ctx[keyword])) {
  14199. const next = Table();
  14200. this.ctx[keyword].push(next);
  14201. this.ctx = next;
  14202. } else {
  14203. throw this.error(new TomlError("Can't redefine an existing key"));
  14204. }
  14205. return this.next(this.parseListEnd);
  14206. } else if (this.char === CHAR_PERIOD) {
  14207. if (!hasKey(this.ctx, keyword)) {
  14208. this.ctx = this.ctx[keyword] = Table();
  14209. } else if (isInlineList(this.ctx[keyword])) {
  14210. throw this.error(new TomlError("Can't extend an inline array"));
  14211. } else if (isInlineTable(this.ctx[keyword])) {
  14212. throw this.error(new TomlError("Can't extend an inline table"));
  14213. } else if (isList(this.ctx[keyword])) {
  14214. this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
  14215. } else if (isTable(this.ctx[keyword])) {
  14216. this.ctx = this.ctx[keyword];
  14217. } else {
  14218. throw this.error(new TomlError("Can't redefine an existing key"));
  14219. }
  14220. return this.next(this.parseListNext);
  14221. } else {
  14222. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  14223. }
  14224. }
  14225. parseListEnd(keyword) {
  14226. if (this.char === CHAR_RSQB) {
  14227. return this.next(this.parseWhitespaceToEOL);
  14228. } else {
  14229. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  14230. }
  14231. }
  14232. /* VALUE string, number, boolean, inline list, inline object */
  14233. parseValue() {
  14234. if (this.char === Parser.END) {
  14235. throw this.error(new TomlError('Key without value'));
  14236. } else if (this.char === CHAR_QUOT) {
  14237. return this.next(this.parseDoubleString);
  14238. }
  14239. if (this.char === CHAR_APOS) {
  14240. return this.next(this.parseSingleString);
  14241. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  14242. return this.goto(this.parseNumberSign);
  14243. } else if (this.char === CHAR_i) {
  14244. return this.next(this.parseInf);
  14245. } else if (this.char === CHAR_n) {
  14246. return this.next(this.parseNan);
  14247. } else if (isDigit(this.char)) {
  14248. return this.goto(this.parseNumberOrDateTime);
  14249. } else if (this.char === CHAR_t || this.char === CHAR_f) {
  14250. return this.goto(this.parseBoolean);
  14251. } else if (this.char === CHAR_LSQB) {
  14252. return this.call(this.parseInlineList, this.recordValue);
  14253. } else if (this.char === CHAR_LCUB) {
  14254. return this.call(this.parseInlineTable, this.recordValue);
  14255. } else {
  14256. throw this.error(new TomlError('Unexpected character, expecting string, number, datetime, boolean, inline array or inline table'));
  14257. }
  14258. }
  14259. recordValue(value) {
  14260. return this.returnNow(value);
  14261. }
  14262. parseInf() {
  14263. if (this.char === CHAR_n) {
  14264. return this.next(this.parseInf2);
  14265. } else {
  14266. throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
  14267. }
  14268. }
  14269. parseInf2() {
  14270. if (this.char === CHAR_f) {
  14271. if (this.state.buf === '-') {
  14272. return this.return(-Infinity);
  14273. } else {
  14274. return this.return(Infinity);
  14275. }
  14276. } else {
  14277. throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
  14278. }
  14279. }
  14280. parseNan() {
  14281. if (this.char === CHAR_a) {
  14282. return this.next(this.parseNan2);
  14283. } else {
  14284. throw this.error(new TomlError('Unexpected character, expected "nan"'));
  14285. }
  14286. }
  14287. parseNan2() {
  14288. if (this.char === CHAR_n) {
  14289. return this.return(NaN);
  14290. } else {
  14291. throw this.error(new TomlError('Unexpected character, expected "nan"'));
  14292. }
  14293. }
  14294. /* KEYS, barewords or basic, literal, or dotted */
  14295. parseKeyword() {
  14296. if (this.char === CHAR_QUOT) {
  14297. return this.next(this.parseBasicString);
  14298. } else if (this.char === CHAR_APOS) {
  14299. return this.next(this.parseLiteralString);
  14300. } else {
  14301. return this.goto(this.parseBareKey);
  14302. }
  14303. }
  14304. /* KEYS: barewords */
  14305. parseBareKey() {
  14306. do {
  14307. if (this.char === Parser.END) {
  14308. throw this.error(new TomlError('Key ended without value'));
  14309. } else if (isAlphaNumHyphen(this.char)) {
  14310. this.consume();
  14311. } else if (this.state.buf.length === 0) {
  14312. throw this.error(new TomlError('Empty bare keys are not allowed'));
  14313. } else {
  14314. return this.returnNow();
  14315. }
  14316. } while (this.nextChar());
  14317. }
  14318. /* STRINGS, single quoted (literal) */
  14319. parseSingleString() {
  14320. if (this.char === CHAR_APOS) {
  14321. return this.next(this.parseLiteralMultiStringMaybe);
  14322. } else {
  14323. return this.goto(this.parseLiteralString);
  14324. }
  14325. }
  14326. parseLiteralString() {
  14327. do {
  14328. if (this.char === CHAR_APOS) {
  14329. return this.return();
  14330. } else if (this.atEndOfLine()) {
  14331. throw this.error(new TomlError('Unterminated string'));
  14332. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
  14333. throw this.errorControlCharInString();
  14334. } else {
  14335. this.consume();
  14336. }
  14337. } while (this.nextChar());
  14338. }
  14339. parseLiteralMultiStringMaybe() {
  14340. if (this.char === CHAR_APOS) {
  14341. return this.next(this.parseLiteralMultiString);
  14342. } else {
  14343. return this.returnNow();
  14344. }
  14345. }
  14346. parseLiteralMultiString() {
  14347. if (this.char === CTRL_M) {
  14348. return null;
  14349. } else if (this.char === CTRL_J) {
  14350. return this.next(this.parseLiteralMultiStringContent);
  14351. } else {
  14352. return this.goto(this.parseLiteralMultiStringContent);
  14353. }
  14354. }
  14355. parseLiteralMultiStringContent() {
  14356. do {
  14357. if (this.char === CHAR_APOS) {
  14358. return this.next(this.parseLiteralMultiEnd);
  14359. } else if (this.char === Parser.END) {
  14360. throw this.error(new TomlError('Unterminated multi-line string'));
  14361. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
  14362. throw this.errorControlCharInString();
  14363. } else {
  14364. this.consume();
  14365. }
  14366. } while (this.nextChar());
  14367. }
  14368. parseLiteralMultiEnd() {
  14369. if (this.char === CHAR_APOS) {
  14370. return this.next(this.parseLiteralMultiEnd2);
  14371. } else {
  14372. this.state.buf += "'";
  14373. return this.goto(this.parseLiteralMultiStringContent);
  14374. }
  14375. }
  14376. parseLiteralMultiEnd2() {
  14377. if (this.char === CHAR_APOS) {
  14378. return this.return();
  14379. } else {
  14380. this.state.buf += "''";
  14381. return this.goto(this.parseLiteralMultiStringContent);
  14382. }
  14383. }
  14384. /* STRINGS double quoted */
  14385. parseDoubleString() {
  14386. if (this.char === CHAR_QUOT) {
  14387. return this.next(this.parseMultiStringMaybe);
  14388. } else {
  14389. return this.goto(this.parseBasicString);
  14390. }
  14391. }
  14392. parseBasicString() {
  14393. do {
  14394. if (this.char === CHAR_BSOL) {
  14395. return this.call(this.parseEscape, this.recordEscapeReplacement);
  14396. } else if (this.char === CHAR_QUOT) {
  14397. return this.return();
  14398. } else if (this.atEndOfLine()) {
  14399. throw this.error(new TomlError('Unterminated string'));
  14400. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
  14401. throw this.errorControlCharInString();
  14402. } else {
  14403. this.consume();
  14404. }
  14405. } while (this.nextChar());
  14406. }
  14407. recordEscapeReplacement(replacement) {
  14408. this.state.buf += replacement;
  14409. return this.goto(this.parseBasicString);
  14410. }
  14411. parseMultiStringMaybe() {
  14412. if (this.char === CHAR_QUOT) {
  14413. return this.next(this.parseMultiString);
  14414. } else {
  14415. return this.returnNow();
  14416. }
  14417. }
  14418. parseMultiString() {
  14419. if (this.char === CTRL_M) {
  14420. return null;
  14421. } else if (this.char === CTRL_J) {
  14422. return this.next(this.parseMultiStringContent);
  14423. } else {
  14424. return this.goto(this.parseMultiStringContent);
  14425. }
  14426. }
  14427. parseMultiStringContent() {
  14428. do {
  14429. if (this.char === CHAR_BSOL) {
  14430. return this.call(this.parseMultiEscape, this.recordMultiEscapeReplacement);
  14431. } else if (this.char === CHAR_QUOT) {
  14432. return this.next(this.parseMultiEnd);
  14433. } else if (this.char === Parser.END) {
  14434. throw this.error(new TomlError('Unterminated multi-line string'));
  14435. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
  14436. throw this.errorControlCharInString();
  14437. } else {
  14438. this.consume();
  14439. }
  14440. } while (this.nextChar());
  14441. }
  14442. errorControlCharInString() {
  14443. let displayCode = '\\u00';
  14444. if (this.char < 16) {
  14445. displayCode += '0';
  14446. }
  14447. displayCode += this.char.toString(16);
  14448. return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${displayCode} instead`));
  14449. }
  14450. recordMultiEscapeReplacement(replacement) {
  14451. this.state.buf += replacement;
  14452. return this.goto(this.parseMultiStringContent);
  14453. }
  14454. parseMultiEnd() {
  14455. if (this.char === CHAR_QUOT) {
  14456. return this.next(this.parseMultiEnd2);
  14457. } else {
  14458. this.state.buf += '"';
  14459. return this.goto(this.parseMultiStringContent);
  14460. }
  14461. }
  14462. parseMultiEnd2() {
  14463. if (this.char === CHAR_QUOT) {
  14464. return this.return();
  14465. } else {
  14466. this.state.buf += '""';
  14467. return this.goto(this.parseMultiStringContent);
  14468. }
  14469. }
  14470. parseMultiEscape() {
  14471. if (this.char === CTRL_M || this.char === CTRL_J) {
  14472. return this.next(this.parseMultiTrim);
  14473. } else if (this.char === CHAR_SP || this.char === CTRL_I) {
  14474. return this.next(this.parsePreMultiTrim);
  14475. } else {
  14476. return this.goto(this.parseEscape);
  14477. }
  14478. }
  14479. parsePreMultiTrim() {
  14480. if (this.char === CHAR_SP || this.char === CTRL_I) {
  14481. return null;
  14482. } else if (this.char === CTRL_M || this.char === CTRL_J) {
  14483. return this.next(this.parseMultiTrim);
  14484. } else {
  14485. throw this.error(new TomlError("Can't escape whitespace"));
  14486. }
  14487. }
  14488. parseMultiTrim() {
  14489. // explicitly whitespace here, END should follow the same path as chars
  14490. if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  14491. return null;
  14492. } else {
  14493. return this.returnNow();
  14494. }
  14495. }
  14496. parseEscape() {
  14497. if (this.char in escapes) {
  14498. return this.return(escapes[this.char]);
  14499. } else if (this.char === CHAR_u) {
  14500. return this.call(this.parseSmallUnicode, this.parseUnicodeReturn);
  14501. } else if (this.char === CHAR_U) {
  14502. return this.call(this.parseLargeUnicode, this.parseUnicodeReturn);
  14503. } else {
  14504. throw this.error(new TomlError('Unknown escape character: ' + this.char));
  14505. }
  14506. }
  14507. parseUnicodeReturn(char) {
  14508. try {
  14509. const codePoint = parseInt(char, 16);
  14510. if (codePoint >= SURROGATE_FIRST && codePoint <= SURROGATE_LAST) {
  14511. throw this.error(new TomlError('Invalid unicode, character in range 0xD800 - 0xDFFF is reserved'));
  14512. }
  14513. return this.returnNow(String.fromCodePoint(codePoint));
  14514. } catch (err) {
  14515. throw this.error(TomlError.wrap(err));
  14516. }
  14517. }
  14518. parseSmallUnicode() {
  14519. if (!isHexit(this.char)) {
  14520. throw this.error(new TomlError('Invalid character in unicode sequence, expected hex'));
  14521. } else {
  14522. this.consume();
  14523. if (this.state.buf.length >= 4) return this.return();
  14524. }
  14525. }
  14526. parseLargeUnicode() {
  14527. if (!isHexit(this.char)) {
  14528. throw this.error(new TomlError('Invalid character in unicode sequence, expected hex'));
  14529. } else {
  14530. this.consume();
  14531. if (this.state.buf.length >= 8) return this.return();
  14532. }
  14533. }
  14534. /* NUMBERS */
  14535. parseNumberSign() {
  14536. this.consume();
  14537. return this.next(this.parseMaybeSignedInfOrNan);
  14538. }
  14539. parseMaybeSignedInfOrNan() {
  14540. if (this.char === CHAR_i) {
  14541. return this.next(this.parseInf);
  14542. } else if (this.char === CHAR_n) {
  14543. return this.next(this.parseNan);
  14544. } else {
  14545. return this.callNow(this.parseNoUnder, this.parseNumberIntegerStart);
  14546. }
  14547. }
  14548. parseNumberIntegerStart() {
  14549. if (this.char === CHAR_0) {
  14550. this.consume();
  14551. return this.next(this.parseNumberIntegerExponentOrDecimal);
  14552. } else {
  14553. return this.goto(this.parseNumberInteger);
  14554. }
  14555. }
  14556. parseNumberIntegerExponentOrDecimal() {
  14557. if (this.char === CHAR_PERIOD) {
  14558. this.consume();
  14559. return this.call(this.parseNoUnder, this.parseNumberFloat);
  14560. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  14561. this.consume();
  14562. return this.next(this.parseNumberExponentSign);
  14563. } else {
  14564. return this.returnNow(Integer(this.state.buf));
  14565. }
  14566. }
  14567. parseNumberInteger() {
  14568. if (isDigit(this.char)) {
  14569. this.consume();
  14570. } else if (this.char === CHAR_LOWBAR) {
  14571. return this.call(this.parseNoUnder);
  14572. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  14573. this.consume();
  14574. return this.next(this.parseNumberExponentSign);
  14575. } else if (this.char === CHAR_PERIOD) {
  14576. this.consume();
  14577. return this.call(this.parseNoUnder, this.parseNumberFloat);
  14578. } else {
  14579. const result = Integer(this.state.buf);
  14580. /* istanbul ignore if */
  14581. if (result.isNaN()) {
  14582. throw this.error(new TomlError('Invalid number'));
  14583. } else {
  14584. return this.returnNow(result);
  14585. }
  14586. }
  14587. }
  14588. parseNoUnder() {
  14589. if (this.char === CHAR_LOWBAR || this.char === CHAR_PERIOD || this.char === CHAR_E || this.char === CHAR_e) {
  14590. throw this.error(new TomlError('Unexpected character, expected digit'));
  14591. } else if (this.atEndOfWord()) {
  14592. throw this.error(new TomlError('Incomplete number'));
  14593. }
  14594. return this.returnNow();
  14595. }
  14596. parseNoUnderHexOctBinLiteral() {
  14597. if (this.char === CHAR_LOWBAR || this.char === CHAR_PERIOD) {
  14598. throw this.error(new TomlError('Unexpected character, expected digit'));
  14599. } else if (this.atEndOfWord()) {
  14600. throw this.error(new TomlError('Incomplete number'));
  14601. }
  14602. return this.returnNow();
  14603. }
  14604. parseNumberFloat() {
  14605. if (this.char === CHAR_LOWBAR) {
  14606. return this.call(this.parseNoUnder, this.parseNumberFloat);
  14607. } else if (isDigit(this.char)) {
  14608. this.consume();
  14609. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  14610. this.consume();
  14611. return this.next(this.parseNumberExponentSign);
  14612. } else {
  14613. return this.returnNow(Float(this.state.buf));
  14614. }
  14615. }
  14616. parseNumberExponentSign() {
  14617. if (isDigit(this.char)) {
  14618. return this.goto(this.parseNumberExponent);
  14619. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  14620. this.consume();
  14621. this.call(this.parseNoUnder, this.parseNumberExponent);
  14622. } else {
  14623. throw this.error(new TomlError('Unexpected character, expected -, + or digit'));
  14624. }
  14625. }
  14626. parseNumberExponent() {
  14627. if (isDigit(this.char)) {
  14628. this.consume();
  14629. } else if (this.char === CHAR_LOWBAR) {
  14630. return this.call(this.parseNoUnder);
  14631. } else {
  14632. return this.returnNow(Float(this.state.buf));
  14633. }
  14634. }
  14635. /* NUMBERS or DATETIMES */
  14636. parseNumberOrDateTime() {
  14637. if (this.char === CHAR_0) {
  14638. this.consume();
  14639. return this.next(this.parseNumberBaseOrDateTime);
  14640. } else {
  14641. return this.goto(this.parseNumberOrDateTimeOnly);
  14642. }
  14643. }
  14644. parseNumberOrDateTimeOnly() {
  14645. // note, if two zeros are in a row then it MUST be a date
  14646. if (this.char === CHAR_LOWBAR) {
  14647. return this.call(this.parseNoUnder, this.parseNumberInteger);
  14648. } else if (isDigit(this.char)) {
  14649. this.consume();
  14650. if (this.state.buf.length > 4) this.next(this.parseNumberInteger);
  14651. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  14652. this.consume();
  14653. return this.next(this.parseNumberExponentSign);
  14654. } else if (this.char === CHAR_PERIOD) {
  14655. this.consume();
  14656. return this.call(this.parseNoUnder, this.parseNumberFloat);
  14657. } else if (this.char === CHAR_HYPHEN) {
  14658. return this.goto(this.parseDateTime);
  14659. } else if (this.char === CHAR_COLON) {
  14660. return this.goto(this.parseOnlyTimeHour);
  14661. } else {
  14662. return this.returnNow(Integer(this.state.buf));
  14663. }
  14664. }
  14665. parseDateTimeOnly() {
  14666. if (this.state.buf.length < 4) {
  14667. if (isDigit(this.char)) {
  14668. return this.consume();
  14669. } else if (this.char === CHAR_COLON) {
  14670. return this.goto(this.parseOnlyTimeHour);
  14671. } else {
  14672. throw this.error(new TomlError('Expected digit while parsing year part of a date'));
  14673. }
  14674. } else {
  14675. if (this.char === CHAR_HYPHEN) {
  14676. return this.goto(this.parseDateTime);
  14677. } else {
  14678. throw this.error(new TomlError('Expected hyphen (-) while parsing year part of date'));
  14679. }
  14680. }
  14681. }
  14682. parseNumberBaseOrDateTime() {
  14683. if (this.char === CHAR_b) {
  14684. this.consume();
  14685. return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerBin);
  14686. } else if (this.char === CHAR_o) {
  14687. this.consume();
  14688. return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerOct);
  14689. } else if (this.char === CHAR_x) {
  14690. this.consume();
  14691. return this.call(this.parseNoUnderHexOctBinLiteral, this.parseIntegerHex);
  14692. } else if (this.char === CHAR_PERIOD) {
  14693. return this.goto(this.parseNumberInteger);
  14694. } else if (isDigit(this.char)) {
  14695. return this.goto(this.parseDateTimeOnly);
  14696. } else {
  14697. return this.returnNow(Integer(this.state.buf));
  14698. }
  14699. }
  14700. parseIntegerHex() {
  14701. if (isHexit(this.char)) {
  14702. this.consume();
  14703. } else if (this.char === CHAR_LOWBAR) {
  14704. return this.call(this.parseNoUnderHexOctBinLiteral);
  14705. } else {
  14706. const result = Integer(this.state.buf);
  14707. /* istanbul ignore if */
  14708. if (result.isNaN()) {
  14709. throw this.error(new TomlError('Invalid number'));
  14710. } else {
  14711. return this.returnNow(result);
  14712. }
  14713. }
  14714. }
  14715. parseIntegerOct() {
  14716. if (isOctit(this.char)) {
  14717. this.consume();
  14718. } else if (this.char === CHAR_LOWBAR) {
  14719. return this.call(this.parseNoUnderHexOctBinLiteral);
  14720. } else {
  14721. const result = Integer(this.state.buf);
  14722. /* istanbul ignore if */
  14723. if (result.isNaN()) {
  14724. throw this.error(new TomlError('Invalid number'));
  14725. } else {
  14726. return this.returnNow(result);
  14727. }
  14728. }
  14729. }
  14730. parseIntegerBin() {
  14731. if (isBit(this.char)) {
  14732. this.consume();
  14733. } else if (this.char === CHAR_LOWBAR) {
  14734. return this.call(this.parseNoUnderHexOctBinLiteral);
  14735. } else {
  14736. const result = Integer(this.state.buf);
  14737. /* istanbul ignore if */
  14738. if (result.isNaN()) {
  14739. throw this.error(new TomlError('Invalid number'));
  14740. } else {
  14741. return this.returnNow(result);
  14742. }
  14743. }
  14744. }
  14745. /* DATETIME */
  14746. parseDateTime() {
  14747. // we enter here having just consumed the year and about to consume the hyphen
  14748. if (this.state.buf.length < 4) {
  14749. throw this.error(new TomlError('Years less than 1000 must be zero padded to four characters'));
  14750. }
  14751. this.state.result = this.state.buf;
  14752. this.state.buf = '';
  14753. return this.next(this.parseDateMonth);
  14754. }
  14755. parseDateMonth() {
  14756. if (this.char === CHAR_HYPHEN) {
  14757. if (this.state.buf.length < 2) {
  14758. throw this.error(new TomlError('Months less than 10 must be zero padded to two characters'));
  14759. }
  14760. this.state.result += '-' + this.state.buf;
  14761. this.state.buf = '';
  14762. return this.next(this.parseDateDay);
  14763. } else if (isDigit(this.char)) {
  14764. this.consume();
  14765. } else {
  14766. throw this.error(new TomlError('Incomplete datetime'));
  14767. }
  14768. }
  14769. parseDateDay() {
  14770. if (this.char === CHAR_T || this.char === CHAR_SP) {
  14771. if (this.state.buf.length < 2) {
  14772. throw this.error(new TomlError('Days less than 10 must be zero padded to two characters'));
  14773. }
  14774. this.state.result += '-' + this.state.buf;
  14775. this.state.buf = '';
  14776. return this.next(this.parseStartTimeHour);
  14777. } else if (this.atEndOfWord()) {
  14778. return this.returnNow(createDate(this.state.result + '-' + this.state.buf));
  14779. } else if (isDigit(this.char)) {
  14780. this.consume();
  14781. } else {
  14782. throw this.error(new TomlError('Incomplete datetime'));
  14783. }
  14784. }
  14785. parseStartTimeHour() {
  14786. if (this.atEndOfWord()) {
  14787. return this.returnNow(createDate(this.state.result));
  14788. } else {
  14789. return this.goto(this.parseTimeHour);
  14790. }
  14791. }
  14792. parseTimeHour() {
  14793. if (this.char === CHAR_COLON) {
  14794. if (this.state.buf.length < 2) {
  14795. throw this.error(new TomlError('Hours less than 10 must be zero padded to two characters'));
  14796. }
  14797. this.state.result += 'T' + this.state.buf;
  14798. this.state.buf = '';
  14799. return this.next(this.parseTimeMin);
  14800. } else if (isDigit(this.char)) {
  14801. this.consume();
  14802. } else {
  14803. throw this.error(new TomlError('Incomplete datetime'));
  14804. }
  14805. }
  14806. parseTimeMin() {
  14807. if (this.state.buf.length < 2 && isDigit(this.char)) {
  14808. this.consume();
  14809. } else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
  14810. this.state.result += ':' + this.state.buf;
  14811. this.state.buf = '';
  14812. return this.next(this.parseTimeSec);
  14813. } else {
  14814. throw this.error(new TomlError('Incomplete datetime'));
  14815. }
  14816. }
  14817. parseTimeSec() {
  14818. if (isDigit(this.char)) {
  14819. this.consume();
  14820. if (this.state.buf.length === 2) {
  14821. this.state.result += ':' + this.state.buf;
  14822. this.state.buf = '';
  14823. return this.next(this.parseTimeZoneOrFraction);
  14824. }
  14825. } else {
  14826. throw this.error(new TomlError('Incomplete datetime'));
  14827. }
  14828. }
  14829. parseOnlyTimeHour() {
  14830. /* istanbul ignore else */
  14831. if (this.char === CHAR_COLON) {
  14832. if (this.state.buf.length < 2) {
  14833. throw this.error(new TomlError('Hours less than 10 must be zero padded to two characters'));
  14834. }
  14835. this.state.result = this.state.buf;
  14836. this.state.buf = '';
  14837. return this.next(this.parseOnlyTimeMin);
  14838. } else {
  14839. throw this.error(new TomlError('Incomplete time'));
  14840. }
  14841. }
  14842. parseOnlyTimeMin() {
  14843. if (this.state.buf.length < 2 && isDigit(this.char)) {
  14844. this.consume();
  14845. } else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
  14846. this.state.result += ':' + this.state.buf;
  14847. this.state.buf = '';
  14848. return this.next(this.parseOnlyTimeSec);
  14849. } else {
  14850. throw this.error(new TomlError('Incomplete time'));
  14851. }
  14852. }
  14853. parseOnlyTimeSec() {
  14854. if (isDigit(this.char)) {
  14855. this.consume();
  14856. if (this.state.buf.length === 2) {
  14857. return this.next(this.parseOnlyTimeFractionMaybe);
  14858. }
  14859. } else {
  14860. throw this.error(new TomlError('Incomplete time'));
  14861. }
  14862. }
  14863. parseOnlyTimeFractionMaybe() {
  14864. this.state.result += ':' + this.state.buf;
  14865. if (this.char === CHAR_PERIOD) {
  14866. this.state.buf = '';
  14867. this.next(this.parseOnlyTimeFraction);
  14868. } else {
  14869. return this.return(createTime(this.state.result));
  14870. }
  14871. }
  14872. parseOnlyTimeFraction() {
  14873. if (isDigit(this.char)) {
  14874. this.consume();
  14875. } else if (this.atEndOfWord()) {
  14876. if (this.state.buf.length === 0) throw this.error(new TomlError('Expected digit in milliseconds'));
  14877. return this.returnNow(createTime(this.state.result + '.' + this.state.buf));
  14878. } else {
  14879. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  14880. }
  14881. }
  14882. parseTimeZoneOrFraction() {
  14883. if (this.char === CHAR_PERIOD) {
  14884. this.consume();
  14885. this.next(this.parseDateTimeFraction);
  14886. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  14887. this.consume();
  14888. this.next(this.parseTimeZoneHour);
  14889. } else if (this.char === CHAR_Z) {
  14890. this.consume();
  14891. return this.return(createDatetime(this.state.result + this.state.buf));
  14892. } else if (this.atEndOfWord()) {
  14893. return this.returnNow(createDatetimeFloat(this.state.result + this.state.buf));
  14894. } else {
  14895. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  14896. }
  14897. }
  14898. parseDateTimeFraction() {
  14899. if (isDigit(this.char)) {
  14900. this.consume();
  14901. } else if (this.state.buf.length === 1) {
  14902. throw this.error(new TomlError('Expected digit in milliseconds'));
  14903. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  14904. this.consume();
  14905. this.next(this.parseTimeZoneHour);
  14906. } else if (this.char === CHAR_Z) {
  14907. this.consume();
  14908. return this.return(createDatetime(this.state.result + this.state.buf));
  14909. } else if (this.atEndOfWord()) {
  14910. return this.returnNow(createDatetimeFloat(this.state.result + this.state.buf));
  14911. } else {
  14912. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  14913. }
  14914. }
  14915. parseTimeZoneHour() {
  14916. if (isDigit(this.char)) {
  14917. this.consume(); // FIXME: No more regexps
  14918. if (/\d\d$/.test(this.state.buf)) return this.next(this.parseTimeZoneSep);
  14919. } else {
  14920. throw this.error(new TomlError('Unexpected character in datetime, expected digit'));
  14921. }
  14922. }
  14923. parseTimeZoneSep() {
  14924. if (this.char === CHAR_COLON) {
  14925. this.consume();
  14926. this.next(this.parseTimeZoneMin);
  14927. } else {
  14928. throw this.error(new TomlError('Unexpected character in datetime, expected colon'));
  14929. }
  14930. }
  14931. parseTimeZoneMin() {
  14932. if (isDigit(this.char)) {
  14933. this.consume();
  14934. if (/\d\d$/.test(this.state.buf)) return this.return(createDatetime(this.state.result + this.state.buf));
  14935. } else {
  14936. throw this.error(new TomlError('Unexpected character in datetime, expected digit'));
  14937. }
  14938. }
  14939. /* BOOLEAN */
  14940. parseBoolean() {
  14941. /* istanbul ignore else */
  14942. if (this.char === CHAR_t) {
  14943. this.consume();
  14944. return this.next(this.parseTrue_r);
  14945. } else if (this.char === CHAR_f) {
  14946. this.consume();
  14947. return this.next(this.parseFalse_a);
  14948. }
  14949. }
  14950. parseTrue_r() {
  14951. if (this.char === CHAR_r) {
  14952. this.consume();
  14953. return this.next(this.parseTrue_u);
  14954. } else {
  14955. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  14956. }
  14957. }
  14958. parseTrue_u() {
  14959. if (this.char === CHAR_u) {
  14960. this.consume();
  14961. return this.next(this.parseTrue_e);
  14962. } else {
  14963. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  14964. }
  14965. }
  14966. parseTrue_e() {
  14967. if (this.char === CHAR_e) {
  14968. return this.return(true);
  14969. } else {
  14970. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  14971. }
  14972. }
  14973. parseFalse_a() {
  14974. if (this.char === CHAR_a) {
  14975. this.consume();
  14976. return this.next(this.parseFalse_l);
  14977. } else {
  14978. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  14979. }
  14980. }
  14981. parseFalse_l() {
  14982. if (this.char === CHAR_l) {
  14983. this.consume();
  14984. return this.next(this.parseFalse_s);
  14985. } else {
  14986. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  14987. }
  14988. }
  14989. parseFalse_s() {
  14990. if (this.char === CHAR_s) {
  14991. this.consume();
  14992. return this.next(this.parseFalse_e);
  14993. } else {
  14994. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  14995. }
  14996. }
  14997. parseFalse_e() {
  14998. if (this.char === CHAR_e) {
  14999. return this.return(false);
  15000. } else {
  15001. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  15002. }
  15003. }
  15004. /* INLINE LISTS */
  15005. parseInlineList() {
  15006. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
  15007. return null;
  15008. } else if (this.char === Parser.END) {
  15009. throw this.error(new TomlError('Unterminated inline array'));
  15010. } else if (this.char === CHAR_NUM) {
  15011. return this.call(this.parseComment);
  15012. } else if (this.char === CHAR_RSQB) {
  15013. return this.return(this.state.resultArr || InlineList());
  15014. } else {
  15015. return this.callNow(this.parseValue, this.recordInlineListValue);
  15016. }
  15017. }
  15018. recordInlineListValue(value) {
  15019. if (this.state.resultArr) {
  15020. const listType = this.state.resultArr[_contentType];
  15021. const valueType = tomlType(value);
  15022. if (listType !== valueType) {
  15023. throw this.error(new TomlError(`Inline lists must be a single type, not a mix of ${listType} and ${valueType}`));
  15024. }
  15025. } else {
  15026. this.state.resultArr = InlineList(tomlType(value));
  15027. }
  15028. if (isFloat(value) || isInteger(value)) {
  15029. // unbox now that we've verified they're ok
  15030. this.state.resultArr.push(value.valueOf());
  15031. } else {
  15032. this.state.resultArr.push(value);
  15033. }
  15034. return this.goto(this.parseInlineListNext);
  15035. }
  15036. parseInlineListNext() {
  15037. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
  15038. return null;
  15039. } else if (this.char === CHAR_NUM) {
  15040. return this.call(this.parseComment);
  15041. } else if (this.char === CHAR_COMMA) {
  15042. return this.next(this.parseInlineList);
  15043. } else if (this.char === CHAR_RSQB) {
  15044. return this.goto(this.parseInlineList);
  15045. } else {
  15046. throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'));
  15047. }
  15048. }
  15049. /* INLINE TABLE */
  15050. parseInlineTable() {
  15051. if (this.char === CHAR_SP || this.char === CTRL_I) {
  15052. return null;
  15053. } else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
  15054. throw this.error(new TomlError('Unterminated inline array'));
  15055. } else if (this.char === CHAR_RCUB) {
  15056. return this.return(this.state.resultTable || InlineTable());
  15057. } else {
  15058. if (!this.state.resultTable) this.state.resultTable = InlineTable();
  15059. return this.callNow(this.parseAssign, this.recordInlineTableValue);
  15060. }
  15061. }
  15062. recordInlineTableValue(kv) {
  15063. let target = this.state.resultTable;
  15064. let finalKey = kv.key.pop();
  15065. for (let kw of kv.key) {
  15066. if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
  15067. throw this.error(new TomlError("Can't redefine existing key"));
  15068. }
  15069. target = target[kw] = target[kw] || Table();
  15070. }
  15071. if (hasKey(target, finalKey)) {
  15072. throw this.error(new TomlError("Can't redefine existing key"));
  15073. }
  15074. if (isInteger(kv.value) || isFloat(kv.value)) {
  15075. target[finalKey] = kv.value.valueOf();
  15076. } else {
  15077. target[finalKey] = kv.value;
  15078. }
  15079. return this.goto(this.parseInlineTableNext);
  15080. }
  15081. parseInlineTableNext() {
  15082. if (this.char === CHAR_SP || this.char === CTRL_I) {
  15083. return null;
  15084. } else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
  15085. throw this.error(new TomlError('Unterminated inline array'));
  15086. } else if (this.char === CHAR_COMMA) {
  15087. return this.next(this.parseInlineTable);
  15088. } else if (this.char === CHAR_RCUB) {
  15089. return this.goto(this.parseInlineTable);
  15090. } else {
  15091. throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'));
  15092. }
  15093. }
  15094. }
  15095. return TOMLParser;
  15096. }
  15097. tomlParser.makeParserClass = makeParserClass_1;
  15098. tomlParser.TomlError = TomlError_1;
  15099. var parsePrettyError = prettyError;
  15100. function prettyError(err, buf) {
  15101. /* istanbul ignore if */
  15102. if (err.pos == null || err.line == null) return err;
  15103. let msg = err.message;
  15104. msg += ` at row ${err.line + 1}, col ${err.col + 1}, pos ${err.pos}:\n`;
  15105. /* istanbul ignore else */
  15106. if (buf && buf.split) {
  15107. const lines = buf.split(/\n/);
  15108. const lineNumWidth = String(Math.min(lines.length, err.line + 3)).length;
  15109. let linePadding = ' ';
  15110. while (linePadding.length < lineNumWidth) linePadding += ' ';
  15111. for (let ii = Math.max(0, err.line - 1); ii < Math.min(lines.length, err.line + 2); ++ii) {
  15112. let lineNum = String(ii + 1);
  15113. if (lineNum.length < lineNumWidth) lineNum = ' ' + lineNum;
  15114. if (err.line === ii) {
  15115. msg += lineNum + '> ' + lines[ii] + '\n';
  15116. msg += linePadding + ' ';
  15117. for (let hh = 0; hh < err.col; ++hh) {
  15118. msg += ' ';
  15119. }
  15120. msg += '^\n';
  15121. } else {
  15122. msg += lineNum + ': ' + lines[ii] + '\n';
  15123. }
  15124. }
  15125. }
  15126. err.message = msg + '\n';
  15127. return err;
  15128. }
  15129. var parseString_1 = parseString;
  15130. function parseString(str) {
  15131. if (global.Buffer && global.Buffer.isBuffer(str)) {
  15132. str = str.toString('utf8');
  15133. }
  15134. const parser = new tomlParser();
  15135. try {
  15136. parser.parse(str);
  15137. return parser.finish();
  15138. } catch (err) {
  15139. throw parsePrettyError(err, str);
  15140. }
  15141. }
  15142. var loadToml = function (filePath, content) {
  15143. try {
  15144. return parseString_1(content);
  15145. } catch (error) {
  15146. error.message = `TOML Error in ${filePath}:\n${error.message}`;
  15147. throw error;
  15148. }
  15149. };
  15150. // This is a generated file. Do not edit.
  15151. var Space_Separator = /[\u1680\u2000-\u200A\u202F\u205F\u3000]/;
  15152. var ID_Start = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\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\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\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\u0AF9\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-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\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-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\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-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\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]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/;
  15153. var ID_Continue = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\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\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\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\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\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-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/;
  15154. var unicode = {
  15155. Space_Separator: Space_Separator,
  15156. ID_Start: ID_Start,
  15157. ID_Continue: ID_Continue
  15158. };
  15159. var util$2 = {
  15160. isSpaceSeparator(c) {
  15161. return typeof c === 'string' && unicode.Space_Separator.test(c);
  15162. },
  15163. isIdStartChar(c) {
  15164. return typeof c === 'string' && (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c === '$' || c === '_' || unicode.ID_Start.test(c));
  15165. },
  15166. isIdContinueChar(c) {
  15167. return typeof c === 'string' && (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c === '$' || c === '_' || c === '\u200C' || c === '\u200D' || unicode.ID_Continue.test(c));
  15168. },
  15169. isDigit(c) {
  15170. return typeof c === 'string' && /[0-9]/.test(c);
  15171. },
  15172. isHexDigit(c) {
  15173. return typeof c === 'string' && /[0-9A-Fa-f]/.test(c);
  15174. }
  15175. };
  15176. let source$1;
  15177. let parseState;
  15178. let stack;
  15179. let pos;
  15180. let line$2;
  15181. let column;
  15182. let token;
  15183. let key;
  15184. let root$1;
  15185. var parse$2 = function parse(text, reviver) {
  15186. source$1 = String(text);
  15187. parseState = 'start';
  15188. stack = [];
  15189. pos = 0;
  15190. line$2 = 1;
  15191. column = 0;
  15192. token = undefined;
  15193. key = undefined;
  15194. root$1 = undefined;
  15195. do {
  15196. token = lex(); // This code is unreachable.
  15197. // if (!parseStates[parseState]) {
  15198. // throw invalidParseState()
  15199. // }
  15200. parseStates[parseState]();
  15201. } while (token.type !== 'eof');
  15202. if (typeof reviver === 'function') {
  15203. return internalize({
  15204. '': root$1
  15205. }, '', reviver);
  15206. }
  15207. return root$1;
  15208. };
  15209. function internalize(holder, name, reviver) {
  15210. const value = holder[name];
  15211. if (value != null && typeof value === 'object') {
  15212. for (const key in value) {
  15213. const replacement = internalize(value, key, reviver);
  15214. if (replacement === undefined) {
  15215. delete value[key];
  15216. } else {
  15217. value[key] = replacement;
  15218. }
  15219. }
  15220. }
  15221. return reviver.call(holder, name, value);
  15222. }
  15223. let lexState;
  15224. let buffer;
  15225. let doubleQuote;
  15226. let sign;
  15227. let c;
  15228. function lex() {
  15229. lexState = 'default';
  15230. buffer = '';
  15231. doubleQuote = false;
  15232. sign = 1;
  15233. for (;;) {
  15234. c = peek(); // This code is unreachable.
  15235. // if (!lexStates[lexState]) {
  15236. // throw invalidLexState(lexState)
  15237. // }
  15238. const token = lexStates[lexState]();
  15239. if (token) {
  15240. return token;
  15241. }
  15242. }
  15243. }
  15244. function peek() {
  15245. if (source$1[pos]) {
  15246. return String.fromCodePoint(source$1.codePointAt(pos));
  15247. }
  15248. }
  15249. function read() {
  15250. const c = peek();
  15251. if (c === '\n') {
  15252. line$2++;
  15253. column = 0;
  15254. } else if (c) {
  15255. column += c.length;
  15256. } else {
  15257. column++;
  15258. }
  15259. if (c) {
  15260. pos += c.length;
  15261. }
  15262. return c;
  15263. }
  15264. const lexStates = {
  15265. default() {
  15266. switch (c) {
  15267. case '\t':
  15268. case '\v':
  15269. case '\f':
  15270. case ' ':
  15271. case '\u00A0':
  15272. case '\uFEFF':
  15273. case '\n':
  15274. case '\r':
  15275. case '\u2028':
  15276. case '\u2029':
  15277. read();
  15278. return;
  15279. case '/':
  15280. read();
  15281. lexState = 'comment';
  15282. return;
  15283. case undefined:
  15284. read();
  15285. return newToken('eof');
  15286. }
  15287. if (util$2.isSpaceSeparator(c)) {
  15288. read();
  15289. return;
  15290. } // This code is unreachable.
  15291. // if (!lexStates[parseState]) {
  15292. // throw invalidLexState(parseState)
  15293. // }
  15294. return lexStates[parseState]();
  15295. },
  15296. comment() {
  15297. switch (c) {
  15298. case '*':
  15299. read();
  15300. lexState = 'multiLineComment';
  15301. return;
  15302. case '/':
  15303. read();
  15304. lexState = 'singleLineComment';
  15305. return;
  15306. }
  15307. throw invalidChar(read());
  15308. },
  15309. multiLineComment() {
  15310. switch (c) {
  15311. case '*':
  15312. read();
  15313. lexState = 'multiLineCommentAsterisk';
  15314. return;
  15315. case undefined:
  15316. throw invalidChar(read());
  15317. }
  15318. read();
  15319. },
  15320. multiLineCommentAsterisk() {
  15321. switch (c) {
  15322. case '*':
  15323. read();
  15324. return;
  15325. case '/':
  15326. read();
  15327. lexState = 'default';
  15328. return;
  15329. case undefined:
  15330. throw invalidChar(read());
  15331. }
  15332. read();
  15333. lexState = 'multiLineComment';
  15334. },
  15335. singleLineComment() {
  15336. switch (c) {
  15337. case '\n':
  15338. case '\r':
  15339. case '\u2028':
  15340. case '\u2029':
  15341. read();
  15342. lexState = 'default';
  15343. return;
  15344. case undefined:
  15345. read();
  15346. return newToken('eof');
  15347. }
  15348. read();
  15349. },
  15350. value() {
  15351. switch (c) {
  15352. case '{':
  15353. case '[':
  15354. return newToken('punctuator', read());
  15355. case 'n':
  15356. read();
  15357. literal('ull');
  15358. return newToken('null', null);
  15359. case 't':
  15360. read();
  15361. literal('rue');
  15362. return newToken('boolean', true);
  15363. case 'f':
  15364. read();
  15365. literal('alse');
  15366. return newToken('boolean', false);
  15367. case '-':
  15368. case '+':
  15369. if (read() === '-') {
  15370. sign = -1;
  15371. }
  15372. lexState = 'sign';
  15373. return;
  15374. case '.':
  15375. buffer = read();
  15376. lexState = 'decimalPointLeading';
  15377. return;
  15378. case '0':
  15379. buffer = read();
  15380. lexState = 'zero';
  15381. return;
  15382. case '1':
  15383. case '2':
  15384. case '3':
  15385. case '4':
  15386. case '5':
  15387. case '6':
  15388. case '7':
  15389. case '8':
  15390. case '9':
  15391. buffer = read();
  15392. lexState = 'decimalInteger';
  15393. return;
  15394. case 'I':
  15395. read();
  15396. literal('nfinity');
  15397. return newToken('numeric', Infinity);
  15398. case 'N':
  15399. read();
  15400. literal('aN');
  15401. return newToken('numeric', NaN);
  15402. case '"':
  15403. case "'":
  15404. doubleQuote = read() === '"';
  15405. buffer = '';
  15406. lexState = 'string';
  15407. return;
  15408. }
  15409. throw invalidChar(read());
  15410. },
  15411. identifierNameStartEscape() {
  15412. if (c !== 'u') {
  15413. throw invalidChar(read());
  15414. }
  15415. read();
  15416. const u = unicodeEscape();
  15417. switch (u) {
  15418. case '$':
  15419. case '_':
  15420. break;
  15421. default:
  15422. if (!util$2.isIdStartChar(u)) {
  15423. throw invalidIdentifier();
  15424. }
  15425. break;
  15426. }
  15427. buffer += u;
  15428. lexState = 'identifierName';
  15429. },
  15430. identifierName() {
  15431. switch (c) {
  15432. case '$':
  15433. case '_':
  15434. case '\u200C':
  15435. case '\u200D':
  15436. buffer += read();
  15437. return;
  15438. case '\\':
  15439. read();
  15440. lexState = 'identifierNameEscape';
  15441. return;
  15442. }
  15443. if (util$2.isIdContinueChar(c)) {
  15444. buffer += read();
  15445. return;
  15446. }
  15447. return newToken('identifier', buffer);
  15448. },
  15449. identifierNameEscape() {
  15450. if (c !== 'u') {
  15451. throw invalidChar(read());
  15452. }
  15453. read();
  15454. const u = unicodeEscape();
  15455. switch (u) {
  15456. case '$':
  15457. case '_':
  15458. case '\u200C':
  15459. case '\u200D':
  15460. break;
  15461. default:
  15462. if (!util$2.isIdContinueChar(u)) {
  15463. throw invalidIdentifier();
  15464. }
  15465. break;
  15466. }
  15467. buffer += u;
  15468. lexState = 'identifierName';
  15469. },
  15470. sign() {
  15471. switch (c) {
  15472. case '.':
  15473. buffer = read();
  15474. lexState = 'decimalPointLeading';
  15475. return;
  15476. case '0':
  15477. buffer = read();
  15478. lexState = 'zero';
  15479. return;
  15480. case '1':
  15481. case '2':
  15482. case '3':
  15483. case '4':
  15484. case '5':
  15485. case '6':
  15486. case '7':
  15487. case '8':
  15488. case '9':
  15489. buffer = read();
  15490. lexState = 'decimalInteger';
  15491. return;
  15492. case 'I':
  15493. read();
  15494. literal('nfinity');
  15495. return newToken('numeric', sign * Infinity);
  15496. case 'N':
  15497. read();
  15498. literal('aN');
  15499. return newToken('numeric', NaN);
  15500. }
  15501. throw invalidChar(read());
  15502. },
  15503. zero() {
  15504. switch (c) {
  15505. case '.':
  15506. buffer += read();
  15507. lexState = 'decimalPoint';
  15508. return;
  15509. case 'e':
  15510. case 'E':
  15511. buffer += read();
  15512. lexState = 'decimalExponent';
  15513. return;
  15514. case 'x':
  15515. case 'X':
  15516. buffer += read();
  15517. lexState = 'hexadecimal';
  15518. return;
  15519. }
  15520. return newToken('numeric', sign * 0);
  15521. },
  15522. decimalInteger() {
  15523. switch (c) {
  15524. case '.':
  15525. buffer += read();
  15526. lexState = 'decimalPoint';
  15527. return;
  15528. case 'e':
  15529. case 'E':
  15530. buffer += read();
  15531. lexState = 'decimalExponent';
  15532. return;
  15533. }
  15534. if (util$2.isDigit(c)) {
  15535. buffer += read();
  15536. return;
  15537. }
  15538. return newToken('numeric', sign * Number(buffer));
  15539. },
  15540. decimalPointLeading() {
  15541. if (util$2.isDigit(c)) {
  15542. buffer += read();
  15543. lexState = 'decimalFraction';
  15544. return;
  15545. }
  15546. throw invalidChar(read());
  15547. },
  15548. decimalPoint() {
  15549. switch (c) {
  15550. case 'e':
  15551. case 'E':
  15552. buffer += read();
  15553. lexState = 'decimalExponent';
  15554. return;
  15555. }
  15556. if (util$2.isDigit(c)) {
  15557. buffer += read();
  15558. lexState = 'decimalFraction';
  15559. return;
  15560. }
  15561. return newToken('numeric', sign * Number(buffer));
  15562. },
  15563. decimalFraction() {
  15564. switch (c) {
  15565. case 'e':
  15566. case 'E':
  15567. buffer += read();
  15568. lexState = 'decimalExponent';
  15569. return;
  15570. }
  15571. if (util$2.isDigit(c)) {
  15572. buffer += read();
  15573. return;
  15574. }
  15575. return newToken('numeric', sign * Number(buffer));
  15576. },
  15577. decimalExponent() {
  15578. switch (c) {
  15579. case '+':
  15580. case '-':
  15581. buffer += read();
  15582. lexState = 'decimalExponentSign';
  15583. return;
  15584. }
  15585. if (util$2.isDigit(c)) {
  15586. buffer += read();
  15587. lexState = 'decimalExponentInteger';
  15588. return;
  15589. }
  15590. throw invalidChar(read());
  15591. },
  15592. decimalExponentSign() {
  15593. if (util$2.isDigit(c)) {
  15594. buffer += read();
  15595. lexState = 'decimalExponentInteger';
  15596. return;
  15597. }
  15598. throw invalidChar(read());
  15599. },
  15600. decimalExponentInteger() {
  15601. if (util$2.isDigit(c)) {
  15602. buffer += read();
  15603. return;
  15604. }
  15605. return newToken('numeric', sign * Number(buffer));
  15606. },
  15607. hexadecimal() {
  15608. if (util$2.isHexDigit(c)) {
  15609. buffer += read();
  15610. lexState = 'hexadecimalInteger';
  15611. return;
  15612. }
  15613. throw invalidChar(read());
  15614. },
  15615. hexadecimalInteger() {
  15616. if (util$2.isHexDigit(c)) {
  15617. buffer += read();
  15618. return;
  15619. }
  15620. return newToken('numeric', sign * Number(buffer));
  15621. },
  15622. string() {
  15623. switch (c) {
  15624. case '\\':
  15625. read();
  15626. buffer += escape();
  15627. return;
  15628. case '"':
  15629. if (doubleQuote) {
  15630. read();
  15631. return newToken('string', buffer);
  15632. }
  15633. buffer += read();
  15634. return;
  15635. case "'":
  15636. if (!doubleQuote) {
  15637. read();
  15638. return newToken('string', buffer);
  15639. }
  15640. buffer += read();
  15641. return;
  15642. case '\n':
  15643. case '\r':
  15644. throw invalidChar(read());
  15645. case '\u2028':
  15646. case '\u2029':
  15647. separatorChar(c);
  15648. break;
  15649. case undefined:
  15650. throw invalidChar(read());
  15651. }
  15652. buffer += read();
  15653. },
  15654. start() {
  15655. switch (c) {
  15656. case '{':
  15657. case '[':
  15658. return newToken('punctuator', read());
  15659. // This code is unreachable since the default lexState handles eof.
  15660. // case undefined:
  15661. // return newToken('eof')
  15662. }
  15663. lexState = 'value';
  15664. },
  15665. beforePropertyName() {
  15666. switch (c) {
  15667. case '$':
  15668. case '_':
  15669. buffer = read();
  15670. lexState = 'identifierName';
  15671. return;
  15672. case '\\':
  15673. read();
  15674. lexState = 'identifierNameStartEscape';
  15675. return;
  15676. case '}':
  15677. return newToken('punctuator', read());
  15678. case '"':
  15679. case "'":
  15680. doubleQuote = read() === '"';
  15681. lexState = 'string';
  15682. return;
  15683. }
  15684. if (util$2.isIdStartChar(c)) {
  15685. buffer += read();
  15686. lexState = 'identifierName';
  15687. return;
  15688. }
  15689. throw invalidChar(read());
  15690. },
  15691. afterPropertyName() {
  15692. if (c === ':') {
  15693. return newToken('punctuator', read());
  15694. }
  15695. throw invalidChar(read());
  15696. },
  15697. beforePropertyValue() {
  15698. lexState = 'value';
  15699. },
  15700. afterPropertyValue() {
  15701. switch (c) {
  15702. case ',':
  15703. case '}':
  15704. return newToken('punctuator', read());
  15705. }
  15706. throw invalidChar(read());
  15707. },
  15708. beforeArrayValue() {
  15709. if (c === ']') {
  15710. return newToken('punctuator', read());
  15711. }
  15712. lexState = 'value';
  15713. },
  15714. afterArrayValue() {
  15715. switch (c) {
  15716. case ',':
  15717. case ']':
  15718. return newToken('punctuator', read());
  15719. }
  15720. throw invalidChar(read());
  15721. },
  15722. end() {
  15723. // This code is unreachable since it's handled by the default lexState.
  15724. // if (c === undefined) {
  15725. // read()
  15726. // return newToken('eof')
  15727. // }
  15728. throw invalidChar(read());
  15729. }
  15730. };
  15731. function newToken(type, value) {
  15732. return {
  15733. type,
  15734. value,
  15735. line: line$2,
  15736. column
  15737. };
  15738. }
  15739. function literal(s) {
  15740. for (const c of s) {
  15741. const p = peek();
  15742. if (p !== c) {
  15743. throw invalidChar(read());
  15744. }
  15745. read();
  15746. }
  15747. }
  15748. function escape() {
  15749. const c = peek();
  15750. switch (c) {
  15751. case 'b':
  15752. read();
  15753. return '\b';
  15754. case 'f':
  15755. read();
  15756. return '\f';
  15757. case 'n':
  15758. read();
  15759. return '\n';
  15760. case 'r':
  15761. read();
  15762. return '\r';
  15763. case 't':
  15764. read();
  15765. return '\t';
  15766. case 'v':
  15767. read();
  15768. return '\v';
  15769. case '0':
  15770. read();
  15771. if (util$2.isDigit(peek())) {
  15772. throw invalidChar(read());
  15773. }
  15774. return '\0';
  15775. case 'x':
  15776. read();
  15777. return hexEscape();
  15778. case 'u':
  15779. read();
  15780. return unicodeEscape();
  15781. case '\n':
  15782. case '\u2028':
  15783. case '\u2029':
  15784. read();
  15785. return '';
  15786. case '\r':
  15787. read();
  15788. if (peek() === '\n') {
  15789. read();
  15790. }
  15791. return '';
  15792. case '1':
  15793. case '2':
  15794. case '3':
  15795. case '4':
  15796. case '5':
  15797. case '6':
  15798. case '7':
  15799. case '8':
  15800. case '9':
  15801. throw invalidChar(read());
  15802. case undefined:
  15803. throw invalidChar(read());
  15804. }
  15805. return read();
  15806. }
  15807. function hexEscape() {
  15808. let buffer = '';
  15809. let c = peek();
  15810. if (!util$2.isHexDigit(c)) {
  15811. throw invalidChar(read());
  15812. }
  15813. buffer += read();
  15814. c = peek();
  15815. if (!util$2.isHexDigit(c)) {
  15816. throw invalidChar(read());
  15817. }
  15818. buffer += read();
  15819. return String.fromCodePoint(parseInt(buffer, 16));
  15820. }
  15821. function unicodeEscape() {
  15822. let buffer = '';
  15823. let count = 4;
  15824. while (count-- > 0) {
  15825. const c = peek();
  15826. if (!util$2.isHexDigit(c)) {
  15827. throw invalidChar(read());
  15828. }
  15829. buffer += read();
  15830. }
  15831. return String.fromCodePoint(parseInt(buffer, 16));
  15832. }
  15833. const parseStates = {
  15834. start() {
  15835. if (token.type === 'eof') {
  15836. throw invalidEOF();
  15837. }
  15838. push();
  15839. },
  15840. beforePropertyName() {
  15841. switch (token.type) {
  15842. case 'identifier':
  15843. case 'string':
  15844. key = token.value;
  15845. parseState = 'afterPropertyName';
  15846. return;
  15847. case 'punctuator':
  15848. // This code is unreachable since it's handled by the lexState.
  15849. // if (token.value !== '}') {
  15850. // throw invalidToken()
  15851. // }
  15852. pop();
  15853. return;
  15854. case 'eof':
  15855. throw invalidEOF();
  15856. } // This code is unreachable since it's handled by the lexState.
  15857. // throw invalidToken()
  15858. },
  15859. afterPropertyName() {
  15860. // This code is unreachable since it's handled by the lexState.
  15861. // if (token.type !== 'punctuator' || token.value !== ':') {
  15862. // throw invalidToken()
  15863. // }
  15864. if (token.type === 'eof') {
  15865. throw invalidEOF();
  15866. }
  15867. parseState = 'beforePropertyValue';
  15868. },
  15869. beforePropertyValue() {
  15870. if (token.type === 'eof') {
  15871. throw invalidEOF();
  15872. }
  15873. push();
  15874. },
  15875. beforeArrayValue() {
  15876. if (token.type === 'eof') {
  15877. throw invalidEOF();
  15878. }
  15879. if (token.type === 'punctuator' && token.value === ']') {
  15880. pop();
  15881. return;
  15882. }
  15883. push();
  15884. },
  15885. afterPropertyValue() {
  15886. // This code is unreachable since it's handled by the lexState.
  15887. // if (token.type !== 'punctuator') {
  15888. // throw invalidToken()
  15889. // }
  15890. if (token.type === 'eof') {
  15891. throw invalidEOF();
  15892. }
  15893. switch (token.value) {
  15894. case ',':
  15895. parseState = 'beforePropertyName';
  15896. return;
  15897. case '}':
  15898. pop();
  15899. } // This code is unreachable since it's handled by the lexState.
  15900. // throw invalidToken()
  15901. },
  15902. afterArrayValue() {
  15903. // This code is unreachable since it's handled by the lexState.
  15904. // if (token.type !== 'punctuator') {
  15905. // throw invalidToken()
  15906. // }
  15907. if (token.type === 'eof') {
  15908. throw invalidEOF();
  15909. }
  15910. switch (token.value) {
  15911. case ',':
  15912. parseState = 'beforeArrayValue';
  15913. return;
  15914. case ']':
  15915. pop();
  15916. } // This code is unreachable since it's handled by the lexState.
  15917. // throw invalidToken()
  15918. },
  15919. end() {// This code is unreachable since it's handled by the lexState.
  15920. // if (token.type !== 'eof') {
  15921. // throw invalidToken()
  15922. // }
  15923. }
  15924. };
  15925. function push() {
  15926. let value;
  15927. switch (token.type) {
  15928. case 'punctuator':
  15929. switch (token.value) {
  15930. case '{':
  15931. value = {};
  15932. break;
  15933. case '[':
  15934. value = [];
  15935. break;
  15936. }
  15937. break;
  15938. case 'null':
  15939. case 'boolean':
  15940. case 'numeric':
  15941. case 'string':
  15942. value = token.value;
  15943. break;
  15944. // This code is unreachable.
  15945. // default:
  15946. // throw invalidToken()
  15947. }
  15948. if (root$1 === undefined) {
  15949. root$1 = value;
  15950. } else {
  15951. const parent = stack[stack.length - 1];
  15952. if (Array.isArray(parent)) {
  15953. parent.push(value);
  15954. } else {
  15955. parent[key] = value;
  15956. }
  15957. }
  15958. if (value !== null && typeof value === 'object') {
  15959. stack.push(value);
  15960. if (Array.isArray(value)) {
  15961. parseState = 'beforeArrayValue';
  15962. } else {
  15963. parseState = 'beforePropertyName';
  15964. }
  15965. } else {
  15966. const current = stack[stack.length - 1];
  15967. if (current == null) {
  15968. parseState = 'end';
  15969. } else if (Array.isArray(current)) {
  15970. parseState = 'afterArrayValue';
  15971. } else {
  15972. parseState = 'afterPropertyValue';
  15973. }
  15974. }
  15975. }
  15976. function pop() {
  15977. stack.pop();
  15978. const current = stack[stack.length - 1];
  15979. if (current == null) {
  15980. parseState = 'end';
  15981. } else if (Array.isArray(current)) {
  15982. parseState = 'afterArrayValue';
  15983. } else {
  15984. parseState = 'afterPropertyValue';
  15985. }
  15986. } // This code is unreachable.
  15987. // function invalidParseState () {
  15988. // return new Error(`JSON5: invalid parse state '${parseState}'`)
  15989. // }
  15990. // This code is unreachable.
  15991. // function invalidLexState (state) {
  15992. // return new Error(`JSON5: invalid lex state '${state}'`)
  15993. // }
  15994. function invalidChar(c) {
  15995. if (c === undefined) {
  15996. return syntaxError(`JSON5: invalid end of input at ${line$2}:${column}`);
  15997. }
  15998. return syntaxError(`JSON5: invalid character '${formatChar(c)}' at ${line$2}:${column}`);
  15999. }
  16000. function invalidEOF() {
  16001. return syntaxError(`JSON5: invalid end of input at ${line$2}:${column}`);
  16002. } // This code is unreachable.
  16003. // function invalidToken () {
  16004. // if (token.type === 'eof') {
  16005. // return syntaxError(`JSON5: invalid end of input at ${line}:${column}`)
  16006. // }
  16007. // const c = String.fromCodePoint(token.value.codePointAt(0))
  16008. // return syntaxError(`JSON5: invalid character '${formatChar(c)}' at ${line}:${column}`)
  16009. // }
  16010. function invalidIdentifier() {
  16011. column -= 5;
  16012. return syntaxError(`JSON5: invalid identifier character at ${line$2}:${column}`);
  16013. }
  16014. function separatorChar(c) {
  16015. console.warn(`JSON5: '${formatChar(c)}' in strings is not valid ECMAScript; consider escaping`);
  16016. }
  16017. function formatChar(c) {
  16018. const replacements = {
  16019. "'": "\\'",
  16020. '"': '\\"',
  16021. '\\': '\\\\',
  16022. '\b': '\\b',
  16023. '\f': '\\f',
  16024. '\n': '\\n',
  16025. '\r': '\\r',
  16026. '\t': '\\t',
  16027. '\v': '\\v',
  16028. '\0': '\\0',
  16029. '\u2028': '\\u2028',
  16030. '\u2029': '\\u2029'
  16031. };
  16032. if (replacements[c]) {
  16033. return replacements[c];
  16034. }
  16035. if (c < ' ') {
  16036. const hexString = c.charCodeAt(0).toString(16);
  16037. return '\\x' + ('00' + hexString).substring(hexString.length);
  16038. }
  16039. return c;
  16040. }
  16041. function syntaxError(message) {
  16042. const err = new SyntaxError(message);
  16043. err.lineNumber = line$2;
  16044. err.columnNumber = column;
  16045. return err;
  16046. }
  16047. var stringify = function stringify(value, replacer, space) {
  16048. const stack = [];
  16049. let indent = '';
  16050. let propertyList;
  16051. let replacerFunc;
  16052. let gap = '';
  16053. let quote;
  16054. if (replacer != null && typeof replacer === 'object' && !Array.isArray(replacer)) {
  16055. space = replacer.space;
  16056. quote = replacer.quote;
  16057. replacer = replacer.replacer;
  16058. }
  16059. if (typeof replacer === 'function') {
  16060. replacerFunc = replacer;
  16061. } else if (Array.isArray(replacer)) {
  16062. propertyList = [];
  16063. for (const v of replacer) {
  16064. let item;
  16065. if (typeof v === 'string') {
  16066. item = v;
  16067. } else if (typeof v === 'number' || v instanceof String || v instanceof Number) {
  16068. item = String(v);
  16069. }
  16070. if (item !== undefined && propertyList.indexOf(item) < 0) {
  16071. propertyList.push(item);
  16072. }
  16073. }
  16074. }
  16075. if (space instanceof Number) {
  16076. space = Number(space);
  16077. } else if (space instanceof String) {
  16078. space = String(space);
  16079. }
  16080. if (typeof space === 'number') {
  16081. if (space > 0) {
  16082. space = Math.min(10, Math.floor(space));
  16083. gap = ' '.substr(0, space);
  16084. }
  16085. } else if (typeof space === 'string') {
  16086. gap = space.substr(0, 10);
  16087. }
  16088. return serializeProperty('', {
  16089. '': value
  16090. });
  16091. function serializeProperty(key, holder) {
  16092. let value = holder[key];
  16093. if (value != null) {
  16094. if (typeof value.toJSON5 === 'function') {
  16095. value = value.toJSON5(key);
  16096. } else if (typeof value.toJSON === 'function') {
  16097. value = value.toJSON(key);
  16098. }
  16099. }
  16100. if (replacerFunc) {
  16101. value = replacerFunc.call(holder, key, value);
  16102. }
  16103. if (value instanceof Number) {
  16104. value = Number(value);
  16105. } else if (value instanceof String) {
  16106. value = String(value);
  16107. } else if (value instanceof Boolean) {
  16108. value = value.valueOf();
  16109. }
  16110. switch (value) {
  16111. case null:
  16112. return 'null';
  16113. case true:
  16114. return 'true';
  16115. case false:
  16116. return 'false';
  16117. }
  16118. if (typeof value === 'string') {
  16119. return quoteString(value);
  16120. }
  16121. if (typeof value === 'number') {
  16122. return String(value);
  16123. }
  16124. if (typeof value === 'object') {
  16125. return Array.isArray(value) ? serializeArray(value) : serializeObject(value);
  16126. }
  16127. return undefined;
  16128. }
  16129. function quoteString(value) {
  16130. const quotes = {
  16131. "'": 0.1,
  16132. '"': 0.2
  16133. };
  16134. const replacements = {
  16135. "'": "\\'",
  16136. '"': '\\"',
  16137. '\\': '\\\\',
  16138. '\b': '\\b',
  16139. '\f': '\\f',
  16140. '\n': '\\n',
  16141. '\r': '\\r',
  16142. '\t': '\\t',
  16143. '\v': '\\v',
  16144. '\0': '\\0',
  16145. '\u2028': '\\u2028',
  16146. '\u2029': '\\u2029'
  16147. };
  16148. let product = '';
  16149. for (let i = 0; i < value.length; i++) {
  16150. const c = value[i];
  16151. switch (c) {
  16152. case "'":
  16153. case '"':
  16154. quotes[c]++;
  16155. product += c;
  16156. continue;
  16157. case '\0':
  16158. if (util$2.isDigit(value[i + 1])) {
  16159. product += '\\x00';
  16160. continue;
  16161. }
  16162. }
  16163. if (replacements[c]) {
  16164. product += replacements[c];
  16165. continue;
  16166. }
  16167. if (c < ' ') {
  16168. let hexString = c.charCodeAt(0).toString(16);
  16169. product += '\\x' + ('00' + hexString).substring(hexString.length);
  16170. continue;
  16171. }
  16172. product += c;
  16173. }
  16174. const quoteChar = quote || Object.keys(quotes).reduce((a, b) => quotes[a] < quotes[b] ? a : b);
  16175. product = product.replace(new RegExp(quoteChar, 'g'), replacements[quoteChar]);
  16176. return quoteChar + product + quoteChar;
  16177. }
  16178. function serializeObject(value) {
  16179. if (stack.indexOf(value) >= 0) {
  16180. throw TypeError('Converting circular structure to JSON5');
  16181. }
  16182. stack.push(value);
  16183. let stepback = indent;
  16184. indent = indent + gap;
  16185. let keys = propertyList || Object.keys(value);
  16186. let partial = [];
  16187. for (const key of keys) {
  16188. const propertyString = serializeProperty(key, value);
  16189. if (propertyString !== undefined) {
  16190. let member = serializeKey(key) + ':';
  16191. if (gap !== '') {
  16192. member += ' ';
  16193. }
  16194. member += propertyString;
  16195. partial.push(member);
  16196. }
  16197. }
  16198. let final;
  16199. if (partial.length === 0) {
  16200. final = '{}';
  16201. } else {
  16202. let properties;
  16203. if (gap === '') {
  16204. properties = partial.join(',');
  16205. final = '{' + properties + '}';
  16206. } else {
  16207. let separator = ',\n' + indent;
  16208. properties = partial.join(separator);
  16209. final = '{\n' + indent + properties + ',\n' + stepback + '}';
  16210. }
  16211. }
  16212. stack.pop();
  16213. indent = stepback;
  16214. return final;
  16215. }
  16216. function serializeKey(key) {
  16217. if (key.length === 0) {
  16218. return quoteString(key);
  16219. }
  16220. const firstChar = String.fromCodePoint(key.codePointAt(0));
  16221. if (!util$2.isIdStartChar(firstChar)) {
  16222. return quoteString(key);
  16223. }
  16224. for (let i = firstChar.length; i < key.length; i++) {
  16225. if (!util$2.isIdContinueChar(String.fromCodePoint(key.codePointAt(i)))) {
  16226. return quoteString(key);
  16227. }
  16228. }
  16229. return key;
  16230. }
  16231. function serializeArray(value) {
  16232. if (stack.indexOf(value) >= 0) {
  16233. throw TypeError('Converting circular structure to JSON5');
  16234. }
  16235. stack.push(value);
  16236. let stepback = indent;
  16237. indent = indent + gap;
  16238. let partial = [];
  16239. for (let i = 0; i < value.length; i++) {
  16240. const propertyString = serializeProperty(String(i), value);
  16241. partial.push(propertyString !== undefined ? propertyString : 'null');
  16242. }
  16243. let final;
  16244. if (partial.length === 0) {
  16245. final = '[]';
  16246. } else {
  16247. if (gap === '') {
  16248. let properties = partial.join(',');
  16249. final = '[' + properties + ']';
  16250. } else {
  16251. let separator = ',\n' + indent;
  16252. let properties = partial.join(separator);
  16253. final = '[\n' + indent + properties + ',\n' + stepback + ']';
  16254. }
  16255. }
  16256. stack.pop();
  16257. indent = stepback;
  16258. return final;
  16259. }
  16260. };
  16261. const JSON5 = {
  16262. parse: parse$2,
  16263. stringify
  16264. };
  16265. var lib$5 = JSON5;
  16266. var dist$1 = /*#__PURE__*/Object.freeze({
  16267. __proto__: null,
  16268. 'default': lib$5
  16269. });
  16270. var require$$0$1 = getCjsExportFromNamespace(dist$1);
  16271. const {
  16272. parse: parse$3
  16273. } = require$$0$1;
  16274. var loadJson5 = function (filePath, content) {
  16275. try {
  16276. return parse$3(content);
  16277. } catch (error) {
  16278. error.message = `JSON5 Error in ${filePath}:\n${error.message}`;
  16279. throw error;
  16280. }
  16281. };
  16282. var caller = function () {
  16283. // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  16284. var origPrepareStackTrace = Error.prepareStackTrace;
  16285. Error.prepareStackTrace = function (_, stack) {
  16286. return stack;
  16287. };
  16288. var stack = new Error().stack;
  16289. Error.prepareStackTrace = origPrepareStackTrace;
  16290. return stack[2].getFileName();
  16291. };
  16292. var pathParse = createCommonjsModule(function (module) {
  16293. var isWindows = process.platform === 'win32'; // Regex to split a windows path into three parts: [*, device, slash,
  16294. // tail] windows-only
  16295. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/; // Regex to split the tail part of the above into [*, dir, basename, ext]
  16296. var splitTailRe = /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
  16297. var win32 = {}; // Function to split a filename into [root, dir, basename, ext]
  16298. function win32SplitPath(filename) {
  16299. // Separate device+slash from tail
  16300. var result = splitDeviceRe.exec(filename),
  16301. device = (result[1] || '') + (result[2] || ''),
  16302. tail = result[3] || ''; // Split the tail into dir, basename and extension
  16303. var result2 = splitTailRe.exec(tail),
  16304. dir = result2[1],
  16305. basename = result2[2],
  16306. ext = result2[3];
  16307. return [device, dir, basename, ext];
  16308. }
  16309. win32.parse = function (pathString) {
  16310. if (typeof pathString !== 'string') {
  16311. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  16312. }
  16313. var allParts = win32SplitPath(pathString);
  16314. if (!allParts || allParts.length !== 4) {
  16315. throw new TypeError("Invalid path '" + pathString + "'");
  16316. }
  16317. return {
  16318. root: allParts[0],
  16319. dir: allParts[0] + allParts[1].slice(0, -1),
  16320. base: allParts[2],
  16321. ext: allParts[3],
  16322. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  16323. };
  16324. }; // Split a filename into [root, dir, basename, ext], unix version
  16325. // 'root' is just a slash, or nothing.
  16326. var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  16327. var posix = {};
  16328. function posixSplitPath(filename) {
  16329. return splitPathRe.exec(filename).slice(1);
  16330. }
  16331. posix.parse = function (pathString) {
  16332. if (typeof pathString !== 'string') {
  16333. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  16334. }
  16335. var allParts = posixSplitPath(pathString);
  16336. if (!allParts || allParts.length !== 4) {
  16337. throw new TypeError("Invalid path '" + pathString + "'");
  16338. }
  16339. allParts[1] = allParts[1] || '';
  16340. allParts[2] = allParts[2] || '';
  16341. allParts[3] = allParts[3] || '';
  16342. return {
  16343. root: allParts[0],
  16344. dir: allParts[0] + allParts[1].slice(0, -1),
  16345. base: allParts[2],
  16346. ext: allParts[3],
  16347. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  16348. };
  16349. };
  16350. if (isWindows) module.exports = win32.parse;else
  16351. /* posix */
  16352. module.exports = posix.parse;
  16353. module.exports.posix = posix.parse;
  16354. module.exports.win32 = win32.parse;
  16355. });
  16356. var parse$4 = path__default['default'].parse || pathParse;
  16357. var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
  16358. var prefix = '/';
  16359. if (/^([A-Za-z]:)/.test(absoluteStart)) {
  16360. prefix = '';
  16361. } else if (/^\\\\/.test(absoluteStart)) {
  16362. prefix = '\\\\';
  16363. }
  16364. var paths = [absoluteStart];
  16365. var parsed = parse$4(absoluteStart);
  16366. while (parsed.dir !== paths[paths.length - 1]) {
  16367. paths.push(parsed.dir);
  16368. parsed = parse$4(parsed.dir);
  16369. }
  16370. return paths.reduce(function (dirs, aPath) {
  16371. return dirs.concat(modules.map(function (moduleDir) {
  16372. return path__default['default'].resolve(prefix, aPath, moduleDir);
  16373. }));
  16374. }, []);
  16375. };
  16376. var nodeModulesPaths = function nodeModulesPaths(start, opts, request) {
  16377. var modules = opts && opts.moduleDirectory ? [].concat(opts.moduleDirectory) : ['node_modules'];
  16378. if (opts && typeof opts.paths === 'function') {
  16379. return opts.paths(request, start, function () {
  16380. return getNodeModulesDirs(start, modules);
  16381. }, opts);
  16382. }
  16383. var dirs = getNodeModulesDirs(start, modules);
  16384. return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
  16385. };
  16386. var normalizeOptions$2 = function (x, opts) {
  16387. /**
  16388. * This file is purposefully a passthrough. It's expected that third-party
  16389. * environments will override it at runtime in order to inject special logic
  16390. * into `resolve` (by manipulating the options). One such example is the PnP
  16391. * code path in Yarn.
  16392. */
  16393. return opts || {};
  16394. };
  16395. var assert = true;
  16396. var async_hooks = ">= 8";
  16397. var buffer_ieee754 = "< 0.9.7";
  16398. var buffer$1 = true;
  16399. var child_process = true;
  16400. var cluster = true;
  16401. var console$1 = true;
  16402. var constants$1 = true;
  16403. var crypto = true;
  16404. var _debug_agent = ">= 1 && < 8";
  16405. var _debugger = "< 8";
  16406. var dgram = true;
  16407. var dns = true;
  16408. var domain = true;
  16409. var events = true;
  16410. var freelist = "< 6";
  16411. var fs = true;
  16412. var _http_agent = ">= 0.11.1";
  16413. var _http_client = ">= 0.11.1";
  16414. var _http_common = ">= 0.11.1";
  16415. var _http_incoming = ">= 0.11.1";
  16416. var _http_outgoing = ">= 0.11.1";
  16417. var _http_server = ">= 0.11.1";
  16418. var http = true;
  16419. var http2 = ">= 8.8";
  16420. var https = true;
  16421. var inspector = ">= 8.0.0";
  16422. var _linklist = "< 8";
  16423. var module$1 = true;
  16424. var net = true;
  16425. var os = true;
  16426. var path$1 = true;
  16427. var perf_hooks = ">= 8.5";
  16428. var process$1 = ">= 1";
  16429. var punycode = true;
  16430. var querystring = true;
  16431. var readline = true;
  16432. var repl = true;
  16433. var smalloc = ">= 0.11.5 && < 3";
  16434. var _stream_duplex = ">= 0.9.4";
  16435. var _stream_transform = ">= 0.9.4";
  16436. var _stream_wrap = ">= 1.4.1";
  16437. var _stream_passthrough = ">= 0.9.4";
  16438. var _stream_readable = ">= 0.9.4";
  16439. var _stream_writable = ">= 0.9.4";
  16440. var stream = true;
  16441. var string_decoder = true;
  16442. var sys = true;
  16443. var timers = true;
  16444. var _tls_common = ">= 0.11.13";
  16445. var _tls_legacy = ">= 0.11.3 && < 10";
  16446. var _tls_wrap = ">= 0.11.3";
  16447. var tls = true;
  16448. var trace_events = ">= 10";
  16449. var tty = true;
  16450. var url = true;
  16451. var util$3 = true;
  16452. var v8 = ">= 1";
  16453. var vm = true;
  16454. var wasi = ">= 13.4 && < 13.5";
  16455. var worker_threads = ">= 11.7";
  16456. var zlib = true;
  16457. var core$1 = {
  16458. assert: assert,
  16459. async_hooks: async_hooks,
  16460. buffer_ieee754: buffer_ieee754,
  16461. buffer: buffer$1,
  16462. child_process: child_process,
  16463. cluster: cluster,
  16464. console: console$1,
  16465. constants: constants$1,
  16466. crypto: crypto,
  16467. _debug_agent: _debug_agent,
  16468. _debugger: _debugger,
  16469. dgram: dgram,
  16470. dns: dns,
  16471. domain: domain,
  16472. events: events,
  16473. freelist: freelist,
  16474. fs: fs,
  16475. "fs/promises": [
  16476. ">= 10 && < 10.1",
  16477. ">= 14"
  16478. ],
  16479. _http_agent: _http_agent,
  16480. _http_client: _http_client,
  16481. _http_common: _http_common,
  16482. _http_incoming: _http_incoming,
  16483. _http_outgoing: _http_outgoing,
  16484. _http_server: _http_server,
  16485. http: http,
  16486. http2: http2,
  16487. https: https,
  16488. inspector: inspector,
  16489. _linklist: _linklist,
  16490. module: module$1,
  16491. net: net,
  16492. "node-inspect/lib/_inspect": ">= 7.6.0 && < 12",
  16493. "node-inspect/lib/internal/inspect_client": ">= 7.6.0 && < 12",
  16494. "node-inspect/lib/internal/inspect_repl": ">= 7.6.0 && < 12",
  16495. os: os,
  16496. path: path$1,
  16497. perf_hooks: perf_hooks,
  16498. process: process$1,
  16499. punycode: punycode,
  16500. querystring: querystring,
  16501. readline: readline,
  16502. repl: repl,
  16503. smalloc: smalloc,
  16504. _stream_duplex: _stream_duplex,
  16505. _stream_transform: _stream_transform,
  16506. _stream_wrap: _stream_wrap,
  16507. _stream_passthrough: _stream_passthrough,
  16508. _stream_readable: _stream_readable,
  16509. _stream_writable: _stream_writable,
  16510. stream: stream,
  16511. string_decoder: string_decoder,
  16512. sys: sys,
  16513. timers: timers,
  16514. _tls_common: _tls_common,
  16515. _tls_legacy: _tls_legacy,
  16516. _tls_wrap: _tls_wrap,
  16517. tls: tls,
  16518. trace_events: trace_events,
  16519. tty: tty,
  16520. url: url,
  16521. util: util$3,
  16522. "v8/tools/arguments": ">= 10 && < 12",
  16523. "v8/tools/codemap": [
  16524. ">= 4.4.0 && < 5",
  16525. ">= 5.2.0 && < 12"
  16526. ],
  16527. "v8/tools/consarray": [
  16528. ">= 4.4.0 && < 5",
  16529. ">= 5.2.0 && < 12"
  16530. ],
  16531. "v8/tools/csvparser": [
  16532. ">= 4.4.0 && < 5",
  16533. ">= 5.2.0 && < 12"
  16534. ],
  16535. "v8/tools/logreader": [
  16536. ">= 4.4.0 && < 5",
  16537. ">= 5.2.0 && < 12"
  16538. ],
  16539. "v8/tools/profile_view": [
  16540. ">= 4.4.0 && < 5",
  16541. ">= 5.2.0 && < 12"
  16542. ],
  16543. "v8/tools/splaytree": [
  16544. ">= 4.4.0 && < 5",
  16545. ">= 5.2.0 && < 12"
  16546. ],
  16547. v8: v8,
  16548. vm: vm,
  16549. wasi: wasi,
  16550. worker_threads: worker_threads,
  16551. zlib: zlib
  16552. };
  16553. var core$2 = /*#__PURE__*/Object.freeze({
  16554. __proto__: null,
  16555. assert: assert,
  16556. async_hooks: async_hooks,
  16557. buffer_ieee754: buffer_ieee754,
  16558. buffer: buffer$1,
  16559. child_process: child_process,
  16560. cluster: cluster,
  16561. console: console$1,
  16562. constants: constants$1,
  16563. crypto: crypto,
  16564. _debug_agent: _debug_agent,
  16565. _debugger: _debugger,
  16566. dgram: dgram,
  16567. dns: dns,
  16568. domain: domain,
  16569. events: events,
  16570. freelist: freelist,
  16571. fs: fs,
  16572. _http_agent: _http_agent,
  16573. _http_client: _http_client,
  16574. _http_common: _http_common,
  16575. _http_incoming: _http_incoming,
  16576. _http_outgoing: _http_outgoing,
  16577. _http_server: _http_server,
  16578. http: http,
  16579. http2: http2,
  16580. https: https,
  16581. inspector: inspector,
  16582. _linklist: _linklist,
  16583. module: module$1,
  16584. net: net,
  16585. os: os,
  16586. path: path$1,
  16587. perf_hooks: perf_hooks,
  16588. process: process$1,
  16589. punycode: punycode,
  16590. querystring: querystring,
  16591. readline: readline,
  16592. repl: repl,
  16593. smalloc: smalloc,
  16594. _stream_duplex: _stream_duplex,
  16595. _stream_transform: _stream_transform,
  16596. _stream_wrap: _stream_wrap,
  16597. _stream_passthrough: _stream_passthrough,
  16598. _stream_readable: _stream_readable,
  16599. _stream_writable: _stream_writable,
  16600. stream: stream,
  16601. string_decoder: string_decoder,
  16602. sys: sys,
  16603. timers: timers,
  16604. _tls_common: _tls_common,
  16605. _tls_legacy: _tls_legacy,
  16606. _tls_wrap: _tls_wrap,
  16607. tls: tls,
  16608. trace_events: trace_events,
  16609. tty: tty,
  16610. url: url,
  16611. util: util$3,
  16612. v8: v8,
  16613. vm: vm,
  16614. wasi: wasi,
  16615. worker_threads: worker_threads,
  16616. zlib: zlib,
  16617. 'default': core$1
  16618. });
  16619. var data = getCjsExportFromNamespace(core$2);
  16620. var current = process.versions && process.versions.node && process.versions.node.split('.') || [];
  16621. function specifierIncluded(specifier) {
  16622. var parts = specifier.split(' ');
  16623. var op = parts.length > 1 ? parts[0] : '=';
  16624. var versionParts = (parts.length > 1 ? parts[1] : parts[0]).split('.');
  16625. for (var i = 0; i < 3; ++i) {
  16626. var cur = Number(current[i] || 0);
  16627. var ver = Number(versionParts[i] || 0);
  16628. if (cur === ver) {
  16629. continue; // eslint-disable-line no-restricted-syntax, no-continue
  16630. }
  16631. if (op === '<') {
  16632. return cur < ver;
  16633. } else if (op === '>=') {
  16634. return cur >= ver;
  16635. } else {
  16636. return false;
  16637. }
  16638. }
  16639. return op === '>=';
  16640. }
  16641. function matchesRange(range) {
  16642. var specifiers = range.split(/ ?&& ?/);
  16643. if (specifiers.length === 0) {
  16644. return false;
  16645. }
  16646. for (var i = 0; i < specifiers.length; ++i) {
  16647. if (!specifierIncluded(specifiers[i])) {
  16648. return false;
  16649. }
  16650. }
  16651. return true;
  16652. }
  16653. function versionIncluded(specifierValue) {
  16654. if (typeof specifierValue === 'boolean') {
  16655. return specifierValue;
  16656. }
  16657. if (specifierValue && typeof specifierValue === 'object') {
  16658. for (var i = 0; i < specifierValue.length; ++i) {
  16659. if (matchesRange(specifierValue[i])) {
  16660. return true;
  16661. }
  16662. }
  16663. return false;
  16664. }
  16665. return matchesRange(specifierValue);
  16666. }
  16667. var core$3 = {};
  16668. for (var mod in data) {
  16669. // eslint-disable-line no-restricted-syntax
  16670. if (Object.prototype.hasOwnProperty.call(data, mod)) {
  16671. core$3[mod] = versionIncluded(data[mod]);
  16672. }
  16673. }
  16674. var core_1 = core$3;
  16675. var isCore = function isCore(x) {
  16676. return Object.prototype.hasOwnProperty.call(core_1, x);
  16677. };
  16678. var realpathFS = fs__default['default'].realpath && typeof fs__default['default'].realpath.native === 'function' ? fs__default['default'].realpath.native : fs__default['default'].realpath;
  16679. var defaultIsFile = function isFile(file, cb) {
  16680. fs__default['default'].stat(file, function (err, stat) {
  16681. if (!err) {
  16682. return cb(null, stat.isFile() || stat.isFIFO());
  16683. }
  16684. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  16685. return cb(err);
  16686. });
  16687. };
  16688. var defaultIsDir = function isDirectory(dir, cb) {
  16689. fs__default['default'].stat(dir, function (err, stat) {
  16690. if (!err) {
  16691. return cb(null, stat.isDirectory());
  16692. }
  16693. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  16694. return cb(err);
  16695. });
  16696. };
  16697. var defaultRealpath = function realpath(x, cb) {
  16698. realpathFS(x, function (realpathErr, realPath) {
  16699. if (realpathErr && realpathErr.code !== 'ENOENT') cb(realpathErr);else cb(null, realpathErr ? x : realPath);
  16700. });
  16701. };
  16702. var maybeRealpath = function maybeRealpath(realpath, x, opts, cb) {
  16703. if (opts && opts.preserveSymlinks === false) {
  16704. realpath(x, cb);
  16705. } else {
  16706. cb(null, x);
  16707. }
  16708. };
  16709. var getPackageCandidates = function getPackageCandidates(x, start, opts) {
  16710. var dirs = nodeModulesPaths(start, opts, x);
  16711. for (var i = 0; i < dirs.length; i++) {
  16712. dirs[i] = path__default['default'].join(dirs[i], x);
  16713. }
  16714. return dirs;
  16715. };
  16716. var async = function resolve(x, options, callback) {
  16717. var cb = callback;
  16718. var opts = options;
  16719. if (typeof options === 'function') {
  16720. cb = opts;
  16721. opts = {};
  16722. }
  16723. if (typeof x !== 'string') {
  16724. var err = new TypeError('Path must be a string.');
  16725. return process.nextTick(function () {
  16726. cb(err);
  16727. });
  16728. }
  16729. opts = normalizeOptions$2(x, opts);
  16730. var isFile = opts.isFile || defaultIsFile;
  16731. var isDirectory = opts.isDirectory || defaultIsDir;
  16732. var readFile = opts.readFile || fs__default['default'].readFile;
  16733. var realpath = opts.realpath || defaultRealpath;
  16734. var packageIterator = opts.packageIterator;
  16735. var extensions = opts.extensions || ['.js'];
  16736. var basedir = opts.basedir || path__default['default'].dirname(caller());
  16737. var parent = opts.filename || basedir;
  16738. opts.paths = opts.paths || []; // ensure that `basedir` is an absolute path at this point, resolving against the process' current working directory
  16739. var absoluteStart = path__default['default'].resolve(basedir);
  16740. maybeRealpath(realpath, absoluteStart, opts, function (err, realStart) {
  16741. if (err) cb(err);else init(realStart);
  16742. });
  16743. var res;
  16744. function init(basedir) {
  16745. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  16746. res = path__default['default'].resolve(basedir, x);
  16747. if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/';
  16748. if (/\/$/.test(x) && res === basedir) {
  16749. loadAsDirectory(res, opts.package, onfile);
  16750. } else loadAsFile(res, opts.package, onfile);
  16751. } else if (isCore(x)) {
  16752. return cb(null, x);
  16753. } else loadNodeModules(x, basedir, function (err, n, pkg) {
  16754. if (err) cb(err);else if (n) {
  16755. return maybeRealpath(realpath, n, opts, function (err, realN) {
  16756. if (err) {
  16757. cb(err);
  16758. } else {
  16759. cb(null, realN, pkg);
  16760. }
  16761. });
  16762. } else {
  16763. var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
  16764. moduleError.code = 'MODULE_NOT_FOUND';
  16765. cb(moduleError);
  16766. }
  16767. });
  16768. }
  16769. function onfile(err, m, pkg) {
  16770. if (err) cb(err);else if (m) cb(null, m, pkg);else loadAsDirectory(res, function (err, d, pkg) {
  16771. if (err) cb(err);else if (d) {
  16772. maybeRealpath(realpath, d, opts, function (err, realD) {
  16773. if (err) {
  16774. cb(err);
  16775. } else {
  16776. cb(null, realD, pkg);
  16777. }
  16778. });
  16779. } else {
  16780. var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
  16781. moduleError.code = 'MODULE_NOT_FOUND';
  16782. cb(moduleError);
  16783. }
  16784. });
  16785. }
  16786. function loadAsFile(x, thePackage, callback) {
  16787. var loadAsFilePackage = thePackage;
  16788. var cb = callback;
  16789. if (typeof loadAsFilePackage === 'function') {
  16790. cb = loadAsFilePackage;
  16791. loadAsFilePackage = undefined;
  16792. }
  16793. var exts = [''].concat(extensions);
  16794. load(exts, x, loadAsFilePackage);
  16795. function load(exts, x, loadPackage) {
  16796. if (exts.length === 0) return cb(null, undefined, loadPackage);
  16797. var file = x + exts[0];
  16798. var pkg = loadPackage;
  16799. if (pkg) onpkg(null, pkg);else loadpkg(path__default['default'].dirname(file), onpkg);
  16800. function onpkg(err, pkg_, dir) {
  16801. pkg = pkg_;
  16802. if (err) return cb(err);
  16803. if (dir && pkg && opts.pathFilter) {
  16804. var rfile = path__default['default'].relative(dir, file);
  16805. var rel = rfile.slice(0, rfile.length - exts[0].length);
  16806. var r = opts.pathFilter(pkg, x, rel);
  16807. if (r) return load([''].concat(extensions.slice()), path__default['default'].resolve(dir, r), pkg);
  16808. }
  16809. isFile(file, onex);
  16810. }
  16811. function onex(err, ex) {
  16812. if (err) return cb(err);
  16813. if (ex) return cb(null, file, pkg);
  16814. load(exts.slice(1), x, pkg);
  16815. }
  16816. }
  16817. }
  16818. function loadpkg(dir, cb) {
  16819. if (dir === '' || dir === '/') return cb(null);
  16820. if (process.platform === 'win32' && /^\w:[/\\]*$/.test(dir)) {
  16821. return cb(null);
  16822. }
  16823. if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null);
  16824. maybeRealpath(realpath, dir, opts, function (unwrapErr, pkgdir) {
  16825. if (unwrapErr) return loadpkg(path__default['default'].dirname(dir), cb);
  16826. var pkgfile = path__default['default'].join(pkgdir, 'package.json');
  16827. isFile(pkgfile, function (err, ex) {
  16828. // on err, ex is false
  16829. if (!ex) return loadpkg(path__default['default'].dirname(dir), cb);
  16830. readFile(pkgfile, function (err, body) {
  16831. if (err) cb(err);
  16832. try {
  16833. var pkg = JSON.parse(body);
  16834. } catch (jsonErr) {}
  16835. if (pkg && opts.packageFilter) {
  16836. pkg = opts.packageFilter(pkg, pkgfile);
  16837. }
  16838. cb(null, pkg, dir);
  16839. });
  16840. });
  16841. });
  16842. }
  16843. function loadAsDirectory(x, loadAsDirectoryPackage, callback) {
  16844. var cb = callback;
  16845. var fpkg = loadAsDirectoryPackage;
  16846. if (typeof fpkg === 'function') {
  16847. cb = fpkg;
  16848. fpkg = opts.package;
  16849. }
  16850. maybeRealpath(realpath, x, opts, function (unwrapErr, pkgdir) {
  16851. if (unwrapErr) return cb(unwrapErr);
  16852. var pkgfile = path__default['default'].join(pkgdir, 'package.json');
  16853. isFile(pkgfile, function (err, ex) {
  16854. if (err) return cb(err);
  16855. if (!ex) return loadAsFile(path__default['default'].join(x, 'index'), fpkg, cb);
  16856. readFile(pkgfile, function (err, body) {
  16857. if (err) return cb(err);
  16858. try {
  16859. var pkg = JSON.parse(body);
  16860. } catch (jsonErr) {}
  16861. if (pkg && opts.packageFilter) {
  16862. pkg = opts.packageFilter(pkg, pkgfile);
  16863. }
  16864. if (pkg && pkg.main) {
  16865. if (typeof pkg.main !== 'string') {
  16866. var mainError = new TypeError('package “' + pkg.name + '” `main` must be a string');
  16867. mainError.code = 'INVALID_PACKAGE_MAIN';
  16868. return cb(mainError);
  16869. }
  16870. if (pkg.main === '.' || pkg.main === './') {
  16871. pkg.main = 'index';
  16872. }
  16873. loadAsFile(path__default['default'].resolve(x, pkg.main), pkg, function (err, m, pkg) {
  16874. if (err) return cb(err);
  16875. if (m) return cb(null, m, pkg);
  16876. if (!pkg) return loadAsFile(path__default['default'].join(x, 'index'), pkg, cb);
  16877. var dir = path__default['default'].resolve(x, pkg.main);
  16878. loadAsDirectory(dir, pkg, function (err, n, pkg) {
  16879. if (err) return cb(err);
  16880. if (n) return cb(null, n, pkg);
  16881. loadAsFile(path__default['default'].join(x, 'index'), pkg, cb);
  16882. });
  16883. });
  16884. return;
  16885. }
  16886. loadAsFile(path__default['default'].join(x, '/index'), pkg, cb);
  16887. });
  16888. });
  16889. });
  16890. }
  16891. function processDirs(cb, dirs) {
  16892. if (dirs.length === 0) return cb(null, undefined);
  16893. var dir = dirs[0];
  16894. isDirectory(path__default['default'].dirname(dir), isdir);
  16895. function isdir(err, isdir) {
  16896. if (err) return cb(err);
  16897. if (!isdir) return processDirs(cb, dirs.slice(1));
  16898. loadAsFile(dir, opts.package, onfile);
  16899. }
  16900. function onfile(err, m, pkg) {
  16901. if (err) return cb(err);
  16902. if (m) return cb(null, m, pkg);
  16903. loadAsDirectory(dir, opts.package, ondir);
  16904. }
  16905. function ondir(err, n, pkg) {
  16906. if (err) return cb(err);
  16907. if (n) return cb(null, n, pkg);
  16908. processDirs(cb, dirs.slice(1));
  16909. }
  16910. }
  16911. function loadNodeModules(x, start, cb) {
  16912. var thunk = function () {
  16913. return getPackageCandidates(x, start, opts);
  16914. };
  16915. processDirs(cb, packageIterator ? packageIterator(x, start, thunk, opts) : thunk());
  16916. }
  16917. };
  16918. var realpathFS$1 = fs__default['default'].realpathSync && typeof fs__default['default'].realpathSync.native === 'function' ? fs__default['default'].realpathSync.native : fs__default['default'].realpathSync;
  16919. var defaultIsFile$1 = function isFile(file) {
  16920. try {
  16921. var stat = fs__default['default'].statSync(file);
  16922. } catch (e) {
  16923. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  16924. throw e;
  16925. }
  16926. return stat.isFile() || stat.isFIFO();
  16927. };
  16928. var defaultIsDir$1 = function isDirectory(dir) {
  16929. try {
  16930. var stat = fs__default['default'].statSync(dir);
  16931. } catch (e) {
  16932. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  16933. throw e;
  16934. }
  16935. return stat.isDirectory();
  16936. };
  16937. var defaultRealpathSync = function realpathSync(x) {
  16938. try {
  16939. return realpathFS$1(x);
  16940. } catch (realpathErr) {
  16941. if (realpathErr.code !== 'ENOENT') {
  16942. throw realpathErr;
  16943. }
  16944. }
  16945. return x;
  16946. };
  16947. var maybeRealpathSync = function maybeRealpathSync(realpathSync, x, opts) {
  16948. if (opts && opts.preserveSymlinks === false) {
  16949. return realpathSync(x);
  16950. }
  16951. return x;
  16952. };
  16953. var getPackageCandidates$1 = function getPackageCandidates(x, start, opts) {
  16954. var dirs = nodeModulesPaths(start, opts, x);
  16955. for (var i = 0; i < dirs.length; i++) {
  16956. dirs[i] = path__default['default'].join(dirs[i], x);
  16957. }
  16958. return dirs;
  16959. };
  16960. var sync = function resolveSync(x, options) {
  16961. if (typeof x !== 'string') {
  16962. throw new TypeError('Path must be a string.');
  16963. }
  16964. var opts = normalizeOptions$2(x, options);
  16965. var isFile = opts.isFile || defaultIsFile$1;
  16966. var readFileSync = opts.readFileSync || fs__default['default'].readFileSync;
  16967. var isDirectory = opts.isDirectory || defaultIsDir$1;
  16968. var realpathSync = opts.realpathSync || defaultRealpathSync;
  16969. var packageIterator = opts.packageIterator;
  16970. var extensions = opts.extensions || ['.js'];
  16971. var basedir = opts.basedir || path__default['default'].dirname(caller());
  16972. var parent = opts.filename || basedir;
  16973. opts.paths = opts.paths || []; // ensure that `basedir` is an absolute path at this point, resolving against the process' current working directory
  16974. var absoluteStart = maybeRealpathSync(realpathSync, path__default['default'].resolve(basedir), opts);
  16975. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  16976. var res = path__default['default'].resolve(absoluteStart, x);
  16977. if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/';
  16978. var m = loadAsFileSync(res) || loadAsDirectorySync(res);
  16979. if (m) return maybeRealpathSync(realpathSync, m, opts);
  16980. } else if (isCore(x)) {
  16981. return x;
  16982. } else {
  16983. var n = loadNodeModulesSync(x, absoluteStart);
  16984. if (n) return maybeRealpathSync(realpathSync, n, opts);
  16985. }
  16986. var err = new Error("Cannot find module '" + x + "' from '" + parent + "'");
  16987. err.code = 'MODULE_NOT_FOUND';
  16988. throw err;
  16989. function loadAsFileSync(x) {
  16990. var pkg = loadpkg(path__default['default'].dirname(x));
  16991. if (pkg && pkg.dir && pkg.pkg && opts.pathFilter) {
  16992. var rfile = path__default['default'].relative(pkg.dir, x);
  16993. var r = opts.pathFilter(pkg.pkg, x, rfile);
  16994. if (r) {
  16995. x = path__default['default'].resolve(pkg.dir, r); // eslint-disable-line no-param-reassign
  16996. }
  16997. }
  16998. if (isFile(x)) {
  16999. return x;
  17000. }
  17001. for (var i = 0; i < extensions.length; i++) {
  17002. var file = x + extensions[i];
  17003. if (isFile(file)) {
  17004. return file;
  17005. }
  17006. }
  17007. }
  17008. function loadpkg(dir) {
  17009. if (dir === '' || dir === '/') return;
  17010. if (process.platform === 'win32' && /^\w:[/\\]*$/.test(dir)) {
  17011. return;
  17012. }
  17013. if (/[/\\]node_modules[/\\]*$/.test(dir)) return;
  17014. var pkgfile = path__default['default'].join(maybeRealpathSync(realpathSync, dir, opts), 'package.json');
  17015. if (!isFile(pkgfile)) {
  17016. return loadpkg(path__default['default'].dirname(dir));
  17017. }
  17018. var body = readFileSync(pkgfile);
  17019. try {
  17020. var pkg = JSON.parse(body);
  17021. } catch (jsonErr) {}
  17022. if (pkg && opts.packageFilter) {
  17023. // v2 will pass pkgfile
  17024. pkg = opts.packageFilter(pkg,
  17025. /*pkgfile,*/
  17026. dir); // eslint-disable-line spaced-comment
  17027. }
  17028. return {
  17029. pkg: pkg,
  17030. dir: dir
  17031. };
  17032. }
  17033. function loadAsDirectorySync(x) {
  17034. var pkgfile = path__default['default'].join(maybeRealpathSync(realpathSync, x, opts), '/package.json');
  17035. if (isFile(pkgfile)) {
  17036. try {
  17037. var body = readFileSync(pkgfile, 'UTF8');
  17038. var pkg = JSON.parse(body);
  17039. } catch (e) {}
  17040. if (pkg && opts.packageFilter) {
  17041. // v2 will pass pkgfile
  17042. pkg = opts.packageFilter(pkg,
  17043. /*pkgfile,*/
  17044. x); // eslint-disable-line spaced-comment
  17045. }
  17046. if (pkg && pkg.main) {
  17047. if (typeof pkg.main !== 'string') {
  17048. var mainError = new TypeError('package “' + pkg.name + '” `main` must be a string');
  17049. mainError.code = 'INVALID_PACKAGE_MAIN';
  17050. throw mainError;
  17051. }
  17052. if (pkg.main === '.' || pkg.main === './') {
  17053. pkg.main = 'index';
  17054. }
  17055. try {
  17056. var m = loadAsFileSync(path__default['default'].resolve(x, pkg.main));
  17057. if (m) return m;
  17058. var n = loadAsDirectorySync(path__default['default'].resolve(x, pkg.main));
  17059. if (n) return n;
  17060. } catch (e) {}
  17061. }
  17062. }
  17063. return loadAsFileSync(path__default['default'].join(x, '/index'));
  17064. }
  17065. function loadNodeModulesSync(x, start) {
  17066. var thunk = function () {
  17067. return getPackageCandidates$1(x, start, opts);
  17068. };
  17069. var dirs = packageIterator ? packageIterator(x, start, thunk, opts) : thunk();
  17070. for (var i = 0; i < dirs.length; i++) {
  17071. var dir = dirs[i];
  17072. if (isDirectory(path__default['default'].dirname(dir))) {
  17073. var m = loadAsFileSync(dir);
  17074. if (m) return m;
  17075. var n = loadAsDirectorySync(dir);
  17076. if (n) return n;
  17077. }
  17078. }
  17079. }
  17080. };
  17081. async.core = core_1;
  17082. async.isCore = isCore;
  17083. async.sync = sync;
  17084. var resolve = async;
  17085. let {
  17086. resolve: resolve$1
  17087. } = require; // In the VS Code and Atom extensions `require` is overridden and `require.resolve` doesn't support the 2nd argument.
  17088. if (resolve$1.length === 1 || process.env.PRETTIER_FALLBACK_RESOLVE) {
  17089. resolve$1 = (id, options) => {
  17090. let basedir;
  17091. if (options && options.paths && options.paths.length === 1) {
  17092. basedir = options.paths[0];
  17093. }
  17094. return resolve.sync(id, {
  17095. basedir
  17096. });
  17097. };
  17098. }
  17099. var resolve_1 = resolve$1;
  17100. var semver$2 = createCommonjsModule(function (module, exports) {
  17101. exports = module.exports = SemVer;
  17102. var debug;
  17103. /* istanbul ignore next */
  17104. if (typeof process === 'object' && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
  17105. debug = function () {
  17106. var args = Array.prototype.slice.call(arguments, 0);
  17107. args.unshift('SEMVER');
  17108. console.log.apply(console, args);
  17109. };
  17110. } else {
  17111. debug = function () {};
  17112. } // Note: this is the semver.org version of the spec that it implements
  17113. // Not necessarily the package version of this code.
  17114. exports.SEMVER_SPEC_VERSION = '2.0.0';
  17115. var MAX_LENGTH = 256;
  17116. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
  17117. /* istanbul ignore next */
  17118. 9007199254740991; // Max safe segment length for coercion.
  17119. var MAX_SAFE_COMPONENT_LENGTH = 16; // The actual regexps go on exports.re
  17120. var re = exports.re = [];
  17121. var src = exports.src = [];
  17122. var R = 0; // The following Regular Expressions can be used for tokenizing,
  17123. // validating, and parsing SemVer version strings.
  17124. // ## Numeric Identifier
  17125. // A single `0`, or a non-zero digit followed by zero or more digits.
  17126. var NUMERICIDENTIFIER = R++;
  17127. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  17128. var NUMERICIDENTIFIERLOOSE = R++;
  17129. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  17130. // Zero or more digits, followed by a letter or hyphen, and then zero or
  17131. // more letters, digits, or hyphens.
  17132. var NONNUMERICIDENTIFIER = R++;
  17133. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  17134. // Three dot-separated numeric identifiers.
  17135. var MAINVERSION = R++;
  17136. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')';
  17137. var MAINVERSIONLOOSE = R++;
  17138. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  17139. // A numeric identifier, or a non-numeric identifier.
  17140. var PRERELEASEIDENTIFIER = R++;
  17141. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')';
  17142. var PRERELEASEIDENTIFIERLOOSE = R++;
  17143. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  17144. // Hyphen, followed by one or more dot-separated pre-release version
  17145. // identifiers.
  17146. var PRERELEASE = R++;
  17147. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  17148. var PRERELEASELOOSE = R++;
  17149. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  17150. // Any combination of digits, letters, or hyphens.
  17151. var BUILDIDENTIFIER = R++;
  17152. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  17153. // Plus sign, followed by one or more period-separated build metadata
  17154. // identifiers.
  17155. var BUILD = R++;
  17156. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  17157. // A main version, followed optionally by a pre-release version and
  17158. // build metadata.
  17159. // Note that the only major, minor, patch, and pre-release sections of
  17160. // the version string are capturing groups. The build metadata is not a
  17161. // capturing group, because it should not ever be used in version
  17162. // comparison.
  17163. var FULL = R++;
  17164. var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?';
  17165. src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  17166. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  17167. // common in the npm registry.
  17168. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?';
  17169. var LOOSE = R++;
  17170. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  17171. var GTLT = R++;
  17172. src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  17173. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  17174. // Only the first item is strictly required.
  17175. var XRANGEIDENTIFIERLOOSE = R++;
  17176. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  17177. var XRANGEIDENTIFIER = R++;
  17178. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  17179. var XRANGEPLAIN = R++;
  17180. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:' + src[PRERELEASE] + ')?' + src[BUILD] + '?' + ')?)?';
  17181. var XRANGEPLAINLOOSE = R++;
  17182. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[PRERELEASELOOSE] + ')?' + src[BUILD] + '?' + ')?)?';
  17183. var XRANGE = R++;
  17184. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  17185. var XRANGELOOSE = R++;
  17186. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Coercion.
  17187. // Extract anything that could conceivably be a part of a valid semver
  17188. var COERCE = R++;
  17189. src[COERCE] = '(?:^|[^\\d])' + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:$|[^\\d])'; // Tilde ranges.
  17190. // Meaning is "reasonably at or greater than"
  17191. var LONETILDE = R++;
  17192. src[LONETILDE] = '(?:~>?)';
  17193. var TILDETRIM = R++;
  17194. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  17195. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  17196. var tildeTrimReplace = '$1~';
  17197. var TILDE = R++;
  17198. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  17199. var TILDELOOSE = R++;
  17200. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  17201. // Meaning is "at least and backwards compatible with"
  17202. var LONECARET = R++;
  17203. src[LONECARET] = '(?:\\^)';
  17204. var CARETTRIM = R++;
  17205. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  17206. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  17207. var caretTrimReplace = '$1^';
  17208. var CARET = R++;
  17209. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  17210. var CARETLOOSE = R++;
  17211. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  17212. var COMPARATORLOOSE = R++;
  17213. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  17214. var COMPARATOR = R++;
  17215. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  17216. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  17217. var COMPARATORTRIM = R++;
  17218. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag
  17219. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  17220. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  17221. // Note that these all use the loose form, because they'll be
  17222. // checked against either the strict or loose comparator form
  17223. // later.
  17224. var HYPHENRANGE = R++;
  17225. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$';
  17226. var HYPHENRANGELOOSE = R++;
  17227. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  17228. var STAR = R++;
  17229. src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  17230. // All are flag-free, unless they were created above with a flag.
  17231. for (var i = 0; i < R; i++) {
  17232. debug(i, src[i]);
  17233. if (!re[i]) {
  17234. re[i] = new RegExp(src[i]);
  17235. }
  17236. }
  17237. exports.parse = parse;
  17238. function parse(version, options) {
  17239. if (!options || typeof options !== 'object') {
  17240. options = {
  17241. loose: !!options,
  17242. includePrerelease: false
  17243. };
  17244. }
  17245. if (version instanceof SemVer) {
  17246. return version;
  17247. }
  17248. if (typeof version !== 'string') {
  17249. return null;
  17250. }
  17251. if (version.length > MAX_LENGTH) {
  17252. return null;
  17253. }
  17254. var r = options.loose ? re[LOOSE] : re[FULL];
  17255. if (!r.test(version)) {
  17256. return null;
  17257. }
  17258. try {
  17259. return new SemVer(version, options);
  17260. } catch (er) {
  17261. return null;
  17262. }
  17263. }
  17264. exports.valid = valid;
  17265. function valid(version, options) {
  17266. var v = parse(version, options);
  17267. return v ? v.version : null;
  17268. }
  17269. exports.clean = clean;
  17270. function clean(version, options) {
  17271. var s = parse(version.trim().replace(/^[=v]+/, ''), options);
  17272. return s ? s.version : null;
  17273. }
  17274. exports.SemVer = SemVer;
  17275. function SemVer(version, options) {
  17276. if (!options || typeof options !== 'object') {
  17277. options = {
  17278. loose: !!options,
  17279. includePrerelease: false
  17280. };
  17281. }
  17282. if (version instanceof SemVer) {
  17283. if (version.loose === options.loose) {
  17284. return version;
  17285. } else {
  17286. version = version.version;
  17287. }
  17288. } else if (typeof version !== 'string') {
  17289. throw new TypeError('Invalid Version: ' + version);
  17290. }
  17291. if (version.length > MAX_LENGTH) {
  17292. throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  17293. }
  17294. if (!(this instanceof SemVer)) {
  17295. return new SemVer(version, options);
  17296. }
  17297. debug('SemVer', version, options);
  17298. this.options = options;
  17299. this.loose = !!options.loose;
  17300. var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL]);
  17301. if (!m) {
  17302. throw new TypeError('Invalid Version: ' + version);
  17303. }
  17304. this.raw = version; // these are actually numbers
  17305. this.major = +m[1];
  17306. this.minor = +m[2];
  17307. this.patch = +m[3];
  17308. if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
  17309. throw new TypeError('Invalid major version');
  17310. }
  17311. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
  17312. throw new TypeError('Invalid minor version');
  17313. }
  17314. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
  17315. throw new TypeError('Invalid patch version');
  17316. } // numberify any prerelease numeric ids
  17317. if (!m[4]) {
  17318. this.prerelease = [];
  17319. } else {
  17320. this.prerelease = m[4].split('.').map(function (id) {
  17321. if (/^[0-9]+$/.test(id)) {
  17322. var num = +id;
  17323. if (num >= 0 && num < MAX_SAFE_INTEGER) {
  17324. return num;
  17325. }
  17326. }
  17327. return id;
  17328. });
  17329. }
  17330. this.build = m[5] ? m[5].split('.') : [];
  17331. this.format();
  17332. }
  17333. SemVer.prototype.format = function () {
  17334. this.version = this.major + '.' + this.minor + '.' + this.patch;
  17335. if (this.prerelease.length) {
  17336. this.version += '-' + this.prerelease.join('.');
  17337. }
  17338. return this.version;
  17339. };
  17340. SemVer.prototype.toString = function () {
  17341. return this.version;
  17342. };
  17343. SemVer.prototype.compare = function (other) {
  17344. debug('SemVer.compare', this.version, this.options, other);
  17345. if (!(other instanceof SemVer)) {
  17346. other = new SemVer(other, this.options);
  17347. }
  17348. return this.compareMain(other) || this.comparePre(other);
  17349. };
  17350. SemVer.prototype.compareMain = function (other) {
  17351. if (!(other instanceof SemVer)) {
  17352. other = new SemVer(other, this.options);
  17353. }
  17354. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  17355. };
  17356. SemVer.prototype.comparePre = function (other) {
  17357. if (!(other instanceof SemVer)) {
  17358. other = new SemVer(other, this.options);
  17359. } // NOT having a prerelease is > having one
  17360. if (this.prerelease.length && !other.prerelease.length) {
  17361. return -1;
  17362. } else if (!this.prerelease.length && other.prerelease.length) {
  17363. return 1;
  17364. } else if (!this.prerelease.length && !other.prerelease.length) {
  17365. return 0;
  17366. }
  17367. var i = 0;
  17368. do {
  17369. var a = this.prerelease[i];
  17370. var b = other.prerelease[i];
  17371. debug('prerelease compare', i, a, b);
  17372. if (a === undefined && b === undefined) {
  17373. return 0;
  17374. } else if (b === undefined) {
  17375. return 1;
  17376. } else if (a === undefined) {
  17377. return -1;
  17378. } else if (a === b) {
  17379. continue;
  17380. } else {
  17381. return compareIdentifiers(a, b);
  17382. }
  17383. } while (++i);
  17384. }; // preminor will bump the version up to the next minor release, and immediately
  17385. // down to pre-release. premajor and prepatch work the same way.
  17386. SemVer.prototype.inc = function (release, identifier) {
  17387. switch (release) {
  17388. case 'premajor':
  17389. this.prerelease.length = 0;
  17390. this.patch = 0;
  17391. this.minor = 0;
  17392. this.major++;
  17393. this.inc('pre', identifier);
  17394. break;
  17395. case 'preminor':
  17396. this.prerelease.length = 0;
  17397. this.patch = 0;
  17398. this.minor++;
  17399. this.inc('pre', identifier);
  17400. break;
  17401. case 'prepatch':
  17402. // If this is already a prerelease, it will bump to the next version
  17403. // drop any prereleases that might already exist, since they are not
  17404. // relevant at this point.
  17405. this.prerelease.length = 0;
  17406. this.inc('patch', identifier);
  17407. this.inc('pre', identifier);
  17408. break;
  17409. // If the input is a non-prerelease version, this acts the same as
  17410. // prepatch.
  17411. case 'prerelease':
  17412. if (this.prerelease.length === 0) {
  17413. this.inc('patch', identifier);
  17414. }
  17415. this.inc('pre', identifier);
  17416. break;
  17417. case 'major':
  17418. // If this is a pre-major version, bump up to the same major version.
  17419. // Otherwise increment major.
  17420. // 1.0.0-5 bumps to 1.0.0
  17421. // 1.1.0 bumps to 2.0.0
  17422. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
  17423. this.major++;
  17424. }
  17425. this.minor = 0;
  17426. this.patch = 0;
  17427. this.prerelease = [];
  17428. break;
  17429. case 'minor':
  17430. // If this is a pre-minor version, bump up to the same minor version.
  17431. // Otherwise increment minor.
  17432. // 1.2.0-5 bumps to 1.2.0
  17433. // 1.2.1 bumps to 1.3.0
  17434. if (this.patch !== 0 || this.prerelease.length === 0) {
  17435. this.minor++;
  17436. }
  17437. this.patch = 0;
  17438. this.prerelease = [];
  17439. break;
  17440. case 'patch':
  17441. // If this is not a pre-release version, it will increment the patch.
  17442. // If it is a pre-release it will bump up to the same patch version.
  17443. // 1.2.0-5 patches to 1.2.0
  17444. // 1.2.0 patches to 1.2.1
  17445. if (this.prerelease.length === 0) {
  17446. this.patch++;
  17447. }
  17448. this.prerelease = [];
  17449. break;
  17450. // This probably shouldn't be used publicly.
  17451. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  17452. case 'pre':
  17453. if (this.prerelease.length === 0) {
  17454. this.prerelease = [0];
  17455. } else {
  17456. var i = this.prerelease.length;
  17457. while (--i >= 0) {
  17458. if (typeof this.prerelease[i] === 'number') {
  17459. this.prerelease[i]++;
  17460. i = -2;
  17461. }
  17462. }
  17463. if (i === -1) {
  17464. // didn't increment anything
  17465. this.prerelease.push(0);
  17466. }
  17467. }
  17468. if (identifier) {
  17469. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  17470. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  17471. if (this.prerelease[0] === identifier) {
  17472. if (isNaN(this.prerelease[1])) {
  17473. this.prerelease = [identifier, 0];
  17474. }
  17475. } else {
  17476. this.prerelease = [identifier, 0];
  17477. }
  17478. }
  17479. break;
  17480. default:
  17481. throw new Error('invalid increment argument: ' + release);
  17482. }
  17483. this.format();
  17484. this.raw = this.version;
  17485. return this;
  17486. };
  17487. exports.inc = inc;
  17488. function inc(version, release, loose, identifier) {
  17489. if (typeof loose === 'string') {
  17490. identifier = loose;
  17491. loose = undefined;
  17492. }
  17493. try {
  17494. return new SemVer(version, loose).inc(release, identifier).version;
  17495. } catch (er) {
  17496. return null;
  17497. }
  17498. }
  17499. exports.diff = diff;
  17500. function diff(version1, version2) {
  17501. if (eq(version1, version2)) {
  17502. return null;
  17503. } else {
  17504. var v1 = parse(version1);
  17505. var v2 = parse(version2);
  17506. var prefix = '';
  17507. if (v1.prerelease.length || v2.prerelease.length) {
  17508. prefix = 'pre';
  17509. var defaultResult = 'prerelease';
  17510. }
  17511. for (var key in v1) {
  17512. if (key === 'major' || key === 'minor' || key === 'patch') {
  17513. if (v1[key] !== v2[key]) {
  17514. return prefix + key;
  17515. }
  17516. }
  17517. }
  17518. return defaultResult; // may be undefined
  17519. }
  17520. }
  17521. exports.compareIdentifiers = compareIdentifiers;
  17522. var numeric = /^[0-9]+$/;
  17523. function compareIdentifiers(a, b) {
  17524. var anum = numeric.test(a);
  17525. var bnum = numeric.test(b);
  17526. if (anum && bnum) {
  17527. a = +a;
  17528. b = +b;
  17529. }
  17530. return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
  17531. }
  17532. exports.rcompareIdentifiers = rcompareIdentifiers;
  17533. function rcompareIdentifiers(a, b) {
  17534. return compareIdentifiers(b, a);
  17535. }
  17536. exports.major = major;
  17537. function major(a, loose) {
  17538. return new SemVer(a, loose).major;
  17539. }
  17540. exports.minor = minor;
  17541. function minor(a, loose) {
  17542. return new SemVer(a, loose).minor;
  17543. }
  17544. exports.patch = patch;
  17545. function patch(a, loose) {
  17546. return new SemVer(a, loose).patch;
  17547. }
  17548. exports.compare = compare;
  17549. function compare(a, b, loose) {
  17550. return new SemVer(a, loose).compare(new SemVer(b, loose));
  17551. }
  17552. exports.compareLoose = compareLoose;
  17553. function compareLoose(a, b) {
  17554. return compare(a, b, true);
  17555. }
  17556. exports.rcompare = rcompare;
  17557. function rcompare(a, b, loose) {
  17558. return compare(b, a, loose);
  17559. }
  17560. exports.sort = sort;
  17561. function sort(list, loose) {
  17562. return list.sort(function (a, b) {
  17563. return exports.compare(a, b, loose);
  17564. });
  17565. }
  17566. exports.rsort = rsort;
  17567. function rsort(list, loose) {
  17568. return list.sort(function (a, b) {
  17569. return exports.rcompare(a, b, loose);
  17570. });
  17571. }
  17572. exports.gt = gt;
  17573. function gt(a, b, loose) {
  17574. return compare(a, b, loose) > 0;
  17575. }
  17576. exports.lt = lt;
  17577. function lt(a, b, loose) {
  17578. return compare(a, b, loose) < 0;
  17579. }
  17580. exports.eq = eq;
  17581. function eq(a, b, loose) {
  17582. return compare(a, b, loose) === 0;
  17583. }
  17584. exports.neq = neq;
  17585. function neq(a, b, loose) {
  17586. return compare(a, b, loose) !== 0;
  17587. }
  17588. exports.gte = gte;
  17589. function gte(a, b, loose) {
  17590. return compare(a, b, loose) >= 0;
  17591. }
  17592. exports.lte = lte;
  17593. function lte(a, b, loose) {
  17594. return compare(a, b, loose) <= 0;
  17595. }
  17596. exports.cmp = cmp;
  17597. function cmp(a, op, b, loose) {
  17598. switch (op) {
  17599. case '===':
  17600. if (typeof a === 'object') a = a.version;
  17601. if (typeof b === 'object') b = b.version;
  17602. return a === b;
  17603. case '!==':
  17604. if (typeof a === 'object') a = a.version;
  17605. if (typeof b === 'object') b = b.version;
  17606. return a !== b;
  17607. case '':
  17608. case '=':
  17609. case '==':
  17610. return eq(a, b, loose);
  17611. case '!=':
  17612. return neq(a, b, loose);
  17613. case '>':
  17614. return gt(a, b, loose);
  17615. case '>=':
  17616. return gte(a, b, loose);
  17617. case '<':
  17618. return lt(a, b, loose);
  17619. case '<=':
  17620. return lte(a, b, loose);
  17621. default:
  17622. throw new TypeError('Invalid operator: ' + op);
  17623. }
  17624. }
  17625. exports.Comparator = Comparator;
  17626. function Comparator(comp, options) {
  17627. if (!options || typeof options !== 'object') {
  17628. options = {
  17629. loose: !!options,
  17630. includePrerelease: false
  17631. };
  17632. }
  17633. if (comp instanceof Comparator) {
  17634. if (comp.loose === !!options.loose) {
  17635. return comp;
  17636. } else {
  17637. comp = comp.value;
  17638. }
  17639. }
  17640. if (!(this instanceof Comparator)) {
  17641. return new Comparator(comp, options);
  17642. }
  17643. debug('comparator', comp, options);
  17644. this.options = options;
  17645. this.loose = !!options.loose;
  17646. this.parse(comp);
  17647. if (this.semver === ANY) {
  17648. this.value = '';
  17649. } else {
  17650. this.value = this.operator + this.semver.version;
  17651. }
  17652. debug('comp', this);
  17653. }
  17654. var ANY = {};
  17655. Comparator.prototype.parse = function (comp) {
  17656. var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  17657. var m = comp.match(r);
  17658. if (!m) {
  17659. throw new TypeError('Invalid comparator: ' + comp);
  17660. }
  17661. this.operator = m[1];
  17662. if (this.operator === '=') {
  17663. this.operator = '';
  17664. } // if it literally is just '>' or '' then allow anything.
  17665. if (!m[2]) {
  17666. this.semver = ANY;
  17667. } else {
  17668. this.semver = new SemVer(m[2], this.options.loose);
  17669. }
  17670. };
  17671. Comparator.prototype.toString = function () {
  17672. return this.value;
  17673. };
  17674. Comparator.prototype.test = function (version) {
  17675. debug('Comparator.test', version, this.options.loose);
  17676. if (this.semver === ANY) {
  17677. return true;
  17678. }
  17679. if (typeof version === 'string') {
  17680. version = new SemVer(version, this.options);
  17681. }
  17682. return cmp(version, this.operator, this.semver, this.options);
  17683. };
  17684. Comparator.prototype.intersects = function (comp, options) {
  17685. if (!(comp instanceof Comparator)) {
  17686. throw new TypeError('a Comparator is required');
  17687. }
  17688. if (!options || typeof options !== 'object') {
  17689. options = {
  17690. loose: !!options,
  17691. includePrerelease: false
  17692. };
  17693. }
  17694. var rangeTmp;
  17695. if (this.operator === '') {
  17696. rangeTmp = new Range(comp.value, options);
  17697. return satisfies(this.value, rangeTmp, options);
  17698. } else if (comp.operator === '') {
  17699. rangeTmp = new Range(this.value, options);
  17700. return satisfies(comp.semver, rangeTmp, options);
  17701. }
  17702. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  17703. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  17704. var sameSemVer = this.semver.version === comp.semver.version;
  17705. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  17706. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, options) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  17707. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, options) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  17708. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  17709. };
  17710. exports.Range = Range;
  17711. function Range(range, options) {
  17712. if (!options || typeof options !== 'object') {
  17713. options = {
  17714. loose: !!options,
  17715. includePrerelease: false
  17716. };
  17717. }
  17718. if (range instanceof Range) {
  17719. if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
  17720. return range;
  17721. } else {
  17722. return new Range(range.raw, options);
  17723. }
  17724. }
  17725. if (range instanceof Comparator) {
  17726. return new Range(range.value, options);
  17727. }
  17728. if (!(this instanceof Range)) {
  17729. return new Range(range, options);
  17730. }
  17731. this.options = options;
  17732. this.loose = !!options.loose;
  17733. this.includePrerelease = !!options.includePrerelease; // First, split based on boolean or ||
  17734. this.raw = range;
  17735. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  17736. return this.parseRange(range.trim());
  17737. }, this).filter(function (c) {
  17738. // throw out any that are not relevant for whatever reason
  17739. return c.length;
  17740. });
  17741. if (!this.set.length) {
  17742. throw new TypeError('Invalid SemVer Range: ' + range);
  17743. }
  17744. this.format();
  17745. }
  17746. Range.prototype.format = function () {
  17747. this.range = this.set.map(function (comps) {
  17748. return comps.join(' ').trim();
  17749. }).join('||').trim();
  17750. return this.range;
  17751. };
  17752. Range.prototype.toString = function () {
  17753. return this.range;
  17754. };
  17755. Range.prototype.parseRange = function (range) {
  17756. var loose = this.options.loose;
  17757. range = range.trim(); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  17758. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  17759. range = range.replace(hr, hyphenReplace);
  17760. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  17761. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  17762. debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  17763. range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  17764. range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces
  17765. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  17766. // ready to be split into comparators.
  17767. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  17768. var set = range.split(' ').map(function (comp) {
  17769. return parseComparator(comp, this.options);
  17770. }, this).join(' ').split(/\s+/);
  17771. if (this.options.loose) {
  17772. // in loose mode, throw out any that are not valid comparators
  17773. set = set.filter(function (comp) {
  17774. return !!comp.match(compRe);
  17775. });
  17776. }
  17777. set = set.map(function (comp) {
  17778. return new Comparator(comp, this.options);
  17779. }, this);
  17780. return set;
  17781. };
  17782. Range.prototype.intersects = function (range, options) {
  17783. if (!(range instanceof Range)) {
  17784. throw new TypeError('a Range is required');
  17785. }
  17786. return this.set.some(function (thisComparators) {
  17787. return thisComparators.every(function (thisComparator) {
  17788. return range.set.some(function (rangeComparators) {
  17789. return rangeComparators.every(function (rangeComparator) {
  17790. return thisComparator.intersects(rangeComparator, options);
  17791. });
  17792. });
  17793. });
  17794. });
  17795. }; // Mostly just for testing and legacy API reasons
  17796. exports.toComparators = toComparators;
  17797. function toComparators(range, options) {
  17798. return new Range(range, options).set.map(function (comp) {
  17799. return comp.map(function (c) {
  17800. return c.value;
  17801. }).join(' ').trim().split(' ');
  17802. });
  17803. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  17804. // already replaced the hyphen ranges
  17805. // turn into a set of JUST comparators.
  17806. function parseComparator(comp, options) {
  17807. debug('comp', comp, options);
  17808. comp = replaceCarets(comp, options);
  17809. debug('caret', comp);
  17810. comp = replaceTildes(comp, options);
  17811. debug('tildes', comp);
  17812. comp = replaceXRanges(comp, options);
  17813. debug('xrange', comp);
  17814. comp = replaceStars(comp, options);
  17815. debug('stars', comp);
  17816. return comp;
  17817. }
  17818. function isX(id) {
  17819. return !id || id.toLowerCase() === 'x' || id === '*';
  17820. } // ~, ~> --> * (any, kinda silly)
  17821. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  17822. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  17823. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  17824. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  17825. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  17826. function replaceTildes(comp, options) {
  17827. return comp.trim().split(/\s+/).map(function (comp) {
  17828. return replaceTilde(comp, options);
  17829. }).join(' ');
  17830. }
  17831. function replaceTilde(comp, options) {
  17832. var r = options.loose ? re[TILDELOOSE] : re[TILDE];
  17833. return comp.replace(r, function (_, M, m, p, pr) {
  17834. debug('tilde', comp, _, M, m, p, pr);
  17835. var ret;
  17836. if (isX(M)) {
  17837. ret = '';
  17838. } else if (isX(m)) {
  17839. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  17840. } else if (isX(p)) {
  17841. // ~1.2 == >=1.2.0 <1.3.0
  17842. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  17843. } else if (pr) {
  17844. debug('replaceTilde pr', pr);
  17845. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + (+m + 1) + '.0';
  17846. } else {
  17847. // ~1.2.3 == >=1.2.3 <1.3.0
  17848. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  17849. }
  17850. debug('tilde return', ret);
  17851. return ret;
  17852. });
  17853. } // ^ --> * (any, kinda silly)
  17854. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  17855. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  17856. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  17857. // ^1.2.3 --> >=1.2.3 <2.0.0
  17858. // ^1.2.0 --> >=1.2.0 <2.0.0
  17859. function replaceCarets(comp, options) {
  17860. return comp.trim().split(/\s+/).map(function (comp) {
  17861. return replaceCaret(comp, options);
  17862. }).join(' ');
  17863. }
  17864. function replaceCaret(comp, options) {
  17865. debug('caret', comp, options);
  17866. var r = options.loose ? re[CARETLOOSE] : re[CARET];
  17867. return comp.replace(r, function (_, M, m, p, pr) {
  17868. debug('caret', comp, _, M, m, p, pr);
  17869. var ret;
  17870. if (isX(M)) {
  17871. ret = '';
  17872. } else if (isX(m)) {
  17873. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  17874. } else if (isX(p)) {
  17875. if (M === '0') {
  17876. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  17877. } else {
  17878. ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  17879. }
  17880. } else if (pr) {
  17881. debug('replaceCaret pr', pr);
  17882. if (M === '0') {
  17883. if (m === '0') {
  17884. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + m + '.' + (+p + 1);
  17885. } else {
  17886. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + (+m + 1) + '.0';
  17887. }
  17888. } else {
  17889. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + (+M + 1) + '.0.0';
  17890. }
  17891. } else {
  17892. debug('no pr');
  17893. if (M === '0') {
  17894. if (m === '0') {
  17895. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);
  17896. } else {
  17897. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  17898. }
  17899. } else {
  17900. ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  17901. }
  17902. }
  17903. debug('caret return', ret);
  17904. return ret;
  17905. });
  17906. }
  17907. function replaceXRanges(comp, options) {
  17908. debug('replaceXRanges', comp, options);
  17909. return comp.split(/\s+/).map(function (comp) {
  17910. return replaceXRange(comp, options);
  17911. }).join(' ');
  17912. }
  17913. function replaceXRange(comp, options) {
  17914. comp = comp.trim();
  17915. var r = options.loose ? re[XRANGELOOSE] : re[XRANGE];
  17916. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  17917. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  17918. var xM = isX(M);
  17919. var xm = xM || isX(m);
  17920. var xp = xm || isX(p);
  17921. var anyX = xp;
  17922. if (gtlt === '=' && anyX) {
  17923. gtlt = '';
  17924. }
  17925. if (xM) {
  17926. if (gtlt === '>' || gtlt === '<') {
  17927. // nothing is allowed
  17928. ret = '<0.0.0';
  17929. } else {
  17930. // nothing is forbidden
  17931. ret = '*';
  17932. }
  17933. } else if (gtlt && anyX) {
  17934. // we know patch is an x, because we have any x at all.
  17935. // replace X with 0
  17936. if (xm) {
  17937. m = 0;
  17938. }
  17939. p = 0;
  17940. if (gtlt === '>') {
  17941. // >1 => >=2.0.0
  17942. // >1.2 => >=1.3.0
  17943. // >1.2.3 => >= 1.2.4
  17944. gtlt = '>=';
  17945. if (xm) {
  17946. M = +M + 1;
  17947. m = 0;
  17948. p = 0;
  17949. } else {
  17950. m = +m + 1;
  17951. p = 0;
  17952. }
  17953. } else if (gtlt === '<=') {
  17954. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  17955. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  17956. gtlt = '<';
  17957. if (xm) {
  17958. M = +M + 1;
  17959. } else {
  17960. m = +m + 1;
  17961. }
  17962. }
  17963. ret = gtlt + M + '.' + m + '.' + p;
  17964. } else if (xm) {
  17965. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  17966. } else if (xp) {
  17967. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  17968. }
  17969. debug('xRange return', ret);
  17970. return ret;
  17971. });
  17972. } // Because * is AND-ed with everything else in the comparator,
  17973. // and '' means "any version", just remove the *s entirely.
  17974. function replaceStars(comp, options) {
  17975. debug('replaceStars', comp, options); // Looseness is ignored here. star is always as loose as it gets!
  17976. return comp.trim().replace(re[STAR], '');
  17977. } // This function is passed to string.replace(re[HYPHENRANGE])
  17978. // M, m, patch, prerelease, build
  17979. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  17980. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  17981. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  17982. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  17983. if (isX(fM)) {
  17984. from = '';
  17985. } else if (isX(fm)) {
  17986. from = '>=' + fM + '.0.0';
  17987. } else if (isX(fp)) {
  17988. from = '>=' + fM + '.' + fm + '.0';
  17989. } else {
  17990. from = '>=' + from;
  17991. }
  17992. if (isX(tM)) {
  17993. to = '';
  17994. } else if (isX(tm)) {
  17995. to = '<' + (+tM + 1) + '.0.0';
  17996. } else if (isX(tp)) {
  17997. to = '<' + tM + '.' + (+tm + 1) + '.0';
  17998. } else if (tpr) {
  17999. to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
  18000. } else {
  18001. to = '<=' + to;
  18002. }
  18003. return (from + ' ' + to).trim();
  18004. } // if ANY of the sets match ALL of its comparators, then pass
  18005. Range.prototype.test = function (version) {
  18006. if (!version) {
  18007. return false;
  18008. }
  18009. if (typeof version === 'string') {
  18010. version = new SemVer(version, this.options);
  18011. }
  18012. for (var i = 0; i < this.set.length; i++) {
  18013. if (testSet(this.set[i], version, this.options)) {
  18014. return true;
  18015. }
  18016. }
  18017. return false;
  18018. };
  18019. function testSet(set, version, options) {
  18020. for (var i = 0; i < set.length; i++) {
  18021. if (!set[i].test(version)) {
  18022. return false;
  18023. }
  18024. }
  18025. if (version.prerelease.length && !options.includePrerelease) {
  18026. // Find the set of versions that are allowed to have prereleases
  18027. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  18028. // That should allow `1.2.3-pr.2` to pass.
  18029. // However, `1.2.4-alpha.notready` should NOT be allowed,
  18030. // even though it's within the range set by the comparators.
  18031. for (i = 0; i < set.length; i++) {
  18032. debug(set[i].semver);
  18033. if (set[i].semver === ANY) {
  18034. continue;
  18035. }
  18036. if (set[i].semver.prerelease.length > 0) {
  18037. var allowed = set[i].semver;
  18038. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) {
  18039. return true;
  18040. }
  18041. }
  18042. } // Version has a -pre, but it's not one of the ones we like.
  18043. return false;
  18044. }
  18045. return true;
  18046. }
  18047. exports.satisfies = satisfies;
  18048. function satisfies(version, range, options) {
  18049. try {
  18050. range = new Range(range, options);
  18051. } catch (er) {
  18052. return false;
  18053. }
  18054. return range.test(version);
  18055. }
  18056. exports.maxSatisfying = maxSatisfying;
  18057. function maxSatisfying(versions, range, options) {
  18058. var max = null;
  18059. var maxSV = null;
  18060. try {
  18061. var rangeObj = new Range(range, options);
  18062. } catch (er) {
  18063. return null;
  18064. }
  18065. versions.forEach(function (v) {
  18066. if (rangeObj.test(v)) {
  18067. // satisfies(v, range, options)
  18068. if (!max || maxSV.compare(v) === -1) {
  18069. // compare(max, v, true)
  18070. max = v;
  18071. maxSV = new SemVer(max, options);
  18072. }
  18073. }
  18074. });
  18075. return max;
  18076. }
  18077. exports.minSatisfying = minSatisfying;
  18078. function minSatisfying(versions, range, options) {
  18079. var min = null;
  18080. var minSV = null;
  18081. try {
  18082. var rangeObj = new Range(range, options);
  18083. } catch (er) {
  18084. return null;
  18085. }
  18086. versions.forEach(function (v) {
  18087. if (rangeObj.test(v)) {
  18088. // satisfies(v, range, options)
  18089. if (!min || minSV.compare(v) === 1) {
  18090. // compare(min, v, true)
  18091. min = v;
  18092. minSV = new SemVer(min, options);
  18093. }
  18094. }
  18095. });
  18096. return min;
  18097. }
  18098. exports.minVersion = minVersion;
  18099. function minVersion(range, loose) {
  18100. range = new Range(range, loose);
  18101. var minver = new SemVer('0.0.0');
  18102. if (range.test(minver)) {
  18103. return minver;
  18104. }
  18105. minver = new SemVer('0.0.0-0');
  18106. if (range.test(minver)) {
  18107. return minver;
  18108. }
  18109. minver = null;
  18110. for (var i = 0; i < range.set.length; ++i) {
  18111. var comparators = range.set[i];
  18112. comparators.forEach(function (comparator) {
  18113. // Clone to avoid manipulating the comparator's semver object.
  18114. var compver = new SemVer(comparator.semver.version);
  18115. switch (comparator.operator) {
  18116. case '>':
  18117. if (compver.prerelease.length === 0) {
  18118. compver.patch++;
  18119. } else {
  18120. compver.prerelease.push(0);
  18121. }
  18122. compver.raw = compver.format();
  18123. /* fallthrough */
  18124. case '':
  18125. case '>=':
  18126. if (!minver || gt(minver, compver)) {
  18127. minver = compver;
  18128. }
  18129. break;
  18130. case '<':
  18131. case '<=':
  18132. /* Ignore maximum versions */
  18133. break;
  18134. /* istanbul ignore next */
  18135. default:
  18136. throw new Error('Unexpected operation: ' + comparator.operator);
  18137. }
  18138. });
  18139. }
  18140. if (minver && range.test(minver)) {
  18141. return minver;
  18142. }
  18143. return null;
  18144. }
  18145. exports.validRange = validRange;
  18146. function validRange(range, options) {
  18147. try {
  18148. // Return '*' instead of '' so that truthiness works.
  18149. // This will throw if it's invalid anyway
  18150. return new Range(range, options).range || '*';
  18151. } catch (er) {
  18152. return null;
  18153. }
  18154. } // Determine if version is less than all the versions possible in the range
  18155. exports.ltr = ltr;
  18156. function ltr(version, range, options) {
  18157. return outside(version, range, '<', options);
  18158. } // Determine if version is greater than all the versions possible in the range.
  18159. exports.gtr = gtr;
  18160. function gtr(version, range, options) {
  18161. return outside(version, range, '>', options);
  18162. }
  18163. exports.outside = outside;
  18164. function outside(version, range, hilo, options) {
  18165. version = new SemVer(version, options);
  18166. range = new Range(range, options);
  18167. var gtfn, ltefn, ltfn, comp, ecomp;
  18168. switch (hilo) {
  18169. case '>':
  18170. gtfn = gt;
  18171. ltefn = lte;
  18172. ltfn = lt;
  18173. comp = '>';
  18174. ecomp = '>=';
  18175. break;
  18176. case '<':
  18177. gtfn = lt;
  18178. ltefn = gte;
  18179. ltfn = gt;
  18180. comp = '<';
  18181. ecomp = '<=';
  18182. break;
  18183. default:
  18184. throw new TypeError('Must provide a hilo val of "<" or ">"');
  18185. } // If it satisifes the range it is not outside
  18186. if (satisfies(version, range, options)) {
  18187. return false;
  18188. } // From now on, variable terms are as if we're in "gtr" mode.
  18189. // but note that everything is flipped for the "ltr" function.
  18190. for (var i = 0; i < range.set.length; ++i) {
  18191. var comparators = range.set[i];
  18192. var high = null;
  18193. var low = null;
  18194. comparators.forEach(function (comparator) {
  18195. if (comparator.semver === ANY) {
  18196. comparator = new Comparator('>=0.0.0');
  18197. }
  18198. high = high || comparator;
  18199. low = low || comparator;
  18200. if (gtfn(comparator.semver, high.semver, options)) {
  18201. high = comparator;
  18202. } else if (ltfn(comparator.semver, low.semver, options)) {
  18203. low = comparator;
  18204. }
  18205. }); // If the edge version comparator has a operator then our version
  18206. // isn't outside it
  18207. if (high.operator === comp || high.operator === ecomp) {
  18208. return false;
  18209. } // If the lowest version comparator has an operator and our version
  18210. // is less than it then it isn't higher than the range
  18211. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  18212. return false;
  18213. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  18214. return false;
  18215. }
  18216. }
  18217. return true;
  18218. }
  18219. exports.prerelease = prerelease;
  18220. function prerelease(version, options) {
  18221. var parsed = parse(version, options);
  18222. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  18223. }
  18224. exports.intersects = intersects;
  18225. function intersects(r1, r2, options) {
  18226. r1 = new Range(r1, options);
  18227. r2 = new Range(r2, options);
  18228. return r1.intersects(r2);
  18229. }
  18230. exports.coerce = coerce;
  18231. function coerce(version) {
  18232. if (version instanceof SemVer) {
  18233. return version;
  18234. }
  18235. if (typeof version !== 'string') {
  18236. return null;
  18237. }
  18238. var match = version.match(re[COERCE]);
  18239. if (match == null) {
  18240. return null;
  18241. }
  18242. return parse(match[1] + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
  18243. }
  18244. });
  18245. var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
  18246. var pseudomap = PseudoMap;
  18247. function PseudoMap(set) {
  18248. if (!(this instanceof PseudoMap)) // whyyyyyyy
  18249. throw new TypeError("Constructor PseudoMap requires 'new'");
  18250. this.clear();
  18251. if (set) {
  18252. if (set instanceof PseudoMap || typeof Map === 'function' && set instanceof Map) set.forEach(function (value, key) {
  18253. this.set(key, value);
  18254. }, this);else if (Array.isArray(set)) set.forEach(function (kv) {
  18255. this.set(kv[0], kv[1]);
  18256. }, this);else throw new TypeError('invalid argument');
  18257. }
  18258. }
  18259. PseudoMap.prototype.forEach = function (fn, thisp) {
  18260. thisp = thisp || this;
  18261. Object.keys(this._data).forEach(function (k) {
  18262. if (k !== 'size') fn.call(thisp, this._data[k].value, this._data[k].key);
  18263. }, this);
  18264. };
  18265. PseudoMap.prototype.has = function (k) {
  18266. return !!find(this._data, k);
  18267. };
  18268. PseudoMap.prototype.get = function (k) {
  18269. var res = find(this._data, k);
  18270. return res && res.value;
  18271. };
  18272. PseudoMap.prototype.set = function (k, v) {
  18273. set(this._data, k, v);
  18274. };
  18275. PseudoMap.prototype.delete = function (k) {
  18276. var res = find(this._data, k);
  18277. if (res) {
  18278. delete this._data[res._index];
  18279. this._data.size--;
  18280. }
  18281. };
  18282. PseudoMap.prototype.clear = function () {
  18283. var data = Object.create(null);
  18284. data.size = 0;
  18285. Object.defineProperty(this, '_data', {
  18286. value: data,
  18287. enumerable: false,
  18288. configurable: true,
  18289. writable: false
  18290. });
  18291. };
  18292. Object.defineProperty(PseudoMap.prototype, 'size', {
  18293. get: function () {
  18294. return this._data.size;
  18295. },
  18296. set: function (n) {},
  18297. enumerable: true,
  18298. configurable: true
  18299. });
  18300. PseudoMap.prototype.values = PseudoMap.prototype.keys = PseudoMap.prototype.entries = function () {
  18301. throw new Error('iterators are not implemented in this version');
  18302. }; // Either identical, or both NaN
  18303. function same(a, b) {
  18304. return a === b || a !== a && b !== b;
  18305. }
  18306. function Entry(k, v, i) {
  18307. this.key = k;
  18308. this.value = v;
  18309. this._index = i;
  18310. }
  18311. function find(data, k) {
  18312. for (var i = 0, s = '_' + k, key = s; hasOwnProperty$3.call(data, key); key = s + i++) {
  18313. if (same(data[key].key, k)) return data[key];
  18314. }
  18315. }
  18316. function set(data, k, v) {
  18317. for (var i = 0, s = '_' + k, key = s; hasOwnProperty$3.call(data, key); key = s + i++) {
  18318. if (same(data[key].key, k)) {
  18319. data[key].value = v;
  18320. return;
  18321. }
  18322. }
  18323. data.size++;
  18324. data[key] = new Entry(k, v, key);
  18325. }
  18326. var map = createCommonjsModule(function (module) {
  18327. if (process.env.npm_package_name === 'pseudomap' && process.env.npm_lifecycle_script === 'test') process.env.TEST_PSEUDOMAP = 'true';
  18328. if (typeof Map === 'function' && !process.env.TEST_PSEUDOMAP) {
  18329. module.exports = Map;
  18330. } else {
  18331. module.exports = pseudomap;
  18332. }
  18333. });
  18334. var yallist = Yallist;
  18335. Yallist.Node = Node;
  18336. Yallist.create = Yallist;
  18337. function Yallist(list) {
  18338. var self = this;
  18339. if (!(self instanceof Yallist)) {
  18340. self = new Yallist();
  18341. }
  18342. self.tail = null;
  18343. self.head = null;
  18344. self.length = 0;
  18345. if (list && typeof list.forEach === 'function') {
  18346. list.forEach(function (item) {
  18347. self.push(item);
  18348. });
  18349. } else if (arguments.length > 0) {
  18350. for (var i = 0, l = arguments.length; i < l; i++) {
  18351. self.push(arguments[i]);
  18352. }
  18353. }
  18354. return self;
  18355. }
  18356. Yallist.prototype.removeNode = function (node) {
  18357. if (node.list !== this) {
  18358. throw new Error('removing node which does not belong to this list');
  18359. }
  18360. var next = node.next;
  18361. var prev = node.prev;
  18362. if (next) {
  18363. next.prev = prev;
  18364. }
  18365. if (prev) {
  18366. prev.next = next;
  18367. }
  18368. if (node === this.head) {
  18369. this.head = next;
  18370. }
  18371. if (node === this.tail) {
  18372. this.tail = prev;
  18373. }
  18374. node.list.length--;
  18375. node.next = null;
  18376. node.prev = null;
  18377. node.list = null;
  18378. };
  18379. Yallist.prototype.unshiftNode = function (node) {
  18380. if (node === this.head) {
  18381. return;
  18382. }
  18383. if (node.list) {
  18384. node.list.removeNode(node);
  18385. }
  18386. var head = this.head;
  18387. node.list = this;
  18388. node.next = head;
  18389. if (head) {
  18390. head.prev = node;
  18391. }
  18392. this.head = node;
  18393. if (!this.tail) {
  18394. this.tail = node;
  18395. }
  18396. this.length++;
  18397. };
  18398. Yallist.prototype.pushNode = function (node) {
  18399. if (node === this.tail) {
  18400. return;
  18401. }
  18402. if (node.list) {
  18403. node.list.removeNode(node);
  18404. }
  18405. var tail = this.tail;
  18406. node.list = this;
  18407. node.prev = tail;
  18408. if (tail) {
  18409. tail.next = node;
  18410. }
  18411. this.tail = node;
  18412. if (!this.head) {
  18413. this.head = node;
  18414. }
  18415. this.length++;
  18416. };
  18417. Yallist.prototype.push = function () {
  18418. for (var i = 0, l = arguments.length; i < l; i++) {
  18419. push$1(this, arguments[i]);
  18420. }
  18421. return this.length;
  18422. };
  18423. Yallist.prototype.unshift = function () {
  18424. for (var i = 0, l = arguments.length; i < l; i++) {
  18425. unshift(this, arguments[i]);
  18426. }
  18427. return this.length;
  18428. };
  18429. Yallist.prototype.pop = function () {
  18430. if (!this.tail) {
  18431. return undefined;
  18432. }
  18433. var res = this.tail.value;
  18434. this.tail = this.tail.prev;
  18435. if (this.tail) {
  18436. this.tail.next = null;
  18437. } else {
  18438. this.head = null;
  18439. }
  18440. this.length--;
  18441. return res;
  18442. };
  18443. Yallist.prototype.shift = function () {
  18444. if (!this.head) {
  18445. return undefined;
  18446. }
  18447. var res = this.head.value;
  18448. this.head = this.head.next;
  18449. if (this.head) {
  18450. this.head.prev = null;
  18451. } else {
  18452. this.tail = null;
  18453. }
  18454. this.length--;
  18455. return res;
  18456. };
  18457. Yallist.prototype.forEach = function (fn, thisp) {
  18458. thisp = thisp || this;
  18459. for (var walker = this.head, i = 0; walker !== null; i++) {
  18460. fn.call(thisp, walker.value, i, this);
  18461. walker = walker.next;
  18462. }
  18463. };
  18464. Yallist.prototype.forEachReverse = function (fn, thisp) {
  18465. thisp = thisp || this;
  18466. for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
  18467. fn.call(thisp, walker.value, i, this);
  18468. walker = walker.prev;
  18469. }
  18470. };
  18471. Yallist.prototype.get = function (n) {
  18472. for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
  18473. // abort out of the list early if we hit a cycle
  18474. walker = walker.next;
  18475. }
  18476. if (i === n && walker !== null) {
  18477. return walker.value;
  18478. }
  18479. };
  18480. Yallist.prototype.getReverse = function (n) {
  18481. for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
  18482. // abort out of the list early if we hit a cycle
  18483. walker = walker.prev;
  18484. }
  18485. if (i === n && walker !== null) {
  18486. return walker.value;
  18487. }
  18488. };
  18489. Yallist.prototype.map = function (fn, thisp) {
  18490. thisp = thisp || this;
  18491. var res = new Yallist();
  18492. for (var walker = this.head; walker !== null;) {
  18493. res.push(fn.call(thisp, walker.value, this));
  18494. walker = walker.next;
  18495. }
  18496. return res;
  18497. };
  18498. Yallist.prototype.mapReverse = function (fn, thisp) {
  18499. thisp = thisp || this;
  18500. var res = new Yallist();
  18501. for (var walker = this.tail; walker !== null;) {
  18502. res.push(fn.call(thisp, walker.value, this));
  18503. walker = walker.prev;
  18504. }
  18505. return res;
  18506. };
  18507. Yallist.prototype.reduce = function (fn, initial) {
  18508. var acc;
  18509. var walker = this.head;
  18510. if (arguments.length > 1) {
  18511. acc = initial;
  18512. } else if (this.head) {
  18513. walker = this.head.next;
  18514. acc = this.head.value;
  18515. } else {
  18516. throw new TypeError('Reduce of empty list with no initial value');
  18517. }
  18518. for (var i = 0; walker !== null; i++) {
  18519. acc = fn(acc, walker.value, i);
  18520. walker = walker.next;
  18521. }
  18522. return acc;
  18523. };
  18524. Yallist.prototype.reduceReverse = function (fn, initial) {
  18525. var acc;
  18526. var walker = this.tail;
  18527. if (arguments.length > 1) {
  18528. acc = initial;
  18529. } else if (this.tail) {
  18530. walker = this.tail.prev;
  18531. acc = this.tail.value;
  18532. } else {
  18533. throw new TypeError('Reduce of empty list with no initial value');
  18534. }
  18535. for (var i = this.length - 1; walker !== null; i--) {
  18536. acc = fn(acc, walker.value, i);
  18537. walker = walker.prev;
  18538. }
  18539. return acc;
  18540. };
  18541. Yallist.prototype.toArray = function () {
  18542. var arr = new Array(this.length);
  18543. for (var i = 0, walker = this.head; walker !== null; i++) {
  18544. arr[i] = walker.value;
  18545. walker = walker.next;
  18546. }
  18547. return arr;
  18548. };
  18549. Yallist.prototype.toArrayReverse = function () {
  18550. var arr = new Array(this.length);
  18551. for (var i = 0, walker = this.tail; walker !== null; i++) {
  18552. arr[i] = walker.value;
  18553. walker = walker.prev;
  18554. }
  18555. return arr;
  18556. };
  18557. Yallist.prototype.slice = function (from, to) {
  18558. to = to || this.length;
  18559. if (to < 0) {
  18560. to += this.length;
  18561. }
  18562. from = from || 0;
  18563. if (from < 0) {
  18564. from += this.length;
  18565. }
  18566. var ret = new Yallist();
  18567. if (to < from || to < 0) {
  18568. return ret;
  18569. }
  18570. if (from < 0) {
  18571. from = 0;
  18572. }
  18573. if (to > this.length) {
  18574. to = this.length;
  18575. }
  18576. for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
  18577. walker = walker.next;
  18578. }
  18579. for (; walker !== null && i < to; i++, walker = walker.next) {
  18580. ret.push(walker.value);
  18581. }
  18582. return ret;
  18583. };
  18584. Yallist.prototype.sliceReverse = function (from, to) {
  18585. to = to || this.length;
  18586. if (to < 0) {
  18587. to += this.length;
  18588. }
  18589. from = from || 0;
  18590. if (from < 0) {
  18591. from += this.length;
  18592. }
  18593. var ret = new Yallist();
  18594. if (to < from || to < 0) {
  18595. return ret;
  18596. }
  18597. if (from < 0) {
  18598. from = 0;
  18599. }
  18600. if (to > this.length) {
  18601. to = this.length;
  18602. }
  18603. for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
  18604. walker = walker.prev;
  18605. }
  18606. for (; walker !== null && i > from; i--, walker = walker.prev) {
  18607. ret.push(walker.value);
  18608. }
  18609. return ret;
  18610. };
  18611. Yallist.prototype.reverse = function () {
  18612. var head = this.head;
  18613. var tail = this.tail;
  18614. for (var walker = head; walker !== null; walker = walker.prev) {
  18615. var p = walker.prev;
  18616. walker.prev = walker.next;
  18617. walker.next = p;
  18618. }
  18619. this.head = tail;
  18620. this.tail = head;
  18621. return this;
  18622. };
  18623. function push$1(self, item) {
  18624. self.tail = new Node(item, self.tail, null, self);
  18625. if (!self.head) {
  18626. self.head = self.tail;
  18627. }
  18628. self.length++;
  18629. }
  18630. function unshift(self, item) {
  18631. self.head = new Node(item, null, self.head, self);
  18632. if (!self.tail) {
  18633. self.tail = self.head;
  18634. }
  18635. self.length++;
  18636. }
  18637. function Node(value, prev, next, list) {
  18638. if (!(this instanceof Node)) {
  18639. return new Node(value, prev, next, list);
  18640. }
  18641. this.list = list;
  18642. this.value = value;
  18643. if (prev) {
  18644. prev.next = this;
  18645. this.prev = prev;
  18646. } else {
  18647. this.prev = null;
  18648. }
  18649. if (next) {
  18650. next.prev = this;
  18651. this.next = next;
  18652. } else {
  18653. this.next = null;
  18654. }
  18655. }
  18656. var lruCache = LRUCache; // This will be a proper iterable 'Map' in engines that support it,
  18657. // or a fakey-fake PseudoMap in older versions.
  18658. // A linked list to keep track of recently-used-ness
  18659. // use symbols if possible, otherwise just _props
  18660. var hasSymbol = typeof Symbol === 'function' && process.env._nodeLRUCacheForceNoSymbol !== '1';
  18661. var makeSymbol;
  18662. if (hasSymbol) {
  18663. makeSymbol = function (key) {
  18664. return Symbol(key);
  18665. };
  18666. } else {
  18667. makeSymbol = function (key) {
  18668. return '_' + key;
  18669. };
  18670. }
  18671. var MAX = makeSymbol('max');
  18672. var LENGTH = makeSymbol('length');
  18673. var LENGTH_CALCULATOR = makeSymbol('lengthCalculator');
  18674. var ALLOW_STALE = makeSymbol('allowStale');
  18675. var MAX_AGE = makeSymbol('maxAge');
  18676. var DISPOSE = makeSymbol('dispose');
  18677. var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet');
  18678. var LRU_LIST = makeSymbol('lruList');
  18679. var CACHE = makeSymbol('cache');
  18680. function naiveLength() {
  18681. return 1;
  18682. } // lruList is a yallist where the head is the youngest
  18683. // item, and the tail is the oldest. the list contains the Hit
  18684. // objects as the entries.
  18685. // Each Hit object has a reference to its Yallist.Node. This
  18686. // never changes.
  18687. //
  18688. // cache is a Map (or PseudoMap) that matches the keys to
  18689. // the Yallist.Node object.
  18690. function LRUCache(options) {
  18691. if (!(this instanceof LRUCache)) {
  18692. return new LRUCache(options);
  18693. }
  18694. if (typeof options === 'number') {
  18695. options = {
  18696. max: options
  18697. };
  18698. }
  18699. if (!options) {
  18700. options = {};
  18701. }
  18702. var max = this[MAX] = options.max; // Kind of weird to have a default max of Infinity, but oh well.
  18703. if (!max || !(typeof max === 'number') || max <= 0) {
  18704. this[MAX] = Infinity;
  18705. }
  18706. var lc = options.length || naiveLength;
  18707. if (typeof lc !== 'function') {
  18708. lc = naiveLength;
  18709. }
  18710. this[LENGTH_CALCULATOR] = lc;
  18711. this[ALLOW_STALE] = options.stale || false;
  18712. this[MAX_AGE] = options.maxAge || 0;
  18713. this[DISPOSE] = options.dispose;
  18714. this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
  18715. this.reset();
  18716. } // resize the cache when the max changes.
  18717. Object.defineProperty(LRUCache.prototype, 'max', {
  18718. set: function (mL) {
  18719. if (!mL || !(typeof mL === 'number') || mL <= 0) {
  18720. mL = Infinity;
  18721. }
  18722. this[MAX] = mL;
  18723. trim$2(this);
  18724. },
  18725. get: function () {
  18726. return this[MAX];
  18727. },
  18728. enumerable: true
  18729. });
  18730. Object.defineProperty(LRUCache.prototype, 'allowStale', {
  18731. set: function (allowStale) {
  18732. this[ALLOW_STALE] = !!allowStale;
  18733. },
  18734. get: function () {
  18735. return this[ALLOW_STALE];
  18736. },
  18737. enumerable: true
  18738. });
  18739. Object.defineProperty(LRUCache.prototype, 'maxAge', {
  18740. set: function (mA) {
  18741. if (!mA || !(typeof mA === 'number') || mA < 0) {
  18742. mA = 0;
  18743. }
  18744. this[MAX_AGE] = mA;
  18745. trim$2(this);
  18746. },
  18747. get: function () {
  18748. return this[MAX_AGE];
  18749. },
  18750. enumerable: true
  18751. }); // resize the cache when the lengthCalculator changes.
  18752. Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
  18753. set: function (lC) {
  18754. if (typeof lC !== 'function') {
  18755. lC = naiveLength;
  18756. }
  18757. if (lC !== this[LENGTH_CALCULATOR]) {
  18758. this[LENGTH_CALCULATOR] = lC;
  18759. this[LENGTH] = 0;
  18760. this[LRU_LIST].forEach(function (hit) {
  18761. hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
  18762. this[LENGTH] += hit.length;
  18763. }, this);
  18764. }
  18765. trim$2(this);
  18766. },
  18767. get: function () {
  18768. return this[LENGTH_CALCULATOR];
  18769. },
  18770. enumerable: true
  18771. });
  18772. Object.defineProperty(LRUCache.prototype, 'length', {
  18773. get: function () {
  18774. return this[LENGTH];
  18775. },
  18776. enumerable: true
  18777. });
  18778. Object.defineProperty(LRUCache.prototype, 'itemCount', {
  18779. get: function () {
  18780. return this[LRU_LIST].length;
  18781. },
  18782. enumerable: true
  18783. });
  18784. LRUCache.prototype.rforEach = function (fn, thisp) {
  18785. thisp = thisp || this;
  18786. for (var walker = this[LRU_LIST].tail; walker !== null;) {
  18787. var prev = walker.prev;
  18788. forEachStep(this, fn, walker, thisp);
  18789. walker = prev;
  18790. }
  18791. };
  18792. function forEachStep(self, fn, node, thisp) {
  18793. var hit = node.value;
  18794. if (isStale(self, hit)) {
  18795. del(self, node);
  18796. if (!self[ALLOW_STALE]) {
  18797. hit = undefined;
  18798. }
  18799. }
  18800. if (hit) {
  18801. fn.call(thisp, hit.value, hit.key, self);
  18802. }
  18803. }
  18804. LRUCache.prototype.forEach = function (fn, thisp) {
  18805. thisp = thisp || this;
  18806. for (var walker = this[LRU_LIST].head; walker !== null;) {
  18807. var next = walker.next;
  18808. forEachStep(this, fn, walker, thisp);
  18809. walker = next;
  18810. }
  18811. };
  18812. LRUCache.prototype.keys = function () {
  18813. return this[LRU_LIST].toArray().map(function (k) {
  18814. return k.key;
  18815. }, this);
  18816. };
  18817. LRUCache.prototype.values = function () {
  18818. return this[LRU_LIST].toArray().map(function (k) {
  18819. return k.value;
  18820. }, this);
  18821. };
  18822. LRUCache.prototype.reset = function () {
  18823. if (this[DISPOSE] && this[LRU_LIST] && this[LRU_LIST].length) {
  18824. this[LRU_LIST].forEach(function (hit) {
  18825. this[DISPOSE](hit.key, hit.value);
  18826. }, this);
  18827. }
  18828. this[CACHE] = new map(); // hash of items by key
  18829. this[LRU_LIST] = new yallist(); // list of items in order of use recency
  18830. this[LENGTH] = 0; // length of items in the list
  18831. };
  18832. LRUCache.prototype.dump = function () {
  18833. return this[LRU_LIST].map(function (hit) {
  18834. if (!isStale(this, hit)) {
  18835. return {
  18836. k: hit.key,
  18837. v: hit.value,
  18838. e: hit.now + (hit.maxAge || 0)
  18839. };
  18840. }
  18841. }, this).toArray().filter(function (h) {
  18842. return h;
  18843. });
  18844. };
  18845. LRUCache.prototype.dumpLru = function () {
  18846. return this[LRU_LIST];
  18847. };
  18848. /* istanbul ignore next */
  18849. LRUCache.prototype.inspect = function (n, opts) {
  18850. var str = 'LRUCache {';
  18851. var extras = false;
  18852. var as = this[ALLOW_STALE];
  18853. if (as) {
  18854. str += '\n allowStale: true';
  18855. extras = true;
  18856. }
  18857. var max = this[MAX];
  18858. if (max && max !== Infinity) {
  18859. if (extras) {
  18860. str += ',';
  18861. }
  18862. str += '\n max: ' + util__default['default'].inspect(max, opts);
  18863. extras = true;
  18864. }
  18865. var maxAge = this[MAX_AGE];
  18866. if (maxAge) {
  18867. if (extras) {
  18868. str += ',';
  18869. }
  18870. str += '\n maxAge: ' + util__default['default'].inspect(maxAge, opts);
  18871. extras = true;
  18872. }
  18873. var lc = this[LENGTH_CALCULATOR];
  18874. if (lc && lc !== naiveLength) {
  18875. if (extras) {
  18876. str += ',';
  18877. }
  18878. str += '\n length: ' + util__default['default'].inspect(this[LENGTH], opts);
  18879. extras = true;
  18880. }
  18881. var didFirst = false;
  18882. this[LRU_LIST].forEach(function (item) {
  18883. if (didFirst) {
  18884. str += ',\n ';
  18885. } else {
  18886. if (extras) {
  18887. str += ',\n';
  18888. }
  18889. didFirst = true;
  18890. str += '\n ';
  18891. }
  18892. var key = util__default['default'].inspect(item.key).split('\n').join('\n ');
  18893. var val = {
  18894. value: item.value
  18895. };
  18896. if (item.maxAge !== maxAge) {
  18897. val.maxAge = item.maxAge;
  18898. }
  18899. if (lc !== naiveLength) {
  18900. val.length = item.length;
  18901. }
  18902. if (isStale(this, item)) {
  18903. val.stale = true;
  18904. }
  18905. val = util__default['default'].inspect(val, opts).split('\n').join('\n ');
  18906. str += key + ' => ' + val;
  18907. });
  18908. if (didFirst || extras) {
  18909. str += '\n';
  18910. }
  18911. str += '}';
  18912. return str;
  18913. };
  18914. LRUCache.prototype.set = function (key, value, maxAge) {
  18915. maxAge = maxAge || this[MAX_AGE];
  18916. var now = maxAge ? Date.now() : 0;
  18917. var len = this[LENGTH_CALCULATOR](value, key);
  18918. if (this[CACHE].has(key)) {
  18919. if (len > this[MAX]) {
  18920. del(this, this[CACHE].get(key));
  18921. return false;
  18922. }
  18923. var node = this[CACHE].get(key);
  18924. var item = node.value; // dispose of the old one before overwriting
  18925. // split out into 2 ifs for better coverage tracking
  18926. if (this[DISPOSE]) {
  18927. if (!this[NO_DISPOSE_ON_SET]) {
  18928. this[DISPOSE](key, item.value);
  18929. }
  18930. }
  18931. item.now = now;
  18932. item.maxAge = maxAge;
  18933. item.value = value;
  18934. this[LENGTH] += len - item.length;
  18935. item.length = len;
  18936. this.get(key);
  18937. trim$2(this);
  18938. return true;
  18939. }
  18940. var hit = new Entry$1(key, value, len, now, maxAge); // oversized objects fall out of cache automatically.
  18941. if (hit.length > this[MAX]) {
  18942. if (this[DISPOSE]) {
  18943. this[DISPOSE](key, value);
  18944. }
  18945. return false;
  18946. }
  18947. this[LENGTH] += hit.length;
  18948. this[LRU_LIST].unshift(hit);
  18949. this[CACHE].set(key, this[LRU_LIST].head);
  18950. trim$2(this);
  18951. return true;
  18952. };
  18953. LRUCache.prototype.has = function (key) {
  18954. if (!this[CACHE].has(key)) return false;
  18955. var hit = this[CACHE].get(key).value;
  18956. if (isStale(this, hit)) {
  18957. return false;
  18958. }
  18959. return true;
  18960. };
  18961. LRUCache.prototype.get = function (key) {
  18962. return get(this, key, true);
  18963. };
  18964. LRUCache.prototype.peek = function (key) {
  18965. return get(this, key, false);
  18966. };
  18967. LRUCache.prototype.pop = function () {
  18968. var node = this[LRU_LIST].tail;
  18969. if (!node) return null;
  18970. del(this, node);
  18971. return node.value;
  18972. };
  18973. LRUCache.prototype.del = function (key) {
  18974. del(this, this[CACHE].get(key));
  18975. };
  18976. LRUCache.prototype.load = function (arr) {
  18977. // reset the cache
  18978. this.reset();
  18979. var now = Date.now(); // A previous serialized cache has the most recent items first
  18980. for (var l = arr.length - 1; l >= 0; l--) {
  18981. var hit = arr[l];
  18982. var expiresAt = hit.e || 0;
  18983. if (expiresAt === 0) {
  18984. // the item was created without expiration in a non aged cache
  18985. this.set(hit.k, hit.v);
  18986. } else {
  18987. var maxAge = expiresAt - now; // dont add already expired items
  18988. if (maxAge > 0) {
  18989. this.set(hit.k, hit.v, maxAge);
  18990. }
  18991. }
  18992. }
  18993. };
  18994. LRUCache.prototype.prune = function () {
  18995. var self = this;
  18996. this[CACHE].forEach(function (value, key) {
  18997. get(self, key, false);
  18998. });
  18999. };
  19000. function get(self, key, doUse) {
  19001. var node = self[CACHE].get(key);
  19002. if (node) {
  19003. var hit = node.value;
  19004. if (isStale(self, hit)) {
  19005. del(self, node);
  19006. if (!self[ALLOW_STALE]) hit = undefined;
  19007. } else {
  19008. if (doUse) {
  19009. self[LRU_LIST].unshiftNode(node);
  19010. }
  19011. }
  19012. if (hit) hit = hit.value;
  19013. }
  19014. return hit;
  19015. }
  19016. function isStale(self, hit) {
  19017. if (!hit || !hit.maxAge && !self[MAX_AGE]) {
  19018. return false;
  19019. }
  19020. var stale = false;
  19021. var diff = Date.now() - hit.now;
  19022. if (hit.maxAge) {
  19023. stale = diff > hit.maxAge;
  19024. } else {
  19025. stale = self[MAX_AGE] && diff > self[MAX_AGE];
  19026. }
  19027. return stale;
  19028. }
  19029. function trim$2(self) {
  19030. if (self[LENGTH] > self[MAX]) {
  19031. for (var walker = self[LRU_LIST].tail; self[LENGTH] > self[MAX] && walker !== null;) {
  19032. // We know that we're about to delete this one, and also
  19033. // what the next least recently used key will be, so just
  19034. // go ahead and set it now.
  19035. var prev = walker.prev;
  19036. del(self, walker);
  19037. walker = prev;
  19038. }
  19039. }
  19040. }
  19041. function del(self, node) {
  19042. if (node) {
  19043. var hit = node.value;
  19044. if (self[DISPOSE]) {
  19045. self[DISPOSE](hit.key, hit.value);
  19046. }
  19047. self[LENGTH] -= hit.length;
  19048. self[CACHE].delete(hit.key);
  19049. self[LRU_LIST].removeNode(node);
  19050. }
  19051. } // classy, since V8 prefers predictable objects.
  19052. function Entry$1(key, value, length, now, maxAge) {
  19053. this.key = key;
  19054. this.value = value;
  19055. this.length = length;
  19056. this.now = now;
  19057. this.maxAge = maxAge || 0;
  19058. }
  19059. var sigmund_1 = sigmund;
  19060. function sigmund(subject, maxSessions) {
  19061. maxSessions = maxSessions || 10;
  19062. var notes = [];
  19063. var analysis = '';
  19064. var RE = RegExp;
  19065. function psychoAnalyze(subject, session) {
  19066. if (session > maxSessions) return;
  19067. if (typeof subject === 'function' || typeof subject === 'undefined') {
  19068. return;
  19069. }
  19070. if (typeof subject !== 'object' || !subject || subject instanceof RE) {
  19071. analysis += subject;
  19072. return;
  19073. }
  19074. if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
  19075. notes.push(subject);
  19076. analysis += '{';
  19077. Object.keys(subject).forEach(function (issue, _, __) {
  19078. // pseudo-private values. skip those.
  19079. if (issue.charAt(0) === '_') return;
  19080. var to = typeof subject[issue];
  19081. if (to === 'function' || to === 'undefined') return;
  19082. analysis += issue;
  19083. psychoAnalyze(subject[issue], session + 1);
  19084. });
  19085. }
  19086. psychoAnalyze(subject, 0);
  19087. return analysis;
  19088. } // vim: set softtabstop=4 shiftwidth=4:
  19089. var fnmatch = createCommonjsModule(function (module, exports) {
  19090. // Based on minimatch.js by isaacs <https://npmjs.org/package/minimatch>
  19091. var platform = typeof process === "object" ? process.platform : "win32";
  19092. if (module) module.exports = minimatch;else exports.minimatch = minimatch;
  19093. minimatch.Minimatch = Minimatch;
  19094. var cache = minimatch.cache = new lruCache({
  19095. max: 100
  19096. }),
  19097. GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  19098. var qmark = "[^/]" // * => any number of characters
  19099. ,
  19100. star = qmark + "*?" // ** when dots are allowed. Anything goes, except .. and .
  19101. // not (^ or / followed by one or two dots followed by $ or /),
  19102. // followed by anything, any number of times.
  19103. ,
  19104. twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?" // not a ^ or / followed by a dot,
  19105. // followed by anything, any number of times.
  19106. ,
  19107. twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?" // characters that need to be escaped in RegExp.
  19108. ,
  19109. reSpecials = charSet("().*{}+?[]^$\\!"); // "abc" -> { a:true, b:true, c:true }
  19110. function charSet(s) {
  19111. return s.split("").reduce(function (set, c) {
  19112. set[c] = true;
  19113. return set;
  19114. }, {});
  19115. } // normalizes slashes.
  19116. var slashSplit = /\/+/;
  19117. minimatch.monkeyPatch = monkeyPatch;
  19118. function monkeyPatch() {
  19119. var desc = Object.getOwnPropertyDescriptor(String.prototype, "match");
  19120. var orig = desc.value;
  19121. desc.value = function (p) {
  19122. if (p instanceof Minimatch) return p.match(this);
  19123. return orig.call(this, p);
  19124. };
  19125. Object.defineProperty(String.prototype, desc);
  19126. }
  19127. minimatch.filter = filter;
  19128. function filter(pattern, options) {
  19129. options = options || {};
  19130. return function (p, i, list) {
  19131. return minimatch(p, pattern, options);
  19132. };
  19133. }
  19134. function ext(a, b) {
  19135. a = a || {};
  19136. b = b || {};
  19137. var t = {};
  19138. Object.keys(b).forEach(function (k) {
  19139. t[k] = b[k];
  19140. });
  19141. Object.keys(a).forEach(function (k) {
  19142. t[k] = a[k];
  19143. });
  19144. return t;
  19145. }
  19146. minimatch.defaults = function (def) {
  19147. if (!def || !Object.keys(def).length) return minimatch;
  19148. var orig = minimatch;
  19149. var m = function minimatch(p, pattern, options) {
  19150. return orig.minimatch(p, pattern, ext(def, options));
  19151. };
  19152. m.Minimatch = function Minimatch(pattern, options) {
  19153. return new orig.Minimatch(pattern, ext(def, options));
  19154. };
  19155. return m;
  19156. };
  19157. Minimatch.defaults = function (def) {
  19158. if (!def || !Object.keys(def).length) return Minimatch;
  19159. return minimatch.defaults(def).Minimatch;
  19160. };
  19161. function minimatch(p, pattern, options) {
  19162. if (typeof pattern !== "string") {
  19163. throw new TypeError("glob pattern string required");
  19164. }
  19165. if (!options) options = {}; // shortcut: comments match nothing.
  19166. if (!options.nocomment && pattern.charAt(0) === "#") {
  19167. return false;
  19168. } // "" only matches ""
  19169. if (pattern.trim() === "") return p === "";
  19170. return new Minimatch(pattern, options).match(p);
  19171. }
  19172. function Minimatch(pattern, options) {
  19173. if (!(this instanceof Minimatch)) {
  19174. return new Minimatch(pattern, options, cache);
  19175. }
  19176. if (typeof pattern !== "string") {
  19177. throw new TypeError("glob pattern string required");
  19178. }
  19179. if (!options) options = {}; // windows: need to use /, not \
  19180. // On other platforms, \ is a valid (albeit bad) filename char.
  19181. if (platform === "win32") {
  19182. pattern = pattern.split("\\").join("/");
  19183. } // lru storage.
  19184. // these things aren't particularly big, but walking down the string
  19185. // and turning it into a regexp can get pretty costly.
  19186. var cacheKey = pattern + "\n" + sigmund_1(options);
  19187. var cached = minimatch.cache.get(cacheKey);
  19188. if (cached) return cached;
  19189. minimatch.cache.set(cacheKey, this);
  19190. this.options = options;
  19191. this.set = [];
  19192. this.pattern = pattern;
  19193. this.regexp = null;
  19194. this.negate = false;
  19195. this.comment = false;
  19196. this.empty = false; // make the set of regexps etc.
  19197. this.make();
  19198. }
  19199. Minimatch.prototype.make = make;
  19200. function make() {
  19201. // don't do it more than once.
  19202. if (this._made) return;
  19203. var pattern = this.pattern;
  19204. var options = this.options; // empty patterns and comments match nothing.
  19205. if (!options.nocomment && pattern.charAt(0) === "#") {
  19206. this.comment = true;
  19207. return;
  19208. }
  19209. if (!pattern) {
  19210. this.empty = true;
  19211. return;
  19212. } // step 1: figure out negation, etc.
  19213. this.parseNegate(); // step 2: expand braces
  19214. var set = this.globSet = this.braceExpand();
  19215. if (options.debug) console.error(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
  19216. // matching patterns.
  19217. // These will be regexps, except in the case of "**", which is
  19218. // set to the GLOBSTAR object for globstar behavior,
  19219. // and will not contain any / characters
  19220. set = this.globParts = set.map(function (s) {
  19221. return s.split(slashSplit);
  19222. });
  19223. if (options.debug) console.error(this.pattern, set); // glob --> regexps
  19224. set = set.map(function (s, si, set) {
  19225. return s.map(this.parse, this);
  19226. }, this);
  19227. if (options.debug) console.error(this.pattern, set); // filter out everything that didn't compile properly.
  19228. set = set.filter(function (s) {
  19229. return -1 === s.indexOf(false);
  19230. });
  19231. if (options.debug) console.error(this.pattern, set);
  19232. this.set = set;
  19233. }
  19234. Minimatch.prototype.parseNegate = parseNegate;
  19235. function parseNegate() {
  19236. var pattern = this.pattern,
  19237. negate = false,
  19238. options = this.options,
  19239. negateOffset = 0;
  19240. if (options.nonegate) return;
  19241. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === "!"; i++) {
  19242. negate = !negate;
  19243. negateOffset++;
  19244. }
  19245. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  19246. this.negate = negate;
  19247. } // Brace expansion:
  19248. // a{b,c}d -> abd acd
  19249. // a{b,}c -> abc ac
  19250. // a{0..3}d -> a0d a1d a2d a3d
  19251. // a{b,c{d,e}f}g -> abg acdfg acefg
  19252. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  19253. //
  19254. // Invalid sets are not expanded.
  19255. // a{2..}b -> a{2..}b
  19256. // a{b}c -> a{b}c
  19257. minimatch.braceExpand = function (pattern, options) {
  19258. return new Minimatch(pattern, options).braceExpand();
  19259. };
  19260. Minimatch.prototype.braceExpand = braceExpand;
  19261. function braceExpand(pattern, options) {
  19262. options = options || this.options;
  19263. pattern = typeof pattern === "undefined" ? this.pattern : pattern;
  19264. if (typeof pattern === "undefined") {
  19265. throw new Error("undefined pattern");
  19266. }
  19267. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  19268. // shortcut. no need to expand.
  19269. return [pattern];
  19270. }
  19271. var escaping = false; // examples and comments refer to this crazy pattern:
  19272. // a{b,c{d,e},{f,g}h}x{y,z}
  19273. // expected:
  19274. // abxy
  19275. // abxz
  19276. // acdxy
  19277. // acdxz
  19278. // acexy
  19279. // acexz
  19280. // afhxy
  19281. // afhxz
  19282. // aghxy
  19283. // aghxz
  19284. // everything before the first \{ is just a prefix.
  19285. // So, we pluck that off, and work with the rest,
  19286. // and then prepend it to everything we find.
  19287. if (pattern.charAt(0) !== "{") {
  19288. // console.error(pattern)
  19289. var prefix = null;
  19290. for (var i = 0, l = pattern.length; i < l; i++) {
  19291. var c = pattern.charAt(i); // console.error(i, c)
  19292. if (c === "\\") {
  19293. escaping = !escaping;
  19294. } else if (c === "{" && !escaping) {
  19295. prefix = pattern.substr(0, i);
  19296. break;
  19297. }
  19298. } // actually no sets, all { were escaped.
  19299. if (prefix === null) {
  19300. // console.error("no sets")
  19301. return [pattern];
  19302. }
  19303. var tail = braceExpand(pattern.substr(i), options);
  19304. return tail.map(function (t) {
  19305. return prefix + t;
  19306. });
  19307. } // now we have something like:
  19308. // {b,c{d,e},{f,g}h}x{y,z}
  19309. // walk through the set, expanding each part, until
  19310. // the set ends. then, we'll expand the suffix.
  19311. // If the set only has a single member, then'll put the {} back
  19312. // first, handle numeric sets, since they're easier
  19313. var numset = pattern.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/);
  19314. if (numset) {
  19315. // console.error("numset", numset[1], numset[2])
  19316. var suf = braceExpand(pattern.substr(numset[0].length), options),
  19317. start = +numset[1],
  19318. end = +numset[2],
  19319. inc = start > end ? -1 : 1,
  19320. set = [];
  19321. for (var i = start; i != end + inc; i += inc) {
  19322. // append all the suffixes
  19323. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  19324. set.push(i + suf[ii]);
  19325. }
  19326. }
  19327. return set;
  19328. } // ok, walk through the set
  19329. // We hope, somewhat optimistically, that there
  19330. // will be a } at the end.
  19331. // If the closing brace isn't found, then the pattern is
  19332. // interpreted as braceExpand("\\" + pattern) so that
  19333. // the leading \{ will be interpreted literally.
  19334. var i = 1 // skip the \{
  19335. ,
  19336. depth = 1,
  19337. set = [],
  19338. member = "",
  19339. escaping = false;
  19340. function addMember() {
  19341. set.push(member);
  19342. member = "";
  19343. } // console.error("Entering for")
  19344. FOR: for (i = 1, l = pattern.length; i < l; i++) {
  19345. var c = pattern.charAt(i); // console.error("", i, c)
  19346. if (escaping) {
  19347. escaping = false;
  19348. member += "\\" + c;
  19349. } else {
  19350. switch (c) {
  19351. case "\\":
  19352. escaping = true;
  19353. continue;
  19354. case "{":
  19355. depth++;
  19356. member += "{";
  19357. continue;
  19358. case "}":
  19359. depth--; // if this closes the actual set, then we're done
  19360. if (depth === 0) {
  19361. addMember(); // pluck off the close-brace
  19362. i++;
  19363. break FOR;
  19364. } else {
  19365. member += c;
  19366. continue;
  19367. }
  19368. case ",":
  19369. if (depth === 1) {
  19370. addMember();
  19371. } else {
  19372. member += c;
  19373. }
  19374. continue;
  19375. default:
  19376. member += c;
  19377. continue;
  19378. } // switch
  19379. } // else
  19380. } // for
  19381. // now we've either finished the set, and the suffix is
  19382. // pattern.substr(i), or we have *not* closed the set,
  19383. // and need to escape the leading brace
  19384. if (depth !== 0) {
  19385. // console.error("didn't close", pattern)
  19386. return braceExpand("\\" + pattern, options);
  19387. } // x{y,z} -> ["xy", "xz"]
  19388. // console.error("set", set)
  19389. // console.error("suffix", pattern.substr(i))
  19390. var suf = braceExpand(pattern.substr(i), options); // ["b", "c{d,e}","{f,g}h"] ->
  19391. // [["b"], ["cd", "ce"], ["fh", "gh"]]
  19392. var addBraces = set.length === 1; // console.error("set pre-expanded", set)
  19393. set = set.map(function (p) {
  19394. return braceExpand(p, options);
  19395. }); // console.error("set expanded", set)
  19396. // [["b"], ["cd", "ce"], ["fh", "gh"]] ->
  19397. // ["b", "cd", "ce", "fh", "gh"]
  19398. set = set.reduce(function (l, r) {
  19399. return l.concat(r);
  19400. });
  19401. if (addBraces) {
  19402. set = set.map(function (s) {
  19403. return "{" + s + "}";
  19404. });
  19405. } // now attach the suffixes.
  19406. var ret = [];
  19407. for (var i = 0, l = set.length; i < l; i++) {
  19408. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  19409. ret.push(set[i] + suf[ii]);
  19410. }
  19411. }
  19412. return ret;
  19413. } // parse a component of the expanded set.
  19414. // At this point, no pattern may contain "/" in it
  19415. // so we're going to return a 2d array, where each entry is the full
  19416. // pattern, split on '/', and then turned into a regular expression.
  19417. // A regexp is made at the end which joins each array with an
  19418. // escaped /, and another full one which joins each regexp with |.
  19419. //
  19420. // Following the lead of Bash 4.1, note that "**" only has special meaning
  19421. // when it is the *only* thing in a path portion. Otherwise, any series
  19422. // of * is equivalent to a single *. Globstar behavior is enabled by
  19423. // default, and can be disabled by setting options.noglobstar.
  19424. Minimatch.prototype.parse = parse;
  19425. var SUBPARSE = {};
  19426. function parse(pattern, isSub) {
  19427. var options = this.options; // shortcuts
  19428. if (!options.noglobstar && pattern === "**") return GLOBSTAR;
  19429. if (pattern === "") return "";
  19430. var re = "",
  19431. hasMagic = !!options.nocase,
  19432. escaping = false // ? => one single character
  19433. ,
  19434. patternListStack = [],
  19435. plType,
  19436. stateChar,
  19437. inClass = false,
  19438. reClassStart = -1,
  19439. classStart = -1 // . and .. never match anything that doesn't start with .,
  19440. // even when options.dot is set.
  19441. ,
  19442. patternStart = pattern.charAt(0) === "." ? "" // anything
  19443. // not (start or / followed by . or .. followed by / or end)
  19444. : options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))" : "(?!\\.)";
  19445. function clearStateChar() {
  19446. if (stateChar) {
  19447. // we had some state-tracking character
  19448. // that wasn't consumed by this pass.
  19449. switch (stateChar) {
  19450. case "*":
  19451. re += star;
  19452. hasMagic = true;
  19453. break;
  19454. case "?":
  19455. re += qmark;
  19456. hasMagic = true;
  19457. break;
  19458. default:
  19459. re += "\\" + stateChar;
  19460. break;
  19461. }
  19462. stateChar = false;
  19463. }
  19464. }
  19465. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  19466. if (options.debug) {
  19467. console.error("%s\t%s %s %j", pattern, i, re, c);
  19468. } // skip over any that are escaped.
  19469. if (escaping && reSpecials[c]) {
  19470. re += "\\" + c;
  19471. escaping = false;
  19472. continue;
  19473. }
  19474. switch (c) {
  19475. case "/":
  19476. // completely not allowed, even escaped.
  19477. // Should already be path-split by now.
  19478. return false;
  19479. case "\\":
  19480. clearStateChar();
  19481. escaping = true;
  19482. continue;
  19483. // the various stateChar values
  19484. // for the "extglob" stuff.
  19485. case "?":
  19486. case "*":
  19487. case "+":
  19488. case "@":
  19489. case "!":
  19490. if (options.debug) {
  19491. console.error("%s\t%s %s %j <-- stateChar", pattern, i, re, c);
  19492. } // all of those are literals inside a class, except that
  19493. // the glob [!a] means [^a] in regexp
  19494. if (inClass) {
  19495. if (c === "!" && i === classStart + 1) c = "^";
  19496. re += c;
  19497. continue;
  19498. } // if we already have a stateChar, then it means
  19499. // that there was something like ** or +? in there.
  19500. // Handle the stateChar, then proceed with this one.
  19501. clearStateChar();
  19502. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  19503. // just clear the statechar *now*, rather than even diving into
  19504. // the patternList stuff.
  19505. if (options.noext) clearStateChar();
  19506. continue;
  19507. case "(":
  19508. if (inClass) {
  19509. re += "(";
  19510. continue;
  19511. }
  19512. if (!stateChar) {
  19513. re += "\\(";
  19514. continue;
  19515. }
  19516. plType = stateChar;
  19517. patternListStack.push({
  19518. type: plType,
  19519. start: i - 1,
  19520. reStart: re.length
  19521. }); // negation is (?:(?!js)[^/]*)
  19522. re += stateChar === "!" ? "(?:(?!" : "(?:";
  19523. stateChar = false;
  19524. continue;
  19525. case ")":
  19526. if (inClass || !patternListStack.length) {
  19527. re += "\\)";
  19528. continue;
  19529. }
  19530. hasMagic = true;
  19531. re += ")";
  19532. plType = patternListStack.pop().type; // negation is (?:(?!js)[^/]*)
  19533. // The others are (?:<pattern>)<type>
  19534. switch (plType) {
  19535. case "!":
  19536. re += "[^/]*?)";
  19537. break;
  19538. case "?":
  19539. case "+":
  19540. case "*":
  19541. re += plType;
  19542. // the default anyway
  19543. }
  19544. continue;
  19545. case "|":
  19546. if (inClass || !patternListStack.length || escaping) {
  19547. re += "\\|";
  19548. escaping = false;
  19549. continue;
  19550. }
  19551. re += "|";
  19552. continue;
  19553. // these are mostly the same in regexp and glob
  19554. case "[":
  19555. // swallow any state-tracking char before the [
  19556. clearStateChar();
  19557. if (inClass) {
  19558. re += "\\" + c;
  19559. continue;
  19560. }
  19561. inClass = true;
  19562. classStart = i;
  19563. reClassStart = re.length;
  19564. re += c;
  19565. continue;
  19566. case "]":
  19567. // a right bracket shall lose its special
  19568. // meaning and represent itself in
  19569. // a bracket expression if it occurs
  19570. // first in the list. -- POSIX.2 2.8.3.2
  19571. if (i === classStart + 1 || !inClass) {
  19572. re += "\\" + c;
  19573. escaping = false;
  19574. continue;
  19575. } // finish up the class.
  19576. hasMagic = true;
  19577. inClass = false;
  19578. re += c;
  19579. continue;
  19580. default:
  19581. // swallow any state char that wasn't consumed
  19582. clearStateChar();
  19583. if (escaping) {
  19584. // no need
  19585. escaping = false;
  19586. } else if (reSpecials[c] && !(c === "^" && inClass)) {
  19587. re += "\\";
  19588. }
  19589. re += c;
  19590. } // switch
  19591. } // for
  19592. // handle the case where we left a class open.
  19593. // "[abc" is valid, equivalent to "\[abc"
  19594. if (inClass) {
  19595. // split where the last [ was, and escape it
  19596. // this is a huge pita. We now have to re-walk
  19597. // the contents of the would-be class to re-translate
  19598. // any characters that were passed through as-is
  19599. var cs = pattern.substr(classStart + 1),
  19600. sp = this.parse(cs, SUBPARSE);
  19601. re = re.substr(0, reClassStart) + "\\[" + sp[0];
  19602. hasMagic = hasMagic || sp[1];
  19603. } // handle the case where we had a +( thing at the *end*
  19604. // of the pattern.
  19605. // each pattern list stack adds 3 chars, and we need to go through
  19606. // and escape any | chars that were passed through as-is for the regexp.
  19607. // Go through and escape them, taking care not to double-escape any
  19608. // | chars that were already escaped.
  19609. var pl;
  19610. while (pl = patternListStack.pop()) {
  19611. var tail = re.slice(pl.reStart + 3); // maybe some even number of \, then maybe 1 \, followed by a |
  19612. tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
  19613. if (!$2) {
  19614. // the | isn't already escaped, so escape it.
  19615. $2 = "\\";
  19616. } // need to escape all those slashes *again*, without escaping the
  19617. // one that we need for escaping the | character. As it works out,
  19618. // escaping an even number of slashes can be done by simply repeating
  19619. // it exactly after itself. That's why this trick works.
  19620. //
  19621. // I am sorry that you have to see this.
  19622. return $1 + $1 + $2 + "|";
  19623. }); // console.error("tail=%j\n %s", tail, tail)
  19624. var t = pl.type === "*" ? star : pl.type === "?" ? qmark : "\\" + pl.type;
  19625. hasMagic = true;
  19626. re = re.slice(0, pl.reStart) + t + "\\(" + tail;
  19627. } // handle trailing things that only matter at the very end.
  19628. clearStateChar();
  19629. if (escaping) {
  19630. // trailing \\
  19631. re += "\\\\";
  19632. } // only need to apply the nodot start if the re starts with
  19633. // something that could conceivably capture a dot
  19634. var addPatternStart = false;
  19635. switch (re.charAt(0)) {
  19636. case ".":
  19637. case "[":
  19638. case "(":
  19639. addPatternStart = true;
  19640. } // if the re is not "" at this point, then we need to make sure
  19641. // it doesn't match against an empty path part.
  19642. // Otherwise a/* will match a/, which it should not.
  19643. if (re !== "" && hasMagic) re = "(?=.)" + re;
  19644. if (addPatternStart) re = patternStart + re; // parsing just a piece of a larger pattern.
  19645. if (isSub === SUBPARSE) {
  19646. return [re, hasMagic];
  19647. } // skip the regexp for non-magical patterns
  19648. // unescape anything in it, though, so that it'll be
  19649. // an exact match against a file etc.
  19650. if (!hasMagic) {
  19651. return globUnescape(pattern);
  19652. }
  19653. var flags = options.nocase ? "i" : "",
  19654. regExp = new RegExp("^" + re + "$", flags);
  19655. regExp._glob = pattern;
  19656. regExp._src = re;
  19657. return regExp;
  19658. }
  19659. minimatch.makeRe = function (pattern, options) {
  19660. return new Minimatch(pattern, options || {}).makeRe();
  19661. };
  19662. Minimatch.prototype.makeRe = makeRe;
  19663. function makeRe() {
  19664. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  19665. // pattern strings, or "**".
  19666. //
  19667. // It's better to use .match(). This function shouldn't
  19668. // be used, really, but it's pretty convenient sometimes,
  19669. // when you just want to work with a regex.
  19670. var set = this.set;
  19671. if (!set.length) return this.regexp = false;
  19672. var options = this.options;
  19673. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot,
  19674. flags = options.nocase ? "i" : "";
  19675. var re = set.map(function (pattern) {
  19676. return pattern.map(function (p) {
  19677. return p === GLOBSTAR ? twoStar : typeof p === "string" ? regExpEscape(p) : p._src;
  19678. }).join("\\\/");
  19679. }).join("|"); // must match entire pattern
  19680. // ending in a * or ** will make it less strict.
  19681. re = "^(?:" + re + ")$"; // can match anything, as long as it's not this.
  19682. if (this.negate) re = "^(?!" + re + ").*$";
  19683. try {
  19684. return this.regexp = new RegExp(re, flags);
  19685. } catch (ex) {
  19686. return this.regexp = false;
  19687. }
  19688. }
  19689. minimatch.match = function (list, pattern, options) {
  19690. var mm = new Minimatch(pattern, options);
  19691. list = list.filter(function (f) {
  19692. return mm.match(f);
  19693. });
  19694. if (options.nonull && !list.length) {
  19695. list.push(pattern);
  19696. }
  19697. return list;
  19698. };
  19699. Minimatch.prototype.match = match;
  19700. function match(f, partial) {
  19701. // console.error("match", f, this.pattern)
  19702. // short-circuit in the case of busted things.
  19703. // comments, etc.
  19704. if (this.comment) return false;
  19705. if (this.empty) return f === "";
  19706. if (f === "/" && partial) return true;
  19707. var options = this.options; // windows: need to use /, not \
  19708. // On other platforms, \ is a valid (albeit bad) filename char.
  19709. if (platform === "win32") {
  19710. f = f.split("\\").join("/");
  19711. } // treat the test path as a set of pathparts.
  19712. f = f.split(slashSplit);
  19713. if (options.debug) {
  19714. console.error(this.pattern, "split", f);
  19715. } // just ONE of the pattern sets in this.set needs to match
  19716. // in order for it to be valid. If negating, then just one
  19717. // match means that we have failed.
  19718. // Either way, return on the first hit.
  19719. var set = this.set; // console.error(this.pattern, "set", set)
  19720. for (var i = 0, l = set.length; i < l; i++) {
  19721. var pattern = set[i];
  19722. var hit = this.matchOne(f, pattern, partial);
  19723. if (hit) {
  19724. if (options.flipNegate) return true;
  19725. return !this.negate;
  19726. }
  19727. } // didn't get any hits. this is success if it's a negative
  19728. // pattern, failure otherwise.
  19729. if (options.flipNegate) return false;
  19730. return this.negate;
  19731. } // set partial to true to test if, for example,
  19732. // "/a/b" matches the start of "/*/b/*/d"
  19733. // Partial means, if you run out of file before you run
  19734. // out of pattern, then that's fine, as long as all
  19735. // the parts match.
  19736. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  19737. var options = this.options;
  19738. if (options.debug) {
  19739. console.error("matchOne", {
  19740. "this": this,
  19741. file: file,
  19742. pattern: pattern
  19743. });
  19744. }
  19745. if (options.matchBase && pattern.length === 1) {
  19746. file = path__default['default'].basename(file.join("/")).split("/");
  19747. }
  19748. if (options.debug) {
  19749. console.error("matchOne", file.length, pattern.length);
  19750. }
  19751. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  19752. if (options.debug) {
  19753. console.error("matchOne loop");
  19754. }
  19755. var p = pattern[pi],
  19756. f = file[fi];
  19757. if (options.debug) {
  19758. console.error(pattern, p, f);
  19759. } // should be impossible.
  19760. // some invalid regexp stuff in the set.
  19761. if (p === false) return false;
  19762. if (p === GLOBSTAR) {
  19763. if (options.debug) console.error('GLOBSTAR', [pattern, p, f]); // "**"
  19764. // a/**/b/**/c would match the following:
  19765. // a/b/x/y/z/c
  19766. // a/x/y/z/b/c
  19767. // a/b/x/b/x/c
  19768. // a/b/c
  19769. // To do this, take the rest of the pattern after
  19770. // the **, and see if it would match the file remainder.
  19771. // If so, return success.
  19772. // If not, the ** "swallows" a segment, and try again.
  19773. // This is recursively awful.
  19774. //
  19775. // a/**/b/**/c matching a/b/x/y/z/c
  19776. // - a matches a
  19777. // - doublestar
  19778. // - matchOne(b/x/y/z/c, b/**/c)
  19779. // - b matches b
  19780. // - doublestar
  19781. // - matchOne(x/y/z/c, c) -> no
  19782. // - matchOne(y/z/c, c) -> no
  19783. // - matchOne(z/c, c) -> no
  19784. // - matchOne(c, c) yes, hit
  19785. var fr = fi,
  19786. pr = pi + 1;
  19787. if (pr === pl) {
  19788. if (options.debug) console.error('** at the end'); // a ** at the end will just swallow the rest.
  19789. // We have found a match.
  19790. // however, it will not swallow /.x, unless
  19791. // options.dot is set.
  19792. // . and .. are *never* matched by **, for explosively
  19793. // exponential reasons.
  19794. for (; fi < fl; fi++) {
  19795. if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".") return false;
  19796. }
  19797. return true;
  19798. } // ok, let's see if we can swallow whatever we can.
  19799. WHILE: while (fr < fl) {
  19800. var swallowee = file[fr];
  19801. if (options.debug) {
  19802. console.error('\nglobstar while', file, fr, pattern, pr, swallowee);
  19803. } // XXX remove this slice. Just pass the start index.
  19804. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  19805. if (options.debug) console.error('globstar found match!', fr, fl, swallowee); // found a match.
  19806. return true;
  19807. } else {
  19808. // can't swallow "." or ".." ever.
  19809. // can only swallow ".foo" when explicitly asked.
  19810. if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
  19811. if (options.debug) console.error("dot detected!", file, fr, pattern, pr);
  19812. break WHILE;
  19813. } // ** swallows a segment, and continue.
  19814. if (options.debug) console.error('globstar swallow a segment, and continue');
  19815. fr++;
  19816. }
  19817. } // no match was found.
  19818. // However, in partial mode, we can't say this is necessarily over.
  19819. // If there's more *pattern* left, then
  19820. if (partial) {
  19821. // ran out of file
  19822. // console.error("\n>>> no match, partial?", file, fr, pattern, pr)
  19823. if (fr === fl) return true;
  19824. }
  19825. return false;
  19826. } // something other than **
  19827. // non-magic patterns just have to match exactly
  19828. // patterns with magic have been turned into regexps.
  19829. var hit;
  19830. if (typeof p === "string") {
  19831. if (options.nocase) {
  19832. hit = f.toLowerCase() === p.toLowerCase();
  19833. } else {
  19834. hit = f === p;
  19835. }
  19836. if (options.debug) {
  19837. console.error("string match", p, f, hit);
  19838. }
  19839. } else {
  19840. hit = f.match(p);
  19841. if (options.debug) {
  19842. console.error("pattern match", p, f, hit);
  19843. }
  19844. }
  19845. if (!hit) return false;
  19846. } // Note: ending in / means that we'll get a final ""
  19847. // at the end of the pattern. This can only match a
  19848. // corresponding "" at the end of the file.
  19849. // If the file ends in /, then it can only match a
  19850. // a pattern that ends in /, unless the pattern just
  19851. // doesn't have any more for it. But, a/b/ should *not*
  19852. // match "a/b/*", even though "" matches against the
  19853. // [^/]*? pattern, except in partial mode, where it might
  19854. // simply not be reached yet.
  19855. // However, a/b/ should still satisfy a/*
  19856. // now either we fell off the end of the pattern, or we're done.
  19857. if (fi === fl && pi === pl) {
  19858. // ran out of pattern and filename at the same time.
  19859. // an exact hit!
  19860. return true;
  19861. } else if (fi === fl) {
  19862. // ran out of file, but still had pattern left.
  19863. // this is ok if we're doing the match as part of
  19864. // a glob fs traversal.
  19865. return partial;
  19866. } else if (pi === pl) {
  19867. // ran out of pattern, still have file left.
  19868. // this is only acceptable if we're on the very last
  19869. // empty segment of a file with a trailing slash.
  19870. // a/* should match a/b/
  19871. var emptyFileEnd = fi === fl - 1 && file[fi] === "";
  19872. return emptyFileEnd;
  19873. } // should be unreachable.
  19874. throw new Error("wtf?");
  19875. }; // replace stuff like \* with *
  19876. function globUnescape(s) {
  19877. return s.replace(/\\(.)/g, "$1");
  19878. }
  19879. function regExpEscape(s) {
  19880. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
  19881. }
  19882. });
  19883. var ini = createCommonjsModule(function (module, exports) {
  19884. var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
  19885. return new (P || (P = Promise))(function (resolve, reject) {
  19886. function fulfilled(value) {
  19887. try {
  19888. step(generator.next(value));
  19889. } catch (e) {
  19890. reject(e);
  19891. }
  19892. }
  19893. function rejected(value) {
  19894. try {
  19895. step(generator["throw"](value));
  19896. } catch (e) {
  19897. reject(e);
  19898. }
  19899. }
  19900. function step(result) {
  19901. result.done ? resolve(result.value) : new P(function (resolve) {
  19902. resolve(result.value);
  19903. }).then(fulfilled, rejected);
  19904. }
  19905. step((generator = generator.apply(thisArg, _arguments || [])).next());
  19906. });
  19907. };
  19908. var __generator = this && this.__generator || function (thisArg, body) {
  19909. var _ = {
  19910. label: 0,
  19911. sent: function () {
  19912. if (t[0] & 1) throw t[1];
  19913. return t[1];
  19914. },
  19915. trys: [],
  19916. ops: []
  19917. },
  19918. f,
  19919. y,
  19920. t,
  19921. g;
  19922. return g = {
  19923. next: verb(0),
  19924. "throw": verb(1),
  19925. "return": verb(2)
  19926. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  19927. return this;
  19928. }), g;
  19929. function verb(n) {
  19930. return function (v) {
  19931. return step([n, v]);
  19932. };
  19933. }
  19934. function step(op) {
  19935. if (f) throw new TypeError("Generator is already executing.");
  19936. while (_) try {
  19937. 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;
  19938. if (y = 0, t) op = [op[0] & 2, t.value];
  19939. switch (op[0]) {
  19940. case 0:
  19941. case 1:
  19942. t = op;
  19943. break;
  19944. case 4:
  19945. _.label++;
  19946. return {
  19947. value: op[1],
  19948. done: false
  19949. };
  19950. case 5:
  19951. _.label++;
  19952. y = op[1];
  19953. op = [0];
  19954. continue;
  19955. case 7:
  19956. op = _.ops.pop();
  19957. _.trys.pop();
  19958. continue;
  19959. default:
  19960. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  19961. _ = 0;
  19962. continue;
  19963. }
  19964. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  19965. _.label = op[1];
  19966. break;
  19967. }
  19968. if (op[0] === 6 && _.label < t[1]) {
  19969. _.label = t[1];
  19970. t = op;
  19971. break;
  19972. }
  19973. if (t && _.label < t[2]) {
  19974. _.label = t[2];
  19975. _.ops.push(op);
  19976. break;
  19977. }
  19978. if (t[2]) _.ops.pop();
  19979. _.trys.pop();
  19980. continue;
  19981. }
  19982. op = body.call(thisArg, _);
  19983. } catch (e) {
  19984. op = [6, e];
  19985. y = 0;
  19986. } finally {
  19987. f = t = 0;
  19988. }
  19989. if (op[0] & 5) throw op[1];
  19990. return {
  19991. value: op[0] ? op[1] : void 0,
  19992. done: true
  19993. };
  19994. }
  19995. };
  19996. var __importStar = this && this.__importStar || function (mod) {
  19997. if (mod && mod.__esModule) return mod;
  19998. var result = {};
  19999. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  20000. result["default"] = mod;
  20001. return result;
  20002. };
  20003. Object.defineProperty(exports, "__esModule", {
  20004. value: true
  20005. });
  20006. var fs = __importStar(fs__default['default']);
  20007. /**
  20008. * define the possible values:
  20009. * section: [section]
  20010. * param: key=value
  20011. * comment: ;this is a comment
  20012. */
  20013. var regex = {
  20014. section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
  20015. param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
  20016. comment: /^\s*[#;].*$/
  20017. };
  20018. /**
  20019. * Parses an .ini file
  20020. * @param file The location of the .ini file
  20021. */
  20022. function parse(file) {
  20023. return __awaiter(this, void 0, void 0, function () {
  20024. return __generator(this, function (_a) {
  20025. return [2
  20026. /*return*/
  20027. , new Promise(function (resolve, reject) {
  20028. fs.readFile(file, 'utf8', function (err, data) {
  20029. if (err) {
  20030. reject(err);
  20031. return;
  20032. }
  20033. resolve(parseString(data));
  20034. });
  20035. })];
  20036. });
  20037. });
  20038. }
  20039. exports.parse = parse;
  20040. function parseSync(file) {
  20041. return parseString(fs.readFileSync(file, 'utf8'));
  20042. }
  20043. exports.parseSync = parseSync;
  20044. function parseString(data) {
  20045. var sectionBody = {};
  20046. var sectionName = null;
  20047. var value = [[sectionName, sectionBody]];
  20048. var lines = data.split(/\r\n|\r|\n/);
  20049. lines.forEach(function (line) {
  20050. var match;
  20051. if (regex.comment.test(line)) {
  20052. return;
  20053. }
  20054. if (regex.param.test(line)) {
  20055. match = line.match(regex.param);
  20056. sectionBody[match[1]] = match[2];
  20057. } else if (regex.section.test(line)) {
  20058. match = line.match(regex.section);
  20059. sectionName = match[1];
  20060. sectionBody = {};
  20061. value.push([sectionName, sectionBody]);
  20062. }
  20063. });
  20064. return value;
  20065. }
  20066. exports.parseString = parseString;
  20067. });
  20068. var name$1 = "editorconfig";
  20069. var version$1 = "0.15.3";
  20070. var description$1 = "EditorConfig File Locator and Interpreter for Node.js";
  20071. var keywords = [
  20072. "editorconfig",
  20073. "core"
  20074. ];
  20075. var main$1 = "src/index.js";
  20076. var contributors = [
  20077. "Hong Xu (topbug.net)",
  20078. "Jed Mao (https://github.com/jedmao/)",
  20079. "Trey Hunner (http://treyhunner.com)"
  20080. ];
  20081. var directories = {
  20082. bin: "./bin",
  20083. lib: "./lib"
  20084. };
  20085. var scripts$1 = {
  20086. clean: "rimraf dist",
  20087. prebuild: "npm run clean",
  20088. build: "tsc",
  20089. pretest: "npm run lint && npm run build && npm run copy && cmake .",
  20090. test: "ctest .",
  20091. "pretest:ci": "npm run pretest",
  20092. "test:ci": "ctest -VV --output-on-failure .",
  20093. lint: "npm run eclint && npm run tslint",
  20094. eclint: "eclint check --indent_size ignore \"src/**\"",
  20095. tslint: "tslint --project tsconfig.json --exclude package.json",
  20096. copy: "cpy .npmignore LICENSE README.md CHANGELOG.md dist && cpy bin/* dist/bin && cpy src/lib/fnmatch*.* dist/src/lib",
  20097. prepub: "npm run lint && npm run build && npm run copy",
  20098. pub: "npm publish ./dist"
  20099. };
  20100. var repository$1 = {
  20101. type: "git",
  20102. url: "git://github.com/editorconfig/editorconfig-core-js.git"
  20103. };
  20104. var bugs = "https://github.com/editorconfig/editorconfig-core-js/issues";
  20105. var author$1 = "EditorConfig Team";
  20106. var license$1 = "MIT";
  20107. var dependencies$1 = {
  20108. commander: "^2.19.0",
  20109. "lru-cache": "^4.1.5",
  20110. semver: "^5.6.0",
  20111. sigmund: "^1.0.1"
  20112. };
  20113. var devDependencies$1 = {
  20114. "@types/mocha": "^5.2.6",
  20115. "@types/node": "^10.12.29",
  20116. "@types/semver": "^5.5.0",
  20117. "cpy-cli": "^2.0.0",
  20118. eclint: "^2.8.1",
  20119. mocha: "^5.2.0",
  20120. rimraf: "^2.6.3",
  20121. should: "^13.2.3",
  20122. tslint: "^5.13.1",
  20123. typescript: "^3.3.3333"
  20124. };
  20125. var _package$2 = {
  20126. name: name$1,
  20127. version: version$1,
  20128. description: description$1,
  20129. keywords: keywords,
  20130. main: main$1,
  20131. contributors: contributors,
  20132. directories: directories,
  20133. scripts: scripts$1,
  20134. repository: repository$1,
  20135. bugs: bugs,
  20136. author: author$1,
  20137. license: license$1,
  20138. dependencies: dependencies$1,
  20139. devDependencies: devDependencies$1
  20140. };
  20141. var _package$3 = /*#__PURE__*/Object.freeze({
  20142. __proto__: null,
  20143. name: name$1,
  20144. version: version$1,
  20145. description: description$1,
  20146. keywords: keywords,
  20147. main: main$1,
  20148. contributors: contributors,
  20149. directories: directories,
  20150. scripts: scripts$1,
  20151. repository: repository$1,
  20152. bugs: bugs,
  20153. author: author$1,
  20154. license: license$1,
  20155. dependencies: dependencies$1,
  20156. devDependencies: devDependencies$1,
  20157. 'default': _package$2
  20158. });
  20159. var require$$4 = getCjsExportFromNamespace(_package$3);
  20160. var src = createCommonjsModule(function (module, exports) {
  20161. var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
  20162. return new (P || (P = Promise))(function (resolve, reject) {
  20163. function fulfilled(value) {
  20164. try {
  20165. step(generator.next(value));
  20166. } catch (e) {
  20167. reject(e);
  20168. }
  20169. }
  20170. function rejected(value) {
  20171. try {
  20172. step(generator["throw"](value));
  20173. } catch (e) {
  20174. reject(e);
  20175. }
  20176. }
  20177. function step(result) {
  20178. result.done ? resolve(result.value) : new P(function (resolve) {
  20179. resolve(result.value);
  20180. }).then(fulfilled, rejected);
  20181. }
  20182. step((generator = generator.apply(thisArg, _arguments || [])).next());
  20183. });
  20184. };
  20185. var __generator = this && this.__generator || function (thisArg, body) {
  20186. var _ = {
  20187. label: 0,
  20188. sent: function () {
  20189. if (t[0] & 1) throw t[1];
  20190. return t[1];
  20191. },
  20192. trys: [],
  20193. ops: []
  20194. },
  20195. f,
  20196. y,
  20197. t,
  20198. g;
  20199. return g = {
  20200. next: verb(0),
  20201. "throw": verb(1),
  20202. "return": verb(2)
  20203. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  20204. return this;
  20205. }), g;
  20206. function verb(n) {
  20207. return function (v) {
  20208. return step([n, v]);
  20209. };
  20210. }
  20211. function step(op) {
  20212. if (f) throw new TypeError("Generator is already executing.");
  20213. while (_) try {
  20214. 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;
  20215. if (y = 0, t) op = [op[0] & 2, t.value];
  20216. switch (op[0]) {
  20217. case 0:
  20218. case 1:
  20219. t = op;
  20220. break;
  20221. case 4:
  20222. _.label++;
  20223. return {
  20224. value: op[1],
  20225. done: false
  20226. };
  20227. case 5:
  20228. _.label++;
  20229. y = op[1];
  20230. op = [0];
  20231. continue;
  20232. case 7:
  20233. op = _.ops.pop();
  20234. _.trys.pop();
  20235. continue;
  20236. default:
  20237. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  20238. _ = 0;
  20239. continue;
  20240. }
  20241. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  20242. _.label = op[1];
  20243. break;
  20244. }
  20245. if (op[0] === 6 && _.label < t[1]) {
  20246. _.label = t[1];
  20247. t = op;
  20248. break;
  20249. }
  20250. if (t && _.label < t[2]) {
  20251. _.label = t[2];
  20252. _.ops.push(op);
  20253. break;
  20254. }
  20255. if (t[2]) _.ops.pop();
  20256. _.trys.pop();
  20257. continue;
  20258. }
  20259. op = body.call(thisArg, _);
  20260. } catch (e) {
  20261. op = [6, e];
  20262. y = 0;
  20263. } finally {
  20264. f = t = 0;
  20265. }
  20266. if (op[0] & 5) throw op[1];
  20267. return {
  20268. value: op[0] ? op[1] : void 0,
  20269. done: true
  20270. };
  20271. }
  20272. };
  20273. var __importStar = this && this.__importStar || function (mod) {
  20274. if (mod && mod.__esModule) return mod;
  20275. var result = {};
  20276. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  20277. result["default"] = mod;
  20278. return result;
  20279. };
  20280. var __importDefault = this && this.__importDefault || function (mod) {
  20281. return mod && mod.__esModule ? mod : {
  20282. "default": mod
  20283. };
  20284. };
  20285. Object.defineProperty(exports, "__esModule", {
  20286. value: true
  20287. });
  20288. var fs = __importStar(fs__default['default']);
  20289. var path = __importStar(path__default['default']);
  20290. var semver = __importStar(semver$2);
  20291. var fnmatch_1 = __importDefault(fnmatch);
  20292. exports.parseString = ini.parseString;
  20293. var package_json_1 = __importDefault(require$$4);
  20294. var knownProps = {
  20295. end_of_line: true,
  20296. indent_style: true,
  20297. indent_size: true,
  20298. insert_final_newline: true,
  20299. trim_trailing_whitespace: true,
  20300. charset: true
  20301. };
  20302. function fnmatch$1(filepath, glob) {
  20303. var matchOptions = {
  20304. matchBase: true,
  20305. dot: true,
  20306. noext: true
  20307. };
  20308. glob = glob.replace(/\*\*/g, '{*,**/**/**}');
  20309. return fnmatch_1.default(filepath, glob, matchOptions);
  20310. }
  20311. function getConfigFileNames(filepath, options) {
  20312. var paths = [];
  20313. do {
  20314. filepath = path.dirname(filepath);
  20315. paths.push(path.join(filepath, options.config));
  20316. } while (filepath !== options.root);
  20317. return paths;
  20318. }
  20319. function processMatches(matches, version) {
  20320. // Set indent_size to 'tab' if indent_size is unspecified and
  20321. // indent_style is set to 'tab'.
  20322. if ('indent_style' in matches && matches.indent_style === 'tab' && !('indent_size' in matches) && semver.gte(version, '0.10.0')) {
  20323. matches.indent_size = 'tab';
  20324. } // Set tab_width to indent_size if indent_size is specified and
  20325. // tab_width is unspecified
  20326. if ('indent_size' in matches && !('tab_width' in matches) && matches.indent_size !== 'tab') {
  20327. matches.tab_width = matches.indent_size;
  20328. } // Set indent_size to tab_width if indent_size is 'tab'
  20329. if ('indent_size' in matches && 'tab_width' in matches && matches.indent_size === 'tab') {
  20330. matches.indent_size = matches.tab_width;
  20331. }
  20332. return matches;
  20333. }
  20334. function processOptions(options, filepath) {
  20335. if (options === void 0) {
  20336. options = {};
  20337. }
  20338. return {
  20339. config: options.config || '.editorconfig',
  20340. version: options.version || package_json_1.default.version,
  20341. root: path.resolve(options.root || path.parse(filepath).root)
  20342. };
  20343. }
  20344. function buildFullGlob(pathPrefix, glob) {
  20345. switch (glob.indexOf('/')) {
  20346. case -1:
  20347. glob = '**/' + glob;
  20348. break;
  20349. case 0:
  20350. glob = glob.substring(1);
  20351. break;
  20352. }
  20353. return path.join(pathPrefix, glob);
  20354. }
  20355. function extendProps(props, options) {
  20356. if (props === void 0) {
  20357. props = {};
  20358. }
  20359. if (options === void 0) {
  20360. options = {};
  20361. }
  20362. for (var key in options) {
  20363. if (options.hasOwnProperty(key)) {
  20364. var value = options[key];
  20365. var key2 = key.toLowerCase();
  20366. var value2 = value;
  20367. if (knownProps[key2]) {
  20368. value2 = value.toLowerCase();
  20369. }
  20370. try {
  20371. value2 = JSON.parse(value);
  20372. } catch (e) {}
  20373. if (typeof value === 'undefined' || value === null) {
  20374. // null and undefined are values specific to JSON (no special meaning
  20375. // in editorconfig) & should just be returned as regular strings.
  20376. value2 = String(value);
  20377. }
  20378. props[key2] = value2;
  20379. }
  20380. }
  20381. return props;
  20382. }
  20383. function parseFromConfigs(configs, filepath, options) {
  20384. return processMatches(configs.reverse().reduce(function (matches, file) {
  20385. var pathPrefix = path.dirname(file.name);
  20386. file.contents.forEach(function (section) {
  20387. var glob = section[0];
  20388. var options2 = section[1];
  20389. if (!glob) {
  20390. return;
  20391. }
  20392. var fullGlob = buildFullGlob(pathPrefix, glob);
  20393. if (!fnmatch$1(filepath, fullGlob)) {
  20394. return;
  20395. }
  20396. matches = extendProps(matches, options2);
  20397. });
  20398. return matches;
  20399. }, {}), options.version);
  20400. }
  20401. function getConfigsForFiles(files) {
  20402. var configs = [];
  20403. for (var i in files) {
  20404. if (files.hasOwnProperty(i)) {
  20405. var file = files[i];
  20406. var contents = ini.parseString(file.contents);
  20407. configs.push({
  20408. name: file.name,
  20409. contents: contents
  20410. });
  20411. if ((contents[0][1].root || '').toLowerCase() === 'true') {
  20412. break;
  20413. }
  20414. }
  20415. }
  20416. return configs;
  20417. }
  20418. function readConfigFiles(filepaths) {
  20419. return __awaiter(this, void 0, void 0, function () {
  20420. return __generator(this, function (_a) {
  20421. return [2
  20422. /*return*/
  20423. , Promise.all(filepaths.map(function (name) {
  20424. return new Promise(function (resolve) {
  20425. fs.readFile(name, 'utf8', function (err, data) {
  20426. resolve({
  20427. name: name,
  20428. contents: err ? '' : data
  20429. });
  20430. });
  20431. });
  20432. }))];
  20433. });
  20434. });
  20435. }
  20436. function readConfigFilesSync(filepaths) {
  20437. var files = [];
  20438. var file;
  20439. filepaths.forEach(function (filepath) {
  20440. try {
  20441. file = fs.readFileSync(filepath, 'utf8');
  20442. } catch (e) {
  20443. file = '';
  20444. }
  20445. files.push({
  20446. name: filepath,
  20447. contents: file
  20448. });
  20449. });
  20450. return files;
  20451. }
  20452. function opts(filepath, options) {
  20453. if (options === void 0) {
  20454. options = {};
  20455. }
  20456. var resolvedFilePath = path.resolve(filepath);
  20457. return [resolvedFilePath, processOptions(options, resolvedFilePath)];
  20458. }
  20459. function parseFromFiles(filepath, files, options) {
  20460. if (options === void 0) {
  20461. options = {};
  20462. }
  20463. return __awaiter(this, void 0, void 0, function () {
  20464. var _a, resolvedFilePath, processedOptions;
  20465. return __generator(this, function (_b) {
  20466. _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
  20467. return [2
  20468. /*return*/
  20469. , files.then(getConfigsForFiles).then(function (configs) {
  20470. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  20471. })];
  20472. });
  20473. });
  20474. }
  20475. exports.parseFromFiles = parseFromFiles;
  20476. function parseFromFilesSync(filepath, files, options) {
  20477. if (options === void 0) {
  20478. options = {};
  20479. }
  20480. var _a = opts(filepath, options),
  20481. resolvedFilePath = _a[0],
  20482. processedOptions = _a[1];
  20483. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  20484. }
  20485. exports.parseFromFilesSync = parseFromFilesSync;
  20486. function parse(_filepath, _options) {
  20487. if (_options === void 0) {
  20488. _options = {};
  20489. }
  20490. return __awaiter(this, void 0, void 0, function () {
  20491. var _a, resolvedFilePath, processedOptions, filepaths;
  20492. return __generator(this, function (_b) {
  20493. _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
  20494. filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  20495. return [2
  20496. /*return*/
  20497. , readConfigFiles(filepaths).then(getConfigsForFiles).then(function (configs) {
  20498. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  20499. })];
  20500. });
  20501. });
  20502. }
  20503. exports.parse = parse;
  20504. function parseSync(_filepath, _options) {
  20505. if (_options === void 0) {
  20506. _options = {};
  20507. }
  20508. var _a = opts(_filepath, _options),
  20509. resolvedFilePath = _a[0],
  20510. processedOptions = _a[1];
  20511. var filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  20512. var files = readConfigFilesSync(filepaths);
  20513. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  20514. }
  20515. exports.parseSync = parseSync;
  20516. });
  20517. var editorconfigToPrettier = editorConfigToPrettier;
  20518. function removeUnset(editorConfig) {
  20519. const result = {};
  20520. const keys = Object.keys(editorConfig);
  20521. for (let i = 0; i < keys.length; i++) {
  20522. const key = keys[i];
  20523. if (editorConfig[key] === "unset") {
  20524. continue;
  20525. }
  20526. result[key] = editorConfig[key];
  20527. }
  20528. return result;
  20529. }
  20530. function editorConfigToPrettier(editorConfig) {
  20531. if (!editorConfig) {
  20532. return null;
  20533. }
  20534. editorConfig = removeUnset(editorConfig);
  20535. if (Object.keys(editorConfig).length === 0) {
  20536. return null;
  20537. }
  20538. const result = {};
  20539. if (editorConfig.indent_style) {
  20540. result.useTabs = editorConfig.indent_style === "tab";
  20541. }
  20542. if (editorConfig.indent_size === "tab") {
  20543. result.useTabs = true;
  20544. }
  20545. if (result.useTabs && editorConfig.tab_width) {
  20546. result.tabWidth = editorConfig.tab_width;
  20547. } else if (editorConfig.indent_style === "space" && editorConfig.indent_size && editorConfig.indent_size !== "tab") {
  20548. result.tabWidth = editorConfig.indent_size;
  20549. } else if (editorConfig.tab_width !== undefined) {
  20550. result.tabWidth = editorConfig.tab_width;
  20551. }
  20552. if (editorConfig.max_line_length && editorConfig.max_line_length !== "off") {
  20553. result.printWidth = editorConfig.max_line_length;
  20554. }
  20555. if (editorConfig.quote_type === "single") {
  20556. result.singleQuote = true;
  20557. } else if (editorConfig.quote_type === "double") {
  20558. result.singleQuote = false;
  20559. }
  20560. if (["cr", "crlf", "lf"].indexOf(editorConfig.end_of_line) !== -1) {
  20561. result.endOfLine = editorConfig.end_of_line;
  20562. }
  20563. return result;
  20564. }
  20565. // https://github.com/kirstein/find-project-root/blob/master/index.js
  20566. const MARKERS = [".git", ".hg"];
  20567. const markerExists = directory => MARKERS.some(mark => fs__default['default'].existsSync(path__default['default'].join(directory, mark)));
  20568. function findProjectRoot(directory) {
  20569. while (!markerExists(directory)) {
  20570. const parentDirectory = path__default['default'].resolve(directory, "..");
  20571. if (parentDirectory === directory) {
  20572. break;
  20573. }
  20574. directory = parentDirectory;
  20575. }
  20576. return directory;
  20577. }
  20578. var findProjectRoot_1 = findProjectRoot;
  20579. const jsonStringifyMem = fn => mem_1(fn, {
  20580. cacheKey: JSON.stringify
  20581. });
  20582. const maybeParse = (filePath, parse) => filePath && parse(filePath, {
  20583. root: findProjectRoot_1(path__default['default'].dirname(path__default['default'].resolve(filePath)))
  20584. });
  20585. const editorconfigAsyncNoCache = async (filePath) => editorconfigToPrettier(await maybeParse(filePath, src.parse));
  20586. const editorconfigAsyncWithCache = jsonStringifyMem(editorconfigAsyncNoCache);
  20587. const editorconfigSyncNoCache = filePath => editorconfigToPrettier(maybeParse(filePath, src.parseSync));
  20588. const editorconfigSyncWithCache = jsonStringifyMem(editorconfigSyncNoCache);
  20589. function getLoadFunction(opts) {
  20590. if (!opts.editorconfig) {
  20591. return () => null;
  20592. }
  20593. if (opts.sync) {
  20594. return opts.cache ? editorconfigSyncWithCache : editorconfigSyncNoCache;
  20595. }
  20596. return opts.cache ? editorconfigAsyncWithCache : editorconfigAsyncNoCache;
  20597. }
  20598. function clearCache() {
  20599. mem_1.clear(editorconfigSyncWithCache);
  20600. mem_1.clear(editorconfigAsyncWithCache);
  20601. }
  20602. var resolveConfigEditorconfig = {
  20603. getLoadFunction,
  20604. clearCache
  20605. };
  20606. const getExplorerMemoized = mem_1(opts => {
  20607. const cosmiconfig = thirdParty["cosmiconfig" + (opts.sync ? "Sync" : "")];
  20608. const explorer = cosmiconfig("prettier", {
  20609. cache: opts.cache,
  20610. transform: result => {
  20611. if (result && result.config) {
  20612. if (typeof result.config === "string") {
  20613. const dir = path__default['default'].dirname(result.filepath);
  20614. const modulePath = resolve_1(result.config, {
  20615. paths: [dir]
  20616. });
  20617. result.config = require(modulePath);
  20618. }
  20619. if (typeof result.config !== "object") {
  20620. throw new Error("Config is only allowed to be an object, " + `but received ${typeof result.config} in "${result.filepath}"`);
  20621. }
  20622. delete result.config.$schema;
  20623. }
  20624. return result;
  20625. },
  20626. searchPlaces: ["package.json", ".prettierrc", ".prettierrc.json", ".prettierrc.yaml", ".prettierrc.yml", ".prettierrc.json5", ".prettierrc.js", ".prettierrc.cjs", "prettier.config.js", "prettier.config.cjs", ".prettierrc.toml"],
  20627. loaders: {
  20628. ".toml": loadToml,
  20629. ".json5": loadJson5
  20630. }
  20631. });
  20632. return explorer;
  20633. }, {
  20634. cacheKey: JSON.stringify
  20635. });
  20636. /** @param {{ cache: boolean, sync: boolean }} opts */
  20637. function getExplorer(opts) {
  20638. // Normalize opts before passing to a memoized function
  20639. opts = Object.assign({
  20640. sync: false,
  20641. cache: false
  20642. }, opts);
  20643. return getExplorerMemoized(opts);
  20644. }
  20645. function _resolveConfig(filePath, opts, sync) {
  20646. opts = Object.assign({
  20647. useCache: true
  20648. }, opts);
  20649. const loadOpts = {
  20650. cache: !!opts.useCache,
  20651. sync: !!sync,
  20652. editorconfig: !!opts.editorconfig
  20653. };
  20654. const {
  20655. load,
  20656. search
  20657. } = getExplorer(loadOpts);
  20658. const loadEditorConfig = resolveConfigEditorconfig.getLoadFunction(loadOpts);
  20659. const arr = [opts.config ? load(opts.config) : search(filePath), loadEditorConfig(filePath)];
  20660. const unwrapAndMerge = ([result, editorConfigured]) => {
  20661. const merged = Object.assign({}, editorConfigured, mergeOverrides(result, filePath));
  20662. ["plugins", "pluginSearchDirs"].forEach(optionName => {
  20663. if (Array.isArray(merged[optionName])) {
  20664. merged[optionName] = merged[optionName].map(value => typeof value === "string" && value.startsWith(".") // relative path
  20665. ? path__default['default'].resolve(path__default['default'].dirname(result.filepath), value) : value);
  20666. }
  20667. });
  20668. if (!result && !editorConfigured) {
  20669. return null;
  20670. }
  20671. return merged;
  20672. };
  20673. if (loadOpts.sync) {
  20674. return unwrapAndMerge(arr);
  20675. }
  20676. return Promise.all(arr).then(unwrapAndMerge);
  20677. }
  20678. const resolveConfig = (filePath, opts) => _resolveConfig(filePath, opts, false);
  20679. resolveConfig.sync = (filePath, opts) => _resolveConfig(filePath, opts, true);
  20680. function clearCache$1() {
  20681. mem_1.clear(getExplorerMemoized);
  20682. resolveConfigEditorconfig.clearCache();
  20683. }
  20684. async function resolveConfigFile(filePath) {
  20685. const {
  20686. search
  20687. } = getExplorer({
  20688. sync: false
  20689. });
  20690. const result = await search(filePath);
  20691. return result ? result.filepath : null;
  20692. }
  20693. resolveConfigFile.sync = filePath => {
  20694. const {
  20695. search
  20696. } = getExplorer({
  20697. sync: true
  20698. });
  20699. const result = search(filePath);
  20700. return result ? result.filepath : null;
  20701. };
  20702. function mergeOverrides(configResult, filePath) {
  20703. const {
  20704. config,
  20705. filepath: configPath
  20706. } = configResult || {};
  20707. const _ref = config || {},
  20708. {
  20709. overrides
  20710. } = _ref,
  20711. options = _objectWithoutPropertiesLoose(_ref, ["overrides"]);
  20712. if (filePath && overrides) {
  20713. const relativeFilePath = path__default['default'].relative(path__default['default'].dirname(configPath), filePath);
  20714. for (const override of overrides) {
  20715. if (pathMatchesGlobs(relativeFilePath, override.files, override.excludeFiles)) {
  20716. Object.assign(options, override.options);
  20717. }
  20718. }
  20719. }
  20720. return options;
  20721. } // Based on eslint: https://github.com/eslint/eslint/blob/master/lib/config/config-ops.js
  20722. function pathMatchesGlobs(filePath, patterns, excludedPatterns) {
  20723. const patternList = [].concat(patterns);
  20724. const excludedPatternList = [].concat(excludedPatterns || []);
  20725. const opts = {
  20726. matchBase: true,
  20727. dot: true
  20728. };
  20729. return patternList.some(pattern => minimatch_1(filePath, pattern, opts)) && !excludedPatternList.some(excludedPattern => minimatch_1(filePath, excludedPattern, opts));
  20730. }
  20731. var resolveConfig_1 = {
  20732. resolveConfig,
  20733. resolveConfigFile,
  20734. clearCache: clearCache$1
  20735. };
  20736. // A simple implementation of make-array
  20737. function make_array(subject) {
  20738. return Array.isArray(subject) ? subject : [subject];
  20739. }
  20740. const REGEX_BLANK_LINE = /^\s+$/;
  20741. const REGEX_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
  20742. const REGEX_LEADING_EXCAPED_HASH = /^\\#/;
  20743. const SLASH = '/';
  20744. const KEY_IGNORE = typeof Symbol !== 'undefined' ? Symbol.for('node-ignore')
  20745. /* istanbul ignore next */
  20746. : 'node-ignore';
  20747. const define = (object, key, value) => Object.defineProperty(object, key, {
  20748. value
  20749. });
  20750. const REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression
  20751. // The cases are complicated, see test cases for details
  20752. const sanitizeRange = range => range.replace(REGEX_REGEXP_RANGE, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match // Invalid range (out of order) which is ok for gitignore rules but
  20753. // fatal for JavaScript regular expression, so eliminate it.
  20754. : ''); // > If the pattern ends with a slash,
  20755. // > it is removed for the purpose of the following description,
  20756. // > but it would only find a match with a directory.
  20757. // > In other words, foo/ will match a directory foo and paths underneath it,
  20758. // > but will not match a regular file or a symbolic link foo
  20759. // > (this is consistent with the way how pathspec works in general in Git).
  20760. // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
  20761. // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
  20762. // you could use option `mark: true` with `glob`
  20763. // '`foo/`' should not continue with the '`..`'
  20764. const DEFAULT_REPLACER_PREFIX = [// > Trailing spaces are ignored unless they are quoted with backslash ("\")
  20765. [// (a\ ) -> (a )
  20766. // (a ) -> (a)
  20767. // (a \ ) -> (a )
  20768. /\\?\s+$/, match => match.indexOf('\\') === 0 ? ' ' : ''], // replace (\ ) with ' '
  20769. [/\\\s/g, () => ' '], // Escape metacharacters
  20770. // which is written down by users but means special for regular expressions.
  20771. // > There are 12 characters with special meanings:
  20772. // > - the backslash \,
  20773. // > - the caret ^,
  20774. // > - the dollar sign $,
  20775. // > - the period or dot .,
  20776. // > - the vertical bar or pipe symbol |,
  20777. // > - the question mark ?,
  20778. // > - the asterisk or star *,
  20779. // > - the plus sign +,
  20780. // > - the opening parenthesis (,
  20781. // > - the closing parenthesis ),
  20782. // > - and the opening square bracket [,
  20783. // > - the opening curly brace {,
  20784. // > These special characters are often called "metacharacters".
  20785. [/[\\^$.|*+(){]/g, match => `\\${match}`], [// > [abc] matches any character inside the brackets
  20786. // > (in this case a, b, or c);
  20787. /\[([^\]/]*)($|\])/g, (match, p1, p2) => p2 === ']' ? `[${sanitizeRange(p1)}]` : `\\${match}`], [// > a question mark (?) matches a single character
  20788. /(?!\\)\?/g, () => '[^/]'], // leading slash
  20789. [// > A leading slash matches the beginning of the pathname.
  20790. // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
  20791. // A leading slash matches the beginning of the pathname
  20792. /^\//, () => '^'], // replace special metacharacter slash after the leading slash
  20793. [/\//g, () => '\\/'], [// > A leading "**" followed by a slash means match in all directories.
  20794. // > For example, "**/foo" matches file or directory "foo" anywhere,
  20795. // > the same as pattern "foo".
  20796. // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
  20797. // > under directory "foo".
  20798. // Notice that the '*'s have been replaced as '\\*'
  20799. /^\^*\\\*\\\*\\\//, // '**/foo' <-> 'foo'
  20800. () => '^(?:.*\\/)?']];
  20801. const DEFAULT_REPLACER_SUFFIX = [// starting
  20802. [// there will be no leading '/'
  20803. // (which has been replaced by section "leading slash")
  20804. // If starts with '**', adding a '^' to the regular expression also works
  20805. /^(?=[^^])/, function startingReplacer() {
  20806. return !/\/(?!$)/.test(this) // > If the pattern does not contain a slash /,
  20807. // > Git treats it as a shell glob pattern
  20808. // Actually, if there is only a trailing slash,
  20809. // git also treats it as a shell glob pattern
  20810. ? '(?:^|\\/)' // > Otherwise, Git treats the pattern as a shell glob suitable for
  20811. // > consumption by fnmatch(3)
  20812. : '^';
  20813. }], // two globstars
  20814. [// Use lookahead assertions so that we could match more than one `'/**'`
  20815. /\\\/\\\*\\\*(?=\\\/|$)/g, // Zero, one or several directories
  20816. // should not use '*', or it will be replaced by the next replacer
  20817. // Check if it is not the last `'/**'`
  20818. (match, index, str) => index + 6 < str.length // case: /**/
  20819. // > A slash followed by two consecutive asterisks then a slash matches
  20820. // > zero or more directories.
  20821. // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
  20822. // '/**/'
  20823. ? '(?:\\/[^\\/]+)*' // case: /**
  20824. // > A trailing `"/**"` matches everything inside.
  20825. // #21: everything inside but it should not include the current folder
  20826. : '\\/.+'], // intermediate wildcards
  20827. [// Never replace escaped '*'
  20828. // ignore rule '\*' will match the path '*'
  20829. // 'abc.*/' -> go
  20830. // 'abc.*' -> skip this rule
  20831. /(^|[^\\]+)\\\*(?=.+)/g, // '*.js' matches '.js'
  20832. // '*.js' doesn't match 'abc'
  20833. (match, p1) => `${p1}[^\\/]*`], // trailing wildcard
  20834. [/(\^|\\\/)?\\\*$/, (match, p1) => {
  20835. const prefix = p1 // '\^':
  20836. // '/*' does not match ''
  20837. // '/*' does not match everything
  20838. // '\\\/':
  20839. // 'abc/*' does not match 'abc/'
  20840. ? `${p1}[^/]+` // 'a*' matches 'a'
  20841. // 'a*' matches 'aa'
  20842. : '[^/]*';
  20843. return `${prefix}(?=$|\\/$)`;
  20844. }], [// unescape
  20845. /\\\\\\/g, () => '\\']];
  20846. const POSITIVE_REPLACERS = [...DEFAULT_REPLACER_PREFIX, // 'f'
  20847. // matches
  20848. // - /f(end)
  20849. // - /f/
  20850. // - (start)f(end)
  20851. // - (start)f/
  20852. // doesn't match
  20853. // - oof
  20854. // - foo
  20855. // pseudo:
  20856. // -> (^|/)f(/|$)
  20857. // ending
  20858. [// 'js' will not match 'js.'
  20859. // 'ab' will not match 'abc'
  20860. /(?:[^*/])$/, // 'js*' will not match 'a.js'
  20861. // 'js/' will not match 'a.js'
  20862. // 'js' will match 'a.js' and 'a.js/'
  20863. match => `${match}(?=$|\\/)`], ...DEFAULT_REPLACER_SUFFIX];
  20864. const NEGATIVE_REPLACERS = [...DEFAULT_REPLACER_PREFIX, // #24, #38
  20865. // The MISSING rule of [gitignore docs](https://git-scm.com/docs/gitignore)
  20866. // A negative pattern without a trailing wildcard should not
  20867. // re-include the things inside that directory.
  20868. // eg:
  20869. // ['node_modules/*', '!node_modules']
  20870. // should ignore `node_modules/a.js`
  20871. [/(?:[^*])$/, match => `${match}(?=$|\\/$)`], ...DEFAULT_REPLACER_SUFFIX]; // A simple cache, because an ignore rule only has only one certain meaning
  20872. const cache = Object.create(null); // @param {pattern}
  20873. const make_regex = (pattern, negative, ignorecase) => {
  20874. const r = cache[pattern];
  20875. if (r) {
  20876. return r;
  20877. }
  20878. const replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS;
  20879. const source = replacers.reduce((prev, current) => prev.replace(current[0], current[1].bind(pattern)), pattern);
  20880. return cache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source);
  20881. }; // > A blank line matches no files, so it can serve as a separator for readability.
  20882. const checkPattern = pattern => pattern && typeof pattern === 'string' && !REGEX_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment.
  20883. && pattern.indexOf('#') !== 0;
  20884. const createRule = (pattern, ignorecase) => {
  20885. const origin = pattern;
  20886. let negative = false; // > An optional prefix "!" which negates the pattern;
  20887. if (pattern.indexOf('!') === 0) {
  20888. negative = true;
  20889. pattern = pattern.substr(1);
  20890. }
  20891. pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that
  20892. // > begin with a literal "!", for example, `"\!important!.txt"`.
  20893. .replace(REGEX_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that
  20894. // > begin with a hash.
  20895. .replace(REGEX_LEADING_EXCAPED_HASH, '#');
  20896. const regex = make_regex(pattern, negative, ignorecase);
  20897. return {
  20898. origin,
  20899. pattern,
  20900. negative,
  20901. regex
  20902. };
  20903. };
  20904. class IgnoreBase {
  20905. constructor({
  20906. ignorecase = true
  20907. } = {}) {
  20908. this._rules = [];
  20909. this._ignorecase = ignorecase;
  20910. define(this, KEY_IGNORE, true);
  20911. this._initCache();
  20912. }
  20913. _initCache() {
  20914. this._cache = Object.create(null);
  20915. } // @param {Array.<string>|string|Ignore} pattern
  20916. add(pattern) {
  20917. this._added = false;
  20918. if (typeof pattern === 'string') {
  20919. pattern = pattern.split(/\r?\n/g);
  20920. }
  20921. make_array(pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore,
  20922. // making the behavior changed.
  20923. if (this._added) {
  20924. this._initCache();
  20925. }
  20926. return this;
  20927. } // legacy
  20928. addPattern(pattern) {
  20929. return this.add(pattern);
  20930. }
  20931. _addPattern(pattern) {
  20932. // #32
  20933. if (pattern && pattern[KEY_IGNORE]) {
  20934. this._rules = this._rules.concat(pattern._rules);
  20935. this._added = true;
  20936. return;
  20937. }
  20938. if (checkPattern(pattern)) {
  20939. const rule = createRule(pattern, this._ignorecase);
  20940. this._added = true;
  20941. this._rules.push(rule);
  20942. }
  20943. }
  20944. filter(paths) {
  20945. return make_array(paths).filter(path => this._filter(path));
  20946. }
  20947. createFilter() {
  20948. return path => this._filter(path);
  20949. }
  20950. ignores(path) {
  20951. return !this._filter(path);
  20952. } // @returns `Boolean` true if the `path` is NOT ignored
  20953. _filter(path, slices) {
  20954. if (!path) {
  20955. return false;
  20956. }
  20957. if (path in this._cache) {
  20958. return this._cache[path];
  20959. }
  20960. if (!slices) {
  20961. // path/to/a.js
  20962. // ['path', 'to', 'a.js']
  20963. slices = path.split(SLASH);
  20964. }
  20965. slices.pop();
  20966. return this._cache[path] = slices.length // > It is not possible to re-include a file if a parent directory of
  20967. // > that file is excluded.
  20968. // If the path contains a parent directory, check the parent first
  20969. ? this._filter(slices.join(SLASH) + SLASH, slices) && this._test(path) // Or only test the path
  20970. : this._test(path);
  20971. } // @returns {Boolean} true if a file is NOT ignored
  20972. _test(path) {
  20973. // Explicitly define variable type by setting matched to `0`
  20974. let matched = 0;
  20975. this._rules.forEach(rule => {
  20976. // if matched = true, then we only test negative rules
  20977. // if matched = false, then we test non-negative rules
  20978. if (!(matched ^ rule.negative)) {
  20979. matched = rule.negative ^ rule.regex.test(path);
  20980. }
  20981. });
  20982. return !matched;
  20983. }
  20984. } // Windows
  20985. // --------------------------------------------------------------
  20986. /* istanbul ignore if */
  20987. if ( // Detect `process` so that it can run in browsers.
  20988. typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
  20989. const filter = IgnoreBase.prototype._filter;
  20990. /* eslint no-control-regex: "off" */
  20991. const make_posix = str => /^\\\\\?\\/.test(str) || /[^\x00-\x80]+/.test(str) ? str : str.replace(/\\/g, '/');
  20992. IgnoreBase.prototype._filter = function filterWin32(path, slices) {
  20993. path = make_posix(path);
  20994. return filter.call(this, path, slices);
  20995. };
  20996. }
  20997. var ignore = options => new IgnoreBase(options);
  20998. /**
  20999. * @param {string} filename
  21000. * @returns {Promise<null | string>}
  21001. */
  21002. function getFileContentOrNull(filename) {
  21003. return new Promise((resolve, reject) => {
  21004. fs__default['default'].readFile(filename, "utf8", (error, data) => {
  21005. if (error && error.code !== "ENOENT") {
  21006. reject(createError(filename, error));
  21007. } else {
  21008. resolve(error ? null : data);
  21009. }
  21010. });
  21011. });
  21012. }
  21013. /**
  21014. * @param {string} filename
  21015. * @returns {null | string}
  21016. */
  21017. getFileContentOrNull.sync = function (filename) {
  21018. try {
  21019. return fs__default['default'].readFileSync(filename, "utf8");
  21020. } catch (error) {
  21021. if (error && error.code === "ENOENT") {
  21022. return null;
  21023. }
  21024. throw createError(filename, error);
  21025. }
  21026. };
  21027. function createError(filename, error) {
  21028. return new Error(`Unable to read ${filename}: ${error.message}`);
  21029. }
  21030. var getFileContentOrNull_1 = getFileContentOrNull;
  21031. /**
  21032. * @param {string?} ignorePath
  21033. * @param {boolean?} withNodeModules
  21034. */
  21035. async function createIgnorer(ignorePath, withNodeModules) {
  21036. const ignoreContent = ignorePath ? await getFileContentOrNull_1(path__default['default'].resolve(ignorePath)) : null;
  21037. return _createIgnorer(ignoreContent, withNodeModules);
  21038. }
  21039. /**
  21040. * @param {string?} ignorePath
  21041. * @param {boolean?} withNodeModules
  21042. */
  21043. createIgnorer.sync = function (ignorePath, withNodeModules) {
  21044. const ignoreContent = !ignorePath ? null : getFileContentOrNull_1.sync(path__default['default'].resolve(ignorePath));
  21045. return _createIgnorer(ignoreContent, withNodeModules);
  21046. };
  21047. /**
  21048. * @param {null | string} ignoreContent
  21049. * @param {boolean?} withNodeModules
  21050. */
  21051. function _createIgnorer(ignoreContent, withNodeModules) {
  21052. const ignorer = ignore().add(ignoreContent || "");
  21053. if (!withNodeModules) {
  21054. ignorer.add("node_modules");
  21055. }
  21056. return ignorer;
  21057. }
  21058. var createIgnorer_1 = createIgnorer;
  21059. /**
  21060. * @typedef {{ ignorePath?: string, withNodeModules?: boolean, plugins: object }} FileInfoOptions
  21061. * @typedef {{ ignored: boolean, inferredParser: string | null }} FileInfoResult
  21062. */
  21063. /**
  21064. * @param {string} filePath
  21065. * @param {FileInfoOptions} opts
  21066. * @returns {Promise<FileInfoResult>}
  21067. *
  21068. * Please note that prettier.getFileInfo() expects opts.plugins to be an array of paths,
  21069. * not an object. A transformation from this array to an object is automatically done
  21070. * internally by the method wrapper. See withPlugins() in index.js.
  21071. */
  21072. async function getFileInfo(filePath, opts) {
  21073. if (typeof filePath !== "string") {
  21074. throw new TypeError(`expect \`filePath\` to be a string, got \`${typeof filePath}\``);
  21075. }
  21076. const ignorer = await createIgnorer_1(opts.ignorePath, opts.withNodeModules);
  21077. return _getFileInfo({
  21078. ignorer,
  21079. filePath,
  21080. plugins: opts.plugins,
  21081. resolveConfig: opts.resolveConfig,
  21082. ignorePath: opts.ignorePath,
  21083. sync: false
  21084. });
  21085. }
  21086. /**
  21087. * @param {string} filePath
  21088. * @param {FileInfoOptions} opts
  21089. * @returns {FileInfoResult}
  21090. */
  21091. getFileInfo.sync = function (filePath, opts) {
  21092. if (typeof filePath !== "string") {
  21093. throw new TypeError(`expect \`filePath\` to be a string, got \`${typeof filePath}\``);
  21094. }
  21095. const ignorer = createIgnorer_1.sync(opts.ignorePath, opts.withNodeModules);
  21096. return _getFileInfo({
  21097. ignorer,
  21098. filePath,
  21099. plugins: opts.plugins,
  21100. resolveConfig: opts.resolveConfig,
  21101. ignorePath: opts.ignorePath,
  21102. sync: true
  21103. });
  21104. };
  21105. function getFileParser(resolvedConfig, filePath, plugins) {
  21106. if (resolvedConfig && resolvedConfig.parser) {
  21107. return resolvedConfig.parser;
  21108. }
  21109. const inferredParser = options$1.inferParser(filePath, plugins);
  21110. if (inferredParser) {
  21111. return inferredParser;
  21112. }
  21113. return null;
  21114. }
  21115. function _getFileInfo({
  21116. ignorer,
  21117. filePath,
  21118. plugins,
  21119. resolveConfig = false,
  21120. ignorePath,
  21121. sync = false
  21122. }) {
  21123. const normalizedFilePath = normalizeFilePath(filePath, ignorePath);
  21124. const fileInfo = {
  21125. ignored: ignorer.ignores(normalizedFilePath),
  21126. inferredParser: null
  21127. };
  21128. if (fileInfo.ignored) {
  21129. return fileInfo;
  21130. }
  21131. let resolvedConfig;
  21132. if (resolveConfig) {
  21133. if (sync) {
  21134. resolvedConfig = resolveConfig_1.resolveConfig.sync(filePath);
  21135. } else {
  21136. return resolveConfig_1.resolveConfig(filePath).then(resolvedConfig => {
  21137. fileInfo.inferredParser = getFileParser(resolvedConfig, filePath, plugins);
  21138. return fileInfo;
  21139. });
  21140. }
  21141. }
  21142. fileInfo.inferredParser = getFileParser(resolvedConfig, filePath, plugins);
  21143. return fileInfo;
  21144. }
  21145. function normalizeFilePath(filePath, ignorePath) {
  21146. return ignorePath ? path__default['default'].relative(path__default['default'].dirname(ignorePath), filePath) : filePath;
  21147. }
  21148. var getFileInfo_1 = getFileInfo;
  21149. const {
  21150. getMaxContinuousCount: getMaxContinuousCount$1,
  21151. getStringWidth: getStringWidth$2,
  21152. getAlignmentSize: getAlignmentSize$2,
  21153. getIndentSize: getIndentSize$1,
  21154. skip: skip$1,
  21155. skipWhitespace: skipWhitespace$1,
  21156. skipSpaces: skipSpaces$2,
  21157. skipNewline: skipNewline$2,
  21158. skipToLineEnd: skipToLineEnd$1,
  21159. skipEverythingButNewLine: skipEverythingButNewLine$1,
  21160. skipInlineComment: skipInlineComment$1,
  21161. skipTrailingComment: skipTrailingComment$1,
  21162. hasNewline: hasNewline$2,
  21163. hasNewlineInRange: hasNewlineInRange$1,
  21164. hasSpaces: hasSpaces$1,
  21165. isNextLineEmpty: isNextLineEmpty$1,
  21166. isNextLineEmptyAfterIndex: isNextLineEmptyAfterIndex$1,
  21167. isPreviousLineEmpty: isPreviousLineEmpty$2,
  21168. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$1,
  21169. makeString: makeString$1,
  21170. addLeadingComment: addLeadingComment$2,
  21171. addDanglingComment: addDanglingComment$2,
  21172. addTrailingComment: addTrailingComment$2
  21173. } = util;
  21174. var utilShared = {
  21175. getMaxContinuousCount: getMaxContinuousCount$1,
  21176. getStringWidth: getStringWidth$2,
  21177. getAlignmentSize: getAlignmentSize$2,
  21178. getIndentSize: getIndentSize$1,
  21179. skip: skip$1,
  21180. skipWhitespace: skipWhitespace$1,
  21181. skipSpaces: skipSpaces$2,
  21182. skipNewline: skipNewline$2,
  21183. skipToLineEnd: skipToLineEnd$1,
  21184. skipEverythingButNewLine: skipEverythingButNewLine$1,
  21185. skipInlineComment: skipInlineComment$1,
  21186. skipTrailingComment: skipTrailingComment$1,
  21187. hasNewline: hasNewline$2,
  21188. hasNewlineInRange: hasNewlineInRange$1,
  21189. hasSpaces: hasSpaces$1,
  21190. isNextLineEmpty: isNextLineEmpty$1,
  21191. isNextLineEmptyAfterIndex: isNextLineEmptyAfterIndex$1,
  21192. isPreviousLineEmpty: isPreviousLineEmpty$2,
  21193. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$1,
  21194. makeString: makeString$1,
  21195. addLeadingComment: addLeadingComment$2,
  21196. addDanglingComment: addDanglingComment$2,
  21197. addTrailingComment: addTrailingComment$2
  21198. };
  21199. /**
  21200. * Removes all key-value entries from the list cache.
  21201. *
  21202. * @private
  21203. * @name clear
  21204. * @memberOf ListCache
  21205. */
  21206. function listCacheClear() {
  21207. this.__data__ = [];
  21208. this.size = 0;
  21209. }
  21210. var _listCacheClear = listCacheClear;
  21211. /**
  21212. * Performs a
  21213. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  21214. * comparison between two values to determine if they are equivalent.
  21215. *
  21216. * @static
  21217. * @memberOf _
  21218. * @since 4.0.0
  21219. * @category Lang
  21220. * @param {*} value The value to compare.
  21221. * @param {*} other The other value to compare.
  21222. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  21223. * @example
  21224. *
  21225. * var object = { 'a': 1 };
  21226. * var other = { 'a': 1 };
  21227. *
  21228. * _.eq(object, object);
  21229. * // => true
  21230. *
  21231. * _.eq(object, other);
  21232. * // => false
  21233. *
  21234. * _.eq('a', 'a');
  21235. * // => true
  21236. *
  21237. * _.eq('a', Object('a'));
  21238. * // => false
  21239. *
  21240. * _.eq(NaN, NaN);
  21241. * // => true
  21242. */
  21243. function eq(value, other) {
  21244. return value === other || value !== value && other !== other;
  21245. }
  21246. var eq_1 = eq;
  21247. /**
  21248. * Gets the index at which the `key` is found in `array` of key-value pairs.
  21249. *
  21250. * @private
  21251. * @param {Array} array The array to inspect.
  21252. * @param {*} key The key to search for.
  21253. * @returns {number} Returns the index of the matched value, else `-1`.
  21254. */
  21255. function assocIndexOf(array, key) {
  21256. var length = array.length;
  21257. while (length--) {
  21258. if (eq_1(array[length][0], key)) {
  21259. return length;
  21260. }
  21261. }
  21262. return -1;
  21263. }
  21264. var _assocIndexOf = assocIndexOf;
  21265. /** Used for built-in method references. */
  21266. var arrayProto = Array.prototype;
  21267. /** Built-in value references. */
  21268. var splice = arrayProto.splice;
  21269. /**
  21270. * Removes `key` and its value from the list cache.
  21271. *
  21272. * @private
  21273. * @name delete
  21274. * @memberOf ListCache
  21275. * @param {string} key The key of the value to remove.
  21276. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  21277. */
  21278. function listCacheDelete(key) {
  21279. var data = this.__data__,
  21280. index = _assocIndexOf(data, key);
  21281. if (index < 0) {
  21282. return false;
  21283. }
  21284. var lastIndex = data.length - 1;
  21285. if (index == lastIndex) {
  21286. data.pop();
  21287. } else {
  21288. splice.call(data, index, 1);
  21289. }
  21290. --this.size;
  21291. return true;
  21292. }
  21293. var _listCacheDelete = listCacheDelete;
  21294. /**
  21295. * Gets the list cache value for `key`.
  21296. *
  21297. * @private
  21298. * @name get
  21299. * @memberOf ListCache
  21300. * @param {string} key The key of the value to get.
  21301. * @returns {*} Returns the entry value.
  21302. */
  21303. function listCacheGet(key) {
  21304. var data = this.__data__,
  21305. index = _assocIndexOf(data, key);
  21306. return index < 0 ? undefined : data[index][1];
  21307. }
  21308. var _listCacheGet = listCacheGet;
  21309. /**
  21310. * Checks if a list cache value for `key` exists.
  21311. *
  21312. * @private
  21313. * @name has
  21314. * @memberOf ListCache
  21315. * @param {string} key The key of the entry to check.
  21316. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  21317. */
  21318. function listCacheHas(key) {
  21319. return _assocIndexOf(this.__data__, key) > -1;
  21320. }
  21321. var _listCacheHas = listCacheHas;
  21322. /**
  21323. * Sets the list cache `key` to `value`.
  21324. *
  21325. * @private
  21326. * @name set
  21327. * @memberOf ListCache
  21328. * @param {string} key The key of the value to set.
  21329. * @param {*} value The value to set.
  21330. * @returns {Object} Returns the list cache instance.
  21331. */
  21332. function listCacheSet(key, value) {
  21333. var data = this.__data__,
  21334. index = _assocIndexOf(data, key);
  21335. if (index < 0) {
  21336. ++this.size;
  21337. data.push([key, value]);
  21338. } else {
  21339. data[index][1] = value;
  21340. }
  21341. return this;
  21342. }
  21343. var _listCacheSet = listCacheSet;
  21344. /**
  21345. * Creates an list cache object.
  21346. *
  21347. * @private
  21348. * @constructor
  21349. * @param {Array} [entries] The key-value pairs to cache.
  21350. */
  21351. function ListCache(entries) {
  21352. var index = -1,
  21353. length = entries == null ? 0 : entries.length;
  21354. this.clear();
  21355. while (++index < length) {
  21356. var entry = entries[index];
  21357. this.set(entry[0], entry[1]);
  21358. }
  21359. } // Add methods to `ListCache`.
  21360. ListCache.prototype.clear = _listCacheClear;
  21361. ListCache.prototype['delete'] = _listCacheDelete;
  21362. ListCache.prototype.get = _listCacheGet;
  21363. ListCache.prototype.has = _listCacheHas;
  21364. ListCache.prototype.set = _listCacheSet;
  21365. var _ListCache = ListCache;
  21366. /**
  21367. * Removes all key-value entries from the stack.
  21368. *
  21369. * @private
  21370. * @name clear
  21371. * @memberOf Stack
  21372. */
  21373. function stackClear() {
  21374. this.__data__ = new _ListCache();
  21375. this.size = 0;
  21376. }
  21377. var _stackClear = stackClear;
  21378. /**
  21379. * Removes `key` and its value from the stack.
  21380. *
  21381. * @private
  21382. * @name delete
  21383. * @memberOf Stack
  21384. * @param {string} key The key of the value to remove.
  21385. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  21386. */
  21387. function stackDelete(key) {
  21388. var data = this.__data__,
  21389. result = data['delete'](key);
  21390. this.size = data.size;
  21391. return result;
  21392. }
  21393. var _stackDelete = stackDelete;
  21394. /**
  21395. * Gets the stack value for `key`.
  21396. *
  21397. * @private
  21398. * @name get
  21399. * @memberOf Stack
  21400. * @param {string} key The key of the value to get.
  21401. * @returns {*} Returns the entry value.
  21402. */
  21403. function stackGet(key) {
  21404. return this.__data__.get(key);
  21405. }
  21406. var _stackGet = stackGet;
  21407. /**
  21408. * Checks if a stack value for `key` exists.
  21409. *
  21410. * @private
  21411. * @name has
  21412. * @memberOf Stack
  21413. * @param {string} key The key of the entry to check.
  21414. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  21415. */
  21416. function stackHas(key) {
  21417. return this.__data__.has(key);
  21418. }
  21419. var _stackHas = stackHas;
  21420. /**
  21421. * Checks if `value` is the
  21422. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  21423. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  21424. *
  21425. * @static
  21426. * @memberOf _
  21427. * @since 0.1.0
  21428. * @category Lang
  21429. * @param {*} value The value to check.
  21430. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  21431. * @example
  21432. *
  21433. * _.isObject({});
  21434. * // => true
  21435. *
  21436. * _.isObject([1, 2, 3]);
  21437. * // => true
  21438. *
  21439. * _.isObject(_.noop);
  21440. * // => true
  21441. *
  21442. * _.isObject(null);
  21443. * // => false
  21444. */
  21445. function isObject(value) {
  21446. var type = typeof value;
  21447. return value != null && (type == 'object' || type == 'function');
  21448. }
  21449. var isObject_1 = isObject;
  21450. /** `Object#toString` result references. */
  21451. var asyncTag = '[object AsyncFunction]',
  21452. funcTag = '[object Function]',
  21453. genTag = '[object GeneratorFunction]',
  21454. proxyTag = '[object Proxy]';
  21455. /**
  21456. * Checks if `value` is classified as a `Function` object.
  21457. *
  21458. * @static
  21459. * @memberOf _
  21460. * @since 0.1.0
  21461. * @category Lang
  21462. * @param {*} value The value to check.
  21463. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  21464. * @example
  21465. *
  21466. * _.isFunction(_);
  21467. * // => true
  21468. *
  21469. * _.isFunction(/abc/);
  21470. * // => false
  21471. */
  21472. function isFunction(value) {
  21473. if (!isObject_1(value)) {
  21474. return false;
  21475. } // The use of `Object#toString` avoids issues with the `typeof` operator
  21476. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  21477. var tag = _baseGetTag(value);
  21478. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  21479. }
  21480. var isFunction_1 = isFunction;
  21481. /** Used to detect overreaching core-js shims. */
  21482. var coreJsData = _root['__core-js_shared__'];
  21483. var _coreJsData = coreJsData;
  21484. /** Used to detect methods masquerading as native. */
  21485. var maskSrcKey = function () {
  21486. var uid = /[^.]+$/.exec(_coreJsData && _coreJsData.keys && _coreJsData.keys.IE_PROTO || '');
  21487. return uid ? 'Symbol(src)_1.' + uid : '';
  21488. }();
  21489. /**
  21490. * Checks if `func` has its source masked.
  21491. *
  21492. * @private
  21493. * @param {Function} func The function to check.
  21494. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  21495. */
  21496. function isMasked(func) {
  21497. return !!maskSrcKey && maskSrcKey in func;
  21498. }
  21499. var _isMasked = isMasked;
  21500. /** Used for built-in method references. */
  21501. var funcProto = Function.prototype;
  21502. /** Used to resolve the decompiled source of functions. */
  21503. var funcToString = funcProto.toString;
  21504. /**
  21505. * Converts `func` to its source code.
  21506. *
  21507. * @private
  21508. * @param {Function} func The function to convert.
  21509. * @returns {string} Returns the source code.
  21510. */
  21511. function toSource(func) {
  21512. if (func != null) {
  21513. try {
  21514. return funcToString.call(func);
  21515. } catch (e) {}
  21516. try {
  21517. return func + '';
  21518. } catch (e) {}
  21519. }
  21520. return '';
  21521. }
  21522. var _toSource = toSource;
  21523. /**
  21524. * Used to match `RegExp`
  21525. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  21526. */
  21527. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  21528. /** Used to detect host constructors (Safari). */
  21529. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  21530. /** Used for built-in method references. */
  21531. var funcProto$1 = Function.prototype,
  21532. objectProto$3 = Object.prototype;
  21533. /** Used to resolve the decompiled source of functions. */
  21534. var funcToString$1 = funcProto$1.toString;
  21535. /** Used to check objects for own properties. */
  21536. var hasOwnProperty$4 = objectProto$3.hasOwnProperty;
  21537. /** Used to detect if a method is native. */
  21538. var reIsNative = RegExp('^' + funcToString$1.call(hasOwnProperty$4).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  21539. /**
  21540. * The base implementation of `_.isNative` without bad shim checks.
  21541. *
  21542. * @private
  21543. * @param {*} value The value to check.
  21544. * @returns {boolean} Returns `true` if `value` is a native function,
  21545. * else `false`.
  21546. */
  21547. function baseIsNative(value) {
  21548. if (!isObject_1(value) || _isMasked(value)) {
  21549. return false;
  21550. }
  21551. var pattern = isFunction_1(value) ? reIsNative : reIsHostCtor;
  21552. return pattern.test(_toSource(value));
  21553. }
  21554. var _baseIsNative = baseIsNative;
  21555. /**
  21556. * Gets the value at `key` of `object`.
  21557. *
  21558. * @private
  21559. * @param {Object} [object] The object to query.
  21560. * @param {string} key The key of the property to get.
  21561. * @returns {*} Returns the property value.
  21562. */
  21563. function getValue(object, key) {
  21564. return object == null ? undefined : object[key];
  21565. }
  21566. var _getValue = getValue;
  21567. /**
  21568. * Gets the native function at `key` of `object`.
  21569. *
  21570. * @private
  21571. * @param {Object} object The object to query.
  21572. * @param {string} key The key of the method to get.
  21573. * @returns {*} Returns the function if it's native, else `undefined`.
  21574. */
  21575. function getNative(object, key) {
  21576. var value = _getValue(object, key);
  21577. return _baseIsNative(value) ? value : undefined;
  21578. }
  21579. var _getNative = getNative;
  21580. /* Built-in method references that are verified to be native. */
  21581. var Map$1 = _getNative(_root, 'Map');
  21582. var _Map = Map$1;
  21583. /* Built-in method references that are verified to be native. */
  21584. var nativeCreate = _getNative(Object, 'create');
  21585. var _nativeCreate = nativeCreate;
  21586. /**
  21587. * Removes all key-value entries from the hash.
  21588. *
  21589. * @private
  21590. * @name clear
  21591. * @memberOf Hash
  21592. */
  21593. function hashClear() {
  21594. this.__data__ = _nativeCreate ? _nativeCreate(null) : {};
  21595. this.size = 0;
  21596. }
  21597. var _hashClear = hashClear;
  21598. /**
  21599. * Removes `key` and its value from the hash.
  21600. *
  21601. * @private
  21602. * @name delete
  21603. * @memberOf Hash
  21604. * @param {Object} hash The hash to modify.
  21605. * @param {string} key The key of the value to remove.
  21606. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  21607. */
  21608. function hashDelete(key) {
  21609. var result = this.has(key) && delete this.__data__[key];
  21610. this.size -= result ? 1 : 0;
  21611. return result;
  21612. }
  21613. var _hashDelete = hashDelete;
  21614. /** Used to stand-in for `undefined` hash values. */
  21615. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  21616. /** Used for built-in method references. */
  21617. var objectProto$4 = Object.prototype;
  21618. /** Used to check objects for own properties. */
  21619. var hasOwnProperty$5 = objectProto$4.hasOwnProperty;
  21620. /**
  21621. * Gets the hash value for `key`.
  21622. *
  21623. * @private
  21624. * @name get
  21625. * @memberOf Hash
  21626. * @param {string} key The key of the value to get.
  21627. * @returns {*} Returns the entry value.
  21628. */
  21629. function hashGet(key) {
  21630. var data = this.__data__;
  21631. if (_nativeCreate) {
  21632. var result = data[key];
  21633. return result === HASH_UNDEFINED ? undefined : result;
  21634. }
  21635. return hasOwnProperty$5.call(data, key) ? data[key] : undefined;
  21636. }
  21637. var _hashGet = hashGet;
  21638. /** Used for built-in method references. */
  21639. var objectProto$5 = Object.prototype;
  21640. /** Used to check objects for own properties. */
  21641. var hasOwnProperty$6 = objectProto$5.hasOwnProperty;
  21642. /**
  21643. * Checks if a hash value for `key` exists.
  21644. *
  21645. * @private
  21646. * @name has
  21647. * @memberOf Hash
  21648. * @param {string} key The key of the entry to check.
  21649. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  21650. */
  21651. function hashHas(key) {
  21652. var data = this.__data__;
  21653. return _nativeCreate ? data[key] !== undefined : hasOwnProperty$6.call(data, key);
  21654. }
  21655. var _hashHas = hashHas;
  21656. /** Used to stand-in for `undefined` hash values. */
  21657. var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
  21658. /**
  21659. * Sets the hash `key` to `value`.
  21660. *
  21661. * @private
  21662. * @name set
  21663. * @memberOf Hash
  21664. * @param {string} key The key of the value to set.
  21665. * @param {*} value The value to set.
  21666. * @returns {Object} Returns the hash instance.
  21667. */
  21668. function hashSet(key, value) {
  21669. var data = this.__data__;
  21670. this.size += this.has(key) ? 0 : 1;
  21671. data[key] = _nativeCreate && value === undefined ? HASH_UNDEFINED$1 : value;
  21672. return this;
  21673. }
  21674. var _hashSet = hashSet;
  21675. /**
  21676. * Creates a hash object.
  21677. *
  21678. * @private
  21679. * @constructor
  21680. * @param {Array} [entries] The key-value pairs to cache.
  21681. */
  21682. function Hash(entries) {
  21683. var index = -1,
  21684. length = entries == null ? 0 : entries.length;
  21685. this.clear();
  21686. while (++index < length) {
  21687. var entry = entries[index];
  21688. this.set(entry[0], entry[1]);
  21689. }
  21690. } // Add methods to `Hash`.
  21691. Hash.prototype.clear = _hashClear;
  21692. Hash.prototype['delete'] = _hashDelete;
  21693. Hash.prototype.get = _hashGet;
  21694. Hash.prototype.has = _hashHas;
  21695. Hash.prototype.set = _hashSet;
  21696. var _Hash = Hash;
  21697. /**
  21698. * Removes all key-value entries from the map.
  21699. *
  21700. * @private
  21701. * @name clear
  21702. * @memberOf MapCache
  21703. */
  21704. function mapCacheClear() {
  21705. this.size = 0;
  21706. this.__data__ = {
  21707. 'hash': new _Hash(),
  21708. 'map': new (_Map || _ListCache)(),
  21709. 'string': new _Hash()
  21710. };
  21711. }
  21712. var _mapCacheClear = mapCacheClear;
  21713. /**
  21714. * Checks if `value` is suitable for use as unique object key.
  21715. *
  21716. * @private
  21717. * @param {*} value The value to check.
  21718. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  21719. */
  21720. function isKeyable(value) {
  21721. var type = typeof value;
  21722. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  21723. }
  21724. var _isKeyable = isKeyable;
  21725. /**
  21726. * Gets the data for `map`.
  21727. *
  21728. * @private
  21729. * @param {Object} map The map to query.
  21730. * @param {string} key The reference key.
  21731. * @returns {*} Returns the map data.
  21732. */
  21733. function getMapData(map, key) {
  21734. var data = map.__data__;
  21735. return _isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  21736. }
  21737. var _getMapData = getMapData;
  21738. /**
  21739. * Removes `key` and its value from the map.
  21740. *
  21741. * @private
  21742. * @name delete
  21743. * @memberOf MapCache
  21744. * @param {string} key The key of the value to remove.
  21745. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  21746. */
  21747. function mapCacheDelete(key) {
  21748. var result = _getMapData(this, key)['delete'](key);
  21749. this.size -= result ? 1 : 0;
  21750. return result;
  21751. }
  21752. var _mapCacheDelete = mapCacheDelete;
  21753. /**
  21754. * Gets the map value for `key`.
  21755. *
  21756. * @private
  21757. * @name get
  21758. * @memberOf MapCache
  21759. * @param {string} key The key of the value to get.
  21760. * @returns {*} Returns the entry value.
  21761. */
  21762. function mapCacheGet(key) {
  21763. return _getMapData(this, key).get(key);
  21764. }
  21765. var _mapCacheGet = mapCacheGet;
  21766. /**
  21767. * Checks if a map value for `key` exists.
  21768. *
  21769. * @private
  21770. * @name has
  21771. * @memberOf MapCache
  21772. * @param {string} key The key of the entry to check.
  21773. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  21774. */
  21775. function mapCacheHas(key) {
  21776. return _getMapData(this, key).has(key);
  21777. }
  21778. var _mapCacheHas = mapCacheHas;
  21779. /**
  21780. * Sets the map `key` to `value`.
  21781. *
  21782. * @private
  21783. * @name set
  21784. * @memberOf MapCache
  21785. * @param {string} key The key of the value to set.
  21786. * @param {*} value The value to set.
  21787. * @returns {Object} Returns the map cache instance.
  21788. */
  21789. function mapCacheSet(key, value) {
  21790. var data = _getMapData(this, key),
  21791. size = data.size;
  21792. data.set(key, value);
  21793. this.size += data.size == size ? 0 : 1;
  21794. return this;
  21795. }
  21796. var _mapCacheSet = mapCacheSet;
  21797. /**
  21798. * Creates a map cache object to store key-value pairs.
  21799. *
  21800. * @private
  21801. * @constructor
  21802. * @param {Array} [entries] The key-value pairs to cache.
  21803. */
  21804. function MapCache(entries) {
  21805. var index = -1,
  21806. length = entries == null ? 0 : entries.length;
  21807. this.clear();
  21808. while (++index < length) {
  21809. var entry = entries[index];
  21810. this.set(entry[0], entry[1]);
  21811. }
  21812. } // Add methods to `MapCache`.
  21813. MapCache.prototype.clear = _mapCacheClear;
  21814. MapCache.prototype['delete'] = _mapCacheDelete;
  21815. MapCache.prototype.get = _mapCacheGet;
  21816. MapCache.prototype.has = _mapCacheHas;
  21817. MapCache.prototype.set = _mapCacheSet;
  21818. var _MapCache = MapCache;
  21819. /** Used as the size to enable large array optimizations. */
  21820. var LARGE_ARRAY_SIZE = 200;
  21821. /**
  21822. * Sets the stack `key` to `value`.
  21823. *
  21824. * @private
  21825. * @name set
  21826. * @memberOf Stack
  21827. * @param {string} key The key of the value to set.
  21828. * @param {*} value The value to set.
  21829. * @returns {Object} Returns the stack cache instance.
  21830. */
  21831. function stackSet(key, value) {
  21832. var data = this.__data__;
  21833. if (data instanceof _ListCache) {
  21834. var pairs = data.__data__;
  21835. if (!_Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  21836. pairs.push([key, value]);
  21837. this.size = ++data.size;
  21838. return this;
  21839. }
  21840. data = this.__data__ = new _MapCache(pairs);
  21841. }
  21842. data.set(key, value);
  21843. this.size = data.size;
  21844. return this;
  21845. }
  21846. var _stackSet = stackSet;
  21847. /**
  21848. * Creates a stack cache object to store key-value pairs.
  21849. *
  21850. * @private
  21851. * @constructor
  21852. * @param {Array} [entries] The key-value pairs to cache.
  21853. */
  21854. function Stack(entries) {
  21855. var data = this.__data__ = new _ListCache(entries);
  21856. this.size = data.size;
  21857. } // Add methods to `Stack`.
  21858. Stack.prototype.clear = _stackClear;
  21859. Stack.prototype['delete'] = _stackDelete;
  21860. Stack.prototype.get = _stackGet;
  21861. Stack.prototype.has = _stackHas;
  21862. Stack.prototype.set = _stackSet;
  21863. var _Stack = Stack;
  21864. /** Used to stand-in for `undefined` hash values. */
  21865. var HASH_UNDEFINED$2 = '__lodash_hash_undefined__';
  21866. /**
  21867. * Adds `value` to the array cache.
  21868. *
  21869. * @private
  21870. * @name add
  21871. * @memberOf SetCache
  21872. * @alias push
  21873. * @param {*} value The value to cache.
  21874. * @returns {Object} Returns the cache instance.
  21875. */
  21876. function setCacheAdd(value) {
  21877. this.__data__.set(value, HASH_UNDEFINED$2);
  21878. return this;
  21879. }
  21880. var _setCacheAdd = setCacheAdd;
  21881. /**
  21882. * Checks if `value` is in the array cache.
  21883. *
  21884. * @private
  21885. * @name has
  21886. * @memberOf SetCache
  21887. * @param {*} value The value to search for.
  21888. * @returns {number} Returns `true` if `value` is found, else `false`.
  21889. */
  21890. function setCacheHas(value) {
  21891. return this.__data__.has(value);
  21892. }
  21893. var _setCacheHas = setCacheHas;
  21894. /**
  21895. *
  21896. * Creates an array cache object to store unique values.
  21897. *
  21898. * @private
  21899. * @constructor
  21900. * @param {Array} [values] The values to cache.
  21901. */
  21902. function SetCache(values) {
  21903. var index = -1,
  21904. length = values == null ? 0 : values.length;
  21905. this.__data__ = new _MapCache();
  21906. while (++index < length) {
  21907. this.add(values[index]);
  21908. }
  21909. } // Add methods to `SetCache`.
  21910. SetCache.prototype.add = SetCache.prototype.push = _setCacheAdd;
  21911. SetCache.prototype.has = _setCacheHas;
  21912. var _SetCache = SetCache;
  21913. /**
  21914. * A specialized version of `_.some` for arrays without support for iteratee
  21915. * shorthands.
  21916. *
  21917. * @private
  21918. * @param {Array} [array] The array to iterate over.
  21919. * @param {Function} predicate The function invoked per iteration.
  21920. * @returns {boolean} Returns `true` if any element passes the predicate check,
  21921. * else `false`.
  21922. */
  21923. function arraySome(array, predicate) {
  21924. var index = -1,
  21925. length = array == null ? 0 : array.length;
  21926. while (++index < length) {
  21927. if (predicate(array[index], index, array)) {
  21928. return true;
  21929. }
  21930. }
  21931. return false;
  21932. }
  21933. var _arraySome = arraySome;
  21934. /**
  21935. * Checks if a `cache` value for `key` exists.
  21936. *
  21937. * @private
  21938. * @param {Object} cache The cache to query.
  21939. * @param {string} key The key of the entry to check.
  21940. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  21941. */
  21942. function cacheHas(cache, key) {
  21943. return cache.has(key);
  21944. }
  21945. var _cacheHas = cacheHas;
  21946. /** Used to compose bitmasks for value comparisons. */
  21947. var COMPARE_PARTIAL_FLAG = 1,
  21948. COMPARE_UNORDERED_FLAG = 2;
  21949. /**
  21950. * A specialized version of `baseIsEqualDeep` for arrays with support for
  21951. * partial deep comparisons.
  21952. *
  21953. * @private
  21954. * @param {Array} array The array to compare.
  21955. * @param {Array} other The other array to compare.
  21956. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  21957. * @param {Function} customizer The function to customize comparisons.
  21958. * @param {Function} equalFunc The function to determine equivalents of values.
  21959. * @param {Object} stack Tracks traversed `array` and `other` objects.
  21960. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  21961. */
  21962. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  21963. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  21964. arrLength = array.length,
  21965. othLength = other.length;
  21966. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  21967. return false;
  21968. } // Check that cyclic values are equal.
  21969. var arrStacked = stack.get(array);
  21970. var othStacked = stack.get(other);
  21971. if (arrStacked && othStacked) {
  21972. return arrStacked == other && othStacked == array;
  21973. }
  21974. var index = -1,
  21975. result = true,
  21976. seen = bitmask & COMPARE_UNORDERED_FLAG ? new _SetCache() : undefined;
  21977. stack.set(array, other);
  21978. stack.set(other, array); // Ignore non-index properties.
  21979. while (++index < arrLength) {
  21980. var arrValue = array[index],
  21981. othValue = other[index];
  21982. if (customizer) {
  21983. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  21984. }
  21985. if (compared !== undefined) {
  21986. if (compared) {
  21987. continue;
  21988. }
  21989. result = false;
  21990. break;
  21991. } // Recursively compare arrays (susceptible to call stack limits).
  21992. if (seen) {
  21993. if (!_arraySome(other, function (othValue, othIndex) {
  21994. if (!_cacheHas(seen, othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  21995. return seen.push(othIndex);
  21996. }
  21997. })) {
  21998. result = false;
  21999. break;
  22000. }
  22001. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  22002. result = false;
  22003. break;
  22004. }
  22005. }
  22006. stack['delete'](array);
  22007. stack['delete'](other);
  22008. return result;
  22009. }
  22010. var _equalArrays = equalArrays;
  22011. /** Built-in value references. */
  22012. var Uint8Array = _root.Uint8Array;
  22013. var _Uint8Array = Uint8Array;
  22014. /**
  22015. * Converts `map` to its key-value pairs.
  22016. *
  22017. * @private
  22018. * @param {Object} map The map to convert.
  22019. * @returns {Array} Returns the key-value pairs.
  22020. */
  22021. function mapToArray(map) {
  22022. var index = -1,
  22023. result = Array(map.size);
  22024. map.forEach(function (value, key) {
  22025. result[++index] = [key, value];
  22026. });
  22027. return result;
  22028. }
  22029. var _mapToArray = mapToArray;
  22030. /**
  22031. * Converts `set` to an array of its values.
  22032. *
  22033. * @private
  22034. * @param {Object} set The set to convert.
  22035. * @returns {Array} Returns the values.
  22036. */
  22037. function setToArray(set) {
  22038. var index = -1,
  22039. result = Array(set.size);
  22040. set.forEach(function (value) {
  22041. result[++index] = value;
  22042. });
  22043. return result;
  22044. }
  22045. var _setToArray = setToArray;
  22046. /** Used to compose bitmasks for value comparisons. */
  22047. var COMPARE_PARTIAL_FLAG$1 = 1,
  22048. COMPARE_UNORDERED_FLAG$1 = 2;
  22049. /** `Object#toString` result references. */
  22050. var boolTag = '[object Boolean]',
  22051. dateTag = '[object Date]',
  22052. errorTag = '[object Error]',
  22053. mapTag = '[object Map]',
  22054. numberTag = '[object Number]',
  22055. regexpTag = '[object RegExp]',
  22056. setTag = '[object Set]',
  22057. stringTag = '[object String]',
  22058. symbolTag = '[object Symbol]';
  22059. var arrayBufferTag = '[object ArrayBuffer]',
  22060. dataViewTag = '[object DataView]';
  22061. /** Used to convert symbols to primitives and strings. */
  22062. var symbolProto = _Symbol ? _Symbol.prototype : undefined,
  22063. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
  22064. /**
  22065. * A specialized version of `baseIsEqualDeep` for comparing objects of
  22066. * the same `toStringTag`.
  22067. *
  22068. * **Note:** This function only supports comparing values with tags of
  22069. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  22070. *
  22071. * @private
  22072. * @param {Object} object The object to compare.
  22073. * @param {Object} other The other object to compare.
  22074. * @param {string} tag The `toStringTag` of the objects to compare.
  22075. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  22076. * @param {Function} customizer The function to customize comparisons.
  22077. * @param {Function} equalFunc The function to determine equivalents of values.
  22078. * @param {Object} stack Tracks traversed `object` and `other` objects.
  22079. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  22080. */
  22081. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  22082. switch (tag) {
  22083. case dataViewTag:
  22084. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  22085. return false;
  22086. }
  22087. object = object.buffer;
  22088. other = other.buffer;
  22089. case arrayBufferTag:
  22090. if (object.byteLength != other.byteLength || !equalFunc(new _Uint8Array(object), new _Uint8Array(other))) {
  22091. return false;
  22092. }
  22093. return true;
  22094. case boolTag:
  22095. case dateTag:
  22096. case numberTag:
  22097. // Coerce booleans to `1` or `0` and dates to milliseconds.
  22098. // Invalid dates are coerced to `NaN`.
  22099. return eq_1(+object, +other);
  22100. case errorTag:
  22101. return object.name == other.name && object.message == other.message;
  22102. case regexpTag:
  22103. case stringTag:
  22104. // Coerce regexes to strings and treat strings, primitives and objects,
  22105. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  22106. // for more details.
  22107. return object == other + '';
  22108. case mapTag:
  22109. var convert = _mapToArray;
  22110. case setTag:
  22111. var isPartial = bitmask & COMPARE_PARTIAL_FLAG$1;
  22112. convert || (convert = _setToArray);
  22113. if (object.size != other.size && !isPartial) {
  22114. return false;
  22115. } // Assume cyclic values are equal.
  22116. var stacked = stack.get(object);
  22117. if (stacked) {
  22118. return stacked == other;
  22119. }
  22120. bitmask |= COMPARE_UNORDERED_FLAG$1; // Recursively compare objects (susceptible to call stack limits).
  22121. stack.set(object, other);
  22122. var result = _equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  22123. stack['delete'](object);
  22124. return result;
  22125. case symbolTag:
  22126. if (symbolValueOf) {
  22127. return symbolValueOf.call(object) == symbolValueOf.call(other);
  22128. }
  22129. }
  22130. return false;
  22131. }
  22132. var _equalByTag = equalByTag;
  22133. /**
  22134. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  22135. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  22136. * symbols of `object`.
  22137. *
  22138. * @private
  22139. * @param {Object} object The object to query.
  22140. * @param {Function} keysFunc The function to get the keys of `object`.
  22141. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  22142. * @returns {Array} Returns the array of property names and symbols.
  22143. */
  22144. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  22145. var result = keysFunc(object);
  22146. return isArray_1(object) ? result : _arrayPush(result, symbolsFunc(object));
  22147. }
  22148. var _baseGetAllKeys = baseGetAllKeys;
  22149. /**
  22150. * A specialized version of `_.filter` for arrays without support for
  22151. * iteratee shorthands.
  22152. *
  22153. * @private
  22154. * @param {Array} [array] The array to iterate over.
  22155. * @param {Function} predicate The function invoked per iteration.
  22156. * @returns {Array} Returns the new filtered array.
  22157. */
  22158. function arrayFilter(array, predicate) {
  22159. var index = -1,
  22160. length = array == null ? 0 : array.length,
  22161. resIndex = 0,
  22162. result = [];
  22163. while (++index < length) {
  22164. var value = array[index];
  22165. if (predicate(value, index, array)) {
  22166. result[resIndex++] = value;
  22167. }
  22168. }
  22169. return result;
  22170. }
  22171. var _arrayFilter = arrayFilter;
  22172. /**
  22173. * This method returns a new empty array.
  22174. *
  22175. * @static
  22176. * @memberOf _
  22177. * @since 4.13.0
  22178. * @category Util
  22179. * @returns {Array} Returns the new empty array.
  22180. * @example
  22181. *
  22182. * var arrays = _.times(2, _.stubArray);
  22183. *
  22184. * console.log(arrays);
  22185. * // => [[], []]
  22186. *
  22187. * console.log(arrays[0] === arrays[1]);
  22188. * // => false
  22189. */
  22190. function stubArray() {
  22191. return [];
  22192. }
  22193. var stubArray_1 = stubArray;
  22194. /** Used for built-in method references. */
  22195. var objectProto$6 = Object.prototype;
  22196. /** Built-in value references. */
  22197. var propertyIsEnumerable$1 = objectProto$6.propertyIsEnumerable;
  22198. /* Built-in method references for those with the same name as other `lodash` methods. */
  22199. var nativeGetSymbols = Object.getOwnPropertySymbols;
  22200. /**
  22201. * Creates an array of the own enumerable symbols of `object`.
  22202. *
  22203. * @private
  22204. * @param {Object} object The object to query.
  22205. * @returns {Array} Returns the array of symbols.
  22206. */
  22207. var getSymbols = !nativeGetSymbols ? stubArray_1 : function (object) {
  22208. if (object == null) {
  22209. return [];
  22210. }
  22211. object = Object(object);
  22212. return _arrayFilter(nativeGetSymbols(object), function (symbol) {
  22213. return propertyIsEnumerable$1.call(object, symbol);
  22214. });
  22215. };
  22216. var _getSymbols = getSymbols;
  22217. /**
  22218. * The base implementation of `_.times` without support for iteratee shorthands
  22219. * or max array length checks.
  22220. *
  22221. * @private
  22222. * @param {number} n The number of times to invoke `iteratee`.
  22223. * @param {Function} iteratee The function invoked per iteration.
  22224. * @returns {Array} Returns the array of results.
  22225. */
  22226. function baseTimes(n, iteratee) {
  22227. var index = -1,
  22228. result = Array(n);
  22229. while (++index < n) {
  22230. result[index] = iteratee(index);
  22231. }
  22232. return result;
  22233. }
  22234. var _baseTimes = baseTimes;
  22235. /**
  22236. * This method returns `false`.
  22237. *
  22238. * @static
  22239. * @memberOf _
  22240. * @since 4.13.0
  22241. * @category Util
  22242. * @returns {boolean} Returns `false`.
  22243. * @example
  22244. *
  22245. * _.times(2, _.stubFalse);
  22246. * // => [false, false]
  22247. */
  22248. function stubFalse() {
  22249. return false;
  22250. }
  22251. var stubFalse_1 = stubFalse;
  22252. var isBuffer_1 = createCommonjsModule(function (module, exports) {
  22253. /** Detect free variable `exports`. */
  22254. var freeExports = exports && !exports.nodeType && exports;
  22255. /** Detect free variable `module`. */
  22256. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  22257. /** Detect the popular CommonJS extension `module.exports`. */
  22258. var moduleExports = freeModule && freeModule.exports === freeExports;
  22259. /** Built-in value references. */
  22260. var Buffer = moduleExports ? _root.Buffer : undefined;
  22261. /* Built-in method references for those with the same name as other `lodash` methods. */
  22262. var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
  22263. /**
  22264. * Checks if `value` is a buffer.
  22265. *
  22266. * @static
  22267. * @memberOf _
  22268. * @since 4.3.0
  22269. * @category Lang
  22270. * @param {*} value The value to check.
  22271. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  22272. * @example
  22273. *
  22274. * _.isBuffer(new Buffer(2));
  22275. * // => true
  22276. *
  22277. * _.isBuffer(new Uint8Array(2));
  22278. * // => false
  22279. */
  22280. var isBuffer = nativeIsBuffer || stubFalse_1;
  22281. module.exports = isBuffer;
  22282. });
  22283. /** Used as references for various `Number` constants. */
  22284. var MAX_SAFE_INTEGER$2 = 9007199254740991;
  22285. /** Used to detect unsigned integer values. */
  22286. var reIsUint = /^(?:0|[1-9]\d*)$/;
  22287. /**
  22288. * Checks if `value` is a valid array-like index.
  22289. *
  22290. * @private
  22291. * @param {*} value The value to check.
  22292. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  22293. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  22294. */
  22295. function isIndex(value, length) {
  22296. var type = typeof value;
  22297. length = length == null ? MAX_SAFE_INTEGER$2 : length;
  22298. return !!length && (type == 'number' || type != 'symbol' && reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  22299. }
  22300. var _isIndex = isIndex;
  22301. /** Used as references for various `Number` constants. */
  22302. var MAX_SAFE_INTEGER$3 = 9007199254740991;
  22303. /**
  22304. * Checks if `value` is a valid array-like length.
  22305. *
  22306. * **Note:** This method is loosely based on
  22307. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  22308. *
  22309. * @static
  22310. * @memberOf _
  22311. * @since 4.0.0
  22312. * @category Lang
  22313. * @param {*} value The value to check.
  22314. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  22315. * @example
  22316. *
  22317. * _.isLength(3);
  22318. * // => true
  22319. *
  22320. * _.isLength(Number.MIN_VALUE);
  22321. * // => false
  22322. *
  22323. * _.isLength(Infinity);
  22324. * // => false
  22325. *
  22326. * _.isLength('3');
  22327. * // => false
  22328. */
  22329. function isLength(value) {
  22330. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER$3;
  22331. }
  22332. var isLength_1 = isLength;
  22333. /** `Object#toString` result references. */
  22334. var argsTag$1 = '[object Arguments]',
  22335. arrayTag = '[object Array]',
  22336. boolTag$1 = '[object Boolean]',
  22337. dateTag$1 = '[object Date]',
  22338. errorTag$1 = '[object Error]',
  22339. funcTag$1 = '[object Function]',
  22340. mapTag$1 = '[object Map]',
  22341. numberTag$1 = '[object Number]',
  22342. objectTag = '[object Object]',
  22343. regexpTag$1 = '[object RegExp]',
  22344. setTag$1 = '[object Set]',
  22345. stringTag$1 = '[object String]',
  22346. weakMapTag = '[object WeakMap]';
  22347. var arrayBufferTag$1 = '[object ArrayBuffer]',
  22348. dataViewTag$1 = '[object DataView]',
  22349. float32Tag = '[object Float32Array]',
  22350. float64Tag = '[object Float64Array]',
  22351. int8Tag = '[object Int8Array]',
  22352. int16Tag = '[object Int16Array]',
  22353. int32Tag = '[object Int32Array]',
  22354. uint8Tag = '[object Uint8Array]',
  22355. uint8ClampedTag = '[object Uint8ClampedArray]',
  22356. uint16Tag = '[object Uint16Array]',
  22357. uint32Tag = '[object Uint32Array]';
  22358. /** Used to identify `toStringTag` values of typed arrays. */
  22359. var typedArrayTags = {};
  22360. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  22361. typedArrayTags[argsTag$1] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag$1] = typedArrayTags[boolTag$1] = typedArrayTags[dataViewTag$1] = typedArrayTags[dateTag$1] = typedArrayTags[errorTag$1] = typedArrayTags[funcTag$1] = typedArrayTags[mapTag$1] = typedArrayTags[numberTag$1] = typedArrayTags[objectTag] = typedArrayTags[regexpTag$1] = typedArrayTags[setTag$1] = typedArrayTags[stringTag$1] = typedArrayTags[weakMapTag] = false;
  22362. /**
  22363. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  22364. *
  22365. * @private
  22366. * @param {*} value The value to check.
  22367. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  22368. */
  22369. function baseIsTypedArray(value) {
  22370. return isObjectLike_1(value) && isLength_1(value.length) && !!typedArrayTags[_baseGetTag(value)];
  22371. }
  22372. var _baseIsTypedArray = baseIsTypedArray;
  22373. /**
  22374. * The base implementation of `_.unary` without support for storing metadata.
  22375. *
  22376. * @private
  22377. * @param {Function} func The function to cap arguments for.
  22378. * @returns {Function} Returns the new capped function.
  22379. */
  22380. function baseUnary(func) {
  22381. return function (value) {
  22382. return func(value);
  22383. };
  22384. }
  22385. var _baseUnary = baseUnary;
  22386. var _nodeUtil = createCommonjsModule(function (module, exports) {
  22387. /** Detect free variable `exports`. */
  22388. var freeExports = exports && !exports.nodeType && exports;
  22389. /** Detect free variable `module`. */
  22390. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  22391. /** Detect the popular CommonJS extension `module.exports`. */
  22392. var moduleExports = freeModule && freeModule.exports === freeExports;
  22393. /** Detect free variable `process` from Node.js. */
  22394. var freeProcess = moduleExports && _freeGlobal.process;
  22395. /** Used to access faster Node.js helpers. */
  22396. var nodeUtil = function () {
  22397. try {
  22398. // Use `util.types` for Node.js 10+.
  22399. var types = freeModule && freeModule.require && freeModule.require('util').types;
  22400. if (types) {
  22401. return types;
  22402. } // Legacy `process.binding('util')` for Node.js < 10.
  22403. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  22404. } catch (e) {}
  22405. }();
  22406. module.exports = nodeUtil;
  22407. });
  22408. /* Node.js helper references. */
  22409. var nodeIsTypedArray = _nodeUtil && _nodeUtil.isTypedArray;
  22410. /**
  22411. * Checks if `value` is classified as a typed array.
  22412. *
  22413. * @static
  22414. * @memberOf _
  22415. * @since 3.0.0
  22416. * @category Lang
  22417. * @param {*} value The value to check.
  22418. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  22419. * @example
  22420. *
  22421. * _.isTypedArray(new Uint8Array);
  22422. * // => true
  22423. *
  22424. * _.isTypedArray([]);
  22425. * // => false
  22426. */
  22427. var isTypedArray = nodeIsTypedArray ? _baseUnary(nodeIsTypedArray) : _baseIsTypedArray;
  22428. var isTypedArray_1 = isTypedArray;
  22429. /** Used for built-in method references. */
  22430. var objectProto$7 = Object.prototype;
  22431. /** Used to check objects for own properties. */
  22432. var hasOwnProperty$7 = objectProto$7.hasOwnProperty;
  22433. /**
  22434. * Creates an array of the enumerable property names of the array-like `value`.
  22435. *
  22436. * @private
  22437. * @param {*} value The value to query.
  22438. * @param {boolean} inherited Specify returning inherited property names.
  22439. * @returns {Array} Returns the array of property names.
  22440. */
  22441. function arrayLikeKeys(value, inherited) {
  22442. var isArr = isArray_1(value),
  22443. isArg = !isArr && isArguments_1(value),
  22444. isBuff = !isArr && !isArg && isBuffer_1(value),
  22445. isType = !isArr && !isArg && !isBuff && isTypedArray_1(value),
  22446. skipIndexes = isArr || isArg || isBuff || isType,
  22447. result = skipIndexes ? _baseTimes(value.length, String) : [],
  22448. length = result.length;
  22449. for (var key in value) {
  22450. if ((inherited || hasOwnProperty$7.call(value, key)) && !(skipIndexes && ( // Safari 9 has enumerable `arguments.length` in strict mode.
  22451. key == 'length' || // Node.js 0.10 has enumerable non-index properties on buffers.
  22452. isBuff && (key == 'offset' || key == 'parent') || // PhantomJS 2 has enumerable non-index properties on typed arrays.
  22453. isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset') || // Skip index properties.
  22454. _isIndex(key, length)))) {
  22455. result.push(key);
  22456. }
  22457. }
  22458. return result;
  22459. }
  22460. var _arrayLikeKeys = arrayLikeKeys;
  22461. /** Used for built-in method references. */
  22462. var objectProto$8 = Object.prototype;
  22463. /**
  22464. * Checks if `value` is likely a prototype object.
  22465. *
  22466. * @private
  22467. * @param {*} value The value to check.
  22468. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  22469. */
  22470. function isPrototype(value) {
  22471. var Ctor = value && value.constructor,
  22472. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto$8;
  22473. return value === proto;
  22474. }
  22475. var _isPrototype = isPrototype;
  22476. /**
  22477. * Creates a unary function that invokes `func` with its argument transformed.
  22478. *
  22479. * @private
  22480. * @param {Function} func The function to wrap.
  22481. * @param {Function} transform The argument transform.
  22482. * @returns {Function} Returns the new function.
  22483. */
  22484. function overArg(func, transform) {
  22485. return function (arg) {
  22486. return func(transform(arg));
  22487. };
  22488. }
  22489. var _overArg = overArg;
  22490. /* Built-in method references for those with the same name as other `lodash` methods. */
  22491. var nativeKeys = _overArg(Object.keys, Object);
  22492. var _nativeKeys = nativeKeys;
  22493. /** Used for built-in method references. */
  22494. var objectProto$9 = Object.prototype;
  22495. /** Used to check objects for own properties. */
  22496. var hasOwnProperty$8 = objectProto$9.hasOwnProperty;
  22497. /**
  22498. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  22499. *
  22500. * @private
  22501. * @param {Object} object The object to query.
  22502. * @returns {Array} Returns the array of property names.
  22503. */
  22504. function baseKeys(object) {
  22505. if (!_isPrototype(object)) {
  22506. return _nativeKeys(object);
  22507. }
  22508. var result = [];
  22509. for (var key in Object(object)) {
  22510. if (hasOwnProperty$8.call(object, key) && key != 'constructor') {
  22511. result.push(key);
  22512. }
  22513. }
  22514. return result;
  22515. }
  22516. var _baseKeys = baseKeys;
  22517. /**
  22518. * Checks if `value` is array-like. A value is considered array-like if it's
  22519. * not a function and has a `value.length` that's an integer greater than or
  22520. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  22521. *
  22522. * @static
  22523. * @memberOf _
  22524. * @since 4.0.0
  22525. * @category Lang
  22526. * @param {*} value The value to check.
  22527. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  22528. * @example
  22529. *
  22530. * _.isArrayLike([1, 2, 3]);
  22531. * // => true
  22532. *
  22533. * _.isArrayLike(document.body.children);
  22534. * // => true
  22535. *
  22536. * _.isArrayLike('abc');
  22537. * // => true
  22538. *
  22539. * _.isArrayLike(_.noop);
  22540. * // => false
  22541. */
  22542. function isArrayLike(value) {
  22543. return value != null && isLength_1(value.length) && !isFunction_1(value);
  22544. }
  22545. var isArrayLike_1 = isArrayLike;
  22546. /**
  22547. * Creates an array of the own enumerable property names of `object`.
  22548. *
  22549. * **Note:** Non-object values are coerced to objects. See the
  22550. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  22551. * for more details.
  22552. *
  22553. * @static
  22554. * @since 0.1.0
  22555. * @memberOf _
  22556. * @category Object
  22557. * @param {Object} object The object to query.
  22558. * @returns {Array} Returns the array of property names.
  22559. * @example
  22560. *
  22561. * function Foo() {
  22562. * this.a = 1;
  22563. * this.b = 2;
  22564. * }
  22565. *
  22566. * Foo.prototype.c = 3;
  22567. *
  22568. * _.keys(new Foo);
  22569. * // => ['a', 'b'] (iteration order is not guaranteed)
  22570. *
  22571. * _.keys('hi');
  22572. * // => ['0', '1']
  22573. */
  22574. function keys(object) {
  22575. return isArrayLike_1(object) ? _arrayLikeKeys(object) : _baseKeys(object);
  22576. }
  22577. var keys_1 = keys;
  22578. /**
  22579. * Creates an array of own enumerable property names and symbols of `object`.
  22580. *
  22581. * @private
  22582. * @param {Object} object The object to query.
  22583. * @returns {Array} Returns the array of property names and symbols.
  22584. */
  22585. function getAllKeys(object) {
  22586. return _baseGetAllKeys(object, keys_1, _getSymbols);
  22587. }
  22588. var _getAllKeys = getAllKeys;
  22589. /** Used to compose bitmasks for value comparisons. */
  22590. var COMPARE_PARTIAL_FLAG$2 = 1;
  22591. /** Used for built-in method references. */
  22592. var objectProto$a = Object.prototype;
  22593. /** Used to check objects for own properties. */
  22594. var hasOwnProperty$9 = objectProto$a.hasOwnProperty;
  22595. /**
  22596. * A specialized version of `baseIsEqualDeep` for objects with support for
  22597. * partial deep comparisons.
  22598. *
  22599. * @private
  22600. * @param {Object} object The object to compare.
  22601. * @param {Object} other The other object to compare.
  22602. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  22603. * @param {Function} customizer The function to customize comparisons.
  22604. * @param {Function} equalFunc The function to determine equivalents of values.
  22605. * @param {Object} stack Tracks traversed `object` and `other` objects.
  22606. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  22607. */
  22608. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  22609. var isPartial = bitmask & COMPARE_PARTIAL_FLAG$2,
  22610. objProps = _getAllKeys(object),
  22611. objLength = objProps.length,
  22612. othProps = _getAllKeys(other),
  22613. othLength = othProps.length;
  22614. if (objLength != othLength && !isPartial) {
  22615. return false;
  22616. }
  22617. var index = objLength;
  22618. while (index--) {
  22619. var key = objProps[index];
  22620. if (!(isPartial ? key in other : hasOwnProperty$9.call(other, key))) {
  22621. return false;
  22622. }
  22623. } // Check that cyclic values are equal.
  22624. var objStacked = stack.get(object);
  22625. var othStacked = stack.get(other);
  22626. if (objStacked && othStacked) {
  22627. return objStacked == other && othStacked == object;
  22628. }
  22629. var result = true;
  22630. stack.set(object, other);
  22631. stack.set(other, object);
  22632. var skipCtor = isPartial;
  22633. while (++index < objLength) {
  22634. key = objProps[index];
  22635. var objValue = object[key],
  22636. othValue = other[key];
  22637. if (customizer) {
  22638. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  22639. } // Recursively compare objects (susceptible to call stack limits).
  22640. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack) : compared)) {
  22641. result = false;
  22642. break;
  22643. }
  22644. skipCtor || (skipCtor = key == 'constructor');
  22645. }
  22646. if (result && !skipCtor) {
  22647. var objCtor = object.constructor,
  22648. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  22649. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  22650. result = false;
  22651. }
  22652. }
  22653. stack['delete'](object);
  22654. stack['delete'](other);
  22655. return result;
  22656. }
  22657. var _equalObjects = equalObjects;
  22658. /* Built-in method references that are verified to be native. */
  22659. var DataView = _getNative(_root, 'DataView');
  22660. var _DataView = DataView;
  22661. /* Built-in method references that are verified to be native. */
  22662. var Promise$1 = _getNative(_root, 'Promise');
  22663. var _Promise = Promise$1;
  22664. /* Built-in method references that are verified to be native. */
  22665. var Set$1 = _getNative(_root, 'Set');
  22666. var _Set = Set$1;
  22667. /* Built-in method references that are verified to be native. */
  22668. var WeakMap$1 = _getNative(_root, 'WeakMap');
  22669. var _WeakMap = WeakMap$1;
  22670. /** `Object#toString` result references. */
  22671. var mapTag$2 = '[object Map]',
  22672. objectTag$1 = '[object Object]',
  22673. promiseTag = '[object Promise]',
  22674. setTag$2 = '[object Set]',
  22675. weakMapTag$1 = '[object WeakMap]';
  22676. var dataViewTag$2 = '[object DataView]';
  22677. /** Used to detect maps, sets, and weakmaps. */
  22678. var dataViewCtorString = _toSource(_DataView),
  22679. mapCtorString = _toSource(_Map),
  22680. promiseCtorString = _toSource(_Promise),
  22681. setCtorString = _toSource(_Set),
  22682. weakMapCtorString = _toSource(_WeakMap);
  22683. /**
  22684. * Gets the `toStringTag` of `value`.
  22685. *
  22686. * @private
  22687. * @param {*} value The value to query.
  22688. * @returns {string} Returns the `toStringTag`.
  22689. */
  22690. var getTag = _baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  22691. if (_DataView && getTag(new _DataView(new ArrayBuffer(1))) != dataViewTag$2 || _Map && getTag(new _Map()) != mapTag$2 || _Promise && getTag(_Promise.resolve()) != promiseTag || _Set && getTag(new _Set()) != setTag$2 || _WeakMap && getTag(new _WeakMap()) != weakMapTag$1) {
  22692. getTag = function (value) {
  22693. var result = _baseGetTag(value),
  22694. Ctor = result == objectTag$1 ? value.constructor : undefined,
  22695. ctorString = Ctor ? _toSource(Ctor) : '';
  22696. if (ctorString) {
  22697. switch (ctorString) {
  22698. case dataViewCtorString:
  22699. return dataViewTag$2;
  22700. case mapCtorString:
  22701. return mapTag$2;
  22702. case promiseCtorString:
  22703. return promiseTag;
  22704. case setCtorString:
  22705. return setTag$2;
  22706. case weakMapCtorString:
  22707. return weakMapTag$1;
  22708. }
  22709. }
  22710. return result;
  22711. };
  22712. }
  22713. var _getTag = getTag;
  22714. /** Used to compose bitmasks for value comparisons. */
  22715. var COMPARE_PARTIAL_FLAG$3 = 1;
  22716. /** `Object#toString` result references. */
  22717. var argsTag$2 = '[object Arguments]',
  22718. arrayTag$1 = '[object Array]',
  22719. objectTag$2 = '[object Object]';
  22720. /** Used for built-in method references. */
  22721. var objectProto$b = Object.prototype;
  22722. /** Used to check objects for own properties. */
  22723. var hasOwnProperty$a = objectProto$b.hasOwnProperty;
  22724. /**
  22725. * A specialized version of `baseIsEqual` for arrays and objects which performs
  22726. * deep comparisons and tracks traversed objects enabling objects with circular
  22727. * references to be compared.
  22728. *
  22729. * @private
  22730. * @param {Object} object The object to compare.
  22731. * @param {Object} other The other object to compare.
  22732. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  22733. * @param {Function} customizer The function to customize comparisons.
  22734. * @param {Function} equalFunc The function to determine equivalents of values.
  22735. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  22736. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  22737. */
  22738. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  22739. var objIsArr = isArray_1(object),
  22740. othIsArr = isArray_1(other),
  22741. objTag = objIsArr ? arrayTag$1 : _getTag(object),
  22742. othTag = othIsArr ? arrayTag$1 : _getTag(other);
  22743. objTag = objTag == argsTag$2 ? objectTag$2 : objTag;
  22744. othTag = othTag == argsTag$2 ? objectTag$2 : othTag;
  22745. var objIsObj = objTag == objectTag$2,
  22746. othIsObj = othTag == objectTag$2,
  22747. isSameTag = objTag == othTag;
  22748. if (isSameTag && isBuffer_1(object)) {
  22749. if (!isBuffer_1(other)) {
  22750. return false;
  22751. }
  22752. objIsArr = true;
  22753. objIsObj = false;
  22754. }
  22755. if (isSameTag && !objIsObj) {
  22756. stack || (stack = new _Stack());
  22757. return objIsArr || isTypedArray_1(object) ? _equalArrays(object, other, bitmask, customizer, equalFunc, stack) : _equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  22758. }
  22759. if (!(bitmask & COMPARE_PARTIAL_FLAG$3)) {
  22760. var objIsWrapped = objIsObj && hasOwnProperty$a.call(object, '__wrapped__'),
  22761. othIsWrapped = othIsObj && hasOwnProperty$a.call(other, '__wrapped__');
  22762. if (objIsWrapped || othIsWrapped) {
  22763. var objUnwrapped = objIsWrapped ? object.value() : object,
  22764. othUnwrapped = othIsWrapped ? other.value() : other;
  22765. stack || (stack = new _Stack());
  22766. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  22767. }
  22768. }
  22769. if (!isSameTag) {
  22770. return false;
  22771. }
  22772. stack || (stack = new _Stack());
  22773. return _equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  22774. }
  22775. var _baseIsEqualDeep = baseIsEqualDeep;
  22776. /**
  22777. * The base implementation of `_.isEqual` which supports partial comparisons
  22778. * and tracks traversed objects.
  22779. *
  22780. * @private
  22781. * @param {*} value The value to compare.
  22782. * @param {*} other The other value to compare.
  22783. * @param {boolean} bitmask The bitmask flags.
  22784. * 1 - Unordered comparison
  22785. * 2 - Partial comparison
  22786. * @param {Function} [customizer] The function to customize comparisons.
  22787. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  22788. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  22789. */
  22790. function baseIsEqual(value, other, bitmask, customizer, stack) {
  22791. if (value === other) {
  22792. return true;
  22793. }
  22794. if (value == null || other == null || !isObjectLike_1(value) && !isObjectLike_1(other)) {
  22795. return value !== value && other !== other;
  22796. }
  22797. return _baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  22798. }
  22799. var _baseIsEqual = baseIsEqual;
  22800. /** Used to compose bitmasks for value comparisons. */
  22801. var COMPARE_PARTIAL_FLAG$4 = 1,
  22802. COMPARE_UNORDERED_FLAG$2 = 2;
  22803. /**
  22804. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  22805. *
  22806. * @private
  22807. * @param {Object} object The object to inspect.
  22808. * @param {Object} source The object of property values to match.
  22809. * @param {Array} matchData The property names, values, and compare flags to match.
  22810. * @param {Function} [customizer] The function to customize comparisons.
  22811. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  22812. */
  22813. function baseIsMatch(object, source, matchData, customizer) {
  22814. var index = matchData.length,
  22815. length = index,
  22816. noCustomizer = !customizer;
  22817. if (object == null) {
  22818. return !length;
  22819. }
  22820. object = Object(object);
  22821. while (index--) {
  22822. var data = matchData[index];
  22823. if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
  22824. return false;
  22825. }
  22826. }
  22827. while (++index < length) {
  22828. data = matchData[index];
  22829. var key = data[0],
  22830. objValue = object[key],
  22831. srcValue = data[1];
  22832. if (noCustomizer && data[2]) {
  22833. if (objValue === undefined && !(key in object)) {
  22834. return false;
  22835. }
  22836. } else {
  22837. var stack = new _Stack();
  22838. if (customizer) {
  22839. var result = customizer(objValue, srcValue, key, object, source, stack);
  22840. }
  22841. if (!(result === undefined ? _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG$4 | COMPARE_UNORDERED_FLAG$2, customizer, stack) : result)) {
  22842. return false;
  22843. }
  22844. }
  22845. }
  22846. return true;
  22847. }
  22848. var _baseIsMatch = baseIsMatch;
  22849. /**
  22850. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  22851. *
  22852. * @private
  22853. * @param {*} value The value to check.
  22854. * @returns {boolean} Returns `true` if `value` if suitable for strict
  22855. * equality comparisons, else `false`.
  22856. */
  22857. function isStrictComparable(value) {
  22858. return value === value && !isObject_1(value);
  22859. }
  22860. var _isStrictComparable = isStrictComparable;
  22861. /**
  22862. * Gets the property names, values, and compare flags of `object`.
  22863. *
  22864. * @private
  22865. * @param {Object} object The object to query.
  22866. * @returns {Array} Returns the match data of `object`.
  22867. */
  22868. function getMatchData(object) {
  22869. var result = keys_1(object),
  22870. length = result.length;
  22871. while (length--) {
  22872. var key = result[length],
  22873. value = object[key];
  22874. result[length] = [key, value, _isStrictComparable(value)];
  22875. }
  22876. return result;
  22877. }
  22878. var _getMatchData = getMatchData;
  22879. /**
  22880. * A specialized version of `matchesProperty` for source values suitable
  22881. * for strict equality comparisons, i.e. `===`.
  22882. *
  22883. * @private
  22884. * @param {string} key The key of the property to get.
  22885. * @param {*} srcValue The value to match.
  22886. * @returns {Function} Returns the new spec function.
  22887. */
  22888. function matchesStrictComparable(key, srcValue) {
  22889. return function (object) {
  22890. if (object == null) {
  22891. return false;
  22892. }
  22893. return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
  22894. };
  22895. }
  22896. var _matchesStrictComparable = matchesStrictComparable;
  22897. /**
  22898. * The base implementation of `_.matches` which doesn't clone `source`.
  22899. *
  22900. * @private
  22901. * @param {Object} source The object of property values to match.
  22902. * @returns {Function} Returns the new spec function.
  22903. */
  22904. function baseMatches(source) {
  22905. var matchData = _getMatchData(source);
  22906. if (matchData.length == 1 && matchData[0][2]) {
  22907. return _matchesStrictComparable(matchData[0][0], matchData[0][1]);
  22908. }
  22909. return function (object) {
  22910. return object === source || _baseIsMatch(object, source, matchData);
  22911. };
  22912. }
  22913. var _baseMatches = baseMatches;
  22914. /** `Object#toString` result references. */
  22915. var symbolTag$1 = '[object Symbol]';
  22916. /**
  22917. * Checks if `value` is classified as a `Symbol` primitive or object.
  22918. *
  22919. * @static
  22920. * @memberOf _
  22921. * @since 4.0.0
  22922. * @category Lang
  22923. * @param {*} value The value to check.
  22924. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  22925. * @example
  22926. *
  22927. * _.isSymbol(Symbol.iterator);
  22928. * // => true
  22929. *
  22930. * _.isSymbol('abc');
  22931. * // => false
  22932. */
  22933. function isSymbol(value) {
  22934. return typeof value == 'symbol' || isObjectLike_1(value) && _baseGetTag(value) == symbolTag$1;
  22935. }
  22936. var isSymbol_1 = isSymbol;
  22937. /** Used to match property names within property paths. */
  22938. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  22939. reIsPlainProp = /^\w*$/;
  22940. /**
  22941. * Checks if `value` is a property name and not a property path.
  22942. *
  22943. * @private
  22944. * @param {*} value The value to check.
  22945. * @param {Object} [object] The object to query keys on.
  22946. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  22947. */
  22948. function isKey(value, object) {
  22949. if (isArray_1(value)) {
  22950. return false;
  22951. }
  22952. var type = typeof value;
  22953. if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol_1(value)) {
  22954. return true;
  22955. }
  22956. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
  22957. }
  22958. var _isKey = isKey;
  22959. /** Error message constants. */
  22960. var FUNC_ERROR_TEXT = 'Expected a function';
  22961. /**
  22962. * Creates a function that memoizes the result of `func`. If `resolver` is
  22963. * provided, it determines the cache key for storing the result based on the
  22964. * arguments provided to the memoized function. By default, the first argument
  22965. * provided to the memoized function is used as the map cache key. The `func`
  22966. * is invoked with the `this` binding of the memoized function.
  22967. *
  22968. * **Note:** The cache is exposed as the `cache` property on the memoized
  22969. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  22970. * constructor with one whose instances implement the
  22971. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  22972. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  22973. *
  22974. * @static
  22975. * @memberOf _
  22976. * @since 0.1.0
  22977. * @category Function
  22978. * @param {Function} func The function to have its output memoized.
  22979. * @param {Function} [resolver] The function to resolve the cache key.
  22980. * @returns {Function} Returns the new memoized function.
  22981. * @example
  22982. *
  22983. * var object = { 'a': 1, 'b': 2 };
  22984. * var other = { 'c': 3, 'd': 4 };
  22985. *
  22986. * var values = _.memoize(_.values);
  22987. * values(object);
  22988. * // => [1, 2]
  22989. *
  22990. * values(other);
  22991. * // => [3, 4]
  22992. *
  22993. * object.a = 2;
  22994. * values(object);
  22995. * // => [1, 2]
  22996. *
  22997. * // Modify the result cache.
  22998. * values.cache.set(object, ['a', 'b']);
  22999. * values(object);
  23000. * // => ['a', 'b']
  23001. *
  23002. * // Replace `_.memoize.Cache`.
  23003. * _.memoize.Cache = WeakMap;
  23004. */
  23005. function memoize(func, resolver) {
  23006. if (typeof func != 'function' || resolver != null && typeof resolver != 'function') {
  23007. throw new TypeError(FUNC_ERROR_TEXT);
  23008. }
  23009. var memoized = function () {
  23010. var args = arguments,
  23011. key = resolver ? resolver.apply(this, args) : args[0],
  23012. cache = memoized.cache;
  23013. if (cache.has(key)) {
  23014. return cache.get(key);
  23015. }
  23016. var result = func.apply(this, args);
  23017. memoized.cache = cache.set(key, result) || cache;
  23018. return result;
  23019. };
  23020. memoized.cache = new (memoize.Cache || _MapCache)();
  23021. return memoized;
  23022. } // Expose `MapCache`.
  23023. memoize.Cache = _MapCache;
  23024. var memoize_1 = memoize;
  23025. /** Used as the maximum memoize cache size. */
  23026. var MAX_MEMOIZE_SIZE = 500;
  23027. /**
  23028. * A specialized version of `_.memoize` which clears the memoized function's
  23029. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  23030. *
  23031. * @private
  23032. * @param {Function} func The function to have its output memoized.
  23033. * @returns {Function} Returns the new memoized function.
  23034. */
  23035. function memoizeCapped(func) {
  23036. var result = memoize_1(func, function (key) {
  23037. if (cache.size === MAX_MEMOIZE_SIZE) {
  23038. cache.clear();
  23039. }
  23040. return key;
  23041. });
  23042. var cache = result.cache;
  23043. return result;
  23044. }
  23045. var _memoizeCapped = memoizeCapped;
  23046. /** Used to match property names within property paths. */
  23047. var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  23048. /** Used to match backslashes in property paths. */
  23049. var reEscapeChar = /\\(\\)?/g;
  23050. /**
  23051. * Converts `string` to a property path array.
  23052. *
  23053. * @private
  23054. * @param {string} string The string to convert.
  23055. * @returns {Array} Returns the property path array.
  23056. */
  23057. var stringToPath = _memoizeCapped(function (string) {
  23058. var result = [];
  23059. if (string.charCodeAt(0) === 46
  23060. /* . */
  23061. ) {
  23062. result.push('');
  23063. }
  23064. string.replace(rePropName, function (match, number, quote, subString) {
  23065. result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match);
  23066. });
  23067. return result;
  23068. });
  23069. var _stringToPath = stringToPath;
  23070. /**
  23071. * A specialized version of `_.map` for arrays without support for iteratee
  23072. * shorthands.
  23073. *
  23074. * @private
  23075. * @param {Array} [array] The array to iterate over.
  23076. * @param {Function} iteratee The function invoked per iteration.
  23077. * @returns {Array} Returns the new mapped array.
  23078. */
  23079. function arrayMap(array, iteratee) {
  23080. var index = -1,
  23081. length = array == null ? 0 : array.length,
  23082. result = Array(length);
  23083. while (++index < length) {
  23084. result[index] = iteratee(array[index], index, array);
  23085. }
  23086. return result;
  23087. }
  23088. var _arrayMap = arrayMap;
  23089. /** Used as references for various `Number` constants. */
  23090. var INFINITY = 1 / 0;
  23091. /** Used to convert symbols to primitives and strings. */
  23092. var symbolProto$1 = _Symbol ? _Symbol.prototype : undefined,
  23093. symbolToString = symbolProto$1 ? symbolProto$1.toString : undefined;
  23094. /**
  23095. * The base implementation of `_.toString` which doesn't convert nullish
  23096. * values to empty strings.
  23097. *
  23098. * @private
  23099. * @param {*} value The value to process.
  23100. * @returns {string} Returns the string.
  23101. */
  23102. function baseToString(value) {
  23103. // Exit early for strings to avoid a performance hit in some environments.
  23104. if (typeof value == 'string') {
  23105. return value;
  23106. }
  23107. if (isArray_1(value)) {
  23108. // Recursively convert values (susceptible to call stack limits).
  23109. return _arrayMap(value, baseToString) + '';
  23110. }
  23111. if (isSymbol_1(value)) {
  23112. return symbolToString ? symbolToString.call(value) : '';
  23113. }
  23114. var result = value + '';
  23115. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  23116. }
  23117. var _baseToString = baseToString;
  23118. /**
  23119. * Converts `value` to a string. An empty string is returned for `null`
  23120. * and `undefined` values. The sign of `-0` is preserved.
  23121. *
  23122. * @static
  23123. * @memberOf _
  23124. * @since 4.0.0
  23125. * @category Lang
  23126. * @param {*} value The value to convert.
  23127. * @returns {string} Returns the converted string.
  23128. * @example
  23129. *
  23130. * _.toString(null);
  23131. * // => ''
  23132. *
  23133. * _.toString(-0);
  23134. * // => '-0'
  23135. *
  23136. * _.toString([1, 2, 3]);
  23137. * // => '1,2,3'
  23138. */
  23139. function toString(value) {
  23140. return value == null ? '' : _baseToString(value);
  23141. }
  23142. var toString_1 = toString;
  23143. /**
  23144. * Casts `value` to a path array if it's not one.
  23145. *
  23146. * @private
  23147. * @param {*} value The value to inspect.
  23148. * @param {Object} [object] The object to query keys on.
  23149. * @returns {Array} Returns the cast property path array.
  23150. */
  23151. function castPath(value, object) {
  23152. if (isArray_1(value)) {
  23153. return value;
  23154. }
  23155. return _isKey(value, object) ? [value] : _stringToPath(toString_1(value));
  23156. }
  23157. var _castPath = castPath;
  23158. /** Used as references for various `Number` constants. */
  23159. var INFINITY$1 = 1 / 0;
  23160. /**
  23161. * Converts `value` to a string key if it's not a string or symbol.
  23162. *
  23163. * @private
  23164. * @param {*} value The value to inspect.
  23165. * @returns {string|symbol} Returns the key.
  23166. */
  23167. function toKey(value) {
  23168. if (typeof value == 'string' || isSymbol_1(value)) {
  23169. return value;
  23170. }
  23171. var result = value + '';
  23172. return result == '0' && 1 / value == -INFINITY$1 ? '-0' : result;
  23173. }
  23174. var _toKey = toKey;
  23175. /**
  23176. * The base implementation of `_.get` without support for default values.
  23177. *
  23178. * @private
  23179. * @param {Object} object The object to query.
  23180. * @param {Array|string} path The path of the property to get.
  23181. * @returns {*} Returns the resolved value.
  23182. */
  23183. function baseGet(object, path) {
  23184. path = _castPath(path, object);
  23185. var index = 0,
  23186. length = path.length;
  23187. while (object != null && index < length) {
  23188. object = object[_toKey(path[index++])];
  23189. }
  23190. return index && index == length ? object : undefined;
  23191. }
  23192. var _baseGet = baseGet;
  23193. /**
  23194. * Gets the value at `path` of `object`. If the resolved value is
  23195. * `undefined`, the `defaultValue` is returned in its place.
  23196. *
  23197. * @static
  23198. * @memberOf _
  23199. * @since 3.7.0
  23200. * @category Object
  23201. * @param {Object} object The object to query.
  23202. * @param {Array|string} path The path of the property to get.
  23203. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  23204. * @returns {*} Returns the resolved value.
  23205. * @example
  23206. *
  23207. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  23208. *
  23209. * _.get(object, 'a[0].b.c');
  23210. * // => 3
  23211. *
  23212. * _.get(object, ['a', '0', 'b', 'c']);
  23213. * // => 3
  23214. *
  23215. * _.get(object, 'a.b.c', 'default');
  23216. * // => 'default'
  23217. */
  23218. function get$1(object, path, defaultValue) {
  23219. var result = object == null ? undefined : _baseGet(object, path);
  23220. return result === undefined ? defaultValue : result;
  23221. }
  23222. var get_1 = get$1;
  23223. /**
  23224. * The base implementation of `_.hasIn` without support for deep paths.
  23225. *
  23226. * @private
  23227. * @param {Object} [object] The object to query.
  23228. * @param {Array|string} key The key to check.
  23229. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  23230. */
  23231. function baseHasIn(object, key) {
  23232. return object != null && key in Object(object);
  23233. }
  23234. var _baseHasIn = baseHasIn;
  23235. /**
  23236. * Checks if `path` exists on `object`.
  23237. *
  23238. * @private
  23239. * @param {Object} object The object to query.
  23240. * @param {Array|string} path The path to check.
  23241. * @param {Function} hasFunc The function to check properties.
  23242. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  23243. */
  23244. function hasPath(object, path, hasFunc) {
  23245. path = _castPath(path, object);
  23246. var index = -1,
  23247. length = path.length,
  23248. result = false;
  23249. while (++index < length) {
  23250. var key = _toKey(path[index]);
  23251. if (!(result = object != null && hasFunc(object, key))) {
  23252. break;
  23253. }
  23254. object = object[key];
  23255. }
  23256. if (result || ++index != length) {
  23257. return result;
  23258. }
  23259. length = object == null ? 0 : object.length;
  23260. return !!length && isLength_1(length) && _isIndex(key, length) && (isArray_1(object) || isArguments_1(object));
  23261. }
  23262. var _hasPath = hasPath;
  23263. /**
  23264. * Checks if `path` is a direct or inherited property of `object`.
  23265. *
  23266. * @static
  23267. * @memberOf _
  23268. * @since 4.0.0
  23269. * @category Object
  23270. * @param {Object} object The object to query.
  23271. * @param {Array|string} path The path to check.
  23272. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  23273. * @example
  23274. *
  23275. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  23276. *
  23277. * _.hasIn(object, 'a');
  23278. * // => true
  23279. *
  23280. * _.hasIn(object, 'a.b');
  23281. * // => true
  23282. *
  23283. * _.hasIn(object, ['a', 'b']);
  23284. * // => true
  23285. *
  23286. * _.hasIn(object, 'b');
  23287. * // => false
  23288. */
  23289. function hasIn(object, path) {
  23290. return object != null && _hasPath(object, path, _baseHasIn);
  23291. }
  23292. var hasIn_1 = hasIn;
  23293. /** Used to compose bitmasks for value comparisons. */
  23294. var COMPARE_PARTIAL_FLAG$5 = 1,
  23295. COMPARE_UNORDERED_FLAG$3 = 2;
  23296. /**
  23297. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  23298. *
  23299. * @private
  23300. * @param {string} path The path of the property to get.
  23301. * @param {*} srcValue The value to match.
  23302. * @returns {Function} Returns the new spec function.
  23303. */
  23304. function baseMatchesProperty(path, srcValue) {
  23305. if (_isKey(path) && _isStrictComparable(srcValue)) {
  23306. return _matchesStrictComparable(_toKey(path), srcValue);
  23307. }
  23308. return function (object) {
  23309. var objValue = get_1(object, path);
  23310. return objValue === undefined && objValue === srcValue ? hasIn_1(object, path) : _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG$5 | COMPARE_UNORDERED_FLAG$3);
  23311. };
  23312. }
  23313. var _baseMatchesProperty = baseMatchesProperty;
  23314. /**
  23315. * This method returns the first argument it receives.
  23316. *
  23317. * @static
  23318. * @since 0.1.0
  23319. * @memberOf _
  23320. * @category Util
  23321. * @param {*} value Any value.
  23322. * @returns {*} Returns `value`.
  23323. * @example
  23324. *
  23325. * var object = { 'a': 1 };
  23326. *
  23327. * console.log(_.identity(object) === object);
  23328. * // => true
  23329. */
  23330. function identity(value) {
  23331. return value;
  23332. }
  23333. var identity_1 = identity;
  23334. /**
  23335. * The base implementation of `_.property` without support for deep paths.
  23336. *
  23337. * @private
  23338. * @param {string} key The key of the property to get.
  23339. * @returns {Function} Returns the new accessor function.
  23340. */
  23341. function baseProperty(key) {
  23342. return function (object) {
  23343. return object == null ? undefined : object[key];
  23344. };
  23345. }
  23346. var _baseProperty = baseProperty;
  23347. /**
  23348. * A specialized version of `baseProperty` which supports deep paths.
  23349. *
  23350. * @private
  23351. * @param {Array|string} path The path of the property to get.
  23352. * @returns {Function} Returns the new accessor function.
  23353. */
  23354. function basePropertyDeep(path) {
  23355. return function (object) {
  23356. return _baseGet(object, path);
  23357. };
  23358. }
  23359. var _basePropertyDeep = basePropertyDeep;
  23360. /**
  23361. * Creates a function that returns the value at `path` of a given object.
  23362. *
  23363. * @static
  23364. * @memberOf _
  23365. * @since 2.4.0
  23366. * @category Util
  23367. * @param {Array|string} path The path of the property to get.
  23368. * @returns {Function} Returns the new accessor function.
  23369. * @example
  23370. *
  23371. * var objects = [
  23372. * { 'a': { 'b': 2 } },
  23373. * { 'a': { 'b': 1 } }
  23374. * ];
  23375. *
  23376. * _.map(objects, _.property('a.b'));
  23377. * // => [2, 1]
  23378. *
  23379. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  23380. * // => [1, 2]
  23381. */
  23382. function property(path) {
  23383. return _isKey(path) ? _baseProperty(_toKey(path)) : _basePropertyDeep(path);
  23384. }
  23385. var property_1 = property;
  23386. /**
  23387. * The base implementation of `_.iteratee`.
  23388. *
  23389. * @private
  23390. * @param {*} [value=_.identity] The value to convert to an iteratee.
  23391. * @returns {Function} Returns the iteratee.
  23392. */
  23393. function baseIteratee(value) {
  23394. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  23395. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  23396. if (typeof value == 'function') {
  23397. return value;
  23398. }
  23399. if (value == null) {
  23400. return identity_1;
  23401. }
  23402. if (typeof value == 'object') {
  23403. return isArray_1(value) ? _baseMatchesProperty(value[0], value[1]) : _baseMatches(value);
  23404. }
  23405. return property_1(value);
  23406. }
  23407. var _baseIteratee = baseIteratee;
  23408. /**
  23409. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  23410. * support for iteratee shorthands.
  23411. *
  23412. * @private
  23413. * @param {Array} array The array to inspect.
  23414. * @param {Function} predicate The function invoked per iteration.
  23415. * @param {number} fromIndex The index to search from.
  23416. * @param {boolean} [fromRight] Specify iterating from right to left.
  23417. * @returns {number} Returns the index of the matched value, else `-1`.
  23418. */
  23419. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  23420. var length = array.length,
  23421. index = fromIndex + (fromRight ? 1 : -1);
  23422. while (fromRight ? index-- : ++index < length) {
  23423. if (predicate(array[index], index, array)) {
  23424. return index;
  23425. }
  23426. }
  23427. return -1;
  23428. }
  23429. var _baseFindIndex = baseFindIndex;
  23430. /**
  23431. * The base implementation of `_.isNaN` without support for number objects.
  23432. *
  23433. * @private
  23434. * @param {*} value The value to check.
  23435. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  23436. */
  23437. function baseIsNaN(value) {
  23438. return value !== value;
  23439. }
  23440. var _baseIsNaN = baseIsNaN;
  23441. /**
  23442. * A specialized version of `_.indexOf` which performs strict equality
  23443. * comparisons of values, i.e. `===`.
  23444. *
  23445. * @private
  23446. * @param {Array} array The array to inspect.
  23447. * @param {*} value The value to search for.
  23448. * @param {number} fromIndex The index to search from.
  23449. * @returns {number} Returns the index of the matched value, else `-1`.
  23450. */
  23451. function strictIndexOf(array, value, fromIndex) {
  23452. var index = fromIndex - 1,
  23453. length = array.length;
  23454. while (++index < length) {
  23455. if (array[index] === value) {
  23456. return index;
  23457. }
  23458. }
  23459. return -1;
  23460. }
  23461. var _strictIndexOf = strictIndexOf;
  23462. /**
  23463. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  23464. *
  23465. * @private
  23466. * @param {Array} array The array to inspect.
  23467. * @param {*} value The value to search for.
  23468. * @param {number} fromIndex The index to search from.
  23469. * @returns {number} Returns the index of the matched value, else `-1`.
  23470. */
  23471. function baseIndexOf(array, value, fromIndex) {
  23472. return value === value ? _strictIndexOf(array, value, fromIndex) : _baseFindIndex(array, _baseIsNaN, fromIndex);
  23473. }
  23474. var _baseIndexOf = baseIndexOf;
  23475. /**
  23476. * A specialized version of `_.includes` for arrays without support for
  23477. * specifying an index to search from.
  23478. *
  23479. * @private
  23480. * @param {Array} [array] The array to inspect.
  23481. * @param {*} target The value to search for.
  23482. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  23483. */
  23484. function arrayIncludes(array, value) {
  23485. var length = array == null ? 0 : array.length;
  23486. return !!length && _baseIndexOf(array, value, 0) > -1;
  23487. }
  23488. var _arrayIncludes = arrayIncludes;
  23489. /**
  23490. * This function is like `arrayIncludes` except that it accepts a comparator.
  23491. *
  23492. * @private
  23493. * @param {Array} [array] The array to inspect.
  23494. * @param {*} target The value to search for.
  23495. * @param {Function} comparator The comparator invoked per element.
  23496. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  23497. */
  23498. function arrayIncludesWith(array, value, comparator) {
  23499. var index = -1,
  23500. length = array == null ? 0 : array.length;
  23501. while (++index < length) {
  23502. if (comparator(value, array[index])) {
  23503. return true;
  23504. }
  23505. }
  23506. return false;
  23507. }
  23508. var _arrayIncludesWith = arrayIncludesWith;
  23509. /**
  23510. * This method returns `undefined`.
  23511. *
  23512. * @static
  23513. * @memberOf _
  23514. * @since 2.3.0
  23515. * @category Util
  23516. * @example
  23517. *
  23518. * _.times(2, _.noop);
  23519. * // => [undefined, undefined]
  23520. */
  23521. function noop() {// No operation performed.
  23522. }
  23523. var noop_1 = noop;
  23524. /** Used as references for various `Number` constants. */
  23525. var INFINITY$2 = 1 / 0;
  23526. /**
  23527. * Creates a set object of `values`.
  23528. *
  23529. * @private
  23530. * @param {Array} values The values to add to the set.
  23531. * @returns {Object} Returns the new set.
  23532. */
  23533. var createSet = !(_Set && 1 / _setToArray(new _Set([, -0]))[1] == INFINITY$2) ? noop_1 : function (values) {
  23534. return new _Set(values);
  23535. };
  23536. var _createSet = createSet;
  23537. /** Used as the size to enable large array optimizations. */
  23538. var LARGE_ARRAY_SIZE$1 = 200;
  23539. /**
  23540. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  23541. *
  23542. * @private
  23543. * @param {Array} array The array to inspect.
  23544. * @param {Function} [iteratee] The iteratee invoked per element.
  23545. * @param {Function} [comparator] The comparator invoked per element.
  23546. * @returns {Array} Returns the new duplicate free array.
  23547. */
  23548. function baseUniq(array, iteratee, comparator) {
  23549. var index = -1,
  23550. includes = _arrayIncludes,
  23551. length = array.length,
  23552. isCommon = true,
  23553. result = [],
  23554. seen = result;
  23555. if (comparator) {
  23556. isCommon = false;
  23557. includes = _arrayIncludesWith;
  23558. } else if (length >= LARGE_ARRAY_SIZE$1) {
  23559. var set = iteratee ? null : _createSet(array);
  23560. if (set) {
  23561. return _setToArray(set);
  23562. }
  23563. isCommon = false;
  23564. includes = _cacheHas;
  23565. seen = new _SetCache();
  23566. } else {
  23567. seen = iteratee ? [] : result;
  23568. }
  23569. outer: while (++index < length) {
  23570. var value = array[index],
  23571. computed = iteratee ? iteratee(value) : value;
  23572. value = comparator || value !== 0 ? value : 0;
  23573. if (isCommon && computed === computed) {
  23574. var seenIndex = seen.length;
  23575. while (seenIndex--) {
  23576. if (seen[seenIndex] === computed) {
  23577. continue outer;
  23578. }
  23579. }
  23580. if (iteratee) {
  23581. seen.push(computed);
  23582. }
  23583. result.push(value);
  23584. } else if (!includes(seen, computed, comparator)) {
  23585. if (seen !== result) {
  23586. seen.push(computed);
  23587. }
  23588. result.push(value);
  23589. }
  23590. }
  23591. return result;
  23592. }
  23593. var _baseUniq = baseUniq;
  23594. /**
  23595. * This method is like `_.uniq` except that it accepts `iteratee` which is
  23596. * invoked for each element in `array` to generate the criterion by which
  23597. * uniqueness is computed. The order of result values is determined by the
  23598. * order they occur in the array. The iteratee is invoked with one argument:
  23599. * (value).
  23600. *
  23601. * @static
  23602. * @memberOf _
  23603. * @since 4.0.0
  23604. * @category Array
  23605. * @param {Array} array The array to inspect.
  23606. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  23607. * @returns {Array} Returns the new duplicate free array.
  23608. * @example
  23609. *
  23610. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  23611. * // => [2.1, 1.2]
  23612. *
  23613. * // The `_.property` iteratee shorthand.
  23614. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  23615. * // => [{ 'x': 1 }, { 'x': 2 }]
  23616. */
  23617. function uniqBy(array, iteratee) {
  23618. return array && array.length ? _baseUniq(array, _baseIteratee(iteratee)) : [];
  23619. }
  23620. var uniqBy_1 = uniqBy;
  23621. /**
  23622. * A specialized version of `baseAggregator` for arrays.
  23623. *
  23624. * @private
  23625. * @param {Array} [array] The array to iterate over.
  23626. * @param {Function} setter The function to set `accumulator` values.
  23627. * @param {Function} iteratee The iteratee to transform keys.
  23628. * @param {Object} accumulator The initial aggregated object.
  23629. * @returns {Function} Returns `accumulator`.
  23630. */
  23631. function arrayAggregator(array, setter, iteratee, accumulator) {
  23632. var index = -1,
  23633. length = array == null ? 0 : array.length;
  23634. while (++index < length) {
  23635. var value = array[index];
  23636. setter(accumulator, value, iteratee(value), array);
  23637. }
  23638. return accumulator;
  23639. }
  23640. var _arrayAggregator = arrayAggregator;
  23641. /**
  23642. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  23643. *
  23644. * @private
  23645. * @param {boolean} [fromRight] Specify iterating from right to left.
  23646. * @returns {Function} Returns the new base function.
  23647. */
  23648. function createBaseFor(fromRight) {
  23649. return function (object, iteratee, keysFunc) {
  23650. var index = -1,
  23651. iterable = Object(object),
  23652. props = keysFunc(object),
  23653. length = props.length;
  23654. while (length--) {
  23655. var key = props[fromRight ? length : ++index];
  23656. if (iteratee(iterable[key], key, iterable) === false) {
  23657. break;
  23658. }
  23659. }
  23660. return object;
  23661. };
  23662. }
  23663. var _createBaseFor = createBaseFor;
  23664. /**
  23665. * The base implementation of `baseForOwn` which iterates over `object`
  23666. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  23667. * Iteratee functions may exit iteration early by explicitly returning `false`.
  23668. *
  23669. * @private
  23670. * @param {Object} object The object to iterate over.
  23671. * @param {Function} iteratee The function invoked per iteration.
  23672. * @param {Function} keysFunc The function to get the keys of `object`.
  23673. * @returns {Object} Returns `object`.
  23674. */
  23675. var baseFor = _createBaseFor();
  23676. var _baseFor = baseFor;
  23677. /**
  23678. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  23679. *
  23680. * @private
  23681. * @param {Object} object The object to iterate over.
  23682. * @param {Function} iteratee The function invoked per iteration.
  23683. * @returns {Object} Returns `object`.
  23684. */
  23685. function baseForOwn(object, iteratee) {
  23686. return object && _baseFor(object, iteratee, keys_1);
  23687. }
  23688. var _baseForOwn = baseForOwn;
  23689. /**
  23690. * Creates a `baseEach` or `baseEachRight` function.
  23691. *
  23692. * @private
  23693. * @param {Function} eachFunc The function to iterate over a collection.
  23694. * @param {boolean} [fromRight] Specify iterating from right to left.
  23695. * @returns {Function} Returns the new base function.
  23696. */
  23697. function createBaseEach(eachFunc, fromRight) {
  23698. return function (collection, iteratee) {
  23699. if (collection == null) {
  23700. return collection;
  23701. }
  23702. if (!isArrayLike_1(collection)) {
  23703. return eachFunc(collection, iteratee);
  23704. }
  23705. var length = collection.length,
  23706. index = fromRight ? length : -1,
  23707. iterable = Object(collection);
  23708. while (fromRight ? index-- : ++index < length) {
  23709. if (iteratee(iterable[index], index, iterable) === false) {
  23710. break;
  23711. }
  23712. }
  23713. return collection;
  23714. };
  23715. }
  23716. var _createBaseEach = createBaseEach;
  23717. /**
  23718. * The base implementation of `_.forEach` without support for iteratee shorthands.
  23719. *
  23720. * @private
  23721. * @param {Array|Object} collection The collection to iterate over.
  23722. * @param {Function} iteratee The function invoked per iteration.
  23723. * @returns {Array|Object} Returns `collection`.
  23724. */
  23725. var baseEach = _createBaseEach(_baseForOwn);
  23726. var _baseEach = baseEach;
  23727. /**
  23728. * Aggregates elements of `collection` on `accumulator` with keys transformed
  23729. * by `iteratee` and values set by `setter`.
  23730. *
  23731. * @private
  23732. * @param {Array|Object} collection The collection to iterate over.
  23733. * @param {Function} setter The function to set `accumulator` values.
  23734. * @param {Function} iteratee The iteratee to transform keys.
  23735. * @param {Object} accumulator The initial aggregated object.
  23736. * @returns {Function} Returns `accumulator`.
  23737. */
  23738. function baseAggregator(collection, setter, iteratee, accumulator) {
  23739. _baseEach(collection, function (value, key, collection) {
  23740. setter(accumulator, value, iteratee(value), collection);
  23741. });
  23742. return accumulator;
  23743. }
  23744. var _baseAggregator = baseAggregator;
  23745. /**
  23746. * Creates a function like `_.groupBy`.
  23747. *
  23748. * @private
  23749. * @param {Function} setter The function to set accumulator values.
  23750. * @param {Function} [initializer] The accumulator object initializer.
  23751. * @returns {Function} Returns the new aggregator function.
  23752. */
  23753. function createAggregator(setter, initializer) {
  23754. return function (collection, iteratee) {
  23755. var func = isArray_1(collection) ? _arrayAggregator : _baseAggregator,
  23756. accumulator = initializer ? initializer() : {};
  23757. return func(collection, setter, _baseIteratee(iteratee), accumulator);
  23758. };
  23759. }
  23760. var _createAggregator = createAggregator;
  23761. /**
  23762. * Creates an array of elements split into two groups, the first of which
  23763. * contains elements `predicate` returns truthy for, the second of which
  23764. * contains elements `predicate` returns falsey for. The predicate is
  23765. * invoked with one argument: (value).
  23766. *
  23767. * @static
  23768. * @memberOf _
  23769. * @since 3.0.0
  23770. * @category Collection
  23771. * @param {Array|Object} collection The collection to iterate over.
  23772. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  23773. * @returns {Array} Returns the array of grouped elements.
  23774. * @example
  23775. *
  23776. * var users = [
  23777. * { 'user': 'barney', 'age': 36, 'active': false },
  23778. * { 'user': 'fred', 'age': 40, 'active': true },
  23779. * { 'user': 'pebbles', 'age': 1, 'active': false }
  23780. * ];
  23781. *
  23782. * _.partition(users, function(o) { return o.active; });
  23783. * // => objects for [['fred'], ['barney', 'pebbles']]
  23784. *
  23785. * // The `_.matches` iteratee shorthand.
  23786. * _.partition(users, { 'age': 1, 'active': false });
  23787. * // => objects for [['pebbles'], ['barney', 'fred']]
  23788. *
  23789. * // The `_.matchesProperty` iteratee shorthand.
  23790. * _.partition(users, ['active', false]);
  23791. * // => objects for [['barney', 'pebbles'], ['fred']]
  23792. *
  23793. * // The `_.property` iteratee shorthand.
  23794. * _.partition(users, 'active');
  23795. * // => objects for [['fred'], ['barney', 'pebbles']]
  23796. */
  23797. var partition = _createAggregator(function (result, value, key) {
  23798. result[key ? 0 : 1].push(value);
  23799. }, function () {
  23800. return [[], []];
  23801. });
  23802. var partition_1 = partition;
  23803. var arrayUnion = (...arguments_) => {
  23804. return [...new Set([].concat(...arguments_))];
  23805. };
  23806. /*
  23807. * merge2
  23808. * https://github.com/teambition/merge2
  23809. *
  23810. * Copyright (c) 2014-2020 Teambition
  23811. * Licensed under the MIT license.
  23812. */
  23813. const PassThrough = stream__default['default'].PassThrough;
  23814. const slice = Array.prototype.slice;
  23815. var merge2_1 = merge2;
  23816. function merge2() {
  23817. const streamsQueue = [];
  23818. const args = slice.call(arguments);
  23819. let merging = false;
  23820. let options = args[args.length - 1];
  23821. if (options && !Array.isArray(options) && options.pipe == null) {
  23822. args.pop();
  23823. } else {
  23824. options = {};
  23825. }
  23826. const doEnd = options.end !== false;
  23827. const doPipeError = options.pipeError === true;
  23828. if (options.objectMode == null) {
  23829. options.objectMode = true;
  23830. }
  23831. if (options.highWaterMark == null) {
  23832. options.highWaterMark = 64 * 1024;
  23833. }
  23834. const mergedStream = PassThrough(options);
  23835. function addStream() {
  23836. for (let i = 0, len = arguments.length; i < len; i++) {
  23837. streamsQueue.push(pauseStreams(arguments[i], options));
  23838. }
  23839. mergeStream();
  23840. return this;
  23841. }
  23842. function mergeStream() {
  23843. if (merging) {
  23844. return;
  23845. }
  23846. merging = true;
  23847. let streams = streamsQueue.shift();
  23848. if (!streams) {
  23849. process.nextTick(endStream);
  23850. return;
  23851. }
  23852. if (!Array.isArray(streams)) {
  23853. streams = [streams];
  23854. }
  23855. let pipesCount = streams.length + 1;
  23856. function next() {
  23857. if (--pipesCount > 0) {
  23858. return;
  23859. }
  23860. merging = false;
  23861. mergeStream();
  23862. }
  23863. function pipe(stream) {
  23864. function onend() {
  23865. stream.removeListener('merge2UnpipeEnd', onend);
  23866. stream.removeListener('end', onend);
  23867. if (doPipeError) {
  23868. stream.removeListener('error', onerror);
  23869. }
  23870. next();
  23871. }
  23872. function onerror(err) {
  23873. mergedStream.emit('error', err);
  23874. } // skip ended stream
  23875. if (stream._readableState.endEmitted) {
  23876. return next();
  23877. }
  23878. stream.on('merge2UnpipeEnd', onend);
  23879. stream.on('end', onend);
  23880. if (doPipeError) {
  23881. stream.on('error', onerror);
  23882. }
  23883. stream.pipe(mergedStream, {
  23884. end: false
  23885. }); // compatible for old stream
  23886. stream.resume();
  23887. }
  23888. for (let i = 0; i < streams.length; i++) {
  23889. pipe(streams[i]);
  23890. }
  23891. next();
  23892. }
  23893. function endStream() {
  23894. merging = false; // emit 'queueDrain' when all streams merged.
  23895. mergedStream.emit('queueDrain');
  23896. if (doEnd) {
  23897. mergedStream.end();
  23898. }
  23899. }
  23900. mergedStream.setMaxListeners(0);
  23901. mergedStream.add = addStream;
  23902. mergedStream.on('unpipe', function (stream) {
  23903. stream.emit('merge2UnpipeEnd');
  23904. });
  23905. if (args.length) {
  23906. addStream.apply(null, args);
  23907. }
  23908. return mergedStream;
  23909. } // check and pause streams for pipe.
  23910. function pauseStreams(streams, options) {
  23911. if (!Array.isArray(streams)) {
  23912. // Backwards-compat with old-style streams
  23913. if (!streams._readableState && streams.pipe) {
  23914. streams = streams.pipe(PassThrough(options));
  23915. }
  23916. if (!streams._readableState || !streams.pause || !streams.pipe) {
  23917. throw new Error('Only readable stream can be merged.');
  23918. }
  23919. streams.pause();
  23920. } else {
  23921. for (let i = 0, len = streams.length; i < len; i++) {
  23922. streams[i] = pauseStreams(streams[i], options);
  23923. }
  23924. }
  23925. return streams;
  23926. }
  23927. var array$2 = createCommonjsModule(function (module, exports) {
  23928. Object.defineProperty(exports, "__esModule", {
  23929. value: true
  23930. });
  23931. exports.splitWhen = exports.flatten = void 0;
  23932. function flatten(items) {
  23933. return items.reduce((collection, item) => [].concat(collection, item), []);
  23934. }
  23935. exports.flatten = flatten;
  23936. function splitWhen(items, predicate) {
  23937. const result = [[]];
  23938. let groupIndex = 0;
  23939. for (const item of items) {
  23940. if (predicate(item)) {
  23941. groupIndex++;
  23942. result[groupIndex] = [];
  23943. } else {
  23944. result[groupIndex].push(item);
  23945. }
  23946. }
  23947. return result;
  23948. }
  23949. exports.splitWhen = splitWhen;
  23950. });
  23951. var errno = createCommonjsModule(function (module, exports) {
  23952. Object.defineProperty(exports, "__esModule", {
  23953. value: true
  23954. });
  23955. exports.isEnoentCodeError = void 0;
  23956. function isEnoentCodeError(error) {
  23957. return error.code === 'ENOENT';
  23958. }
  23959. exports.isEnoentCodeError = isEnoentCodeError;
  23960. });
  23961. var fs$1 = createCommonjsModule(function (module, exports) {
  23962. Object.defineProperty(exports, "__esModule", {
  23963. value: true
  23964. });
  23965. exports.createDirentFromStats = void 0;
  23966. class DirentFromStats {
  23967. constructor(name, stats) {
  23968. this.name = name;
  23969. this.isBlockDevice = stats.isBlockDevice.bind(stats);
  23970. this.isCharacterDevice = stats.isCharacterDevice.bind(stats);
  23971. this.isDirectory = stats.isDirectory.bind(stats);
  23972. this.isFIFO = stats.isFIFO.bind(stats);
  23973. this.isFile = stats.isFile.bind(stats);
  23974. this.isSocket = stats.isSocket.bind(stats);
  23975. this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
  23976. }
  23977. }
  23978. function createDirentFromStats(name, stats) {
  23979. return new DirentFromStats(name, stats);
  23980. }
  23981. exports.createDirentFromStats = createDirentFromStats;
  23982. });
  23983. var path_1 = createCommonjsModule(function (module, exports) {
  23984. Object.defineProperty(exports, "__esModule", {
  23985. value: true
  23986. });
  23987. exports.removeLeadingDotSegment = exports.escape = exports.makeAbsolute = exports.unixify = void 0;
  23988. const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
  23989. const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
  23990. /**
  23991. * Designed to work only with simple paths: `dir\\file`.
  23992. */
  23993. function unixify(filepath) {
  23994. return filepath.replace(/\\/g, '/');
  23995. }
  23996. exports.unixify = unixify;
  23997. function makeAbsolute(cwd, filepath) {
  23998. return path__default['default'].resolve(cwd, filepath);
  23999. }
  24000. exports.makeAbsolute = makeAbsolute;
  24001. function escape(pattern) {
  24002. return pattern.replace(UNESCAPED_GLOB_SYMBOLS_RE, '\\$2');
  24003. }
  24004. exports.escape = escape;
  24005. function removeLeadingDotSegment(entry) {
  24006. // We do not use `startsWith` because this is 10x slower than current implementation for some cases.
  24007. // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
  24008. if (entry.charAt(0) === '.') {
  24009. const secondCharactery = entry.charAt(1);
  24010. if (secondCharactery === '/' || secondCharactery === '\\') {
  24011. return entry.slice(LEADING_DOT_SEGMENT_CHARACTERS_COUNT);
  24012. }
  24013. }
  24014. return entry;
  24015. }
  24016. exports.removeLeadingDotSegment = removeLeadingDotSegment;
  24017. });
  24018. /*!
  24019. * is-extglob <https://github.com/jonschlinkert/is-extglob>
  24020. *
  24021. * Copyright (c) 2014-2016, Jon Schlinkert.
  24022. * Licensed under the MIT License.
  24023. */
  24024. var isExtglob = function isExtglob(str) {
  24025. if (typeof str !== 'string' || str === '') {
  24026. return false;
  24027. }
  24028. var match;
  24029. while (match = /(\\).|([@?!+*]\(.*\))/g.exec(str)) {
  24030. if (match[2]) return true;
  24031. str = str.slice(match.index + match[0].length);
  24032. }
  24033. return false;
  24034. };
  24035. /*!
  24036. * is-glob <https://github.com/jonschlinkert/is-glob>
  24037. *
  24038. * Copyright (c) 2014-2017, Jon Schlinkert.
  24039. * Released under the MIT License.
  24040. */
  24041. var chars = {
  24042. '{': '}',
  24043. '(': ')',
  24044. '[': ']'
  24045. };
  24046. var strictRegex = /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/;
  24047. var relaxedRegex = /\\(.)|(^!|[*?{}()[\]]|\(\?)/;
  24048. var isGlob = function isGlob(str, options) {
  24049. if (typeof str !== 'string' || str === '') {
  24050. return false;
  24051. }
  24052. if (isExtglob(str)) {
  24053. return true;
  24054. }
  24055. var regex = strictRegex;
  24056. var match; // optionally relax regex
  24057. if (options && options.strict === false) {
  24058. regex = relaxedRegex;
  24059. }
  24060. while (match = regex.exec(str)) {
  24061. if (match[2]) return true;
  24062. var idx = match.index + match[0].length; // if an open bracket/brace/paren is escaped,
  24063. // set the index to the next closing character
  24064. var open = match[1];
  24065. var close = open ? chars[open] : null;
  24066. if (open && close) {
  24067. var n = str.indexOf(close, idx);
  24068. if (n !== -1) {
  24069. idx = n + 1;
  24070. }
  24071. }
  24072. str = str.slice(idx);
  24073. }
  24074. return false;
  24075. };
  24076. var pathPosixDirname = path__default['default'].posix.dirname;
  24077. var isWin32 = os__default['default'].platform() === 'win32';
  24078. var slash = '/';
  24079. var backslash = /\\/g;
  24080. var enclosure = /[\{\[].*[\/]*.*[\}\]]$/;
  24081. var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
  24082. var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
  24083. /**
  24084. * @param {string} str
  24085. * @param {Object} opts
  24086. * @param {boolean} [opts.flipBackslashes=true]
  24087. */
  24088. var globParent = function globParent(str, opts) {
  24089. var options = Object.assign({
  24090. flipBackslashes: true
  24091. }, opts); // flip windows path separators
  24092. if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
  24093. str = str.replace(backslash, slash);
  24094. } // special case for strings ending in enclosure containing path separator
  24095. if (enclosure.test(str)) {
  24096. str += slash;
  24097. } // preserves full path in case of trailing path separator
  24098. str += 'a'; // remove path parts that are globby
  24099. do {
  24100. str = pathPosixDirname(str);
  24101. } while (isGlob(str) || globby.test(str)); // remove escape chars and return result
  24102. return str.replace(escaped, '$1');
  24103. };
  24104. var utils$1 = createCommonjsModule(function (module, exports) {
  24105. exports.isInteger = num => {
  24106. if (typeof num === 'number') {
  24107. return Number.isInteger(num);
  24108. }
  24109. if (typeof num === 'string' && num.trim() !== '') {
  24110. return Number.isInteger(Number(num));
  24111. }
  24112. return false;
  24113. };
  24114. /**
  24115. * Find a node of the given type
  24116. */
  24117. exports.find = (node, type) => node.nodes.find(node => node.type === type);
  24118. /**
  24119. * Find a node of the given type
  24120. */
  24121. exports.exceedsLimit = (min, max, step = 1, limit) => {
  24122. if (limit === false) return false;
  24123. if (!exports.isInteger(min) || !exports.isInteger(max)) return false;
  24124. return (Number(max) - Number(min)) / Number(step) >= limit;
  24125. };
  24126. /**
  24127. * Escape the given node with '\\' before node.value
  24128. */
  24129. exports.escapeNode = (block, n = 0, type) => {
  24130. let node = block.nodes[n];
  24131. if (!node) return;
  24132. if (type && node.type === type || node.type === 'open' || node.type === 'close') {
  24133. if (node.escaped !== true) {
  24134. node.value = '\\' + node.value;
  24135. node.escaped = true;
  24136. }
  24137. }
  24138. };
  24139. /**
  24140. * Returns true if the given brace node should be enclosed in literal braces
  24141. */
  24142. exports.encloseBrace = node => {
  24143. if (node.type !== 'brace') return false;
  24144. if (node.commas >> 0 + node.ranges >> 0 === 0) {
  24145. node.invalid = true;
  24146. return true;
  24147. }
  24148. return false;
  24149. };
  24150. /**
  24151. * Returns true if a brace node is invalid.
  24152. */
  24153. exports.isInvalidBrace = block => {
  24154. if (block.type !== 'brace') return false;
  24155. if (block.invalid === true || block.dollar) return true;
  24156. if (block.commas >> 0 + block.ranges >> 0 === 0) {
  24157. block.invalid = true;
  24158. return true;
  24159. }
  24160. if (block.open !== true || block.close !== true) {
  24161. block.invalid = true;
  24162. return true;
  24163. }
  24164. return false;
  24165. };
  24166. /**
  24167. * Returns true if a node is an open or close node
  24168. */
  24169. exports.isOpenOrClose = node => {
  24170. if (node.type === 'open' || node.type === 'close') {
  24171. return true;
  24172. }
  24173. return node.open === true || node.close === true;
  24174. };
  24175. /**
  24176. * Reduce an array of text nodes.
  24177. */
  24178. exports.reduce = nodes => nodes.reduce((acc, node) => {
  24179. if (node.type === 'text') acc.push(node.value);
  24180. if (node.type === 'range') node.type = 'text';
  24181. return acc;
  24182. }, []);
  24183. /**
  24184. * Flatten an array
  24185. */
  24186. exports.flatten = (...args) => {
  24187. const result = [];
  24188. const flat = arr => {
  24189. for (let i = 0; i < arr.length; i++) {
  24190. let ele = arr[i];
  24191. Array.isArray(ele) ? flat(ele) : ele !== void 0 && result.push(ele);
  24192. }
  24193. return result;
  24194. };
  24195. flat(args);
  24196. return result;
  24197. };
  24198. });
  24199. var stringify$1 = (ast, options = {}) => {
  24200. let stringify = (node, parent = {}) => {
  24201. let invalidBlock = options.escapeInvalid && utils$1.isInvalidBrace(parent);
  24202. let invalidNode = node.invalid === true && options.escapeInvalid === true;
  24203. let output = '';
  24204. if (node.value) {
  24205. if ((invalidBlock || invalidNode) && utils$1.isOpenOrClose(node)) {
  24206. return '\\' + node.value;
  24207. }
  24208. return node.value;
  24209. }
  24210. if (node.value) {
  24211. return node.value;
  24212. }
  24213. if (node.nodes) {
  24214. for (let child of node.nodes) {
  24215. output += stringify(child);
  24216. }
  24217. }
  24218. return output;
  24219. };
  24220. return stringify(ast);
  24221. };
  24222. /*!
  24223. * is-number <https://github.com/jonschlinkert/is-number>
  24224. *
  24225. * Copyright (c) 2014-present, Jon Schlinkert.
  24226. * Released under the MIT License.
  24227. */
  24228. var isNumber = function (num) {
  24229. if (typeof num === 'number') {
  24230. return num - num === 0;
  24231. }
  24232. if (typeof num === 'string' && num.trim() !== '') {
  24233. return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
  24234. }
  24235. return false;
  24236. };
  24237. const toRegexRange = (min, max, options) => {
  24238. if (isNumber(min) === false) {
  24239. throw new TypeError('toRegexRange: expected the first argument to be a number');
  24240. }
  24241. if (max === void 0 || min === max) {
  24242. return String(min);
  24243. }
  24244. if (isNumber(max) === false) {
  24245. throw new TypeError('toRegexRange: expected the second argument to be a number.');
  24246. }
  24247. let opts = Object.assign({
  24248. relaxZeros: true
  24249. }, options);
  24250. if (typeof opts.strictZeros === 'boolean') {
  24251. opts.relaxZeros = opts.strictZeros === false;
  24252. }
  24253. let relax = String(opts.relaxZeros);
  24254. let shorthand = String(opts.shorthand);
  24255. let capture = String(opts.capture);
  24256. let wrap = String(opts.wrap);
  24257. let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
  24258. if (toRegexRange.cache.hasOwnProperty(cacheKey)) {
  24259. return toRegexRange.cache[cacheKey].result;
  24260. }
  24261. let a = Math.min(min, max);
  24262. let b = Math.max(min, max);
  24263. if (Math.abs(a - b) === 1) {
  24264. let result = min + '|' + max;
  24265. if (opts.capture) {
  24266. return `(${result})`;
  24267. }
  24268. if (opts.wrap === false) {
  24269. return result;
  24270. }
  24271. return `(?:${result})`;
  24272. }
  24273. let isPadded = hasPadding(min) || hasPadding(max);
  24274. let state = {
  24275. min,
  24276. max,
  24277. a,
  24278. b
  24279. };
  24280. let positives = [];
  24281. let negatives = [];
  24282. if (isPadded) {
  24283. state.isPadded = isPadded;
  24284. state.maxLen = String(state.max).length;
  24285. }
  24286. if (a < 0) {
  24287. let newMin = b < 0 ? Math.abs(b) : 1;
  24288. negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
  24289. a = state.a = 0;
  24290. }
  24291. if (b >= 0) {
  24292. positives = splitToPatterns(a, b, state, opts);
  24293. }
  24294. state.negatives = negatives;
  24295. state.positives = positives;
  24296. state.result = collatePatterns(negatives, positives);
  24297. if (opts.capture === true) {
  24298. state.result = `(${state.result})`;
  24299. } else if (opts.wrap !== false && positives.length + negatives.length > 1) {
  24300. state.result = `(?:${state.result})`;
  24301. }
  24302. toRegexRange.cache[cacheKey] = state;
  24303. return state.result;
  24304. };
  24305. function collatePatterns(neg, pos, options) {
  24306. let onlyNegative = filterPatterns(neg, pos, '-', false) || [];
  24307. let onlyPositive = filterPatterns(pos, neg, '', false) || [];
  24308. let intersected = filterPatterns(neg, pos, '-?', true) || [];
  24309. let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
  24310. return subpatterns.join('|');
  24311. }
  24312. function splitToRanges(min, max) {
  24313. let nines = 1;
  24314. let zeros = 1;
  24315. let stop = countNines(min, nines);
  24316. let stops = new Set([max]);
  24317. while (min <= stop && stop <= max) {
  24318. stops.add(stop);
  24319. nines += 1;
  24320. stop = countNines(min, nines);
  24321. }
  24322. stop = countZeros(max + 1, zeros) - 1;
  24323. while (min < stop && stop <= max) {
  24324. stops.add(stop);
  24325. zeros += 1;
  24326. stop = countZeros(max + 1, zeros) - 1;
  24327. }
  24328. stops = [...stops];
  24329. stops.sort(compare$1);
  24330. return stops;
  24331. }
  24332. /**
  24333. * Convert a range to a regex pattern
  24334. * @param {Number} `start`
  24335. * @param {Number} `stop`
  24336. * @return {String}
  24337. */
  24338. function rangeToPattern(start, stop, options) {
  24339. if (start === stop) {
  24340. return {
  24341. pattern: start,
  24342. count: [],
  24343. digits: 0
  24344. };
  24345. }
  24346. let zipped = zip(start, stop);
  24347. let digits = zipped.length;
  24348. let pattern = '';
  24349. let count = 0;
  24350. for (let i = 0; i < digits; i++) {
  24351. let [startDigit, stopDigit] = zipped[i];
  24352. if (startDigit === stopDigit) {
  24353. pattern += startDigit;
  24354. } else if (startDigit !== '0' || stopDigit !== '9') {
  24355. pattern += toCharacterClass(startDigit, stopDigit);
  24356. } else {
  24357. count++;
  24358. }
  24359. }
  24360. if (count) {
  24361. pattern += options.shorthand === true ? '\\d' : '[0-9]';
  24362. }
  24363. return {
  24364. pattern,
  24365. count: [count],
  24366. digits
  24367. };
  24368. }
  24369. function splitToPatterns(min, max, tok, options) {
  24370. let ranges = splitToRanges(min, max);
  24371. let tokens = [];
  24372. let start = min;
  24373. let prev;
  24374. for (let i = 0; i < ranges.length; i++) {
  24375. let max = ranges[i];
  24376. let obj = rangeToPattern(String(start), String(max), options);
  24377. let zeros = '';
  24378. if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
  24379. if (prev.count.length > 1) {
  24380. prev.count.pop();
  24381. }
  24382. prev.count.push(obj.count[0]);
  24383. prev.string = prev.pattern + toQuantifier(prev.count);
  24384. start = max + 1;
  24385. continue;
  24386. }
  24387. if (tok.isPadded) {
  24388. zeros = padZeros(max, tok, options);
  24389. }
  24390. obj.string = zeros + obj.pattern + toQuantifier(obj.count);
  24391. tokens.push(obj);
  24392. start = max + 1;
  24393. prev = obj;
  24394. }
  24395. return tokens;
  24396. }
  24397. function filterPatterns(arr, comparison, prefix, intersection, options) {
  24398. let result = [];
  24399. for (let ele of arr) {
  24400. let {
  24401. string
  24402. } = ele; // only push if _both_ are negative...
  24403. if (!intersection && !contains(comparison, 'string', string)) {
  24404. result.push(prefix + string);
  24405. } // or _both_ are positive
  24406. if (intersection && contains(comparison, 'string', string)) {
  24407. result.push(prefix + string);
  24408. }
  24409. }
  24410. return result;
  24411. }
  24412. /**
  24413. * Zip strings
  24414. */
  24415. function zip(a, b) {
  24416. let arr = [];
  24417. for (let i = 0; i < a.length; i++) arr.push([a[i], b[i]]);
  24418. return arr;
  24419. }
  24420. function compare$1(a, b) {
  24421. return a > b ? 1 : b > a ? -1 : 0;
  24422. }
  24423. function contains(arr, key, val) {
  24424. return arr.some(ele => ele[key] === val);
  24425. }
  24426. function countNines(min, len) {
  24427. return Number(String(min).slice(0, -len) + '9'.repeat(len));
  24428. }
  24429. function countZeros(integer, zeros) {
  24430. return integer - integer % Math.pow(10, zeros);
  24431. }
  24432. function toQuantifier(digits) {
  24433. let [start = 0, stop = ''] = digits;
  24434. if (stop || start > 1) {
  24435. return `{${start + (stop ? ',' + stop : '')}}`;
  24436. }
  24437. return '';
  24438. }
  24439. function toCharacterClass(a, b, options) {
  24440. return `[${a}${b - a === 1 ? '' : '-'}${b}]`;
  24441. }
  24442. function hasPadding(str) {
  24443. return /^-?(0+)\d/.test(str);
  24444. }
  24445. function padZeros(value, tok, options) {
  24446. if (!tok.isPadded) {
  24447. return value;
  24448. }
  24449. let diff = Math.abs(tok.maxLen - String(value).length);
  24450. let relax = options.relaxZeros !== false;
  24451. switch (diff) {
  24452. case 0:
  24453. return '';
  24454. case 1:
  24455. return relax ? '0?' : '0';
  24456. case 2:
  24457. return relax ? '0{0,2}' : '00';
  24458. default:
  24459. {
  24460. return relax ? `0{0,${diff}}` : `0{${diff}}`;
  24461. }
  24462. }
  24463. }
  24464. /**
  24465. * Cache
  24466. */
  24467. toRegexRange.cache = {};
  24468. toRegexRange.clearCache = () => toRegexRange.cache = {};
  24469. /**
  24470. * Expose `toRegexRange`
  24471. */
  24472. var toRegexRange_1 = toRegexRange;
  24473. const isObject$1 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  24474. const transform = toNumber => {
  24475. return value => toNumber === true ? Number(value) : String(value);
  24476. };
  24477. const isValidValue = value => {
  24478. return typeof value === 'number' || typeof value === 'string' && value !== '';
  24479. };
  24480. const isNumber$1 = num => Number.isInteger(+num);
  24481. const zeros = input => {
  24482. let value = `${input}`;
  24483. let index = -1;
  24484. if (value[0] === '-') value = value.slice(1);
  24485. if (value === '0') return false;
  24486. while (value[++index] === '0');
  24487. return index > 0;
  24488. };
  24489. const stringify$2 = (start, end, options) => {
  24490. if (typeof start === 'string' || typeof end === 'string') {
  24491. return true;
  24492. }
  24493. return options.stringify === true;
  24494. };
  24495. const pad = (input, maxLength, toNumber) => {
  24496. if (maxLength > 0) {
  24497. let dash = input[0] === '-' ? '-' : '';
  24498. if (dash) input = input.slice(1);
  24499. input = dash + input.padStart(dash ? maxLength - 1 : maxLength, '0');
  24500. }
  24501. if (toNumber === false) {
  24502. return String(input);
  24503. }
  24504. return input;
  24505. };
  24506. const toMaxLen = (input, maxLength) => {
  24507. let negative = input[0] === '-' ? '-' : '';
  24508. if (negative) {
  24509. input = input.slice(1);
  24510. maxLength--;
  24511. }
  24512. while (input.length < maxLength) input = '0' + input;
  24513. return negative ? '-' + input : input;
  24514. };
  24515. const toSequence = (parts, options) => {
  24516. parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
  24517. parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
  24518. let prefix = options.capture ? '' : '?:';
  24519. let positives = '';
  24520. let negatives = '';
  24521. let result;
  24522. if (parts.positives.length) {
  24523. positives = parts.positives.join('|');
  24524. }
  24525. if (parts.negatives.length) {
  24526. negatives = `-(${prefix}${parts.negatives.join('|')})`;
  24527. }
  24528. if (positives && negatives) {
  24529. result = `${positives}|${negatives}`;
  24530. } else {
  24531. result = positives || negatives;
  24532. }
  24533. if (options.wrap) {
  24534. return `(${prefix}${result})`;
  24535. }
  24536. return result;
  24537. };
  24538. const toRange = (a, b, isNumbers, options) => {
  24539. if (isNumbers) {
  24540. return toRegexRange_1(a, b, Object.assign({
  24541. wrap: false
  24542. }, options));
  24543. }
  24544. let start = String.fromCharCode(a);
  24545. if (a === b) return start;
  24546. let stop = String.fromCharCode(b);
  24547. return `[${start}-${stop}]`;
  24548. };
  24549. const toRegex = (start, end, options) => {
  24550. if (Array.isArray(start)) {
  24551. let wrap = options.wrap === true;
  24552. let prefix = options.capture ? '' : '?:';
  24553. return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
  24554. }
  24555. return toRegexRange_1(start, end, options);
  24556. };
  24557. const rangeError = (...args) => {
  24558. return new RangeError('Invalid range arguments: ' + util__default['default'].inspect(...args));
  24559. };
  24560. const invalidRange = (start, end, options) => {
  24561. if (options.strictRanges === true) throw rangeError([start, end]);
  24562. return [];
  24563. };
  24564. const invalidStep = (step, options) => {
  24565. if (options.strictRanges === true) {
  24566. throw new TypeError(`Expected step "${step}" to be a number`);
  24567. }
  24568. return [];
  24569. };
  24570. const fillNumbers = (start, end, step = 1, options = {}) => {
  24571. let a = Number(start);
  24572. let b = Number(end);
  24573. if (!Number.isInteger(a) || !Number.isInteger(b)) {
  24574. if (options.strictRanges === true) throw rangeError([start, end]);
  24575. return [];
  24576. } // fix negative zero
  24577. if (a === 0) a = 0;
  24578. if (b === 0) b = 0;
  24579. let descending = a > b;
  24580. let startString = String(start);
  24581. let endString = String(end);
  24582. let stepString = String(step);
  24583. step = Math.max(Math.abs(step), 1);
  24584. let padded = zeros(startString) || zeros(endString) || zeros(stepString);
  24585. let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
  24586. let toNumber = padded === false && stringify$2(start, end, options) === false;
  24587. let format = options.transform || transform(toNumber);
  24588. if (options.toRegex && step === 1) {
  24589. return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
  24590. }
  24591. let parts = {
  24592. negatives: [],
  24593. positives: []
  24594. };
  24595. let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
  24596. let range = [];
  24597. let index = 0;
  24598. while (descending ? a >= b : a <= b) {
  24599. if (options.toRegex === true && step > 1) {
  24600. push(a);
  24601. } else {
  24602. range.push(pad(format(a, index), maxLen, toNumber));
  24603. }
  24604. a = descending ? a - step : a + step;
  24605. index++;
  24606. }
  24607. if (options.toRegex === true) {
  24608. return step > 1 ? toSequence(parts, options) : toRegex(range, null, Object.assign({
  24609. wrap: false
  24610. }, options));
  24611. }
  24612. return range;
  24613. };
  24614. const fillLetters = (start, end, step = 1, options = {}) => {
  24615. if (!isNumber$1(start) && start.length > 1 || !isNumber$1(end) && end.length > 1) {
  24616. return invalidRange(start, end, options);
  24617. }
  24618. let format = options.transform || (val => String.fromCharCode(val));
  24619. let a = `${start}`.charCodeAt(0);
  24620. let b = `${end}`.charCodeAt(0);
  24621. let descending = a > b;
  24622. let min = Math.min(a, b);
  24623. let max = Math.max(a, b);
  24624. if (options.toRegex && step === 1) {
  24625. return toRange(min, max, false, options);
  24626. }
  24627. let range = [];
  24628. let index = 0;
  24629. while (descending ? a >= b : a <= b) {
  24630. range.push(format(a, index));
  24631. a = descending ? a - step : a + step;
  24632. index++;
  24633. }
  24634. if (options.toRegex === true) {
  24635. return toRegex(range, null, {
  24636. wrap: false,
  24637. options
  24638. });
  24639. }
  24640. return range;
  24641. };
  24642. const fill$2 = (start, end, step, options = {}) => {
  24643. if (end == null && isValidValue(start)) {
  24644. return [start];
  24645. }
  24646. if (!isValidValue(start) || !isValidValue(end)) {
  24647. return invalidRange(start, end, options);
  24648. }
  24649. if (typeof step === 'function') {
  24650. return fill$2(start, end, 1, {
  24651. transform: step
  24652. });
  24653. }
  24654. if (isObject$1(step)) {
  24655. return fill$2(start, end, 0, step);
  24656. }
  24657. let opts = Object.assign({}, options);
  24658. if (opts.capture === true) opts.wrap = true;
  24659. step = step || opts.step || 1;
  24660. if (!isNumber$1(step)) {
  24661. if (step != null && !isObject$1(step)) return invalidStep(step, opts);
  24662. return fill$2(start, end, 1, step);
  24663. }
  24664. if (isNumber$1(start) && isNumber$1(end)) {
  24665. return fillNumbers(start, end, step, opts);
  24666. }
  24667. return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
  24668. };
  24669. var fillRange = fill$2;
  24670. const compile = (ast, options = {}) => {
  24671. let walk = (node, parent = {}) => {
  24672. let invalidBlock = utils$1.isInvalidBrace(parent);
  24673. let invalidNode = node.invalid === true && options.escapeInvalid === true;
  24674. let invalid = invalidBlock === true || invalidNode === true;
  24675. let prefix = options.escapeInvalid === true ? '\\' : '';
  24676. let output = '';
  24677. if (node.isOpen === true) {
  24678. return prefix + node.value;
  24679. }
  24680. if (node.isClose === true) {
  24681. return prefix + node.value;
  24682. }
  24683. if (node.type === 'open') {
  24684. return invalid ? prefix + node.value : '(';
  24685. }
  24686. if (node.type === 'close') {
  24687. return invalid ? prefix + node.value : ')';
  24688. }
  24689. if (node.type === 'comma') {
  24690. return node.prev.type === 'comma' ? '' : invalid ? node.value : '|';
  24691. }
  24692. if (node.value) {
  24693. return node.value;
  24694. }
  24695. if (node.nodes && node.ranges > 0) {
  24696. let args = utils$1.reduce(node.nodes);
  24697. let range = fillRange(...args, Object.assign({}, options, {
  24698. wrap: false,
  24699. toRegex: true
  24700. }));
  24701. if (range.length !== 0) {
  24702. return args.length > 1 && range.length > 1 ? `(${range})` : range;
  24703. }
  24704. }
  24705. if (node.nodes) {
  24706. for (let child of node.nodes) {
  24707. output += walk(child, node);
  24708. }
  24709. }
  24710. return output;
  24711. };
  24712. return walk(ast);
  24713. };
  24714. var compile_1 = compile;
  24715. const append = (queue = '', stash = '', enclose = false) => {
  24716. let result = [];
  24717. queue = [].concat(queue);
  24718. stash = [].concat(stash);
  24719. if (!stash.length) return queue;
  24720. if (!queue.length) {
  24721. return enclose ? utils$1.flatten(stash).map(ele => `{${ele}}`) : stash;
  24722. }
  24723. for (let item of queue) {
  24724. if (Array.isArray(item)) {
  24725. for (let value of item) {
  24726. result.push(append(value, stash, enclose));
  24727. }
  24728. } else {
  24729. for (let ele of stash) {
  24730. if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
  24731. result.push(Array.isArray(ele) ? append(item, ele, enclose) : item + ele);
  24732. }
  24733. }
  24734. }
  24735. return utils$1.flatten(result);
  24736. };
  24737. const expand$1 = (ast, options = {}) => {
  24738. let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
  24739. let walk = (node, parent = {}) => {
  24740. node.queue = [];
  24741. let p = parent;
  24742. let q = parent.queue;
  24743. while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
  24744. p = p.parent;
  24745. q = p.queue;
  24746. }
  24747. if (node.invalid || node.dollar) {
  24748. q.push(append(q.pop(), stringify$1(node, options)));
  24749. return;
  24750. }
  24751. if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
  24752. q.push(append(q.pop(), ['{}']));
  24753. return;
  24754. }
  24755. if (node.nodes && node.ranges > 0) {
  24756. let args = utils$1.reduce(node.nodes);
  24757. if (utils$1.exceedsLimit(...args, options.step, rangeLimit)) {
  24758. throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
  24759. }
  24760. let range = fillRange(...args, options);
  24761. if (range.length === 0) {
  24762. range = stringify$1(node, options);
  24763. }
  24764. q.push(append(q.pop(), range));
  24765. node.nodes = [];
  24766. return;
  24767. }
  24768. let enclose = utils$1.encloseBrace(node);
  24769. let queue = node.queue;
  24770. let block = node;
  24771. while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
  24772. block = block.parent;
  24773. queue = block.queue;
  24774. }
  24775. for (let i = 0; i < node.nodes.length; i++) {
  24776. let child = node.nodes[i];
  24777. if (child.type === 'comma' && node.type === 'brace') {
  24778. if (i === 1) queue.push('');
  24779. queue.push('');
  24780. continue;
  24781. }
  24782. if (child.type === 'close') {
  24783. q.push(append(q.pop(), queue, enclose));
  24784. continue;
  24785. }
  24786. if (child.value && child.type !== 'open') {
  24787. queue.push(append(queue.pop(), child.value));
  24788. continue;
  24789. }
  24790. if (child.nodes) {
  24791. walk(child, node);
  24792. }
  24793. }
  24794. return queue;
  24795. };
  24796. return utils$1.flatten(walk(ast));
  24797. };
  24798. var expand_1 = expand$1;
  24799. var constants$2 = {
  24800. MAX_LENGTH: 1024 * 64,
  24801. // Digits
  24802. CHAR_0: '0',
  24803. /* 0 */
  24804. CHAR_9: '9',
  24805. /* 9 */
  24806. // Alphabet chars.
  24807. CHAR_UPPERCASE_A: 'A',
  24808. /* A */
  24809. CHAR_LOWERCASE_A: 'a',
  24810. /* a */
  24811. CHAR_UPPERCASE_Z: 'Z',
  24812. /* Z */
  24813. CHAR_LOWERCASE_Z: 'z',
  24814. /* z */
  24815. CHAR_LEFT_PARENTHESES: '(',
  24816. /* ( */
  24817. CHAR_RIGHT_PARENTHESES: ')',
  24818. /* ) */
  24819. CHAR_ASTERISK: '*',
  24820. /* * */
  24821. // Non-alphabetic chars.
  24822. CHAR_AMPERSAND: '&',
  24823. /* & */
  24824. CHAR_AT: '@',
  24825. /* @ */
  24826. CHAR_BACKSLASH: '\\',
  24827. /* \ */
  24828. CHAR_BACKTICK: '`',
  24829. /* ` */
  24830. CHAR_CARRIAGE_RETURN: '\r',
  24831. /* \r */
  24832. CHAR_CIRCUMFLEX_ACCENT: '^',
  24833. /* ^ */
  24834. CHAR_COLON: ':',
  24835. /* : */
  24836. CHAR_COMMA: ',',
  24837. /* , */
  24838. CHAR_DOLLAR: '$',
  24839. /* . */
  24840. CHAR_DOT: '.',
  24841. /* . */
  24842. CHAR_DOUBLE_QUOTE: '"',
  24843. /* " */
  24844. CHAR_EQUAL: '=',
  24845. /* = */
  24846. CHAR_EXCLAMATION_MARK: '!',
  24847. /* ! */
  24848. CHAR_FORM_FEED: '\f',
  24849. /* \f */
  24850. CHAR_FORWARD_SLASH: '/',
  24851. /* / */
  24852. CHAR_HASH: '#',
  24853. /* # */
  24854. CHAR_HYPHEN_MINUS: '-',
  24855. /* - */
  24856. CHAR_LEFT_ANGLE_BRACKET: '<',
  24857. /* < */
  24858. CHAR_LEFT_CURLY_BRACE: '{',
  24859. /* { */
  24860. CHAR_LEFT_SQUARE_BRACKET: '[',
  24861. /* [ */
  24862. CHAR_LINE_FEED: '\n',
  24863. /* \n */
  24864. CHAR_NO_BREAK_SPACE: '\u00A0',
  24865. /* \u00A0 */
  24866. CHAR_PERCENT: '%',
  24867. /* % */
  24868. CHAR_PLUS: '+',
  24869. /* + */
  24870. CHAR_QUESTION_MARK: '?',
  24871. /* ? */
  24872. CHAR_RIGHT_ANGLE_BRACKET: '>',
  24873. /* > */
  24874. CHAR_RIGHT_CURLY_BRACE: '}',
  24875. /* } */
  24876. CHAR_RIGHT_SQUARE_BRACKET: ']',
  24877. /* ] */
  24878. CHAR_SEMICOLON: ';',
  24879. /* ; */
  24880. CHAR_SINGLE_QUOTE: '\'',
  24881. /* ' */
  24882. CHAR_SPACE: ' ',
  24883. /* */
  24884. CHAR_TAB: '\t',
  24885. /* \t */
  24886. CHAR_UNDERSCORE: '_',
  24887. /* _ */
  24888. CHAR_VERTICAL_LINE: '|',
  24889. /* | */
  24890. CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF'
  24891. /* \uFEFF */
  24892. };
  24893. /**
  24894. * Constants
  24895. */
  24896. const {
  24897. MAX_LENGTH: MAX_LENGTH$2,
  24898. CHAR_BACKSLASH,
  24899. /* \ */
  24900. CHAR_BACKTICK,
  24901. /* ` */
  24902. CHAR_COMMA: CHAR_COMMA$1,
  24903. /* , */
  24904. CHAR_DOT,
  24905. /* . */
  24906. CHAR_LEFT_PARENTHESES,
  24907. /* ( */
  24908. CHAR_RIGHT_PARENTHESES,
  24909. /* ) */
  24910. CHAR_LEFT_CURLY_BRACE,
  24911. /* { */
  24912. CHAR_RIGHT_CURLY_BRACE,
  24913. /* } */
  24914. CHAR_LEFT_SQUARE_BRACKET,
  24915. /* [ */
  24916. CHAR_RIGHT_SQUARE_BRACKET,
  24917. /* ] */
  24918. CHAR_DOUBLE_QUOTE,
  24919. /* " */
  24920. CHAR_SINGLE_QUOTE,
  24921. /* ' */
  24922. CHAR_NO_BREAK_SPACE,
  24923. CHAR_ZERO_WIDTH_NOBREAK_SPACE
  24924. } = constants$2;
  24925. /**
  24926. * parse
  24927. */
  24928. const parse$5 = (input, options = {}) => {
  24929. if (typeof input !== 'string') {
  24930. throw new TypeError('Expected a string');
  24931. }
  24932. let opts = options || {};
  24933. let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$2, opts.maxLength) : MAX_LENGTH$2;
  24934. if (input.length > max) {
  24935. throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
  24936. }
  24937. let ast = {
  24938. type: 'root',
  24939. input,
  24940. nodes: []
  24941. };
  24942. let stack = [ast];
  24943. let block = ast;
  24944. let prev = ast;
  24945. let brackets = 0;
  24946. let length = input.length;
  24947. let index = 0;
  24948. let depth = 0;
  24949. let value;
  24950. /**
  24951. * Helpers
  24952. */
  24953. const advance = () => input[index++];
  24954. const push = node => {
  24955. if (node.type === 'text' && prev.type === 'dot') {
  24956. prev.type = 'text';
  24957. }
  24958. if (prev && prev.type === 'text' && node.type === 'text') {
  24959. prev.value += node.value;
  24960. return;
  24961. }
  24962. block.nodes.push(node);
  24963. node.parent = block;
  24964. node.prev = prev;
  24965. prev = node;
  24966. return node;
  24967. };
  24968. push({
  24969. type: 'bos'
  24970. });
  24971. while (index < length) {
  24972. block = stack[stack.length - 1];
  24973. value = advance();
  24974. /**
  24975. * Invalid chars
  24976. */
  24977. if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
  24978. continue;
  24979. }
  24980. /**
  24981. * Escaped chars
  24982. */
  24983. if (value === CHAR_BACKSLASH) {
  24984. push({
  24985. type: 'text',
  24986. value: (options.keepEscaping ? value : '') + advance()
  24987. });
  24988. continue;
  24989. }
  24990. /**
  24991. * Right square bracket (literal): ']'
  24992. */
  24993. if (value === CHAR_RIGHT_SQUARE_BRACKET) {
  24994. push({
  24995. type: 'text',
  24996. value: '\\' + value
  24997. });
  24998. continue;
  24999. }
  25000. /**
  25001. * Left square bracket: '['
  25002. */
  25003. if (value === CHAR_LEFT_SQUARE_BRACKET) {
  25004. brackets++;
  25005. let next;
  25006. while (index < length && (next = advance())) {
  25007. value += next;
  25008. if (next === CHAR_LEFT_SQUARE_BRACKET) {
  25009. brackets++;
  25010. continue;
  25011. }
  25012. if (next === CHAR_BACKSLASH) {
  25013. value += advance();
  25014. continue;
  25015. }
  25016. if (next === CHAR_RIGHT_SQUARE_BRACKET) {
  25017. brackets--;
  25018. if (brackets === 0) {
  25019. break;
  25020. }
  25021. }
  25022. }
  25023. push({
  25024. type: 'text',
  25025. value
  25026. });
  25027. continue;
  25028. }
  25029. /**
  25030. * Parentheses
  25031. */
  25032. if (value === CHAR_LEFT_PARENTHESES) {
  25033. block = push({
  25034. type: 'paren',
  25035. nodes: []
  25036. });
  25037. stack.push(block);
  25038. push({
  25039. type: 'text',
  25040. value
  25041. });
  25042. continue;
  25043. }
  25044. if (value === CHAR_RIGHT_PARENTHESES) {
  25045. if (block.type !== 'paren') {
  25046. push({
  25047. type: 'text',
  25048. value
  25049. });
  25050. continue;
  25051. }
  25052. block = stack.pop();
  25053. push({
  25054. type: 'text',
  25055. value
  25056. });
  25057. block = stack[stack.length - 1];
  25058. continue;
  25059. }
  25060. /**
  25061. * Quotes: '|"|`
  25062. */
  25063. if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
  25064. let open = value;
  25065. let next;
  25066. if (options.keepQuotes !== true) {
  25067. value = '';
  25068. }
  25069. while (index < length && (next = advance())) {
  25070. if (next === CHAR_BACKSLASH) {
  25071. value += next + advance();
  25072. continue;
  25073. }
  25074. if (next === open) {
  25075. if (options.keepQuotes === true) value += next;
  25076. break;
  25077. }
  25078. value += next;
  25079. }
  25080. push({
  25081. type: 'text',
  25082. value
  25083. });
  25084. continue;
  25085. }
  25086. /**
  25087. * Left curly brace: '{'
  25088. */
  25089. if (value === CHAR_LEFT_CURLY_BRACE) {
  25090. depth++;
  25091. let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
  25092. let brace = {
  25093. type: 'brace',
  25094. open: true,
  25095. close: false,
  25096. dollar,
  25097. depth,
  25098. commas: 0,
  25099. ranges: 0,
  25100. nodes: []
  25101. };
  25102. block = push(brace);
  25103. stack.push(block);
  25104. push({
  25105. type: 'open',
  25106. value
  25107. });
  25108. continue;
  25109. }
  25110. /**
  25111. * Right curly brace: '}'
  25112. */
  25113. if (value === CHAR_RIGHT_CURLY_BRACE) {
  25114. if (block.type !== 'brace') {
  25115. push({
  25116. type: 'text',
  25117. value
  25118. });
  25119. continue;
  25120. }
  25121. let type = 'close';
  25122. block = stack.pop();
  25123. block.close = true;
  25124. push({
  25125. type,
  25126. value
  25127. });
  25128. depth--;
  25129. block = stack[stack.length - 1];
  25130. continue;
  25131. }
  25132. /**
  25133. * Comma: ','
  25134. */
  25135. if (value === CHAR_COMMA$1 && depth > 0) {
  25136. if (block.ranges > 0) {
  25137. block.ranges = 0;
  25138. let open = block.nodes.shift();
  25139. block.nodes = [open, {
  25140. type: 'text',
  25141. value: stringify$1(block)
  25142. }];
  25143. }
  25144. push({
  25145. type: 'comma',
  25146. value
  25147. });
  25148. block.commas++;
  25149. continue;
  25150. }
  25151. /**
  25152. * Dot: '.'
  25153. */
  25154. if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
  25155. let siblings = block.nodes;
  25156. if (depth === 0 || siblings.length === 0) {
  25157. push({
  25158. type: 'text',
  25159. value
  25160. });
  25161. continue;
  25162. }
  25163. if (prev.type === 'dot') {
  25164. block.range = [];
  25165. prev.value += value;
  25166. prev.type = 'range';
  25167. if (block.nodes.length !== 3 && block.nodes.length !== 5) {
  25168. block.invalid = true;
  25169. block.ranges = 0;
  25170. prev.type = 'text';
  25171. continue;
  25172. }
  25173. block.ranges++;
  25174. block.args = [];
  25175. continue;
  25176. }
  25177. if (prev.type === 'range') {
  25178. siblings.pop();
  25179. let before = siblings[siblings.length - 1];
  25180. before.value += prev.value + value;
  25181. prev = before;
  25182. block.ranges--;
  25183. continue;
  25184. }
  25185. push({
  25186. type: 'dot',
  25187. value
  25188. });
  25189. continue;
  25190. }
  25191. /**
  25192. * Text
  25193. */
  25194. push({
  25195. type: 'text',
  25196. value
  25197. });
  25198. } // Mark imbalanced braces and brackets as invalid
  25199. do {
  25200. block = stack.pop();
  25201. if (block.type !== 'root') {
  25202. block.nodes.forEach(node => {
  25203. if (!node.nodes) {
  25204. if (node.type === 'open') node.isOpen = true;
  25205. if (node.type === 'close') node.isClose = true;
  25206. if (!node.nodes) node.type = 'text';
  25207. node.invalid = true;
  25208. }
  25209. }); // get the location of the block on parent.nodes (block's siblings)
  25210. let parent = stack[stack.length - 1];
  25211. let index = parent.nodes.indexOf(block); // replace the (invalid) block with it's nodes
  25212. parent.nodes.splice(index, 1, ...block.nodes);
  25213. }
  25214. } while (stack.length > 0);
  25215. push({
  25216. type: 'eos'
  25217. });
  25218. return ast;
  25219. };
  25220. var parse_1 = parse$5;
  25221. /**
  25222. * Expand the given pattern or create a regex-compatible string.
  25223. *
  25224. * ```js
  25225. * const braces = require('braces');
  25226. * console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
  25227. * console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
  25228. * ```
  25229. * @param {String} `str`
  25230. * @param {Object} `options`
  25231. * @return {String}
  25232. * @api public
  25233. */
  25234. const braces = (input, options = {}) => {
  25235. let output = [];
  25236. if (Array.isArray(input)) {
  25237. for (let pattern of input) {
  25238. let result = braces.create(pattern, options);
  25239. if (Array.isArray(result)) {
  25240. output.push(...result);
  25241. } else {
  25242. output.push(result);
  25243. }
  25244. }
  25245. } else {
  25246. output = [].concat(braces.create(input, options));
  25247. }
  25248. if (options && options.expand === true && options.nodupes === true) {
  25249. output = [...new Set(output)];
  25250. }
  25251. return output;
  25252. };
  25253. /**
  25254. * Parse the given `str` with the given `options`.
  25255. *
  25256. * ```js
  25257. * // braces.parse(pattern, [, options]);
  25258. * const ast = braces.parse('a/{b,c}/d');
  25259. * console.log(ast);
  25260. * ```
  25261. * @param {String} pattern Brace pattern to parse
  25262. * @param {Object} options
  25263. * @return {Object} Returns an AST
  25264. * @api public
  25265. */
  25266. braces.parse = (input, options = {}) => parse_1(input, options);
  25267. /**
  25268. * Creates a braces string from an AST, or an AST node.
  25269. *
  25270. * ```js
  25271. * const braces = require('braces');
  25272. * let ast = braces.parse('foo/{a,b}/bar');
  25273. * console.log(stringify(ast.nodes[2])); //=> '{a,b}'
  25274. * ```
  25275. * @param {String} `input` Brace pattern or AST.
  25276. * @param {Object} `options`
  25277. * @return {Array} Returns an array of expanded values.
  25278. * @api public
  25279. */
  25280. braces.stringify = (input, options = {}) => {
  25281. if (typeof input === 'string') {
  25282. return stringify$1(braces.parse(input, options), options);
  25283. }
  25284. return stringify$1(input, options);
  25285. };
  25286. /**
  25287. * Compiles a brace pattern into a regex-compatible, optimized string.
  25288. * This method is called by the main [braces](#braces) function by default.
  25289. *
  25290. * ```js
  25291. * const braces = require('braces');
  25292. * console.log(braces.compile('a/{b,c}/d'));
  25293. * //=> ['a/(b|c)/d']
  25294. * ```
  25295. * @param {String} `input` Brace pattern or AST.
  25296. * @param {Object} `options`
  25297. * @return {Array} Returns an array of expanded values.
  25298. * @api public
  25299. */
  25300. braces.compile = (input, options = {}) => {
  25301. if (typeof input === 'string') {
  25302. input = braces.parse(input, options);
  25303. }
  25304. return compile_1(input, options);
  25305. };
  25306. /**
  25307. * Expands a brace pattern into an array. This method is called by the
  25308. * main [braces](#braces) function when `options.expand` is true. Before
  25309. * using this method it's recommended that you read the [performance notes](#performance))
  25310. * and advantages of using [.compile](#compile) instead.
  25311. *
  25312. * ```js
  25313. * const braces = require('braces');
  25314. * console.log(braces.expand('a/{b,c}/d'));
  25315. * //=> ['a/b/d', 'a/c/d'];
  25316. * ```
  25317. * @param {String} `pattern` Brace pattern
  25318. * @param {Object} `options`
  25319. * @return {Array} Returns an array of expanded values.
  25320. * @api public
  25321. */
  25322. braces.expand = (input, options = {}) => {
  25323. if (typeof input === 'string') {
  25324. input = braces.parse(input, options);
  25325. }
  25326. let result = expand_1(input, options); // filter out empty strings if specified
  25327. if (options.noempty === true) {
  25328. result = result.filter(Boolean);
  25329. } // filter out duplicates if specified
  25330. if (options.nodupes === true) {
  25331. result = [...new Set(result)];
  25332. }
  25333. return result;
  25334. };
  25335. /**
  25336. * Processes a brace pattern and returns either an expanded array
  25337. * (if `options.expand` is true), a highly optimized regex-compatible string.
  25338. * This method is called by the main [braces](#braces) function.
  25339. *
  25340. * ```js
  25341. * const braces = require('braces');
  25342. * console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
  25343. * //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
  25344. * ```
  25345. * @param {String} `pattern` Brace pattern
  25346. * @param {Object} `options`
  25347. * @return {Array} Returns an array of expanded values.
  25348. * @api public
  25349. */
  25350. braces.create = (input, options = {}) => {
  25351. if (input === '' || input.length < 3) {
  25352. return [input];
  25353. }
  25354. return options.expand !== true ? braces.compile(input, options) : braces.expand(input, options);
  25355. };
  25356. /**
  25357. * Expose "braces"
  25358. */
  25359. var braces_1 = braces;
  25360. const WIN_SLASH = '\\\\/';
  25361. const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
  25362. /**
  25363. * Posix glob regex
  25364. */
  25365. const DOT_LITERAL = '\\.';
  25366. const PLUS_LITERAL = '\\+';
  25367. const QMARK_LITERAL = '\\?';
  25368. const SLASH_LITERAL = '\\/';
  25369. const ONE_CHAR = '(?=.)';
  25370. const QMARK = '[^/]';
  25371. const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
  25372. const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
  25373. const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
  25374. const NO_DOT = `(?!${DOT_LITERAL})`;
  25375. const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
  25376. const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
  25377. const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
  25378. const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
  25379. const STAR = `${QMARK}*?`;
  25380. const POSIX_CHARS = {
  25381. DOT_LITERAL,
  25382. PLUS_LITERAL,
  25383. QMARK_LITERAL,
  25384. SLASH_LITERAL,
  25385. ONE_CHAR,
  25386. QMARK,
  25387. END_ANCHOR,
  25388. DOTS_SLASH,
  25389. NO_DOT,
  25390. NO_DOTS,
  25391. NO_DOT_SLASH,
  25392. NO_DOTS_SLASH,
  25393. QMARK_NO_DOT,
  25394. STAR,
  25395. START_ANCHOR
  25396. };
  25397. /**
  25398. * Windows glob regex
  25399. */
  25400. const WINDOWS_CHARS = Object.assign({}, POSIX_CHARS, {
  25401. SLASH_LITERAL: `[${WIN_SLASH}]`,
  25402. QMARK: WIN_NO_SLASH,
  25403. STAR: `${WIN_NO_SLASH}*?`,
  25404. DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
  25405. NO_DOT: `(?!${DOT_LITERAL})`,
  25406. NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
  25407. NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
  25408. NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
  25409. QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
  25410. START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
  25411. END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
  25412. });
  25413. /**
  25414. * POSIX Bracket Regex
  25415. */
  25416. const POSIX_REGEX_SOURCE = {
  25417. alnum: 'a-zA-Z0-9',
  25418. alpha: 'a-zA-Z',
  25419. ascii: '\\x00-\\x7F',
  25420. blank: ' \\t',
  25421. cntrl: '\\x00-\\x1F\\x7F',
  25422. digit: '0-9',
  25423. graph: '\\x21-\\x7E',
  25424. lower: 'a-z',
  25425. print: '\\x20-\\x7E ',
  25426. punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
  25427. space: ' \\t\\r\\n\\v\\f',
  25428. upper: 'A-Z',
  25429. word: 'A-Za-z0-9_',
  25430. xdigit: 'A-Fa-f0-9'
  25431. };
  25432. var constants$3 = {
  25433. MAX_LENGTH: 1024 * 64,
  25434. POSIX_REGEX_SOURCE,
  25435. // regular expressions
  25436. REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
  25437. REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
  25438. REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
  25439. REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
  25440. REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
  25441. REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
  25442. // Replace globs with equivalent patterns to reduce parsing time.
  25443. REPLACEMENTS: {
  25444. '***': '*',
  25445. '**/**': '**',
  25446. '**/**/**': '**'
  25447. },
  25448. // Digits
  25449. CHAR_0: 48,
  25450. /* 0 */
  25451. CHAR_9: 57,
  25452. /* 9 */
  25453. // Alphabet chars.
  25454. CHAR_UPPERCASE_A: 65,
  25455. /* A */
  25456. CHAR_LOWERCASE_A: 97,
  25457. /* a */
  25458. CHAR_UPPERCASE_Z: 90,
  25459. /* Z */
  25460. CHAR_LOWERCASE_Z: 122,
  25461. /* z */
  25462. CHAR_LEFT_PARENTHESES: 40,
  25463. /* ( */
  25464. CHAR_RIGHT_PARENTHESES: 41,
  25465. /* ) */
  25466. CHAR_ASTERISK: 42,
  25467. /* * */
  25468. // Non-alphabetic chars.
  25469. CHAR_AMPERSAND: 38,
  25470. /* & */
  25471. CHAR_AT: 64,
  25472. /* @ */
  25473. CHAR_BACKWARD_SLASH: 92,
  25474. /* \ */
  25475. CHAR_CARRIAGE_RETURN: 13,
  25476. /* \r */
  25477. CHAR_CIRCUMFLEX_ACCENT: 94,
  25478. /* ^ */
  25479. CHAR_COLON: 58,
  25480. /* : */
  25481. CHAR_COMMA: 44,
  25482. /* , */
  25483. CHAR_DOT: 46,
  25484. /* . */
  25485. CHAR_DOUBLE_QUOTE: 34,
  25486. /* " */
  25487. CHAR_EQUAL: 61,
  25488. /* = */
  25489. CHAR_EXCLAMATION_MARK: 33,
  25490. /* ! */
  25491. CHAR_FORM_FEED: 12,
  25492. /* \f */
  25493. CHAR_FORWARD_SLASH: 47,
  25494. /* / */
  25495. CHAR_GRAVE_ACCENT: 96,
  25496. /* ` */
  25497. CHAR_HASH: 35,
  25498. /* # */
  25499. CHAR_HYPHEN_MINUS: 45,
  25500. /* - */
  25501. CHAR_LEFT_ANGLE_BRACKET: 60,
  25502. /* < */
  25503. CHAR_LEFT_CURLY_BRACE: 123,
  25504. /* { */
  25505. CHAR_LEFT_SQUARE_BRACKET: 91,
  25506. /* [ */
  25507. CHAR_LINE_FEED: 10,
  25508. /* \n */
  25509. CHAR_NO_BREAK_SPACE: 160,
  25510. /* \u00A0 */
  25511. CHAR_PERCENT: 37,
  25512. /* % */
  25513. CHAR_PLUS: 43,
  25514. /* + */
  25515. CHAR_QUESTION_MARK: 63,
  25516. /* ? */
  25517. CHAR_RIGHT_ANGLE_BRACKET: 62,
  25518. /* > */
  25519. CHAR_RIGHT_CURLY_BRACE: 125,
  25520. /* } */
  25521. CHAR_RIGHT_SQUARE_BRACKET: 93,
  25522. /* ] */
  25523. CHAR_SEMICOLON: 59,
  25524. /* ; */
  25525. CHAR_SINGLE_QUOTE: 39,
  25526. /* ' */
  25527. CHAR_SPACE: 32,
  25528. /* */
  25529. CHAR_TAB: 9,
  25530. /* \t */
  25531. CHAR_UNDERSCORE: 95,
  25532. /* _ */
  25533. CHAR_VERTICAL_LINE: 124,
  25534. /* | */
  25535. CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
  25536. /* \uFEFF */
  25537. SEP: path__default['default'].sep,
  25538. /**
  25539. * Create EXTGLOB_CHARS
  25540. */
  25541. extglobChars(chars) {
  25542. return {
  25543. '!': {
  25544. type: 'negate',
  25545. open: '(?:(?!(?:',
  25546. close: `))${chars.STAR})`
  25547. },
  25548. '?': {
  25549. type: 'qmark',
  25550. open: '(?:',
  25551. close: ')?'
  25552. },
  25553. '+': {
  25554. type: 'plus',
  25555. open: '(?:',
  25556. close: ')+'
  25557. },
  25558. '*': {
  25559. type: 'star',
  25560. open: '(?:',
  25561. close: ')*'
  25562. },
  25563. '@': {
  25564. type: 'at',
  25565. open: '(?:',
  25566. close: ')'
  25567. }
  25568. };
  25569. },
  25570. /**
  25571. * Create GLOB_CHARS
  25572. */
  25573. globChars(win32) {
  25574. return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
  25575. }
  25576. };
  25577. var utils$2 = createCommonjsModule(function (module, exports) {
  25578. const win32 = process.platform === 'win32';
  25579. const {
  25580. REGEX_BACKSLASH,
  25581. REGEX_REMOVE_BACKSLASH,
  25582. REGEX_SPECIAL_CHARS,
  25583. REGEX_SPECIAL_CHARS_GLOBAL
  25584. } = constants$3;
  25585. exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  25586. exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
  25587. exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
  25588. exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
  25589. exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
  25590. exports.removeBackslashes = str => {
  25591. return str.replace(REGEX_REMOVE_BACKSLASH, match => {
  25592. return match === '\\' ? '' : match;
  25593. });
  25594. };
  25595. exports.supportsLookbehinds = () => {
  25596. const segs = process.version.slice(1).split('.').map(Number);
  25597. if (segs.length === 3 && segs[0] >= 9 || segs[0] === 8 && segs[1] >= 10) {
  25598. return true;
  25599. }
  25600. return false;
  25601. };
  25602. exports.isWindows = options => {
  25603. if (options && typeof options.windows === 'boolean') {
  25604. return options.windows;
  25605. }
  25606. return win32 === true || path__default['default'].sep === '\\';
  25607. };
  25608. exports.escapeLast = (input, char, lastIdx) => {
  25609. const idx = input.lastIndexOf(char, lastIdx);
  25610. if (idx === -1) return input;
  25611. if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
  25612. return `${input.slice(0, idx)}\\${input.slice(idx)}`;
  25613. };
  25614. exports.removePrefix = (input, state = {}) => {
  25615. let output = input;
  25616. if (output.startsWith('./')) {
  25617. output = output.slice(2);
  25618. state.prefix = './';
  25619. }
  25620. return output;
  25621. };
  25622. exports.wrapOutput = (input, state = {}, options = {}) => {
  25623. const prepend = options.contains ? '' : '^';
  25624. const append = options.contains ? '' : '$';
  25625. let output = `${prepend}(?:${input})${append}`;
  25626. if (state.negated === true) {
  25627. output = `(?:^(?!${output}).*$)`;
  25628. }
  25629. return output;
  25630. };
  25631. });
  25632. const {
  25633. CHAR_ASTERISK,
  25634. /* * */
  25635. CHAR_AT,
  25636. /* @ */
  25637. CHAR_BACKWARD_SLASH,
  25638. /* \ */
  25639. CHAR_COMMA: CHAR_COMMA$2,
  25640. /* , */
  25641. CHAR_DOT: CHAR_DOT$1,
  25642. /* . */
  25643. CHAR_EXCLAMATION_MARK,
  25644. /* ! */
  25645. CHAR_FORWARD_SLASH,
  25646. /* / */
  25647. CHAR_LEFT_CURLY_BRACE: CHAR_LEFT_CURLY_BRACE$1,
  25648. /* { */
  25649. CHAR_LEFT_PARENTHESES: CHAR_LEFT_PARENTHESES$1,
  25650. /* ( */
  25651. CHAR_LEFT_SQUARE_BRACKET: CHAR_LEFT_SQUARE_BRACKET$1,
  25652. /* [ */
  25653. CHAR_PLUS: CHAR_PLUS$1,
  25654. /* + */
  25655. CHAR_QUESTION_MARK,
  25656. /* ? */
  25657. CHAR_RIGHT_CURLY_BRACE: CHAR_RIGHT_CURLY_BRACE$1,
  25658. /* } */
  25659. CHAR_RIGHT_PARENTHESES: CHAR_RIGHT_PARENTHESES$1,
  25660. /* ) */
  25661. CHAR_RIGHT_SQUARE_BRACKET: CHAR_RIGHT_SQUARE_BRACKET$1
  25662. /* ] */
  25663. } = constants$3;
  25664. const isPathSeparator = code => {
  25665. return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
  25666. };
  25667. const depth = token => {
  25668. if (token.isPrefix !== true) {
  25669. token.depth = token.isGlobstar ? Infinity : 1;
  25670. }
  25671. };
  25672. /**
  25673. * Quickly scans a glob pattern and returns an object with a handful of
  25674. * useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
  25675. * `glob` (the actual pattern), and `negated` (true if the path starts with `!`).
  25676. *
  25677. * ```js
  25678. * const pm = require('picomatch');
  25679. * console.log(pm.scan('foo/bar/*.js'));
  25680. * { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
  25681. * ```
  25682. * @param {String} `str`
  25683. * @param {Object} `options`
  25684. * @return {Object} Returns an object with tokens and regex source string.
  25685. * @api public
  25686. */
  25687. const scan = (input, options) => {
  25688. const opts = options || {};
  25689. const length = input.length - 1;
  25690. const scanToEnd = opts.parts === true || opts.scanToEnd === true;
  25691. const slashes = [];
  25692. const tokens = [];
  25693. const parts = [];
  25694. let str = input;
  25695. let index = -1;
  25696. let start = 0;
  25697. let lastIndex = 0;
  25698. let isBrace = false;
  25699. let isBracket = false;
  25700. let isGlob = false;
  25701. let isExtglob = false;
  25702. let isGlobstar = false;
  25703. let braceEscaped = false;
  25704. let backslashes = false;
  25705. let negated = false;
  25706. let finished = false;
  25707. let braces = 0;
  25708. let prev;
  25709. let code;
  25710. let token = {
  25711. value: '',
  25712. depth: 0,
  25713. isGlob: false
  25714. };
  25715. const eos = () => index >= length;
  25716. const peek = () => str.charCodeAt(index + 1);
  25717. const advance = () => {
  25718. prev = code;
  25719. return str.charCodeAt(++index);
  25720. };
  25721. while (index < length) {
  25722. code = advance();
  25723. let next;
  25724. if (code === CHAR_BACKWARD_SLASH) {
  25725. backslashes = token.backslashes = true;
  25726. code = advance();
  25727. if (code === CHAR_LEFT_CURLY_BRACE$1) {
  25728. braceEscaped = true;
  25729. }
  25730. continue;
  25731. }
  25732. if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE$1) {
  25733. braces++;
  25734. while (eos() !== true && (code = advance())) {
  25735. if (code === CHAR_BACKWARD_SLASH) {
  25736. backslashes = token.backslashes = true;
  25737. advance();
  25738. continue;
  25739. }
  25740. if (code === CHAR_LEFT_CURLY_BRACE$1) {
  25741. braces++;
  25742. continue;
  25743. }
  25744. if (braceEscaped !== true && code === CHAR_DOT$1 && (code = advance()) === CHAR_DOT$1) {
  25745. isBrace = token.isBrace = true;
  25746. isGlob = token.isGlob = true;
  25747. finished = true;
  25748. if (scanToEnd === true) {
  25749. continue;
  25750. }
  25751. break;
  25752. }
  25753. if (braceEscaped !== true && code === CHAR_COMMA$2) {
  25754. isBrace = token.isBrace = true;
  25755. isGlob = token.isGlob = true;
  25756. finished = true;
  25757. if (scanToEnd === true) {
  25758. continue;
  25759. }
  25760. break;
  25761. }
  25762. if (code === CHAR_RIGHT_CURLY_BRACE$1) {
  25763. braces--;
  25764. if (braces === 0) {
  25765. braceEscaped = false;
  25766. isBrace = token.isBrace = true;
  25767. finished = true;
  25768. break;
  25769. }
  25770. }
  25771. }
  25772. if (scanToEnd === true) {
  25773. continue;
  25774. }
  25775. break;
  25776. }
  25777. if (code === CHAR_FORWARD_SLASH) {
  25778. slashes.push(index);
  25779. tokens.push(token);
  25780. token = {
  25781. value: '',
  25782. depth: 0,
  25783. isGlob: false
  25784. };
  25785. if (finished === true) continue;
  25786. if (prev === CHAR_DOT$1 && index === start + 1) {
  25787. start += 2;
  25788. continue;
  25789. }
  25790. lastIndex = index + 1;
  25791. continue;
  25792. }
  25793. if (opts.noext !== true) {
  25794. const isExtglobChar = code === CHAR_PLUS$1 || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
  25795. if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES$1) {
  25796. isGlob = token.isGlob = true;
  25797. isExtglob = token.isExtglob = true;
  25798. finished = true;
  25799. if (scanToEnd === true) {
  25800. while (eos() !== true && (code = advance())) {
  25801. if (code === CHAR_BACKWARD_SLASH) {
  25802. backslashes = token.backslashes = true;
  25803. code = advance();
  25804. continue;
  25805. }
  25806. if (code === CHAR_RIGHT_PARENTHESES$1) {
  25807. isGlob = token.isGlob = true;
  25808. finished = true;
  25809. break;
  25810. }
  25811. }
  25812. continue;
  25813. }
  25814. break;
  25815. }
  25816. }
  25817. if (code === CHAR_ASTERISK) {
  25818. if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
  25819. isGlob = token.isGlob = true;
  25820. finished = true;
  25821. if (scanToEnd === true) {
  25822. continue;
  25823. }
  25824. break;
  25825. }
  25826. if (code === CHAR_QUESTION_MARK) {
  25827. isGlob = token.isGlob = true;
  25828. finished = true;
  25829. if (scanToEnd === true) {
  25830. continue;
  25831. }
  25832. break;
  25833. }
  25834. if (code === CHAR_LEFT_SQUARE_BRACKET$1) {
  25835. while (eos() !== true && (next = advance())) {
  25836. if (next === CHAR_BACKWARD_SLASH) {
  25837. backslashes = token.backslashes = true;
  25838. advance();
  25839. continue;
  25840. }
  25841. if (next === CHAR_RIGHT_SQUARE_BRACKET$1) {
  25842. isBracket = token.isBracket = true;
  25843. isGlob = token.isGlob = true;
  25844. finished = true;
  25845. if (scanToEnd === true) {
  25846. continue;
  25847. }
  25848. break;
  25849. }
  25850. }
  25851. }
  25852. if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
  25853. negated = token.negated = true;
  25854. start++;
  25855. continue;
  25856. }
  25857. if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES$1) {
  25858. isGlob = token.isGlob = true;
  25859. if (scanToEnd === true) {
  25860. while (eos() !== true && (code = advance())) {
  25861. if (code === CHAR_LEFT_PARENTHESES$1) {
  25862. backslashes = token.backslashes = true;
  25863. code = advance();
  25864. continue;
  25865. }
  25866. if (code === CHAR_RIGHT_PARENTHESES$1) {
  25867. finished = true;
  25868. break;
  25869. }
  25870. }
  25871. continue;
  25872. }
  25873. break;
  25874. }
  25875. if (isGlob === true) {
  25876. finished = true;
  25877. if (scanToEnd === true) {
  25878. continue;
  25879. }
  25880. break;
  25881. }
  25882. }
  25883. if (opts.noext === true) {
  25884. isExtglob = false;
  25885. isGlob = false;
  25886. }
  25887. let base = str;
  25888. let prefix = '';
  25889. let glob = '';
  25890. if (start > 0) {
  25891. prefix = str.slice(0, start);
  25892. str = str.slice(start);
  25893. lastIndex -= start;
  25894. }
  25895. if (base && isGlob === true && lastIndex > 0) {
  25896. base = str.slice(0, lastIndex);
  25897. glob = str.slice(lastIndex);
  25898. } else if (isGlob === true) {
  25899. base = '';
  25900. glob = str;
  25901. } else {
  25902. base = str;
  25903. }
  25904. if (base && base !== '' && base !== '/' && base !== str) {
  25905. if (isPathSeparator(base.charCodeAt(base.length - 1))) {
  25906. base = base.slice(0, -1);
  25907. }
  25908. }
  25909. if (opts.unescape === true) {
  25910. if (glob) glob = utils$2.removeBackslashes(glob);
  25911. if (base && backslashes === true) {
  25912. base = utils$2.removeBackslashes(base);
  25913. }
  25914. }
  25915. const state = {
  25916. prefix,
  25917. input,
  25918. start,
  25919. base,
  25920. glob,
  25921. isBrace,
  25922. isBracket,
  25923. isGlob,
  25924. isExtglob,
  25925. isGlobstar,
  25926. negated
  25927. };
  25928. if (opts.tokens === true) {
  25929. state.maxDepth = 0;
  25930. if (!isPathSeparator(code)) {
  25931. tokens.push(token);
  25932. }
  25933. state.tokens = tokens;
  25934. }
  25935. if (opts.parts === true || opts.tokens === true) {
  25936. let prevIndex;
  25937. for (let idx = 0; idx < slashes.length; idx++) {
  25938. const n = prevIndex ? prevIndex + 1 : start;
  25939. const i = slashes[idx];
  25940. const value = input.slice(n, i);
  25941. if (opts.tokens) {
  25942. if (idx === 0 && start !== 0) {
  25943. tokens[idx].isPrefix = true;
  25944. tokens[idx].value = prefix;
  25945. } else {
  25946. tokens[idx].value = value;
  25947. }
  25948. depth(tokens[idx]);
  25949. state.maxDepth += tokens[idx].depth;
  25950. }
  25951. if (idx !== 0 || value !== '') {
  25952. parts.push(value);
  25953. }
  25954. prevIndex = i;
  25955. }
  25956. if (prevIndex && prevIndex + 1 < input.length) {
  25957. const value = input.slice(prevIndex + 1);
  25958. parts.push(value);
  25959. if (opts.tokens) {
  25960. tokens[tokens.length - 1].value = value;
  25961. depth(tokens[tokens.length - 1]);
  25962. state.maxDepth += tokens[tokens.length - 1].depth;
  25963. }
  25964. }
  25965. state.slashes = slashes;
  25966. state.parts = parts;
  25967. }
  25968. return state;
  25969. };
  25970. var scan_1 = scan;
  25971. /**
  25972. * Constants
  25973. */
  25974. const {
  25975. MAX_LENGTH: MAX_LENGTH$3,
  25976. POSIX_REGEX_SOURCE: POSIX_REGEX_SOURCE$1,
  25977. REGEX_NON_SPECIAL_CHARS,
  25978. REGEX_SPECIAL_CHARS_BACKREF,
  25979. REPLACEMENTS
  25980. } = constants$3;
  25981. /**
  25982. * Helpers
  25983. */
  25984. const expandRange = (args, options) => {
  25985. if (typeof options.expandRange === 'function') {
  25986. return options.expandRange(...args, options);
  25987. }
  25988. args.sort();
  25989. const value = `[${args.join('-')}]`;
  25990. try {
  25991. /* eslint-disable-next-line no-new */
  25992. new RegExp(value);
  25993. } catch (ex) {
  25994. return args.map(v => utils$2.escapeRegex(v)).join('..');
  25995. }
  25996. return value;
  25997. };
  25998. /**
  25999. * Create the message for a syntax error
  26000. */
  26001. const syntaxError$1 = (type, char) => {
  26002. return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
  26003. };
  26004. /**
  26005. * Parse the given input string.
  26006. * @param {String} input
  26007. * @param {Object} options
  26008. * @return {Object}
  26009. */
  26010. const parse$6 = (input, options) => {
  26011. if (typeof input !== 'string') {
  26012. throw new TypeError('Expected a string');
  26013. }
  26014. input = REPLACEMENTS[input] || input;
  26015. const opts = Object.assign({}, options);
  26016. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$3, opts.maxLength) : MAX_LENGTH$3;
  26017. let len = input.length;
  26018. if (len > max) {
  26019. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  26020. }
  26021. const bos = {
  26022. type: 'bos',
  26023. value: '',
  26024. output: opts.prepend || ''
  26025. };
  26026. const tokens = [bos];
  26027. const capture = opts.capture ? '' : '?:';
  26028. const win32 = utils$2.isWindows(options); // create constants based on platform, for windows or posix
  26029. const PLATFORM_CHARS = constants$3.globChars(win32);
  26030. const EXTGLOB_CHARS = constants$3.extglobChars(PLATFORM_CHARS);
  26031. const {
  26032. DOT_LITERAL,
  26033. PLUS_LITERAL,
  26034. SLASH_LITERAL,
  26035. ONE_CHAR,
  26036. DOTS_SLASH,
  26037. NO_DOT,
  26038. NO_DOT_SLASH,
  26039. NO_DOTS_SLASH,
  26040. QMARK,
  26041. QMARK_NO_DOT,
  26042. STAR,
  26043. START_ANCHOR
  26044. } = PLATFORM_CHARS;
  26045. const globstar = opts => {
  26046. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  26047. };
  26048. const nodot = opts.dot ? '' : NO_DOT;
  26049. const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
  26050. let star = opts.bash === true ? globstar(opts) : STAR;
  26051. if (opts.capture) {
  26052. star = `(${star})`;
  26053. } // minimatch options support
  26054. if (typeof opts.noext === 'boolean') {
  26055. opts.noextglob = opts.noext;
  26056. }
  26057. const state = {
  26058. input,
  26059. index: -1,
  26060. start: 0,
  26061. dot: opts.dot === true,
  26062. consumed: '',
  26063. output: '',
  26064. prefix: '',
  26065. backtrack: false,
  26066. negated: false,
  26067. brackets: 0,
  26068. braces: 0,
  26069. parens: 0,
  26070. quotes: 0,
  26071. globstar: false,
  26072. tokens
  26073. };
  26074. input = utils$2.removePrefix(input, state);
  26075. len = input.length;
  26076. const extglobs = [];
  26077. const braces = [];
  26078. const stack = [];
  26079. let prev = bos;
  26080. let value;
  26081. /**
  26082. * Tokenizing helpers
  26083. */
  26084. const eos = () => state.index === len - 1;
  26085. const peek = state.peek = (n = 1) => input[state.index + n];
  26086. const advance = state.advance = () => input[++state.index];
  26087. const remaining = () => input.slice(state.index + 1);
  26088. const consume = (value = '', num = 0) => {
  26089. state.consumed += value;
  26090. state.index += num;
  26091. };
  26092. const append = token => {
  26093. state.output += token.output != null ? token.output : token.value;
  26094. consume(token.value);
  26095. };
  26096. const negate = () => {
  26097. let count = 1;
  26098. while (peek() === '!' && (peek(2) !== '(' || peek(3) === '?')) {
  26099. advance();
  26100. state.start++;
  26101. count++;
  26102. }
  26103. if (count % 2 === 0) {
  26104. return false;
  26105. }
  26106. state.negated = true;
  26107. state.start++;
  26108. return true;
  26109. };
  26110. const increment = type => {
  26111. state[type]++;
  26112. stack.push(type);
  26113. };
  26114. const decrement = type => {
  26115. state[type]--;
  26116. stack.pop();
  26117. };
  26118. /**
  26119. * Push tokens onto the tokens array. This helper speeds up
  26120. * tokenizing by 1) helping us avoid backtracking as much as possible,
  26121. * and 2) helping us avoid creating extra tokens when consecutive
  26122. * characters are plain text. This improves performance and simplifies
  26123. * lookbehinds.
  26124. */
  26125. const push = tok => {
  26126. if (prev.type === 'globstar') {
  26127. const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
  26128. const isExtglob = tok.extglob === true || extglobs.length && (tok.type === 'pipe' || tok.type === 'paren');
  26129. if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
  26130. state.output = state.output.slice(0, -prev.output.length);
  26131. prev.type = 'star';
  26132. prev.value = '*';
  26133. prev.output = star;
  26134. state.output += prev.output;
  26135. }
  26136. }
  26137. if (extglobs.length && tok.type !== 'paren' && !EXTGLOB_CHARS[tok.value]) {
  26138. extglobs[extglobs.length - 1].inner += tok.value;
  26139. }
  26140. if (tok.value || tok.output) append(tok);
  26141. if (prev && prev.type === 'text' && tok.type === 'text') {
  26142. prev.value += tok.value;
  26143. prev.output = (prev.output || '') + tok.value;
  26144. return;
  26145. }
  26146. tok.prev = prev;
  26147. tokens.push(tok);
  26148. prev = tok;
  26149. };
  26150. const extglobOpen = (type, value) => {
  26151. const token = Object.assign({}, EXTGLOB_CHARS[value], {
  26152. conditions: 1,
  26153. inner: ''
  26154. });
  26155. token.prev = prev;
  26156. token.parens = state.parens;
  26157. token.output = state.output;
  26158. const output = (opts.capture ? '(' : '') + token.open;
  26159. increment('parens');
  26160. push({
  26161. type,
  26162. value,
  26163. output: state.output ? '' : ONE_CHAR
  26164. });
  26165. push({
  26166. type: 'paren',
  26167. extglob: true,
  26168. value: advance(),
  26169. output
  26170. });
  26171. extglobs.push(token);
  26172. };
  26173. const extglobClose = token => {
  26174. let output = token.close + (opts.capture ? ')' : '');
  26175. if (token.type === 'negate') {
  26176. let extglobStar = star;
  26177. if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
  26178. extglobStar = globstar(opts);
  26179. }
  26180. if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
  26181. output = token.close = `)$))${extglobStar}`;
  26182. }
  26183. if (token.prev.type === 'bos' && eos()) {
  26184. state.negatedExtglob = true;
  26185. }
  26186. }
  26187. push({
  26188. type: 'paren',
  26189. extglob: true,
  26190. value,
  26191. output
  26192. });
  26193. decrement('parens');
  26194. };
  26195. /**
  26196. * Fast paths
  26197. */
  26198. if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
  26199. let backslashes = false;
  26200. let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
  26201. if (first === '\\') {
  26202. backslashes = true;
  26203. return m;
  26204. }
  26205. if (first === '?') {
  26206. if (esc) {
  26207. return esc + first + (rest ? QMARK.repeat(rest.length) : '');
  26208. }
  26209. if (index === 0) {
  26210. return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
  26211. }
  26212. return QMARK.repeat(chars.length);
  26213. }
  26214. if (first === '.') {
  26215. return DOT_LITERAL.repeat(chars.length);
  26216. }
  26217. if (first === '*') {
  26218. if (esc) {
  26219. return esc + first + (rest ? star : '');
  26220. }
  26221. return star;
  26222. }
  26223. return esc ? m : `\\${m}`;
  26224. });
  26225. if (backslashes === true) {
  26226. if (opts.unescape === true) {
  26227. output = output.replace(/\\/g, '');
  26228. } else {
  26229. output = output.replace(/\\+/g, m => {
  26230. return m.length % 2 === 0 ? '\\\\' : m ? '\\' : '';
  26231. });
  26232. }
  26233. }
  26234. if (output === input && opts.contains === true) {
  26235. state.output = input;
  26236. return state;
  26237. }
  26238. state.output = utils$2.wrapOutput(output, state, options);
  26239. return state;
  26240. }
  26241. /**
  26242. * Tokenize input until we reach end-of-string
  26243. */
  26244. while (!eos()) {
  26245. value = advance();
  26246. if (value === '\u0000') {
  26247. continue;
  26248. }
  26249. /**
  26250. * Escaped characters
  26251. */
  26252. if (value === '\\') {
  26253. const next = peek();
  26254. if (next === '/' && opts.bash !== true) {
  26255. continue;
  26256. }
  26257. if (next === '.' || next === ';') {
  26258. continue;
  26259. }
  26260. if (!next) {
  26261. value += '\\';
  26262. push({
  26263. type: 'text',
  26264. value
  26265. });
  26266. continue;
  26267. } // collapse slashes to reduce potential for exploits
  26268. const match = /^\\+/.exec(remaining());
  26269. let slashes = 0;
  26270. if (match && match[0].length > 2) {
  26271. slashes = match[0].length;
  26272. state.index += slashes;
  26273. if (slashes % 2 !== 0) {
  26274. value += '\\';
  26275. }
  26276. }
  26277. if (opts.unescape === true) {
  26278. value = advance() || '';
  26279. } else {
  26280. value += advance() || '';
  26281. }
  26282. if (state.brackets === 0) {
  26283. push({
  26284. type: 'text',
  26285. value
  26286. });
  26287. continue;
  26288. }
  26289. }
  26290. /**
  26291. * If we're inside a regex character class, continue
  26292. * until we reach the closing bracket.
  26293. */
  26294. if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
  26295. if (opts.posix !== false && value === ':') {
  26296. const inner = prev.value.slice(1);
  26297. if (inner.includes('[')) {
  26298. prev.posix = true;
  26299. if (inner.includes(':')) {
  26300. const idx = prev.value.lastIndexOf('[');
  26301. const pre = prev.value.slice(0, idx);
  26302. const rest = prev.value.slice(idx + 2);
  26303. const posix = POSIX_REGEX_SOURCE$1[rest];
  26304. if (posix) {
  26305. prev.value = pre + posix;
  26306. state.backtrack = true;
  26307. advance();
  26308. if (!bos.output && tokens.indexOf(prev) === 1) {
  26309. bos.output = ONE_CHAR;
  26310. }
  26311. continue;
  26312. }
  26313. }
  26314. }
  26315. }
  26316. if (value === '[' && peek() !== ':' || value === '-' && peek() === ']') {
  26317. value = `\\${value}`;
  26318. }
  26319. if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
  26320. value = `\\${value}`;
  26321. }
  26322. if (opts.posix === true && value === '!' && prev.value === '[') {
  26323. value = '^';
  26324. }
  26325. prev.value += value;
  26326. append({
  26327. value
  26328. });
  26329. continue;
  26330. }
  26331. /**
  26332. * If we're inside a quoted string, continue
  26333. * until we reach the closing double quote.
  26334. */
  26335. if (state.quotes === 1 && value !== '"') {
  26336. value = utils$2.escapeRegex(value);
  26337. prev.value += value;
  26338. append({
  26339. value
  26340. });
  26341. continue;
  26342. }
  26343. /**
  26344. * Double quotes
  26345. */
  26346. if (value === '"') {
  26347. state.quotes = state.quotes === 1 ? 0 : 1;
  26348. if (opts.keepQuotes === true) {
  26349. push({
  26350. type: 'text',
  26351. value
  26352. });
  26353. }
  26354. continue;
  26355. }
  26356. /**
  26357. * Parentheses
  26358. */
  26359. if (value === '(') {
  26360. increment('parens');
  26361. push({
  26362. type: 'paren',
  26363. value
  26364. });
  26365. continue;
  26366. }
  26367. if (value === ')') {
  26368. if (state.parens === 0 && opts.strictBrackets === true) {
  26369. throw new SyntaxError(syntaxError$1('opening', '('));
  26370. }
  26371. const extglob = extglobs[extglobs.length - 1];
  26372. if (extglob && state.parens === extglob.parens + 1) {
  26373. extglobClose(extglobs.pop());
  26374. continue;
  26375. }
  26376. push({
  26377. type: 'paren',
  26378. value,
  26379. output: state.parens ? ')' : '\\)'
  26380. });
  26381. decrement('parens');
  26382. continue;
  26383. }
  26384. /**
  26385. * Square brackets
  26386. */
  26387. if (value === '[') {
  26388. if (opts.nobracket === true || !remaining().includes(']')) {
  26389. if (opts.nobracket !== true && opts.strictBrackets === true) {
  26390. throw new SyntaxError(syntaxError$1('closing', ']'));
  26391. }
  26392. value = `\\${value}`;
  26393. } else {
  26394. increment('brackets');
  26395. }
  26396. push({
  26397. type: 'bracket',
  26398. value
  26399. });
  26400. continue;
  26401. }
  26402. if (value === ']') {
  26403. if (opts.nobracket === true || prev && prev.type === 'bracket' && prev.value.length === 1) {
  26404. push({
  26405. type: 'text',
  26406. value,
  26407. output: `\\${value}`
  26408. });
  26409. continue;
  26410. }
  26411. if (state.brackets === 0) {
  26412. if (opts.strictBrackets === true) {
  26413. throw new SyntaxError(syntaxError$1('opening', '['));
  26414. }
  26415. push({
  26416. type: 'text',
  26417. value,
  26418. output: `\\${value}`
  26419. });
  26420. continue;
  26421. }
  26422. decrement('brackets');
  26423. const prevValue = prev.value.slice(1);
  26424. if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
  26425. value = `/${value}`;
  26426. }
  26427. prev.value += value;
  26428. append({
  26429. value
  26430. }); // when literal brackets are explicitly disabled
  26431. // assume we should match with a regex character class
  26432. if (opts.literalBrackets === false || utils$2.hasRegexChars(prevValue)) {
  26433. continue;
  26434. }
  26435. const escaped = utils$2.escapeRegex(prev.value);
  26436. state.output = state.output.slice(0, -prev.value.length); // when literal brackets are explicitly enabled
  26437. // assume we should escape the brackets to match literal characters
  26438. if (opts.literalBrackets === true) {
  26439. state.output += escaped;
  26440. prev.value = escaped;
  26441. continue;
  26442. } // when the user specifies nothing, try to match both
  26443. prev.value = `(${capture}${escaped}|${prev.value})`;
  26444. state.output += prev.value;
  26445. continue;
  26446. }
  26447. /**
  26448. * Braces
  26449. */
  26450. if (value === '{' && opts.nobrace !== true) {
  26451. increment('braces');
  26452. const open = {
  26453. type: 'brace',
  26454. value,
  26455. output: '(',
  26456. outputIndex: state.output.length,
  26457. tokensIndex: state.tokens.length
  26458. };
  26459. braces.push(open);
  26460. push(open);
  26461. continue;
  26462. }
  26463. if (value === '}') {
  26464. const brace = braces[braces.length - 1];
  26465. if (opts.nobrace === true || !brace) {
  26466. push({
  26467. type: 'text',
  26468. value,
  26469. output: value
  26470. });
  26471. continue;
  26472. }
  26473. let output = ')';
  26474. if (brace.dots === true) {
  26475. const arr = tokens.slice();
  26476. const range = [];
  26477. for (let i = arr.length - 1; i >= 0; i--) {
  26478. tokens.pop();
  26479. if (arr[i].type === 'brace') {
  26480. break;
  26481. }
  26482. if (arr[i].type !== 'dots') {
  26483. range.unshift(arr[i].value);
  26484. }
  26485. }
  26486. output = expandRange(range, opts);
  26487. state.backtrack = true;
  26488. }
  26489. if (brace.comma !== true && brace.dots !== true) {
  26490. const out = state.output.slice(0, brace.outputIndex);
  26491. const toks = state.tokens.slice(brace.tokensIndex);
  26492. brace.value = brace.output = '\\{';
  26493. value = output = '\\}';
  26494. state.output = out;
  26495. for (const t of toks) {
  26496. state.output += t.output || t.value;
  26497. }
  26498. }
  26499. push({
  26500. type: 'brace',
  26501. value,
  26502. output
  26503. });
  26504. decrement('braces');
  26505. braces.pop();
  26506. continue;
  26507. }
  26508. /**
  26509. * Pipes
  26510. */
  26511. if (value === '|') {
  26512. if (extglobs.length > 0) {
  26513. extglobs[extglobs.length - 1].conditions++;
  26514. }
  26515. push({
  26516. type: 'text',
  26517. value
  26518. });
  26519. continue;
  26520. }
  26521. /**
  26522. * Commas
  26523. */
  26524. if (value === ',') {
  26525. let output = value;
  26526. const brace = braces[braces.length - 1];
  26527. if (brace && stack[stack.length - 1] === 'braces') {
  26528. brace.comma = true;
  26529. output = '|';
  26530. }
  26531. push({
  26532. type: 'comma',
  26533. value,
  26534. output
  26535. });
  26536. continue;
  26537. }
  26538. /**
  26539. * Slashes
  26540. */
  26541. if (value === '/') {
  26542. // if the beginning of the glob is "./", advance the start
  26543. // to the current index, and don't add the "./" characters
  26544. // to the state. This greatly simplifies lookbehinds when
  26545. // checking for BOS characters like "!" and "." (not "./")
  26546. if (prev.type === 'dot' && state.index === state.start + 1) {
  26547. state.start = state.index + 1;
  26548. state.consumed = '';
  26549. state.output = '';
  26550. tokens.pop();
  26551. prev = bos; // reset "prev" to the first token
  26552. continue;
  26553. }
  26554. push({
  26555. type: 'slash',
  26556. value,
  26557. output: SLASH_LITERAL
  26558. });
  26559. continue;
  26560. }
  26561. /**
  26562. * Dots
  26563. */
  26564. if (value === '.') {
  26565. if (state.braces > 0 && prev.type === 'dot') {
  26566. if (prev.value === '.') prev.output = DOT_LITERAL;
  26567. const brace = braces[braces.length - 1];
  26568. prev.type = 'dots';
  26569. prev.output += value;
  26570. prev.value += value;
  26571. brace.dots = true;
  26572. continue;
  26573. }
  26574. if (state.braces + state.parens === 0 && prev.type !== 'bos' && prev.type !== 'slash') {
  26575. push({
  26576. type: 'text',
  26577. value,
  26578. output: DOT_LITERAL
  26579. });
  26580. continue;
  26581. }
  26582. push({
  26583. type: 'dot',
  26584. value,
  26585. output: DOT_LITERAL
  26586. });
  26587. continue;
  26588. }
  26589. /**
  26590. * Question marks
  26591. */
  26592. if (value === '?') {
  26593. const isGroup = prev && prev.value === '(';
  26594. if (!isGroup && opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  26595. extglobOpen('qmark', value);
  26596. continue;
  26597. }
  26598. if (prev && prev.type === 'paren') {
  26599. const next = peek();
  26600. let output = value;
  26601. if (next === '<' && !utils$2.supportsLookbehinds()) {
  26602. throw new Error('Node.js v10 or higher is required for regex lookbehinds');
  26603. }
  26604. if (prev.value === '(' && !/[!=<:]/.test(next) || next === '<' && !/<([!=]|\w+>)/.test(remaining())) {
  26605. output = `\\${value}`;
  26606. }
  26607. push({
  26608. type: 'text',
  26609. value,
  26610. output
  26611. });
  26612. continue;
  26613. }
  26614. if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
  26615. push({
  26616. type: 'qmark',
  26617. value,
  26618. output: QMARK_NO_DOT
  26619. });
  26620. continue;
  26621. }
  26622. push({
  26623. type: 'qmark',
  26624. value,
  26625. output: QMARK
  26626. });
  26627. continue;
  26628. }
  26629. /**
  26630. * Exclamation
  26631. */
  26632. if (value === '!') {
  26633. if (opts.noextglob !== true && peek() === '(') {
  26634. if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
  26635. extglobOpen('negate', value);
  26636. continue;
  26637. }
  26638. }
  26639. if (opts.nonegate !== true && state.index === 0) {
  26640. negate();
  26641. continue;
  26642. }
  26643. }
  26644. /**
  26645. * Plus
  26646. */
  26647. if (value === '+') {
  26648. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  26649. extglobOpen('plus', value);
  26650. continue;
  26651. }
  26652. if (prev && prev.value === '(' || opts.regex === false) {
  26653. push({
  26654. type: 'plus',
  26655. value,
  26656. output: PLUS_LITERAL
  26657. });
  26658. continue;
  26659. }
  26660. if (prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace') || state.parens > 0) {
  26661. push({
  26662. type: 'plus',
  26663. value
  26664. });
  26665. continue;
  26666. }
  26667. push({
  26668. type: 'plus',
  26669. value: PLUS_LITERAL
  26670. });
  26671. continue;
  26672. }
  26673. /**
  26674. * Plain text
  26675. */
  26676. if (value === '@') {
  26677. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  26678. push({
  26679. type: 'at',
  26680. extglob: true,
  26681. value,
  26682. output: ''
  26683. });
  26684. continue;
  26685. }
  26686. push({
  26687. type: 'text',
  26688. value
  26689. });
  26690. continue;
  26691. }
  26692. /**
  26693. * Plain text
  26694. */
  26695. if (value !== '*') {
  26696. if (value === '$' || value === '^') {
  26697. value = `\\${value}`;
  26698. }
  26699. const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
  26700. if (match) {
  26701. value += match[0];
  26702. state.index += match[0].length;
  26703. }
  26704. push({
  26705. type: 'text',
  26706. value
  26707. });
  26708. continue;
  26709. }
  26710. /**
  26711. * Stars
  26712. */
  26713. if (prev && (prev.type === 'globstar' || prev.star === true)) {
  26714. prev.type = 'star';
  26715. prev.star = true;
  26716. prev.value += value;
  26717. prev.output = star;
  26718. state.backtrack = true;
  26719. state.globstar = true;
  26720. consume(value);
  26721. continue;
  26722. }
  26723. let rest = remaining();
  26724. if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
  26725. extglobOpen('star', value);
  26726. continue;
  26727. }
  26728. if (prev.type === 'star') {
  26729. if (opts.noglobstar === true) {
  26730. consume(value);
  26731. continue;
  26732. }
  26733. const prior = prev.prev;
  26734. const before = prior.prev;
  26735. const isStart = prior.type === 'slash' || prior.type === 'bos';
  26736. const afterStar = before && (before.type === 'star' || before.type === 'globstar');
  26737. if (opts.bash === true && (!isStart || rest[0] && rest[0] !== '/')) {
  26738. push({
  26739. type: 'star',
  26740. value,
  26741. output: ''
  26742. });
  26743. continue;
  26744. }
  26745. const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
  26746. const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
  26747. if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
  26748. push({
  26749. type: 'star',
  26750. value,
  26751. output: ''
  26752. });
  26753. continue;
  26754. } // strip consecutive `/**/`
  26755. while (rest.slice(0, 3) === '/**') {
  26756. const after = input[state.index + 4];
  26757. if (after && after !== '/') {
  26758. break;
  26759. }
  26760. rest = rest.slice(3);
  26761. consume('/**', 3);
  26762. }
  26763. if (prior.type === 'bos' && eos()) {
  26764. prev.type = 'globstar';
  26765. prev.value += value;
  26766. prev.output = globstar(opts);
  26767. state.output = prev.output;
  26768. state.globstar = true;
  26769. consume(value);
  26770. continue;
  26771. }
  26772. if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
  26773. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  26774. prior.output = `(?:${prior.output}`;
  26775. prev.type = 'globstar';
  26776. prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)');
  26777. prev.value += value;
  26778. state.globstar = true;
  26779. state.output += prior.output + prev.output;
  26780. consume(value);
  26781. continue;
  26782. }
  26783. if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
  26784. const end = rest[1] !== void 0 ? '|$' : '';
  26785. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  26786. prior.output = `(?:${prior.output}`;
  26787. prev.type = 'globstar';
  26788. prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
  26789. prev.value += value;
  26790. state.output += prior.output + prev.output;
  26791. state.globstar = true;
  26792. consume(value + advance());
  26793. push({
  26794. type: 'slash',
  26795. value: '/',
  26796. output: ''
  26797. });
  26798. continue;
  26799. }
  26800. if (prior.type === 'bos' && rest[0] === '/') {
  26801. prev.type = 'globstar';
  26802. prev.value += value;
  26803. prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
  26804. state.output = prev.output;
  26805. state.globstar = true;
  26806. consume(value + advance());
  26807. push({
  26808. type: 'slash',
  26809. value: '/',
  26810. output: ''
  26811. });
  26812. continue;
  26813. } // remove single star from output
  26814. state.output = state.output.slice(0, -prev.output.length); // reset previous token to globstar
  26815. prev.type = 'globstar';
  26816. prev.output = globstar(opts);
  26817. prev.value += value; // reset output with globstar
  26818. state.output += prev.output;
  26819. state.globstar = true;
  26820. consume(value);
  26821. continue;
  26822. }
  26823. const token = {
  26824. type: 'star',
  26825. value,
  26826. output: star
  26827. };
  26828. if (opts.bash === true) {
  26829. token.output = '.*?';
  26830. if (prev.type === 'bos' || prev.type === 'slash') {
  26831. token.output = nodot + token.output;
  26832. }
  26833. push(token);
  26834. continue;
  26835. }
  26836. if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
  26837. token.output = value;
  26838. push(token);
  26839. continue;
  26840. }
  26841. if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
  26842. if (prev.type === 'dot') {
  26843. state.output += NO_DOT_SLASH;
  26844. prev.output += NO_DOT_SLASH;
  26845. } else if (opts.dot === true) {
  26846. state.output += NO_DOTS_SLASH;
  26847. prev.output += NO_DOTS_SLASH;
  26848. } else {
  26849. state.output += nodot;
  26850. prev.output += nodot;
  26851. }
  26852. if (peek() !== '*') {
  26853. state.output += ONE_CHAR;
  26854. prev.output += ONE_CHAR;
  26855. }
  26856. }
  26857. push(token);
  26858. }
  26859. while (state.brackets > 0) {
  26860. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError$1('closing', ']'));
  26861. state.output = utils$2.escapeLast(state.output, '[');
  26862. decrement('brackets');
  26863. }
  26864. while (state.parens > 0) {
  26865. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError$1('closing', ')'));
  26866. state.output = utils$2.escapeLast(state.output, '(');
  26867. decrement('parens');
  26868. }
  26869. while (state.braces > 0) {
  26870. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError$1('closing', '}'));
  26871. state.output = utils$2.escapeLast(state.output, '{');
  26872. decrement('braces');
  26873. }
  26874. if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
  26875. push({
  26876. type: 'maybe_slash',
  26877. value: '',
  26878. output: `${SLASH_LITERAL}?`
  26879. });
  26880. } // rebuild the output if we had to backtrack at any point
  26881. if (state.backtrack === true) {
  26882. state.output = '';
  26883. for (const token of state.tokens) {
  26884. state.output += token.output != null ? token.output : token.value;
  26885. if (token.suffix) {
  26886. state.output += token.suffix;
  26887. }
  26888. }
  26889. }
  26890. return state;
  26891. };
  26892. /**
  26893. * Fast paths for creating regular expressions for common glob patterns.
  26894. * This can significantly speed up processing and has very little downside
  26895. * impact when none of the fast paths match.
  26896. */
  26897. parse$6.fastpaths = (input, options) => {
  26898. const opts = Object.assign({}, options);
  26899. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$3, opts.maxLength) : MAX_LENGTH$3;
  26900. const len = input.length;
  26901. if (len > max) {
  26902. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  26903. }
  26904. input = REPLACEMENTS[input] || input;
  26905. const win32 = utils$2.isWindows(options); // create constants based on platform, for windows or posix
  26906. const {
  26907. DOT_LITERAL,
  26908. SLASH_LITERAL,
  26909. ONE_CHAR,
  26910. DOTS_SLASH,
  26911. NO_DOT,
  26912. NO_DOTS,
  26913. NO_DOTS_SLASH,
  26914. STAR,
  26915. START_ANCHOR
  26916. } = constants$3.globChars(win32);
  26917. const nodot = opts.dot ? NO_DOTS : NO_DOT;
  26918. const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
  26919. const capture = opts.capture ? '' : '?:';
  26920. const state = {
  26921. negated: false,
  26922. prefix: ''
  26923. };
  26924. let star = opts.bash === true ? '.*?' : STAR;
  26925. if (opts.capture) {
  26926. star = `(${star})`;
  26927. }
  26928. const globstar = opts => {
  26929. if (opts.noglobstar === true) return star;
  26930. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  26931. };
  26932. const create = str => {
  26933. switch (str) {
  26934. case '*':
  26935. return `${nodot}${ONE_CHAR}${star}`;
  26936. case '.*':
  26937. return `${DOT_LITERAL}${ONE_CHAR}${star}`;
  26938. case '*.*':
  26939. return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  26940. case '*/*':
  26941. return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
  26942. case '**':
  26943. return nodot + globstar(opts);
  26944. case '**/*':
  26945. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
  26946. case '**/*.*':
  26947. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  26948. case '**/.*':
  26949. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
  26950. default:
  26951. {
  26952. const match = /^(.*?)\.(\w+)$/.exec(str);
  26953. if (!match) return;
  26954. const source = create(match[1]);
  26955. if (!source) return;
  26956. return source + DOT_LITERAL + match[2];
  26957. }
  26958. }
  26959. };
  26960. const output = utils$2.removePrefix(input, state);
  26961. let source = create(output);
  26962. if (source && opts.strictSlashes !== true) {
  26963. source += `${SLASH_LITERAL}?`;
  26964. }
  26965. return source;
  26966. };
  26967. var parse_1$1 = parse$6;
  26968. const isObject$2 = val => val && typeof val === 'object' && !Array.isArray(val);
  26969. /**
  26970. * Creates a matcher function from one or more glob patterns. The
  26971. * returned function takes a string to match as its first argument,
  26972. * and returns true if the string is a match. The returned matcher
  26973. * function also takes a boolean as the second argument that, when true,
  26974. * returns an object with additional information.
  26975. *
  26976. * ```js
  26977. * const picomatch = require('picomatch');
  26978. * // picomatch(glob[, options]);
  26979. *
  26980. * const isMatch = picomatch('*.!(*a)');
  26981. * console.log(isMatch('a.a')); //=> false
  26982. * console.log(isMatch('a.b')); //=> true
  26983. * ```
  26984. * @name picomatch
  26985. * @param {String|Array} `globs` One or more glob patterns.
  26986. * @param {Object=} `options`
  26987. * @return {Function=} Returns a matcher function.
  26988. * @api public
  26989. */
  26990. const picomatch = (glob, options, returnState = false) => {
  26991. if (Array.isArray(glob)) {
  26992. const fns = glob.map(input => picomatch(input, options, returnState));
  26993. const arrayMatcher = str => {
  26994. for (const isMatch of fns) {
  26995. const state = isMatch(str);
  26996. if (state) return state;
  26997. }
  26998. return false;
  26999. };
  27000. return arrayMatcher;
  27001. }
  27002. const isState = isObject$2(glob) && glob.tokens && glob.input;
  27003. if (glob === '' || typeof glob !== 'string' && !isState) {
  27004. throw new TypeError('Expected pattern to be a non-empty string');
  27005. }
  27006. const opts = options || {};
  27007. const posix = utils$2.isWindows(options);
  27008. const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
  27009. const state = regex.state;
  27010. delete regex.state;
  27011. let isIgnored = () => false;
  27012. if (opts.ignore) {
  27013. const ignoreOpts = Object.assign({}, options, {
  27014. ignore: null,
  27015. onMatch: null,
  27016. onResult: null
  27017. });
  27018. isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
  27019. }
  27020. const matcher = (input, returnObject = false) => {
  27021. const {
  27022. isMatch,
  27023. match,
  27024. output
  27025. } = picomatch.test(input, regex, options, {
  27026. glob,
  27027. posix
  27028. });
  27029. const result = {
  27030. glob,
  27031. state,
  27032. regex,
  27033. posix,
  27034. input,
  27035. output,
  27036. match,
  27037. isMatch
  27038. };
  27039. if (typeof opts.onResult === 'function') {
  27040. opts.onResult(result);
  27041. }
  27042. if (isMatch === false) {
  27043. result.isMatch = false;
  27044. return returnObject ? result : false;
  27045. }
  27046. if (isIgnored(input)) {
  27047. if (typeof opts.onIgnore === 'function') {
  27048. opts.onIgnore(result);
  27049. }
  27050. result.isMatch = false;
  27051. return returnObject ? result : false;
  27052. }
  27053. if (typeof opts.onMatch === 'function') {
  27054. opts.onMatch(result);
  27055. }
  27056. return returnObject ? result : true;
  27057. };
  27058. if (returnState) {
  27059. matcher.state = state;
  27060. }
  27061. return matcher;
  27062. };
  27063. /**
  27064. * Test `input` with the given `regex`. This is used by the main
  27065. * `picomatch()` function to test the input string.
  27066. *
  27067. * ```js
  27068. * const picomatch = require('picomatch');
  27069. * // picomatch.test(input, regex[, options]);
  27070. *
  27071. * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
  27072. * // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
  27073. * ```
  27074. * @param {String} `input` String to test.
  27075. * @param {RegExp} `regex`
  27076. * @return {Object} Returns an object with matching info.
  27077. * @api public
  27078. */
  27079. picomatch.test = (input, regex, options, {
  27080. glob,
  27081. posix
  27082. } = {}) => {
  27083. if (typeof input !== 'string') {
  27084. throw new TypeError('Expected input to be a string');
  27085. }
  27086. if (input === '') {
  27087. return {
  27088. isMatch: false,
  27089. output: ''
  27090. };
  27091. }
  27092. const opts = options || {};
  27093. const format = opts.format || (posix ? utils$2.toPosixSlashes : null);
  27094. let match = input === glob;
  27095. let output = match && format ? format(input) : input;
  27096. if (match === false) {
  27097. output = format ? format(input) : input;
  27098. match = output === glob;
  27099. }
  27100. if (match === false || opts.capture === true) {
  27101. if (opts.matchBase === true || opts.basename === true) {
  27102. match = picomatch.matchBase(input, regex, options, posix);
  27103. } else {
  27104. match = regex.exec(output);
  27105. }
  27106. }
  27107. return {
  27108. isMatch: Boolean(match),
  27109. match,
  27110. output
  27111. };
  27112. };
  27113. /**
  27114. * Match the basename of a filepath.
  27115. *
  27116. * ```js
  27117. * const picomatch = require('picomatch');
  27118. * // picomatch.matchBase(input, glob[, options]);
  27119. * console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
  27120. * ```
  27121. * @param {String} `input` String to test.
  27122. * @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
  27123. * @return {Boolean}
  27124. * @api public
  27125. */
  27126. picomatch.matchBase = (input, glob, options, posix = utils$2.isWindows(options)) => {
  27127. const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
  27128. return regex.test(path__default['default'].basename(input));
  27129. };
  27130. /**
  27131. * Returns true if **any** of the given glob `patterns` match the specified `string`.
  27132. *
  27133. * ```js
  27134. * const picomatch = require('picomatch');
  27135. * // picomatch.isMatch(string, patterns[, options]);
  27136. *
  27137. * console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
  27138. * console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
  27139. * ```
  27140. * @param {String|Array} str The string to test.
  27141. * @param {String|Array} patterns One or more glob patterns to use for matching.
  27142. * @param {Object} [options] See available [options](#options).
  27143. * @return {Boolean} Returns true if any patterns match `str`
  27144. * @api public
  27145. */
  27146. picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
  27147. /**
  27148. * Parse a glob pattern to create the source string for a regular
  27149. * expression.
  27150. *
  27151. * ```js
  27152. * const picomatch = require('picomatch');
  27153. * const result = picomatch.parse(pattern[, options]);
  27154. * ```
  27155. * @param {String} `pattern`
  27156. * @param {Object} `options`
  27157. * @return {Object} Returns an object with useful properties and output to be used as a regex source string.
  27158. * @api public
  27159. */
  27160. picomatch.parse = (pattern, options) => {
  27161. if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
  27162. return parse_1$1(pattern, Object.assign({}, options, {
  27163. fastpaths: false
  27164. }));
  27165. };
  27166. /**
  27167. * Scan a glob pattern to separate the pattern into segments.
  27168. *
  27169. * ```js
  27170. * const picomatch = require('picomatch');
  27171. * // picomatch.scan(input[, options]);
  27172. *
  27173. * const result = picomatch.scan('!./foo/*.js');
  27174. * console.log(result);
  27175. * { prefix: '!./',
  27176. * input: '!./foo/*.js',
  27177. * start: 3,
  27178. * base: 'foo',
  27179. * glob: '*.js',
  27180. * isBrace: false,
  27181. * isBracket: false,
  27182. * isGlob: true,
  27183. * isExtglob: false,
  27184. * isGlobstar: false,
  27185. * negated: true }
  27186. * ```
  27187. * @param {String} `input` Glob pattern to scan.
  27188. * @param {Object} `options`
  27189. * @return {Object} Returns an object with
  27190. * @api public
  27191. */
  27192. picomatch.scan = (input, options) => scan_1(input, options);
  27193. /**
  27194. * Create a regular expression from a parsed glob pattern.
  27195. *
  27196. * ```js
  27197. * const picomatch = require('picomatch');
  27198. * const state = picomatch.parse('*.js');
  27199. * // picomatch.compileRe(state[, options]);
  27200. *
  27201. * console.log(picomatch.compileRe(state));
  27202. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  27203. * ```
  27204. * @param {String} `state` The object returned from the `.parse` method.
  27205. * @param {Object} `options`
  27206. * @return {RegExp} Returns a regex created from the given pattern.
  27207. * @api public
  27208. */
  27209. picomatch.compileRe = (parsed, options, returnOutput = false, returnState = false) => {
  27210. if (returnOutput === true) {
  27211. return parsed.output;
  27212. }
  27213. const opts = options || {};
  27214. const prepend = opts.contains ? '' : '^';
  27215. const append = opts.contains ? '' : '$';
  27216. let source = `${prepend}(?:${parsed.output})${append}`;
  27217. if (parsed && parsed.negated === true) {
  27218. source = `^(?!${source}).*$`;
  27219. }
  27220. const regex = picomatch.toRegex(source, options);
  27221. if (returnState === true) {
  27222. regex.state = parsed;
  27223. }
  27224. return regex;
  27225. };
  27226. picomatch.makeRe = (input, options, returnOutput = false, returnState = false) => {
  27227. if (!input || typeof input !== 'string') {
  27228. throw new TypeError('Expected a non-empty string');
  27229. }
  27230. const opts = options || {};
  27231. let parsed = {
  27232. negated: false,
  27233. fastpaths: true
  27234. };
  27235. let prefix = '';
  27236. let output;
  27237. if (input.startsWith('./')) {
  27238. input = input.slice(2);
  27239. prefix = parsed.prefix = './';
  27240. }
  27241. if (opts.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
  27242. output = parse_1$1.fastpaths(input, options);
  27243. }
  27244. if (output === undefined) {
  27245. parsed = parse_1$1(input, options);
  27246. parsed.prefix = prefix + (parsed.prefix || '');
  27247. } else {
  27248. parsed.output = output;
  27249. }
  27250. return picomatch.compileRe(parsed, options, returnOutput, returnState);
  27251. };
  27252. /**
  27253. * Create a regular expression from the given regex source string.
  27254. *
  27255. * ```js
  27256. * const picomatch = require('picomatch');
  27257. * // picomatch.toRegex(source[, options]);
  27258. *
  27259. * const { output } = picomatch.parse('*.js');
  27260. * console.log(picomatch.toRegex(output));
  27261. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  27262. * ```
  27263. * @param {String} `source` Regular expression source string.
  27264. * @param {Object} `options`
  27265. * @return {RegExp}
  27266. * @api public
  27267. */
  27268. picomatch.toRegex = (source, options) => {
  27269. try {
  27270. const opts = options || {};
  27271. return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
  27272. } catch (err) {
  27273. if (options && options.debug === true) throw err;
  27274. return /$^/;
  27275. }
  27276. };
  27277. /**
  27278. * Picomatch constants.
  27279. * @return {Object}
  27280. */
  27281. picomatch.constants = constants$3;
  27282. /**
  27283. * Expose "picomatch"
  27284. */
  27285. var picomatch_1 = picomatch;
  27286. var picomatch$1 = picomatch_1;
  27287. const isEmptyString = val => typeof val === 'string' && (val === '' || val === './');
  27288. /**
  27289. * Returns an array of strings that match one or more glob patterns.
  27290. *
  27291. * ```js
  27292. * const mm = require('micromatch');
  27293. * // mm(list, patterns[, options]);
  27294. *
  27295. * console.log(mm(['a.js', 'a.txt'], ['*.js']));
  27296. * //=> [ 'a.js' ]
  27297. * ```
  27298. * @param {String|Array<string>} list List of strings to match.
  27299. * @param {String|Array<string>} patterns One or more glob patterns to use for matching.
  27300. * @param {Object} options See available [options](#options)
  27301. * @return {Array} Returns an array of matches
  27302. * @summary false
  27303. * @api public
  27304. */
  27305. const micromatch = (list, patterns, options) => {
  27306. patterns = [].concat(patterns);
  27307. list = [].concat(list);
  27308. let omit = new Set();
  27309. let keep = new Set();
  27310. let items = new Set();
  27311. let negatives = 0;
  27312. let onResult = state => {
  27313. items.add(state.output);
  27314. if (options && options.onResult) {
  27315. options.onResult(state);
  27316. }
  27317. };
  27318. for (let i = 0; i < patterns.length; i++) {
  27319. let isMatch = picomatch$1(String(patterns[i]), Object.assign({}, options, {
  27320. onResult
  27321. }), true);
  27322. let negated = isMatch.state.negated || isMatch.state.negatedExtglob;
  27323. if (negated) negatives++;
  27324. for (let item of list) {
  27325. let matched = isMatch(item, true);
  27326. let match = negated ? !matched.isMatch : matched.isMatch;
  27327. if (!match) continue;
  27328. if (negated) {
  27329. omit.add(matched.output);
  27330. } else {
  27331. omit.delete(matched.output);
  27332. keep.add(matched.output);
  27333. }
  27334. }
  27335. }
  27336. let result = negatives === patterns.length ? [...items] : [...keep];
  27337. let matches = result.filter(item => !omit.has(item));
  27338. if (options && matches.length === 0) {
  27339. if (options.failglob === true) {
  27340. throw new Error(`No matches found for "${patterns.join(', ')}"`);
  27341. }
  27342. if (options.nonull === true || options.nullglob === true) {
  27343. return options.unescape ? patterns.map(p => p.replace(/\\/g, '')) : patterns;
  27344. }
  27345. }
  27346. return matches;
  27347. };
  27348. /**
  27349. * Backwards compatibility
  27350. */
  27351. micromatch.match = micromatch;
  27352. /**
  27353. * Returns a matcher function from the given glob `pattern` and `options`.
  27354. * The returned function takes a string to match as its only argument and returns
  27355. * true if the string is a match.
  27356. *
  27357. * ```js
  27358. * const mm = require('micromatch');
  27359. * // mm.matcher(pattern[, options]);
  27360. *
  27361. * const isMatch = mm.matcher('*.!(*a)');
  27362. * console.log(isMatch('a.a')); //=> false
  27363. * console.log(isMatch('a.b')); //=> true
  27364. * ```
  27365. * @param {String} `pattern` Glob pattern
  27366. * @param {Object} `options`
  27367. * @return {Function} Returns a matcher function.
  27368. * @api public
  27369. */
  27370. micromatch.matcher = (pattern, options) => picomatch$1(pattern, options);
  27371. /**
  27372. * Returns true if **any** of the given glob `patterns` match the specified `string`.
  27373. *
  27374. * ```js
  27375. * const mm = require('micromatch');
  27376. * // mm.isMatch(string, patterns[, options]);
  27377. *
  27378. * console.log(mm.isMatch('a.a', ['b.*', '*.a'])); //=> true
  27379. * console.log(mm.isMatch('a.a', 'b.*')); //=> false
  27380. * ```
  27381. * @param {String} str The string to test.
  27382. * @param {String|Array} patterns One or more glob patterns to use for matching.
  27383. * @param {Object} [options] See available [options](#options).
  27384. * @return {Boolean} Returns true if any patterns match `str`
  27385. * @api public
  27386. */
  27387. micromatch.isMatch = (str, patterns, options) => picomatch$1(patterns, options)(str);
  27388. /**
  27389. * Backwards compatibility
  27390. */
  27391. micromatch.any = micromatch.isMatch;
  27392. /**
  27393. * Returns a list of strings that _**do not match any**_ of the given `patterns`.
  27394. *
  27395. * ```js
  27396. * const mm = require('micromatch');
  27397. * // mm.not(list, patterns[, options]);
  27398. *
  27399. * console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
  27400. * //=> ['b.b', 'c.c']
  27401. * ```
  27402. * @param {Array} `list` Array of strings to match.
  27403. * @param {String|Array} `patterns` One or more glob pattern to use for matching.
  27404. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  27405. * @return {Array} Returns an array of strings that **do not match** the given patterns.
  27406. * @api public
  27407. */
  27408. micromatch.not = (list, patterns, options = {}) => {
  27409. patterns = [].concat(patterns).map(String);
  27410. let result = new Set();
  27411. let items = [];
  27412. let onResult = state => {
  27413. if (options.onResult) options.onResult(state);
  27414. items.push(state.output);
  27415. };
  27416. let matches = micromatch(list, patterns, Object.assign({}, options, {
  27417. onResult
  27418. }));
  27419. for (let item of items) {
  27420. if (!matches.includes(item)) {
  27421. result.add(item);
  27422. }
  27423. }
  27424. return [...result];
  27425. };
  27426. /**
  27427. * Returns true if the given `string` contains the given pattern. Similar
  27428. * to [.isMatch](#isMatch) but the pattern can match any part of the string.
  27429. *
  27430. * ```js
  27431. * var mm = require('micromatch');
  27432. * // mm.contains(string, pattern[, options]);
  27433. *
  27434. * console.log(mm.contains('aa/bb/cc', '*b'));
  27435. * //=> true
  27436. * console.log(mm.contains('aa/bb/cc', '*d'));
  27437. * //=> false
  27438. * ```
  27439. * @param {String} `str` The string to match.
  27440. * @param {String|Array} `patterns` Glob pattern to use for matching.
  27441. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  27442. * @return {Boolean} Returns true if the patter matches any part of `str`.
  27443. * @api public
  27444. */
  27445. micromatch.contains = (str, pattern, options) => {
  27446. if (typeof str !== 'string') {
  27447. throw new TypeError(`Expected a string: "${util__default['default'].inspect(str)}"`);
  27448. }
  27449. if (Array.isArray(pattern)) {
  27450. return pattern.some(p => micromatch.contains(str, p, options));
  27451. }
  27452. if (typeof pattern === 'string') {
  27453. if (isEmptyString(str) || isEmptyString(pattern)) {
  27454. return false;
  27455. }
  27456. if (str.includes(pattern) || str.startsWith('./') && str.slice(2).includes(pattern)) {
  27457. return true;
  27458. }
  27459. }
  27460. return micromatch.isMatch(str, pattern, Object.assign({}, options, {
  27461. contains: true
  27462. }));
  27463. };
  27464. /**
  27465. * Filter the keys of the given object with the given `glob` pattern
  27466. * and `options`. Does not attempt to match nested keys. If you need this feature,
  27467. * use [glob-object][] instead.
  27468. *
  27469. * ```js
  27470. * const mm = require('micromatch');
  27471. * // mm.matchKeys(object, patterns[, options]);
  27472. *
  27473. * const obj = { aa: 'a', ab: 'b', ac: 'c' };
  27474. * console.log(mm.matchKeys(obj, '*b'));
  27475. * //=> { ab: 'b' }
  27476. * ```
  27477. * @param {Object} `object` The object with keys to filter.
  27478. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  27479. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  27480. * @return {Object} Returns an object with only keys that match the given patterns.
  27481. * @api public
  27482. */
  27483. micromatch.matchKeys = (obj, patterns, options) => {
  27484. if (!utils$2.isObject(obj)) {
  27485. throw new TypeError('Expected the first argument to be an object');
  27486. }
  27487. let keys = micromatch(Object.keys(obj), patterns, options);
  27488. let res = {};
  27489. for (let key of keys) res[key] = obj[key];
  27490. return res;
  27491. };
  27492. /**
  27493. * Returns true if some of the strings in the given `list` match any of the given glob `patterns`.
  27494. *
  27495. * ```js
  27496. * const mm = require('micromatch');
  27497. * // mm.some(list, patterns[, options]);
  27498. *
  27499. * console.log(mm.some(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
  27500. * // true
  27501. * console.log(mm.some(['foo.js'], ['*.js', '!foo.js']));
  27502. * // false
  27503. * ```
  27504. * @param {String|Array} `list` The string or array of strings to test. Returns as soon as the first match is found.
  27505. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  27506. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  27507. * @return {Boolean} Returns true if any patterns match `str`
  27508. * @api public
  27509. */
  27510. micromatch.some = (list, patterns, options) => {
  27511. let items = [].concat(list);
  27512. for (let pattern of [].concat(patterns)) {
  27513. let isMatch = picomatch$1(String(pattern), options);
  27514. if (items.some(item => isMatch(item))) {
  27515. return true;
  27516. }
  27517. }
  27518. return false;
  27519. };
  27520. /**
  27521. * Returns true if every string in the given `list` matches
  27522. * any of the given glob `patterns`.
  27523. *
  27524. * ```js
  27525. * const mm = require('micromatch');
  27526. * // mm.every(list, patterns[, options]);
  27527. *
  27528. * console.log(mm.every('foo.js', ['foo.js']));
  27529. * // true
  27530. * console.log(mm.every(['foo.js', 'bar.js'], ['*.js']));
  27531. * // true
  27532. * console.log(mm.every(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
  27533. * // false
  27534. * console.log(mm.every(['foo.js'], ['*.js', '!foo.js']));
  27535. * // false
  27536. * ```
  27537. * @param {String|Array} `list` The string or array of strings to test.
  27538. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  27539. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  27540. * @return {Boolean} Returns true if any patterns match `str`
  27541. * @api public
  27542. */
  27543. micromatch.every = (list, patterns, options) => {
  27544. let items = [].concat(list);
  27545. for (let pattern of [].concat(patterns)) {
  27546. let isMatch = picomatch$1(String(pattern), options);
  27547. if (!items.every(item => isMatch(item))) {
  27548. return false;
  27549. }
  27550. }
  27551. return true;
  27552. };
  27553. /**
  27554. * Returns true if **all** of the given `patterns` match
  27555. * the specified string.
  27556. *
  27557. * ```js
  27558. * const mm = require('micromatch');
  27559. * // mm.all(string, patterns[, options]);
  27560. *
  27561. * console.log(mm.all('foo.js', ['foo.js']));
  27562. * // true
  27563. *
  27564. * console.log(mm.all('foo.js', ['*.js', '!foo.js']));
  27565. * // false
  27566. *
  27567. * console.log(mm.all('foo.js', ['*.js', 'foo.js']));
  27568. * // true
  27569. *
  27570. * console.log(mm.all('foo.js', ['*.js', 'f*', '*o*', '*o.js']));
  27571. * // true
  27572. * ```
  27573. * @param {String|Array} `str` The string to test.
  27574. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  27575. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  27576. * @return {Boolean} Returns true if any patterns match `str`
  27577. * @api public
  27578. */
  27579. micromatch.all = (str, patterns, options) => {
  27580. if (typeof str !== 'string') {
  27581. throw new TypeError(`Expected a string: "${util__default['default'].inspect(str)}"`);
  27582. }
  27583. return [].concat(patterns).every(p => picomatch$1(p, options)(str));
  27584. };
  27585. /**
  27586. * Returns an array of matches captured by `pattern` in `string, or `null` if the pattern did not match.
  27587. *
  27588. * ```js
  27589. * const mm = require('micromatch');
  27590. * // mm.capture(pattern, string[, options]);
  27591. *
  27592. * console.log(mm.capture('test/*.js', 'test/foo.js'));
  27593. * //=> ['foo']
  27594. * console.log(mm.capture('test/*.js', 'foo/bar.css'));
  27595. * //=> null
  27596. * ```
  27597. * @param {String} `glob` Glob pattern to use for matching.
  27598. * @param {String} `input` String to match
  27599. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  27600. * @return {Boolean} Returns an array of captures if the input matches the glob pattern, otherwise `null`.
  27601. * @api public
  27602. */
  27603. micromatch.capture = (glob, input, options) => {
  27604. let posix = utils$2.isWindows(options);
  27605. let regex = picomatch$1.makeRe(String(glob), Object.assign({}, options, {
  27606. capture: true
  27607. }));
  27608. let match = regex.exec(posix ? utils$2.toPosixSlashes(input) : input);
  27609. if (match) {
  27610. return match.slice(1).map(v => v === void 0 ? '' : v);
  27611. }
  27612. };
  27613. /**
  27614. * Create a regular expression from the given glob `pattern`.
  27615. *
  27616. * ```js
  27617. * const mm = require('micromatch');
  27618. * // mm.makeRe(pattern[, options]);
  27619. *
  27620. * console.log(mm.makeRe('*.js'));
  27621. * //=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
  27622. * ```
  27623. * @param {String} `pattern` A glob pattern to convert to regex.
  27624. * @param {Object} `options`
  27625. * @return {RegExp} Returns a regex created from the given pattern.
  27626. * @api public
  27627. */
  27628. micromatch.makeRe = (...args) => picomatch$1.makeRe(...args);
  27629. /**
  27630. * Scan a glob pattern to separate the pattern into segments. Used
  27631. * by the [split](#split) method.
  27632. *
  27633. * ```js
  27634. * const mm = require('micromatch');
  27635. * const state = mm.scan(pattern[, options]);
  27636. * ```
  27637. * @param {String} `pattern`
  27638. * @param {Object} `options`
  27639. * @return {Object} Returns an object with
  27640. * @api public
  27641. */
  27642. micromatch.scan = (...args) => picomatch$1.scan(...args);
  27643. /**
  27644. * Parse a glob pattern to create the source string for a regular
  27645. * expression.
  27646. *
  27647. * ```js
  27648. * const mm = require('micromatch');
  27649. * const state = mm(pattern[, options]);
  27650. * ```
  27651. * @param {String} `glob`
  27652. * @param {Object} `options`
  27653. * @return {Object} Returns an object with useful properties and output to be used as regex source string.
  27654. * @api public
  27655. */
  27656. micromatch.parse = (patterns, options) => {
  27657. let res = [];
  27658. for (let pattern of [].concat(patterns || [])) {
  27659. for (let str of braces_1(String(pattern), options)) {
  27660. res.push(picomatch$1.parse(str, options));
  27661. }
  27662. }
  27663. return res;
  27664. };
  27665. /**
  27666. * Process the given brace `pattern`.
  27667. *
  27668. * ```js
  27669. * const { braces } = require('micromatch');
  27670. * console.log(braces('foo/{a,b,c}/bar'));
  27671. * //=> [ 'foo/(a|b|c)/bar' ]
  27672. *
  27673. * console.log(braces('foo/{a,b,c}/bar', { expand: true }));
  27674. * //=> [ 'foo/a/bar', 'foo/b/bar', 'foo/c/bar' ]
  27675. * ```
  27676. * @param {String} `pattern` String with brace pattern to process.
  27677. * @param {Object} `options` Any [options](#options) to change how expansion is performed. See the [braces][] library for all available options.
  27678. * @return {Array}
  27679. * @api public
  27680. */
  27681. micromatch.braces = (pattern, options) => {
  27682. if (typeof pattern !== 'string') throw new TypeError('Expected a string');
  27683. if (options && options.nobrace === true || !/\{.*\}/.test(pattern)) {
  27684. return [pattern];
  27685. }
  27686. return braces_1(pattern, options);
  27687. };
  27688. /**
  27689. * Expand braces
  27690. */
  27691. micromatch.braceExpand = (pattern, options) => {
  27692. if (typeof pattern !== 'string') throw new TypeError('Expected a string');
  27693. return micromatch.braces(pattern, Object.assign({}, options, {
  27694. expand: true
  27695. }));
  27696. };
  27697. /**
  27698. * Expose micromatch
  27699. */
  27700. var micromatch_1 = micromatch;
  27701. var pattern = createCommonjsModule(function (module, exports) {
  27702. Object.defineProperty(exports, "__esModule", {
  27703. value: true
  27704. });
  27705. exports.matchAny = exports.convertPatternsToRe = exports.makeRe = exports.getPatternParts = exports.expandBraceExpansion = exports.expandPatternsWithBraceExpansion = exports.isAffectDepthOfReadingPattern = exports.endsWithSlashGlobStar = exports.hasGlobStar = exports.getBaseDirectory = exports.getPositivePatterns = exports.getNegativePatterns = exports.isPositivePattern = exports.isNegativePattern = exports.convertToNegativePattern = exports.convertToPositivePattern = exports.isDynamicPattern = exports.isStaticPattern = void 0;
  27706. const GLOBSTAR = '**';
  27707. const ESCAPE_SYMBOL = '\\';
  27708. const COMMON_GLOB_SYMBOLS_RE = /[*?]|^!/;
  27709. const REGEX_CHARACTER_CLASS_SYMBOLS_RE = /\[.*]/;
  27710. const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^!*+?@])\(.*\|.*\)/;
  27711. const GLOB_EXTENSION_SYMBOLS_RE = /[!*+?@]\(.*\)/;
  27712. const BRACE_EXPANSIONS_SYMBOLS_RE = /{.*(?:,|\.\.).*}/;
  27713. function isStaticPattern(pattern, options = {}) {
  27714. return !isDynamicPattern(pattern, options);
  27715. }
  27716. exports.isStaticPattern = isStaticPattern;
  27717. function isDynamicPattern(pattern, options = {}) {
  27718. /**
  27719. * A special case with an empty string is necessary for matching patterns that start with a forward slash.
  27720. * An empty string cannot be a dynamic pattern.
  27721. * For example, the pattern `/lib/*` will be spread into parts: '', 'lib', '*'.
  27722. */
  27723. if (pattern === '') {
  27724. return false;
  27725. }
  27726. /**
  27727. * When the `caseSensitiveMatch` option is disabled, all patterns must be marked as dynamic, because we cannot check
  27728. * filepath directly (without read directory).
  27729. */
  27730. if (options.caseSensitiveMatch === false || pattern.includes(ESCAPE_SYMBOL)) {
  27731. return true;
  27732. }
  27733. if (COMMON_GLOB_SYMBOLS_RE.test(pattern) || REGEX_CHARACTER_CLASS_SYMBOLS_RE.test(pattern) || REGEX_GROUP_SYMBOLS_RE.test(pattern)) {
  27734. return true;
  27735. }
  27736. if (options.extglob !== false && GLOB_EXTENSION_SYMBOLS_RE.test(pattern)) {
  27737. return true;
  27738. }
  27739. if (options.braceExpansion !== false && BRACE_EXPANSIONS_SYMBOLS_RE.test(pattern)) {
  27740. return true;
  27741. }
  27742. return false;
  27743. }
  27744. exports.isDynamicPattern = isDynamicPattern;
  27745. function convertToPositivePattern(pattern) {
  27746. return isNegativePattern(pattern) ? pattern.slice(1) : pattern;
  27747. }
  27748. exports.convertToPositivePattern = convertToPositivePattern;
  27749. function convertToNegativePattern(pattern) {
  27750. return '!' + pattern;
  27751. }
  27752. exports.convertToNegativePattern = convertToNegativePattern;
  27753. function isNegativePattern(pattern) {
  27754. return pattern.startsWith('!') && pattern[1] !== '(';
  27755. }
  27756. exports.isNegativePattern = isNegativePattern;
  27757. function isPositivePattern(pattern) {
  27758. return !isNegativePattern(pattern);
  27759. }
  27760. exports.isPositivePattern = isPositivePattern;
  27761. function getNegativePatterns(patterns) {
  27762. return patterns.filter(isNegativePattern);
  27763. }
  27764. exports.getNegativePatterns = getNegativePatterns;
  27765. function getPositivePatterns(patterns) {
  27766. return patterns.filter(isPositivePattern);
  27767. }
  27768. exports.getPositivePatterns = getPositivePatterns;
  27769. function getBaseDirectory(pattern) {
  27770. return globParent(pattern, {
  27771. flipBackslashes: false
  27772. });
  27773. }
  27774. exports.getBaseDirectory = getBaseDirectory;
  27775. function hasGlobStar(pattern) {
  27776. return pattern.includes(GLOBSTAR);
  27777. }
  27778. exports.hasGlobStar = hasGlobStar;
  27779. function endsWithSlashGlobStar(pattern) {
  27780. return pattern.endsWith('/' + GLOBSTAR);
  27781. }
  27782. exports.endsWithSlashGlobStar = endsWithSlashGlobStar;
  27783. function isAffectDepthOfReadingPattern(pattern) {
  27784. const basename = path__default['default'].basename(pattern);
  27785. return endsWithSlashGlobStar(pattern) || isStaticPattern(basename);
  27786. }
  27787. exports.isAffectDepthOfReadingPattern = isAffectDepthOfReadingPattern;
  27788. function expandPatternsWithBraceExpansion(patterns) {
  27789. return patterns.reduce((collection, pattern) => {
  27790. return collection.concat(expandBraceExpansion(pattern));
  27791. }, []);
  27792. }
  27793. exports.expandPatternsWithBraceExpansion = expandPatternsWithBraceExpansion;
  27794. function expandBraceExpansion(pattern) {
  27795. return micromatch_1.braces(pattern, {
  27796. expand: true,
  27797. nodupes: true
  27798. });
  27799. }
  27800. exports.expandBraceExpansion = expandBraceExpansion;
  27801. function getPatternParts(pattern, options) {
  27802. let {
  27803. parts
  27804. } = picomatch$1.scan(pattern, Object.assign(Object.assign({}, options), {
  27805. parts: true
  27806. }));
  27807. /**
  27808. * The scan method returns an empty array in some cases.
  27809. * See micromatch/picomatch#58 for more details.
  27810. */
  27811. if (parts.length === 0) {
  27812. parts = [pattern];
  27813. }
  27814. /**
  27815. * The scan method does not return an empty part for the pattern with a forward slash.
  27816. * This is another part of micromatch/picomatch#58.
  27817. */
  27818. if (parts[0].startsWith('/')) {
  27819. parts[0] = parts[0].slice(1);
  27820. parts.unshift('');
  27821. }
  27822. return parts;
  27823. }
  27824. exports.getPatternParts = getPatternParts;
  27825. function makeRe(pattern, options) {
  27826. return micromatch_1.makeRe(pattern, options);
  27827. }
  27828. exports.makeRe = makeRe;
  27829. function convertPatternsToRe(patterns, options) {
  27830. return patterns.map(pattern => makeRe(pattern, options));
  27831. }
  27832. exports.convertPatternsToRe = convertPatternsToRe;
  27833. function matchAny(entry, patternsRe) {
  27834. return patternsRe.some(patternRe => patternRe.test(entry));
  27835. }
  27836. exports.matchAny = matchAny;
  27837. });
  27838. var stream$1 = createCommonjsModule(function (module, exports) {
  27839. Object.defineProperty(exports, "__esModule", {
  27840. value: true
  27841. });
  27842. exports.merge = void 0;
  27843. function merge(streams) {
  27844. const mergedStream = merge2_1(streams);
  27845. streams.forEach(stream => {
  27846. stream.once('error', error => mergedStream.emit('error', error));
  27847. });
  27848. mergedStream.once('close', () => propagateCloseEventToSources(streams));
  27849. mergedStream.once('end', () => propagateCloseEventToSources(streams));
  27850. return mergedStream;
  27851. }
  27852. exports.merge = merge;
  27853. function propagateCloseEventToSources(streams) {
  27854. streams.forEach(stream => stream.emit('close'));
  27855. }
  27856. });
  27857. var string$1 = createCommonjsModule(function (module, exports) {
  27858. Object.defineProperty(exports, "__esModule", {
  27859. value: true
  27860. });
  27861. exports.isEmpty = exports.isString = void 0;
  27862. function isString(input) {
  27863. return typeof input === 'string';
  27864. }
  27865. exports.isString = isString;
  27866. function isEmpty(input) {
  27867. return input === '';
  27868. }
  27869. exports.isEmpty = isEmpty;
  27870. });
  27871. var utils$3 = createCommonjsModule(function (module, exports) {
  27872. Object.defineProperty(exports, "__esModule", {
  27873. value: true
  27874. });
  27875. exports.string = exports.stream = exports.pattern = exports.path = exports.fs = exports.errno = exports.array = void 0;
  27876. exports.array = array$2;
  27877. exports.errno = errno;
  27878. exports.fs = fs$1;
  27879. exports.path = path_1;
  27880. exports.pattern = pattern;
  27881. exports.stream = stream$1;
  27882. exports.string = string$1;
  27883. });
  27884. var tasks = createCommonjsModule(function (module, exports) {
  27885. Object.defineProperty(exports, "__esModule", {
  27886. value: true
  27887. });
  27888. exports.convertPatternGroupToTask = exports.convertPatternGroupsToTasks = exports.groupPatternsByBaseDirectory = exports.getNegativePatternsAsPositive = exports.getPositivePatterns = exports.convertPatternsToTasks = exports.generate = void 0;
  27889. function generate(patterns, settings) {
  27890. const positivePatterns = getPositivePatterns(patterns);
  27891. const negativePatterns = getNegativePatternsAsPositive(patterns, settings.ignore);
  27892. const staticPatterns = positivePatterns.filter(pattern => utils$3.pattern.isStaticPattern(pattern, settings));
  27893. const dynamicPatterns = positivePatterns.filter(pattern => utils$3.pattern.isDynamicPattern(pattern, settings));
  27894. const staticTasks = convertPatternsToTasks(staticPatterns, negativePatterns,
  27895. /* dynamic */
  27896. false);
  27897. const dynamicTasks = convertPatternsToTasks(dynamicPatterns, negativePatterns,
  27898. /* dynamic */
  27899. true);
  27900. return staticTasks.concat(dynamicTasks);
  27901. }
  27902. exports.generate = generate;
  27903. function convertPatternsToTasks(positive, negative, dynamic) {
  27904. const positivePatternsGroup = groupPatternsByBaseDirectory(positive); // When we have a global group – there is no reason to divide the patterns into independent tasks.
  27905. // In this case, the global task covers the rest.
  27906. if ('.' in positivePatternsGroup) {
  27907. const task = convertPatternGroupToTask('.', positive, negative, dynamic);
  27908. return [task];
  27909. }
  27910. return convertPatternGroupsToTasks(positivePatternsGroup, negative, dynamic);
  27911. }
  27912. exports.convertPatternsToTasks = convertPatternsToTasks;
  27913. function getPositivePatterns(patterns) {
  27914. return utils$3.pattern.getPositivePatterns(patterns);
  27915. }
  27916. exports.getPositivePatterns = getPositivePatterns;
  27917. function getNegativePatternsAsPositive(patterns, ignore) {
  27918. const negative = utils$3.pattern.getNegativePatterns(patterns).concat(ignore);
  27919. const positive = negative.map(utils$3.pattern.convertToPositivePattern);
  27920. return positive;
  27921. }
  27922. exports.getNegativePatternsAsPositive = getNegativePatternsAsPositive;
  27923. function groupPatternsByBaseDirectory(patterns) {
  27924. const group = {};
  27925. return patterns.reduce((collection, pattern) => {
  27926. const base = utils$3.pattern.getBaseDirectory(pattern);
  27927. if (base in collection) {
  27928. collection[base].push(pattern);
  27929. } else {
  27930. collection[base] = [pattern];
  27931. }
  27932. return collection;
  27933. }, group);
  27934. }
  27935. exports.groupPatternsByBaseDirectory = groupPatternsByBaseDirectory;
  27936. function convertPatternGroupsToTasks(positive, negative, dynamic) {
  27937. return Object.keys(positive).map(base => {
  27938. return convertPatternGroupToTask(base, positive[base], negative, dynamic);
  27939. });
  27940. }
  27941. exports.convertPatternGroupsToTasks = convertPatternGroupsToTasks;
  27942. function convertPatternGroupToTask(base, positive, negative, dynamic) {
  27943. return {
  27944. dynamic,
  27945. positive,
  27946. negative,
  27947. base,
  27948. patterns: [].concat(positive, negative.map(utils$3.pattern.convertToNegativePattern))
  27949. };
  27950. }
  27951. exports.convertPatternGroupToTask = convertPatternGroupToTask;
  27952. });
  27953. var async$1 = createCommonjsModule(function (module, exports) {
  27954. Object.defineProperty(exports, "__esModule", {
  27955. value: true
  27956. });
  27957. function read(path, settings, callback) {
  27958. settings.fs.lstat(path, (lstatError, lstat) => {
  27959. if (lstatError !== null) {
  27960. return callFailureCallback(callback, lstatError);
  27961. }
  27962. if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) {
  27963. return callSuccessCallback(callback, lstat);
  27964. }
  27965. settings.fs.stat(path, (statError, stat) => {
  27966. if (statError !== null) {
  27967. if (settings.throwErrorOnBrokenSymbolicLink) {
  27968. return callFailureCallback(callback, statError);
  27969. }
  27970. return callSuccessCallback(callback, lstat);
  27971. }
  27972. if (settings.markSymbolicLink) {
  27973. stat.isSymbolicLink = () => true;
  27974. }
  27975. callSuccessCallback(callback, stat);
  27976. });
  27977. });
  27978. }
  27979. exports.read = read;
  27980. function callFailureCallback(callback, error) {
  27981. callback(error);
  27982. }
  27983. function callSuccessCallback(callback, result) {
  27984. callback(null, result);
  27985. }
  27986. });
  27987. var sync$1 = createCommonjsModule(function (module, exports) {
  27988. Object.defineProperty(exports, "__esModule", {
  27989. value: true
  27990. });
  27991. function read(path, settings) {
  27992. const lstat = settings.fs.lstatSync(path);
  27993. if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) {
  27994. return lstat;
  27995. }
  27996. try {
  27997. const stat = settings.fs.statSync(path);
  27998. if (settings.markSymbolicLink) {
  27999. stat.isSymbolicLink = () => true;
  28000. }
  28001. return stat;
  28002. } catch (error) {
  28003. if (!settings.throwErrorOnBrokenSymbolicLink) {
  28004. return lstat;
  28005. }
  28006. throw error;
  28007. }
  28008. }
  28009. exports.read = read;
  28010. });
  28011. var fs_1 = createCommonjsModule(function (module, exports) {
  28012. Object.defineProperty(exports, "__esModule", {
  28013. value: true
  28014. });
  28015. exports.FILE_SYSTEM_ADAPTER = {
  28016. lstat: fs__default['default'].lstat,
  28017. stat: fs__default['default'].stat,
  28018. lstatSync: fs__default['default'].lstatSync,
  28019. statSync: fs__default['default'].statSync
  28020. };
  28021. function createFileSystemAdapter(fsMethods) {
  28022. if (fsMethods === undefined) {
  28023. return exports.FILE_SYSTEM_ADAPTER;
  28024. }
  28025. return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods);
  28026. }
  28027. exports.createFileSystemAdapter = createFileSystemAdapter;
  28028. });
  28029. var settings = createCommonjsModule(function (module, exports) {
  28030. Object.defineProperty(exports, "__esModule", {
  28031. value: true
  28032. });
  28033. class Settings {
  28034. constructor(_options = {}) {
  28035. this._options = _options;
  28036. this.followSymbolicLink = this._getValue(this._options.followSymbolicLink, true);
  28037. this.fs = fs_1.createFileSystemAdapter(this._options.fs);
  28038. this.markSymbolicLink = this._getValue(this._options.markSymbolicLink, false);
  28039. this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
  28040. }
  28041. _getValue(option, value) {
  28042. return option === undefined ? value : option;
  28043. }
  28044. }
  28045. exports.default = Settings;
  28046. });
  28047. var out = createCommonjsModule(function (module, exports) {
  28048. Object.defineProperty(exports, "__esModule", {
  28049. value: true
  28050. });
  28051. exports.Settings = settings.default;
  28052. function stat(path, optionsOrSettingsOrCallback, callback) {
  28053. if (typeof optionsOrSettingsOrCallback === 'function') {
  28054. return async$1.read(path, getSettings(), optionsOrSettingsOrCallback);
  28055. }
  28056. async$1.read(path, getSettings(optionsOrSettingsOrCallback), callback);
  28057. }
  28058. exports.stat = stat;
  28059. function statSync(path, optionsOrSettings) {
  28060. const settings = getSettings(optionsOrSettings);
  28061. return sync$1.read(path, settings);
  28062. }
  28063. exports.statSync = statSync;
  28064. function getSettings(settingsOrOptions = {}) {
  28065. if (settingsOrOptions instanceof settings.default) {
  28066. return settingsOrOptions;
  28067. }
  28068. return new settings.default(settingsOrOptions);
  28069. }
  28070. });
  28071. var runParallel_1 = runParallel;
  28072. function runParallel(tasks, cb) {
  28073. var results, pending, keys;
  28074. var isSync = true;
  28075. if (Array.isArray(tasks)) {
  28076. results = [];
  28077. pending = tasks.length;
  28078. } else {
  28079. keys = Object.keys(tasks);
  28080. results = {};
  28081. pending = keys.length;
  28082. }
  28083. function done(err) {
  28084. function end() {
  28085. if (cb) cb(err, results);
  28086. cb = null;
  28087. }
  28088. if (isSync) process.nextTick(end);else end();
  28089. }
  28090. function each(i, err, result) {
  28091. results[i] = result;
  28092. if (--pending === 0 || err) {
  28093. done(err);
  28094. }
  28095. }
  28096. if (!pending) {
  28097. // empty
  28098. done(null);
  28099. } else if (keys) {
  28100. // object
  28101. keys.forEach(function (key) {
  28102. tasks[key](function (err, result) {
  28103. each(key, err, result);
  28104. });
  28105. });
  28106. } else {
  28107. // array
  28108. tasks.forEach(function (task, i) {
  28109. task(function (err, result) {
  28110. each(i, err, result);
  28111. });
  28112. });
  28113. }
  28114. isSync = false;
  28115. }
  28116. var constants$4 = createCommonjsModule(function (module, exports) {
  28117. Object.defineProperty(exports, "__esModule", {
  28118. value: true
  28119. });
  28120. const NODE_PROCESS_VERSION_PARTS = process.versions.node.split('.');
  28121. const MAJOR_VERSION = parseInt(NODE_PROCESS_VERSION_PARTS[0], 10);
  28122. const MINOR_VERSION = parseInt(NODE_PROCESS_VERSION_PARTS[1], 10);
  28123. const SUPPORTED_MAJOR_VERSION = 10;
  28124. const SUPPORTED_MINOR_VERSION = 10;
  28125. const IS_MATCHED_BY_MAJOR = MAJOR_VERSION > SUPPORTED_MAJOR_VERSION;
  28126. const IS_MATCHED_BY_MAJOR_AND_MINOR = MAJOR_VERSION === SUPPORTED_MAJOR_VERSION && MINOR_VERSION >= SUPPORTED_MINOR_VERSION;
  28127. /**
  28128. * IS `true` for Node.js 10.10 and greater.
  28129. */
  28130. exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = IS_MATCHED_BY_MAJOR || IS_MATCHED_BY_MAJOR_AND_MINOR;
  28131. });
  28132. var fs$2 = createCommonjsModule(function (module, exports) {
  28133. Object.defineProperty(exports, "__esModule", {
  28134. value: true
  28135. });
  28136. class DirentFromStats {
  28137. constructor(name, stats) {
  28138. this.name = name;
  28139. this.isBlockDevice = stats.isBlockDevice.bind(stats);
  28140. this.isCharacterDevice = stats.isCharacterDevice.bind(stats);
  28141. this.isDirectory = stats.isDirectory.bind(stats);
  28142. this.isFIFO = stats.isFIFO.bind(stats);
  28143. this.isFile = stats.isFile.bind(stats);
  28144. this.isSocket = stats.isSocket.bind(stats);
  28145. this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
  28146. }
  28147. }
  28148. function createDirentFromStats(name, stats) {
  28149. return new DirentFromStats(name, stats);
  28150. }
  28151. exports.createDirentFromStats = createDirentFromStats;
  28152. });
  28153. var utils$4 = createCommonjsModule(function (module, exports) {
  28154. Object.defineProperty(exports, "__esModule", {
  28155. value: true
  28156. });
  28157. exports.fs = fs$2;
  28158. });
  28159. var async$2 = createCommonjsModule(function (module, exports) {
  28160. Object.defineProperty(exports, "__esModule", {
  28161. value: true
  28162. });
  28163. function read(directory, settings, callback) {
  28164. if (!settings.stats && constants$4.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
  28165. return readdirWithFileTypes(directory, settings, callback);
  28166. }
  28167. return readdir(directory, settings, callback);
  28168. }
  28169. exports.read = read;
  28170. function readdirWithFileTypes(directory, settings, callback) {
  28171. settings.fs.readdir(directory, {
  28172. withFileTypes: true
  28173. }, (readdirError, dirents) => {
  28174. if (readdirError !== null) {
  28175. return callFailureCallback(callback, readdirError);
  28176. }
  28177. const entries = dirents.map(dirent => ({
  28178. dirent,
  28179. name: dirent.name,
  28180. path: `${directory}${settings.pathSegmentSeparator}${dirent.name}`
  28181. }));
  28182. if (!settings.followSymbolicLinks) {
  28183. return callSuccessCallback(callback, entries);
  28184. }
  28185. const tasks = entries.map(entry => makeRplTaskEntry(entry, settings));
  28186. runParallel_1(tasks, (rplError, rplEntries) => {
  28187. if (rplError !== null) {
  28188. return callFailureCallback(callback, rplError);
  28189. }
  28190. callSuccessCallback(callback, rplEntries);
  28191. });
  28192. });
  28193. }
  28194. exports.readdirWithFileTypes = readdirWithFileTypes;
  28195. function makeRplTaskEntry(entry, settings) {
  28196. return done => {
  28197. if (!entry.dirent.isSymbolicLink()) {
  28198. return done(null, entry);
  28199. }
  28200. settings.fs.stat(entry.path, (statError, stats) => {
  28201. if (statError !== null) {
  28202. if (settings.throwErrorOnBrokenSymbolicLink) {
  28203. return done(statError);
  28204. }
  28205. return done(null, entry);
  28206. }
  28207. entry.dirent = utils$4.fs.createDirentFromStats(entry.name, stats);
  28208. return done(null, entry);
  28209. });
  28210. };
  28211. }
  28212. function readdir(directory, settings, callback) {
  28213. settings.fs.readdir(directory, (readdirError, names) => {
  28214. if (readdirError !== null) {
  28215. return callFailureCallback(callback, readdirError);
  28216. }
  28217. const filepaths = names.map(name => `${directory}${settings.pathSegmentSeparator}${name}`);
  28218. const tasks = filepaths.map(filepath => {
  28219. return done => out.stat(filepath, settings.fsStatSettings, done);
  28220. });
  28221. runParallel_1(tasks, (rplError, results) => {
  28222. if (rplError !== null) {
  28223. return callFailureCallback(callback, rplError);
  28224. }
  28225. const entries = [];
  28226. names.forEach((name, index) => {
  28227. const stats = results[index];
  28228. const entry = {
  28229. name,
  28230. path: filepaths[index],
  28231. dirent: utils$4.fs.createDirentFromStats(name, stats)
  28232. };
  28233. if (settings.stats) {
  28234. entry.stats = stats;
  28235. }
  28236. entries.push(entry);
  28237. });
  28238. callSuccessCallback(callback, entries);
  28239. });
  28240. });
  28241. }
  28242. exports.readdir = readdir;
  28243. function callFailureCallback(callback, error) {
  28244. callback(error);
  28245. }
  28246. function callSuccessCallback(callback, result) {
  28247. callback(null, result);
  28248. }
  28249. });
  28250. var sync$2 = createCommonjsModule(function (module, exports) {
  28251. Object.defineProperty(exports, "__esModule", {
  28252. value: true
  28253. });
  28254. function read(directory, settings) {
  28255. if (!settings.stats && constants$4.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
  28256. return readdirWithFileTypes(directory, settings);
  28257. }
  28258. return readdir(directory, settings);
  28259. }
  28260. exports.read = read;
  28261. function readdirWithFileTypes(directory, settings) {
  28262. const dirents = settings.fs.readdirSync(directory, {
  28263. withFileTypes: true
  28264. });
  28265. return dirents.map(dirent => {
  28266. const entry = {
  28267. dirent,
  28268. name: dirent.name,
  28269. path: `${directory}${settings.pathSegmentSeparator}${dirent.name}`
  28270. };
  28271. if (entry.dirent.isSymbolicLink() && settings.followSymbolicLinks) {
  28272. try {
  28273. const stats = settings.fs.statSync(entry.path);
  28274. entry.dirent = utils$4.fs.createDirentFromStats(entry.name, stats);
  28275. } catch (error) {
  28276. if (settings.throwErrorOnBrokenSymbolicLink) {
  28277. throw error;
  28278. }
  28279. }
  28280. }
  28281. return entry;
  28282. });
  28283. }
  28284. exports.readdirWithFileTypes = readdirWithFileTypes;
  28285. function readdir(directory, settings) {
  28286. const names = settings.fs.readdirSync(directory);
  28287. return names.map(name => {
  28288. const entryPath = `${directory}${settings.pathSegmentSeparator}${name}`;
  28289. const stats = out.statSync(entryPath, settings.fsStatSettings);
  28290. const entry = {
  28291. name,
  28292. path: entryPath,
  28293. dirent: utils$4.fs.createDirentFromStats(name, stats)
  28294. };
  28295. if (settings.stats) {
  28296. entry.stats = stats;
  28297. }
  28298. return entry;
  28299. });
  28300. }
  28301. exports.readdir = readdir;
  28302. });
  28303. var fs_1$1 = createCommonjsModule(function (module, exports) {
  28304. Object.defineProperty(exports, "__esModule", {
  28305. value: true
  28306. });
  28307. exports.FILE_SYSTEM_ADAPTER = {
  28308. lstat: fs__default['default'].lstat,
  28309. stat: fs__default['default'].stat,
  28310. lstatSync: fs__default['default'].lstatSync,
  28311. statSync: fs__default['default'].statSync,
  28312. readdir: fs__default['default'].readdir,
  28313. readdirSync: fs__default['default'].readdirSync
  28314. };
  28315. function createFileSystemAdapter(fsMethods) {
  28316. if (fsMethods === undefined) {
  28317. return exports.FILE_SYSTEM_ADAPTER;
  28318. }
  28319. return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods);
  28320. }
  28321. exports.createFileSystemAdapter = createFileSystemAdapter;
  28322. });
  28323. var settings$1 = createCommonjsModule(function (module, exports) {
  28324. Object.defineProperty(exports, "__esModule", {
  28325. value: true
  28326. });
  28327. class Settings {
  28328. constructor(_options = {}) {
  28329. this._options = _options;
  28330. this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
  28331. this.fs = fs_1$1.createFileSystemAdapter(this._options.fs);
  28332. this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path__default['default'].sep);
  28333. this.stats = this._getValue(this._options.stats, false);
  28334. this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
  28335. this.fsStatSettings = new out.Settings({
  28336. followSymbolicLink: this.followSymbolicLinks,
  28337. fs: this.fs,
  28338. throwErrorOnBrokenSymbolicLink: this.throwErrorOnBrokenSymbolicLink
  28339. });
  28340. }
  28341. _getValue(option, value) {
  28342. return option === undefined ? value : option;
  28343. }
  28344. }
  28345. exports.default = Settings;
  28346. });
  28347. var out$1 = createCommonjsModule(function (module, exports) {
  28348. Object.defineProperty(exports, "__esModule", {
  28349. value: true
  28350. });
  28351. exports.Settings = settings$1.default;
  28352. function scandir(path, optionsOrSettingsOrCallback, callback) {
  28353. if (typeof optionsOrSettingsOrCallback === 'function') {
  28354. return async$2.read(path, getSettings(), optionsOrSettingsOrCallback);
  28355. }
  28356. async$2.read(path, getSettings(optionsOrSettingsOrCallback), callback);
  28357. }
  28358. exports.scandir = scandir;
  28359. function scandirSync(path, optionsOrSettings) {
  28360. const settings = getSettings(optionsOrSettings);
  28361. return sync$2.read(path, settings);
  28362. }
  28363. exports.scandirSync = scandirSync;
  28364. function getSettings(settingsOrOptions = {}) {
  28365. if (settingsOrOptions instanceof settings$1.default) {
  28366. return settingsOrOptions;
  28367. }
  28368. return new settings$1.default(settingsOrOptions);
  28369. }
  28370. });
  28371. function reusify(Constructor) {
  28372. var head = new Constructor();
  28373. var tail = head;
  28374. function get() {
  28375. var current = head;
  28376. if (current.next) {
  28377. head = current.next;
  28378. } else {
  28379. head = new Constructor();
  28380. tail = head;
  28381. }
  28382. current.next = null;
  28383. return current;
  28384. }
  28385. function release(obj) {
  28386. tail.next = obj;
  28387. tail = obj;
  28388. }
  28389. return {
  28390. get: get,
  28391. release: release
  28392. };
  28393. }
  28394. var reusify_1 = reusify;
  28395. function fastqueue(context, worker, concurrency) {
  28396. if (typeof context === 'function') {
  28397. concurrency = worker;
  28398. worker = context;
  28399. context = null;
  28400. }
  28401. var cache = reusify_1(Task);
  28402. var queueHead = null;
  28403. var queueTail = null;
  28404. var _running = 0;
  28405. var self = {
  28406. push: push,
  28407. drain: noop$1,
  28408. saturated: noop$1,
  28409. pause: pause,
  28410. paused: false,
  28411. concurrency: concurrency,
  28412. running: running,
  28413. resume: resume,
  28414. idle: idle,
  28415. length: length,
  28416. getQueue: getQueue,
  28417. unshift: unshift,
  28418. empty: noop$1,
  28419. kill: kill,
  28420. killAndDrain: killAndDrain
  28421. };
  28422. return self;
  28423. function running() {
  28424. return _running;
  28425. }
  28426. function pause() {
  28427. self.paused = true;
  28428. }
  28429. function length() {
  28430. var current = queueHead;
  28431. var counter = 0;
  28432. while (current) {
  28433. current = current.next;
  28434. counter++;
  28435. }
  28436. return counter;
  28437. }
  28438. function getQueue() {
  28439. var current = queueHead;
  28440. var tasks = [];
  28441. while (current) {
  28442. tasks.push(current.value);
  28443. current = current.next;
  28444. }
  28445. return tasks;
  28446. }
  28447. function resume() {
  28448. if (!self.paused) return;
  28449. self.paused = false;
  28450. for (var i = 0; i < self.concurrency; i++) {
  28451. _running++;
  28452. release();
  28453. }
  28454. }
  28455. function idle() {
  28456. return _running === 0 && self.length() === 0;
  28457. }
  28458. function push(value, done) {
  28459. var current = cache.get();
  28460. current.context = context;
  28461. current.release = release;
  28462. current.value = value;
  28463. current.callback = done || noop$1;
  28464. if (_running === self.concurrency || self.paused) {
  28465. if (queueTail) {
  28466. queueTail.next = current;
  28467. queueTail = current;
  28468. } else {
  28469. queueHead = current;
  28470. queueTail = current;
  28471. self.saturated();
  28472. }
  28473. } else {
  28474. _running++;
  28475. worker.call(context, current.value, current.worked);
  28476. }
  28477. }
  28478. function unshift(value, done) {
  28479. var current = cache.get();
  28480. current.context = context;
  28481. current.release = release;
  28482. current.value = value;
  28483. current.callback = done || noop$1;
  28484. if (_running === self.concurrency || self.paused) {
  28485. if (queueHead) {
  28486. current.next = queueHead;
  28487. queueHead = current;
  28488. } else {
  28489. queueHead = current;
  28490. queueTail = current;
  28491. self.saturated();
  28492. }
  28493. } else {
  28494. _running++;
  28495. worker.call(context, current.value, current.worked);
  28496. }
  28497. }
  28498. function release(holder) {
  28499. if (holder) {
  28500. cache.release(holder);
  28501. }
  28502. var next = queueHead;
  28503. if (next) {
  28504. if (!self.paused) {
  28505. if (queueTail === queueHead) {
  28506. queueTail = null;
  28507. }
  28508. queueHead = next.next;
  28509. next.next = null;
  28510. worker.call(context, next.value, next.worked);
  28511. if (queueTail === null) {
  28512. self.empty();
  28513. }
  28514. } else {
  28515. _running--;
  28516. }
  28517. } else if (--_running === 0) {
  28518. self.drain();
  28519. }
  28520. }
  28521. function kill() {
  28522. queueHead = null;
  28523. queueTail = null;
  28524. self.drain = noop$1;
  28525. }
  28526. function killAndDrain() {
  28527. queueHead = null;
  28528. queueTail = null;
  28529. self.drain();
  28530. self.drain = noop$1;
  28531. }
  28532. }
  28533. function noop$1() {}
  28534. function Task() {
  28535. this.value = null;
  28536. this.callback = noop$1;
  28537. this.next = null;
  28538. this.release = noop$1;
  28539. this.context = null;
  28540. var self = this;
  28541. this.worked = function worked(err, result) {
  28542. var callback = self.callback;
  28543. self.value = null;
  28544. self.callback = noop$1;
  28545. callback.call(self.context, err, result);
  28546. self.release(self);
  28547. };
  28548. }
  28549. var queue = fastqueue;
  28550. var common$2 = createCommonjsModule(function (module, exports) {
  28551. Object.defineProperty(exports, "__esModule", {
  28552. value: true
  28553. });
  28554. function isFatalError(settings, error) {
  28555. if (settings.errorFilter === null) {
  28556. return true;
  28557. }
  28558. return !settings.errorFilter(error);
  28559. }
  28560. exports.isFatalError = isFatalError;
  28561. function isAppliedFilter(filter, value) {
  28562. return filter === null || filter(value);
  28563. }
  28564. exports.isAppliedFilter = isAppliedFilter;
  28565. function replacePathSegmentSeparator(filepath, separator) {
  28566. return filepath.split(/[\\/]/).join(separator);
  28567. }
  28568. exports.replacePathSegmentSeparator = replacePathSegmentSeparator;
  28569. function joinPathSegments(a, b, separator) {
  28570. if (a === '') {
  28571. return b;
  28572. }
  28573. return a + separator + b;
  28574. }
  28575. exports.joinPathSegments = joinPathSegments;
  28576. });
  28577. var reader = createCommonjsModule(function (module, exports) {
  28578. Object.defineProperty(exports, "__esModule", {
  28579. value: true
  28580. });
  28581. class Reader {
  28582. constructor(_root, _settings) {
  28583. this._root = _root;
  28584. this._settings = _settings;
  28585. this._root = common$2.replacePathSegmentSeparator(_root, _settings.pathSegmentSeparator);
  28586. }
  28587. }
  28588. exports.default = Reader;
  28589. });
  28590. var async$3 = createCommonjsModule(function (module, exports) {
  28591. Object.defineProperty(exports, "__esModule", {
  28592. value: true
  28593. });
  28594. class AsyncReader extends reader.default {
  28595. constructor(_root, _settings) {
  28596. super(_root, _settings);
  28597. this._settings = _settings;
  28598. this._scandir = out$1.scandir;
  28599. this._emitter = new events__default['default'].EventEmitter();
  28600. this._queue = queue(this._worker.bind(this), this._settings.concurrency);
  28601. this._isFatalError = false;
  28602. this._isDestroyed = false;
  28603. this._queue.drain = () => {
  28604. if (!this._isFatalError) {
  28605. this._emitter.emit('end');
  28606. }
  28607. };
  28608. }
  28609. read() {
  28610. this._isFatalError = false;
  28611. this._isDestroyed = false;
  28612. setImmediate(() => {
  28613. this._pushToQueue(this._root, this._settings.basePath);
  28614. });
  28615. return this._emitter;
  28616. }
  28617. destroy() {
  28618. if (this._isDestroyed) {
  28619. throw new Error('The reader is already destroyed');
  28620. }
  28621. this._isDestroyed = true;
  28622. this._queue.killAndDrain();
  28623. }
  28624. onEntry(callback) {
  28625. this._emitter.on('entry', callback);
  28626. }
  28627. onError(callback) {
  28628. this._emitter.once('error', callback);
  28629. }
  28630. onEnd(callback) {
  28631. this._emitter.once('end', callback);
  28632. }
  28633. _pushToQueue(directory, base) {
  28634. const queueItem = {
  28635. directory,
  28636. base
  28637. };
  28638. this._queue.push(queueItem, error => {
  28639. if (error !== null) {
  28640. this._handleError(error);
  28641. }
  28642. });
  28643. }
  28644. _worker(item, done) {
  28645. this._scandir(item.directory, this._settings.fsScandirSettings, (error, entries) => {
  28646. if (error !== null) {
  28647. return done(error, undefined);
  28648. }
  28649. for (const entry of entries) {
  28650. this._handleEntry(entry, item.base);
  28651. }
  28652. done(null, undefined);
  28653. });
  28654. }
  28655. _handleError(error) {
  28656. if (!common$2.isFatalError(this._settings, error)) {
  28657. return;
  28658. }
  28659. this._isFatalError = true;
  28660. this._isDestroyed = true;
  28661. this._emitter.emit('error', error);
  28662. }
  28663. _handleEntry(entry, base) {
  28664. if (this._isDestroyed || this._isFatalError) {
  28665. return;
  28666. }
  28667. const fullpath = entry.path;
  28668. if (base !== undefined) {
  28669. entry.path = common$2.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
  28670. }
  28671. if (common$2.isAppliedFilter(this._settings.entryFilter, entry)) {
  28672. this._emitEntry(entry);
  28673. }
  28674. if (entry.dirent.isDirectory() && common$2.isAppliedFilter(this._settings.deepFilter, entry)) {
  28675. this._pushToQueue(fullpath, entry.path);
  28676. }
  28677. }
  28678. _emitEntry(entry) {
  28679. this._emitter.emit('entry', entry);
  28680. }
  28681. }
  28682. exports.default = AsyncReader;
  28683. });
  28684. var async$4 = createCommonjsModule(function (module, exports) {
  28685. Object.defineProperty(exports, "__esModule", {
  28686. value: true
  28687. });
  28688. class AsyncProvider {
  28689. constructor(_root, _settings) {
  28690. this._root = _root;
  28691. this._settings = _settings;
  28692. this._reader = new async$3.default(this._root, this._settings);
  28693. this._storage = new Set();
  28694. }
  28695. read(callback) {
  28696. this._reader.onError(error => {
  28697. callFailureCallback(callback, error);
  28698. });
  28699. this._reader.onEntry(entry => {
  28700. this._storage.add(entry);
  28701. });
  28702. this._reader.onEnd(() => {
  28703. callSuccessCallback(callback, [...this._storage]);
  28704. });
  28705. this._reader.read();
  28706. }
  28707. }
  28708. exports.default = AsyncProvider;
  28709. function callFailureCallback(callback, error) {
  28710. callback(error);
  28711. }
  28712. function callSuccessCallback(callback, entries) {
  28713. callback(null, entries);
  28714. }
  28715. });
  28716. var stream$2 = createCommonjsModule(function (module, exports) {
  28717. Object.defineProperty(exports, "__esModule", {
  28718. value: true
  28719. });
  28720. class StreamProvider {
  28721. constructor(_root, _settings) {
  28722. this._root = _root;
  28723. this._settings = _settings;
  28724. this._reader = new async$3.default(this._root, this._settings);
  28725. this._stream = new stream__default['default'].Readable({
  28726. objectMode: true,
  28727. read: () => {},
  28728. destroy: this._reader.destroy.bind(this._reader)
  28729. });
  28730. }
  28731. read() {
  28732. this._reader.onError(error => {
  28733. this._stream.emit('error', error);
  28734. });
  28735. this._reader.onEntry(entry => {
  28736. this._stream.push(entry);
  28737. });
  28738. this._reader.onEnd(() => {
  28739. this._stream.push(null);
  28740. });
  28741. this._reader.read();
  28742. return this._stream;
  28743. }
  28744. }
  28745. exports.default = StreamProvider;
  28746. });
  28747. var sync$3 = createCommonjsModule(function (module, exports) {
  28748. Object.defineProperty(exports, "__esModule", {
  28749. value: true
  28750. });
  28751. class SyncReader extends reader.default {
  28752. constructor() {
  28753. super(...arguments);
  28754. this._scandir = out$1.scandirSync;
  28755. this._storage = new Set();
  28756. this._queue = new Set();
  28757. }
  28758. read() {
  28759. this._pushToQueue(this._root, this._settings.basePath);
  28760. this._handleQueue();
  28761. return [...this._storage];
  28762. }
  28763. _pushToQueue(directory, base) {
  28764. this._queue.add({
  28765. directory,
  28766. base
  28767. });
  28768. }
  28769. _handleQueue() {
  28770. for (const item of this._queue.values()) {
  28771. this._handleDirectory(item.directory, item.base);
  28772. }
  28773. }
  28774. _handleDirectory(directory, base) {
  28775. try {
  28776. const entries = this._scandir(directory, this._settings.fsScandirSettings);
  28777. for (const entry of entries) {
  28778. this._handleEntry(entry, base);
  28779. }
  28780. } catch (error) {
  28781. this._handleError(error);
  28782. }
  28783. }
  28784. _handleError(error) {
  28785. if (!common$2.isFatalError(this._settings, error)) {
  28786. return;
  28787. }
  28788. throw error;
  28789. }
  28790. _handleEntry(entry, base) {
  28791. const fullpath = entry.path;
  28792. if (base !== undefined) {
  28793. entry.path = common$2.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
  28794. }
  28795. if (common$2.isAppliedFilter(this._settings.entryFilter, entry)) {
  28796. this._pushToStorage(entry);
  28797. }
  28798. if (entry.dirent.isDirectory() && common$2.isAppliedFilter(this._settings.deepFilter, entry)) {
  28799. this._pushToQueue(fullpath, entry.path);
  28800. }
  28801. }
  28802. _pushToStorage(entry) {
  28803. this._storage.add(entry);
  28804. }
  28805. }
  28806. exports.default = SyncReader;
  28807. });
  28808. var sync$4 = createCommonjsModule(function (module, exports) {
  28809. Object.defineProperty(exports, "__esModule", {
  28810. value: true
  28811. });
  28812. class SyncProvider {
  28813. constructor(_root, _settings) {
  28814. this._root = _root;
  28815. this._settings = _settings;
  28816. this._reader = new sync$3.default(this._root, this._settings);
  28817. }
  28818. read() {
  28819. return this._reader.read();
  28820. }
  28821. }
  28822. exports.default = SyncProvider;
  28823. });
  28824. var settings$2 = createCommonjsModule(function (module, exports) {
  28825. Object.defineProperty(exports, "__esModule", {
  28826. value: true
  28827. });
  28828. class Settings {
  28829. constructor(_options = {}) {
  28830. this._options = _options;
  28831. this.basePath = this._getValue(this._options.basePath, undefined);
  28832. this.concurrency = this._getValue(this._options.concurrency, Infinity);
  28833. this.deepFilter = this._getValue(this._options.deepFilter, null);
  28834. this.entryFilter = this._getValue(this._options.entryFilter, null);
  28835. this.errorFilter = this._getValue(this._options.errorFilter, null);
  28836. this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path__default['default'].sep);
  28837. this.fsScandirSettings = new out$1.Settings({
  28838. followSymbolicLinks: this._options.followSymbolicLinks,
  28839. fs: this._options.fs,
  28840. pathSegmentSeparator: this._options.pathSegmentSeparator,
  28841. stats: this._options.stats,
  28842. throwErrorOnBrokenSymbolicLink: this._options.throwErrorOnBrokenSymbolicLink
  28843. });
  28844. }
  28845. _getValue(option, value) {
  28846. return option === undefined ? value : option;
  28847. }
  28848. }
  28849. exports.default = Settings;
  28850. });
  28851. var out$2 = createCommonjsModule(function (module, exports) {
  28852. Object.defineProperty(exports, "__esModule", {
  28853. value: true
  28854. });
  28855. exports.Settings = settings$2.default;
  28856. function walk(directory, optionsOrSettingsOrCallback, callback) {
  28857. if (typeof optionsOrSettingsOrCallback === 'function') {
  28858. return new async$4.default(directory, getSettings()).read(optionsOrSettingsOrCallback);
  28859. }
  28860. new async$4.default(directory, getSettings(optionsOrSettingsOrCallback)).read(callback);
  28861. }
  28862. exports.walk = walk;
  28863. function walkSync(directory, optionsOrSettings) {
  28864. const settings = getSettings(optionsOrSettings);
  28865. const provider = new sync$4.default(directory, settings);
  28866. return provider.read();
  28867. }
  28868. exports.walkSync = walkSync;
  28869. function walkStream(directory, optionsOrSettings) {
  28870. const settings = getSettings(optionsOrSettings);
  28871. const provider = new stream$2.default(directory, settings);
  28872. return provider.read();
  28873. }
  28874. exports.walkStream = walkStream;
  28875. function getSettings(settingsOrOptions = {}) {
  28876. if (settingsOrOptions instanceof settings$2.default) {
  28877. return settingsOrOptions;
  28878. }
  28879. return new settings$2.default(settingsOrOptions);
  28880. }
  28881. });
  28882. var reader$1 = createCommonjsModule(function (module, exports) {
  28883. Object.defineProperty(exports, "__esModule", {
  28884. value: true
  28885. });
  28886. class Reader {
  28887. constructor(_settings) {
  28888. this._settings = _settings;
  28889. this._fsStatSettings = new out.Settings({
  28890. followSymbolicLink: this._settings.followSymbolicLinks,
  28891. fs: this._settings.fs,
  28892. throwErrorOnBrokenSymbolicLink: this._settings.followSymbolicLinks
  28893. });
  28894. }
  28895. _getFullEntryPath(filepath) {
  28896. return path__default['default'].resolve(this._settings.cwd, filepath);
  28897. }
  28898. _makeEntry(stats, pattern) {
  28899. const entry = {
  28900. name: pattern,
  28901. path: pattern,
  28902. dirent: utils$3.fs.createDirentFromStats(pattern, stats)
  28903. };
  28904. if (this._settings.stats) {
  28905. entry.stats = stats;
  28906. }
  28907. return entry;
  28908. }
  28909. _isFatalError(error) {
  28910. return !utils$3.errno.isEnoentCodeError(error) && !this._settings.suppressErrors;
  28911. }
  28912. }
  28913. exports.default = Reader;
  28914. });
  28915. var stream$3 = createCommonjsModule(function (module, exports) {
  28916. Object.defineProperty(exports, "__esModule", {
  28917. value: true
  28918. });
  28919. class ReaderStream extends reader$1.default {
  28920. constructor() {
  28921. super(...arguments);
  28922. this._walkStream = out$2.walkStream;
  28923. this._stat = out.stat;
  28924. }
  28925. dynamic(root, options) {
  28926. return this._walkStream(root, options);
  28927. }
  28928. static(patterns, options) {
  28929. const filepaths = patterns.map(this._getFullEntryPath, this);
  28930. const stream = new stream__default['default'].PassThrough({
  28931. objectMode: true
  28932. });
  28933. stream._write = (index, _enc, done) => {
  28934. return this._getEntry(filepaths[index], patterns[index], options).then(entry => {
  28935. if (entry !== null && options.entryFilter(entry)) {
  28936. stream.push(entry);
  28937. }
  28938. if (index === filepaths.length - 1) {
  28939. stream.end();
  28940. }
  28941. done();
  28942. }).catch(done);
  28943. };
  28944. for (let i = 0; i < filepaths.length; i++) {
  28945. stream.write(i);
  28946. }
  28947. return stream;
  28948. }
  28949. _getEntry(filepath, pattern, options) {
  28950. return this._getStat(filepath).then(stats => this._makeEntry(stats, pattern)).catch(error => {
  28951. if (options.errorFilter(error)) {
  28952. return null;
  28953. }
  28954. throw error;
  28955. });
  28956. }
  28957. _getStat(filepath) {
  28958. return new Promise((resolve, reject) => {
  28959. this._stat(filepath, this._fsStatSettings, (error, stats) => {
  28960. return error === null ? resolve(stats) : reject(error);
  28961. });
  28962. });
  28963. }
  28964. }
  28965. exports.default = ReaderStream;
  28966. });
  28967. var matcher = createCommonjsModule(function (module, exports) {
  28968. Object.defineProperty(exports, "__esModule", {
  28969. value: true
  28970. });
  28971. class Matcher {
  28972. constructor(_patterns, _settings, _micromatchOptions) {
  28973. this._patterns = _patterns;
  28974. this._settings = _settings;
  28975. this._micromatchOptions = _micromatchOptions;
  28976. this._storage = [];
  28977. this._fillStorage();
  28978. }
  28979. _fillStorage() {
  28980. /**
  28981. * The original pattern may include `{,*,**,a/*}`, which will lead to problems with matching (unresolved level).
  28982. * So, before expand patterns with brace expansion into separated patterns.
  28983. */
  28984. const patterns = utils$3.pattern.expandPatternsWithBraceExpansion(this._patterns);
  28985. for (const pattern of patterns) {
  28986. const segments = this._getPatternSegments(pattern);
  28987. const sections = this._splitSegmentsIntoSections(segments);
  28988. this._storage.push({
  28989. complete: sections.length <= 1,
  28990. pattern,
  28991. segments,
  28992. sections
  28993. });
  28994. }
  28995. }
  28996. _getPatternSegments(pattern) {
  28997. const parts = utils$3.pattern.getPatternParts(pattern, this._micromatchOptions);
  28998. return parts.map(part => {
  28999. const dynamic = utils$3.pattern.isDynamicPattern(part, this._settings);
  29000. if (!dynamic) {
  29001. return {
  29002. dynamic: false,
  29003. pattern: part
  29004. };
  29005. }
  29006. return {
  29007. dynamic: true,
  29008. pattern: part,
  29009. patternRe: utils$3.pattern.makeRe(part, this._micromatchOptions)
  29010. };
  29011. });
  29012. }
  29013. _splitSegmentsIntoSections(segments) {
  29014. return utils$3.array.splitWhen(segments, segment => segment.dynamic && utils$3.pattern.hasGlobStar(segment.pattern));
  29015. }
  29016. }
  29017. exports.default = Matcher;
  29018. });
  29019. var partial = createCommonjsModule(function (module, exports) {
  29020. Object.defineProperty(exports, "__esModule", {
  29021. value: true
  29022. });
  29023. class PartialMatcher extends matcher.default {
  29024. match(filepath) {
  29025. const parts = filepath.split('/');
  29026. const levels = parts.length;
  29027. const patterns = this._storage.filter(info => !info.complete || info.segments.length > levels);
  29028. for (const pattern of patterns) {
  29029. const section = pattern.sections[0];
  29030. /**
  29031. * In this case, the pattern has a globstar and we must read all directories unconditionally,
  29032. * but only if the level has reached the end of the first group.
  29033. *
  29034. * fixtures/{a,b}/**
  29035. * ^ true/false ^ always true
  29036. */
  29037. if (!pattern.complete && levels > section.length) {
  29038. return true;
  29039. }
  29040. const match = parts.every((part, index) => {
  29041. const segment = pattern.segments[index];
  29042. if (segment.dynamic && segment.patternRe.test(part)) {
  29043. return true;
  29044. }
  29045. if (!segment.dynamic && segment.pattern === part) {
  29046. return true;
  29047. }
  29048. return false;
  29049. });
  29050. if (match) {
  29051. return true;
  29052. }
  29053. }
  29054. return false;
  29055. }
  29056. }
  29057. exports.default = PartialMatcher;
  29058. });
  29059. var deep = createCommonjsModule(function (module, exports) {
  29060. Object.defineProperty(exports, "__esModule", {
  29061. value: true
  29062. });
  29063. class DeepFilter {
  29064. constructor(_settings, _micromatchOptions) {
  29065. this._settings = _settings;
  29066. this._micromatchOptions = _micromatchOptions;
  29067. }
  29068. getFilter(basePath, positive, negative) {
  29069. const matcher = this._getMatcher(positive);
  29070. const negativeRe = this._getNegativePatternsRe(negative);
  29071. return entry => this._filter(basePath, entry, matcher, negativeRe);
  29072. }
  29073. _getMatcher(patterns) {
  29074. return new partial.default(patterns, this._settings, this._micromatchOptions);
  29075. }
  29076. _getNegativePatternsRe(patterns) {
  29077. const affectDepthOfReadingPatterns = patterns.filter(utils$3.pattern.isAffectDepthOfReadingPattern);
  29078. return utils$3.pattern.convertPatternsToRe(affectDepthOfReadingPatterns, this._micromatchOptions);
  29079. }
  29080. _filter(basePath, entry, matcher, negativeRe) {
  29081. if (this._isSkippedByDeep(basePath, entry.path)) {
  29082. return false;
  29083. }
  29084. if (this._isSkippedSymbolicLink(entry)) {
  29085. return false;
  29086. }
  29087. const filepath = utils$3.path.removeLeadingDotSegment(entry.path);
  29088. if (this._isSkippedByPositivePatterns(filepath, matcher)) {
  29089. return false;
  29090. }
  29091. return this._isSkippedByNegativePatterns(filepath, negativeRe);
  29092. }
  29093. _isSkippedByDeep(basePath, entryPath) {
  29094. /**
  29095. * Avoid unnecessary depth calculations when it doesn't matter.
  29096. */
  29097. if (this._settings.deep === Infinity) {
  29098. return false;
  29099. }
  29100. return this._getEntryLevel(basePath, entryPath) >= this._settings.deep;
  29101. }
  29102. _getEntryLevel(basePath, entryPath) {
  29103. const entryPathDepth = entryPath.split('/').length;
  29104. if (basePath === '') {
  29105. return entryPathDepth;
  29106. }
  29107. const basePathDepth = basePath.split('/').length;
  29108. return entryPathDepth - basePathDepth;
  29109. }
  29110. _isSkippedSymbolicLink(entry) {
  29111. return !this._settings.followSymbolicLinks && entry.dirent.isSymbolicLink();
  29112. }
  29113. _isSkippedByPositivePatterns(entryPath, matcher) {
  29114. return !this._settings.baseNameMatch && !matcher.match(entryPath);
  29115. }
  29116. _isSkippedByNegativePatterns(entryPath, patternsRe) {
  29117. return !utils$3.pattern.matchAny(entryPath, patternsRe);
  29118. }
  29119. }
  29120. exports.default = DeepFilter;
  29121. });
  29122. var entry = createCommonjsModule(function (module, exports) {
  29123. Object.defineProperty(exports, "__esModule", {
  29124. value: true
  29125. });
  29126. class EntryFilter {
  29127. constructor(_settings, _micromatchOptions) {
  29128. this._settings = _settings;
  29129. this._micromatchOptions = _micromatchOptions;
  29130. this.index = new Map();
  29131. }
  29132. getFilter(positive, negative) {
  29133. const positiveRe = utils$3.pattern.convertPatternsToRe(positive, this._micromatchOptions);
  29134. const negativeRe = utils$3.pattern.convertPatternsToRe(negative, this._micromatchOptions);
  29135. return entry => this._filter(entry, positiveRe, negativeRe);
  29136. }
  29137. _filter(entry, positiveRe, negativeRe) {
  29138. if (this._settings.unique && this._isDuplicateEntry(entry)) {
  29139. return false;
  29140. }
  29141. if (this._onlyFileFilter(entry) || this._onlyDirectoryFilter(entry)) {
  29142. return false;
  29143. }
  29144. if (this._isSkippedByAbsoluteNegativePatterns(entry.path, negativeRe)) {
  29145. return false;
  29146. }
  29147. const filepath = this._settings.baseNameMatch ? entry.name : entry.path;
  29148. const isMatched = this._isMatchToPatterns(filepath, positiveRe) && !this._isMatchToPatterns(entry.path, negativeRe);
  29149. if (this._settings.unique && isMatched) {
  29150. this._createIndexRecord(entry);
  29151. }
  29152. return isMatched;
  29153. }
  29154. _isDuplicateEntry(entry) {
  29155. return this.index.has(entry.path);
  29156. }
  29157. _createIndexRecord(entry) {
  29158. this.index.set(entry.path, undefined);
  29159. }
  29160. _onlyFileFilter(entry) {
  29161. return this._settings.onlyFiles && !entry.dirent.isFile();
  29162. }
  29163. _onlyDirectoryFilter(entry) {
  29164. return this._settings.onlyDirectories && !entry.dirent.isDirectory();
  29165. }
  29166. _isSkippedByAbsoluteNegativePatterns(entryPath, patternsRe) {
  29167. if (!this._settings.absolute) {
  29168. return false;
  29169. }
  29170. const fullpath = utils$3.path.makeAbsolute(this._settings.cwd, entryPath);
  29171. return utils$3.pattern.matchAny(fullpath, patternsRe);
  29172. }
  29173. _isMatchToPatterns(entryPath, patternsRe) {
  29174. const filepath = utils$3.path.removeLeadingDotSegment(entryPath);
  29175. return utils$3.pattern.matchAny(filepath, patternsRe);
  29176. }
  29177. }
  29178. exports.default = EntryFilter;
  29179. });
  29180. var error = createCommonjsModule(function (module, exports) {
  29181. Object.defineProperty(exports, "__esModule", {
  29182. value: true
  29183. });
  29184. class ErrorFilter {
  29185. constructor(_settings) {
  29186. this._settings = _settings;
  29187. }
  29188. getFilter() {
  29189. return error => this._isNonFatalError(error);
  29190. }
  29191. _isNonFatalError(error) {
  29192. return utils$3.errno.isEnoentCodeError(error) || this._settings.suppressErrors;
  29193. }
  29194. }
  29195. exports.default = ErrorFilter;
  29196. });
  29197. var entry$1 = createCommonjsModule(function (module, exports) {
  29198. Object.defineProperty(exports, "__esModule", {
  29199. value: true
  29200. });
  29201. class EntryTransformer {
  29202. constructor(_settings) {
  29203. this._settings = _settings;
  29204. }
  29205. getTransformer() {
  29206. return entry => this._transform(entry);
  29207. }
  29208. _transform(entry) {
  29209. let filepath = entry.path;
  29210. if (this._settings.absolute) {
  29211. filepath = utils$3.path.makeAbsolute(this._settings.cwd, filepath);
  29212. filepath = utils$3.path.unixify(filepath);
  29213. }
  29214. if (this._settings.markDirectories && entry.dirent.isDirectory()) {
  29215. filepath += '/';
  29216. }
  29217. if (!this._settings.objectMode) {
  29218. return filepath;
  29219. }
  29220. return Object.assign(Object.assign({}, entry), {
  29221. path: filepath
  29222. });
  29223. }
  29224. }
  29225. exports.default = EntryTransformer;
  29226. });
  29227. var provider = createCommonjsModule(function (module, exports) {
  29228. Object.defineProperty(exports, "__esModule", {
  29229. value: true
  29230. });
  29231. class Provider {
  29232. constructor(_settings) {
  29233. this._settings = _settings;
  29234. this.errorFilter = new error.default(this._settings);
  29235. this.entryFilter = new entry.default(this._settings, this._getMicromatchOptions());
  29236. this.deepFilter = new deep.default(this._settings, this._getMicromatchOptions());
  29237. this.entryTransformer = new entry$1.default(this._settings);
  29238. }
  29239. _getRootDirectory(task) {
  29240. return path__default['default'].resolve(this._settings.cwd, task.base);
  29241. }
  29242. _getReaderOptions(task) {
  29243. const basePath = task.base === '.' ? '' : task.base;
  29244. return {
  29245. basePath,
  29246. pathSegmentSeparator: '/',
  29247. concurrency: this._settings.concurrency,
  29248. deepFilter: this.deepFilter.getFilter(basePath, task.positive, task.negative),
  29249. entryFilter: this.entryFilter.getFilter(task.positive, task.negative),
  29250. errorFilter: this.errorFilter.getFilter(),
  29251. followSymbolicLinks: this._settings.followSymbolicLinks,
  29252. fs: this._settings.fs,
  29253. stats: this._settings.stats,
  29254. throwErrorOnBrokenSymbolicLink: this._settings.throwErrorOnBrokenSymbolicLink,
  29255. transform: this.entryTransformer.getTransformer()
  29256. };
  29257. }
  29258. _getMicromatchOptions() {
  29259. return {
  29260. dot: this._settings.dot,
  29261. matchBase: this._settings.baseNameMatch,
  29262. nobrace: !this._settings.braceExpansion,
  29263. nocase: !this._settings.caseSensitiveMatch,
  29264. noext: !this._settings.extglob,
  29265. noglobstar: !this._settings.globstar,
  29266. posix: true,
  29267. strictSlashes: false
  29268. };
  29269. }
  29270. }
  29271. exports.default = Provider;
  29272. });
  29273. var async$5 = createCommonjsModule(function (module, exports) {
  29274. Object.defineProperty(exports, "__esModule", {
  29275. value: true
  29276. });
  29277. class ProviderAsync extends provider.default {
  29278. constructor() {
  29279. super(...arguments);
  29280. this._reader = new stream$3.default(this._settings);
  29281. }
  29282. read(task) {
  29283. const root = this._getRootDirectory(task);
  29284. const options = this._getReaderOptions(task);
  29285. const entries = [];
  29286. return new Promise((resolve, reject) => {
  29287. const stream = this.api(root, task, options);
  29288. stream.once('error', reject);
  29289. stream.on('data', entry => entries.push(options.transform(entry)));
  29290. stream.once('end', () => resolve(entries));
  29291. });
  29292. }
  29293. api(root, task, options) {
  29294. if (task.dynamic) {
  29295. return this._reader.dynamic(root, options);
  29296. }
  29297. return this._reader.static(task.patterns, options);
  29298. }
  29299. }
  29300. exports.default = ProviderAsync;
  29301. });
  29302. var stream$4 = createCommonjsModule(function (module, exports) {
  29303. Object.defineProperty(exports, "__esModule", {
  29304. value: true
  29305. });
  29306. class ProviderStream extends provider.default {
  29307. constructor() {
  29308. super(...arguments);
  29309. this._reader = new stream$3.default(this._settings);
  29310. }
  29311. read(task) {
  29312. const root = this._getRootDirectory(task);
  29313. const options = this._getReaderOptions(task);
  29314. const source = this.api(root, task, options);
  29315. const destination = new stream__default['default'].Readable({
  29316. objectMode: true,
  29317. read: () => {}
  29318. });
  29319. source.once('error', error => destination.emit('error', error)).on('data', entry => destination.emit('data', options.transform(entry))).once('end', () => destination.emit('end'));
  29320. destination.once('close', () => source.destroy());
  29321. return destination;
  29322. }
  29323. api(root, task, options) {
  29324. if (task.dynamic) {
  29325. return this._reader.dynamic(root, options);
  29326. }
  29327. return this._reader.static(task.patterns, options);
  29328. }
  29329. }
  29330. exports.default = ProviderStream;
  29331. });
  29332. var sync$5 = createCommonjsModule(function (module, exports) {
  29333. Object.defineProperty(exports, "__esModule", {
  29334. value: true
  29335. });
  29336. class ReaderSync extends reader$1.default {
  29337. constructor() {
  29338. super(...arguments);
  29339. this._walkSync = out$2.walkSync;
  29340. this._statSync = out.statSync;
  29341. }
  29342. dynamic(root, options) {
  29343. return this._walkSync(root, options);
  29344. }
  29345. static(patterns, options) {
  29346. const entries = [];
  29347. for (const pattern of patterns) {
  29348. const filepath = this._getFullEntryPath(pattern);
  29349. const entry = this._getEntry(filepath, pattern, options);
  29350. if (entry === null || !options.entryFilter(entry)) {
  29351. continue;
  29352. }
  29353. entries.push(entry);
  29354. }
  29355. return entries;
  29356. }
  29357. _getEntry(filepath, pattern, options) {
  29358. try {
  29359. const stats = this._getStat(filepath);
  29360. return this._makeEntry(stats, pattern);
  29361. } catch (error) {
  29362. if (options.errorFilter(error)) {
  29363. return null;
  29364. }
  29365. throw error;
  29366. }
  29367. }
  29368. _getStat(filepath) {
  29369. return this._statSync(filepath, this._fsStatSettings);
  29370. }
  29371. }
  29372. exports.default = ReaderSync;
  29373. });
  29374. var sync$6 = createCommonjsModule(function (module, exports) {
  29375. Object.defineProperty(exports, "__esModule", {
  29376. value: true
  29377. });
  29378. class ProviderSync extends provider.default {
  29379. constructor() {
  29380. super(...arguments);
  29381. this._reader = new sync$5.default(this._settings);
  29382. }
  29383. read(task) {
  29384. const root = this._getRootDirectory(task);
  29385. const options = this._getReaderOptions(task);
  29386. const entries = this.api(root, task, options);
  29387. return entries.map(options.transform);
  29388. }
  29389. api(root, task, options) {
  29390. if (task.dynamic) {
  29391. return this._reader.dynamic(root, options);
  29392. }
  29393. return this._reader.static(task.patterns, options);
  29394. }
  29395. }
  29396. exports.default = ProviderSync;
  29397. });
  29398. var settings$3 = createCommonjsModule(function (module, exports) {
  29399. Object.defineProperty(exports, "__esModule", {
  29400. value: true
  29401. });
  29402. exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
  29403. const CPU_COUNT = os__default['default'].cpus().length;
  29404. exports.DEFAULT_FILE_SYSTEM_ADAPTER = {
  29405. lstat: fs__default['default'].lstat,
  29406. lstatSync: fs__default['default'].lstatSync,
  29407. stat: fs__default['default'].stat,
  29408. statSync: fs__default['default'].statSync,
  29409. readdir: fs__default['default'].readdir,
  29410. readdirSync: fs__default['default'].readdirSync
  29411. };
  29412. class Settings {
  29413. constructor(_options = {}) {
  29414. this._options = _options;
  29415. this.absolute = this._getValue(this._options.absolute, false);
  29416. this.baseNameMatch = this._getValue(this._options.baseNameMatch, false);
  29417. this.braceExpansion = this._getValue(this._options.braceExpansion, true);
  29418. this.caseSensitiveMatch = this._getValue(this._options.caseSensitiveMatch, true);
  29419. this.concurrency = this._getValue(this._options.concurrency, CPU_COUNT);
  29420. this.cwd = this._getValue(this._options.cwd, process.cwd());
  29421. this.deep = this._getValue(this._options.deep, Infinity);
  29422. this.dot = this._getValue(this._options.dot, false);
  29423. this.extglob = this._getValue(this._options.extglob, true);
  29424. this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, true);
  29425. this.fs = this._getFileSystemMethods(this._options.fs);
  29426. this.globstar = this._getValue(this._options.globstar, true);
  29427. this.ignore = this._getValue(this._options.ignore, []);
  29428. this.markDirectories = this._getValue(this._options.markDirectories, false);
  29429. this.objectMode = this._getValue(this._options.objectMode, false);
  29430. this.onlyDirectories = this._getValue(this._options.onlyDirectories, false);
  29431. this.onlyFiles = this._getValue(this._options.onlyFiles, true);
  29432. this.stats = this._getValue(this._options.stats, false);
  29433. this.suppressErrors = this._getValue(this._options.suppressErrors, false);
  29434. this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, false);
  29435. this.unique = this._getValue(this._options.unique, true);
  29436. if (this.onlyDirectories) {
  29437. this.onlyFiles = false;
  29438. }
  29439. if (this.stats) {
  29440. this.objectMode = true;
  29441. }
  29442. }
  29443. _getValue(option, value) {
  29444. return option === undefined ? value : option;
  29445. }
  29446. _getFileSystemMethods(methods = {}) {
  29447. return Object.assign(Object.assign({}, exports.DEFAULT_FILE_SYSTEM_ADAPTER), methods);
  29448. }
  29449. }
  29450. exports.default = Settings;
  29451. });
  29452. async function FastGlob(source, options) {
  29453. assertPatternsInput(source);
  29454. const works = getWorks(source, async$5.default, options);
  29455. const result = await Promise.all(works);
  29456. return utils$3.array.flatten(result);
  29457. } // https://github.com/typescript-eslint/typescript-eslint/issues/60
  29458. // eslint-disable-next-line no-redeclare
  29459. (function (FastGlob) {
  29460. function sync(source, options) {
  29461. assertPatternsInput(source);
  29462. const works = getWorks(source, sync$6.default, options);
  29463. return utils$3.array.flatten(works);
  29464. }
  29465. FastGlob.sync = sync;
  29466. function stream(source, options) {
  29467. assertPatternsInput(source);
  29468. const works = getWorks(source, stream$4.default, options);
  29469. /**
  29470. * The stream returned by the provider cannot work with an asynchronous iterator.
  29471. * To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams.
  29472. * This affects performance (+25%). I don't see best solution right now.
  29473. */
  29474. return utils$3.stream.merge(works);
  29475. }
  29476. FastGlob.stream = stream;
  29477. function generateTasks(source, options) {
  29478. assertPatternsInput(source);
  29479. const patterns = [].concat(source);
  29480. const settings = new settings$3.default(options);
  29481. return tasks.generate(patterns, settings);
  29482. }
  29483. FastGlob.generateTasks = generateTasks;
  29484. function isDynamicPattern(source, options) {
  29485. assertPatternsInput(source);
  29486. const settings = new settings$3.default(options);
  29487. return utils$3.pattern.isDynamicPattern(source, settings);
  29488. }
  29489. FastGlob.isDynamicPattern = isDynamicPattern;
  29490. function escapePath(source) {
  29491. assertPatternsInput(source);
  29492. return utils$3.path.escape(source);
  29493. }
  29494. FastGlob.escapePath = escapePath;
  29495. })(FastGlob || (FastGlob = {}));
  29496. function getWorks(source, _Provider, options) {
  29497. const patterns = [].concat(source);
  29498. const settings = new settings$3.default(options);
  29499. const tasks$1 = tasks.generate(patterns, settings);
  29500. const provider = new _Provider(settings);
  29501. return tasks$1.map(provider.read, provider);
  29502. }
  29503. function assertPatternsInput(input) {
  29504. const source = [].concat(input);
  29505. const isValidSource = source.every(item => utils$3.string.isString(item) && !utils$3.string.isEmpty(item));
  29506. if (!isValidSource) {
  29507. throw new TypeError('Patterns must be a string (non empty) or an array of strings');
  29508. }
  29509. }
  29510. var out$3 = FastGlob;
  29511. const {
  29512. promisify
  29513. } = util__default['default'];
  29514. async function isType(fsStatType, statsMethodName, filePath) {
  29515. if (typeof filePath !== 'string') {
  29516. throw new TypeError(`Expected a string, got ${typeof filePath}`);
  29517. }
  29518. try {
  29519. const stats = await promisify(fs__default['default'][fsStatType])(filePath);
  29520. return stats[statsMethodName]();
  29521. } catch (error) {
  29522. if (error.code === 'ENOENT') {
  29523. return false;
  29524. }
  29525. throw error;
  29526. }
  29527. }
  29528. function isTypeSync(fsStatType, statsMethodName, filePath) {
  29529. if (typeof filePath !== 'string') {
  29530. throw new TypeError(`Expected a string, got ${typeof filePath}`);
  29531. }
  29532. try {
  29533. return fs__default['default'][fsStatType](filePath)[statsMethodName]();
  29534. } catch (error) {
  29535. if (error.code === 'ENOENT') {
  29536. return false;
  29537. }
  29538. throw error;
  29539. }
  29540. }
  29541. var isFile = isType.bind(null, 'stat', 'isFile');
  29542. var isDirectory = isType.bind(null, 'stat', 'isDirectory');
  29543. var isSymlink = isType.bind(null, 'lstat', 'isSymbolicLink');
  29544. var isFileSync = isTypeSync.bind(null, 'statSync', 'isFile');
  29545. var isDirectorySync = isTypeSync.bind(null, 'statSync', 'isDirectory');
  29546. var isSymlinkSync = isTypeSync.bind(null, 'lstatSync', 'isSymbolicLink');
  29547. var pathType = {
  29548. isFile: isFile,
  29549. isDirectory: isDirectory,
  29550. isSymlink: isSymlink,
  29551. isFileSync: isFileSync,
  29552. isDirectorySync: isDirectorySync,
  29553. isSymlinkSync: isSymlinkSync
  29554. };
  29555. const getExtensions = extensions => extensions.length > 1 ? `{${extensions.join(',')}}` : extensions[0];
  29556. const getPath = (filepath, cwd) => {
  29557. const pth = filepath[0] === '!' ? filepath.slice(1) : filepath;
  29558. return path__default['default'].isAbsolute(pth) ? pth : path__default['default'].join(cwd, pth);
  29559. };
  29560. const addExtensions = (file, extensions) => {
  29561. if (path__default['default'].extname(file)) {
  29562. return `**/${file}`;
  29563. }
  29564. return `**/${file}.${getExtensions(extensions)}`;
  29565. };
  29566. const getGlob = (directory, options) => {
  29567. if (options.files && !Array.isArray(options.files)) {
  29568. throw new TypeError(`Expected \`files\` to be of type \`Array\` but received type \`${typeof options.files}\``);
  29569. }
  29570. if (options.extensions && !Array.isArray(options.extensions)) {
  29571. throw new TypeError(`Expected \`extensions\` to be of type \`Array\` but received type \`${typeof options.extensions}\``);
  29572. }
  29573. if (options.files && options.extensions) {
  29574. return options.files.map(x => path__default['default'].posix.join(directory, addExtensions(x, options.extensions)));
  29575. }
  29576. if (options.files) {
  29577. return options.files.map(x => path__default['default'].posix.join(directory, `**/${x}`));
  29578. }
  29579. if (options.extensions) {
  29580. return [path__default['default'].posix.join(directory, `**/*.${getExtensions(options.extensions)}`)];
  29581. }
  29582. return [path__default['default'].posix.join(directory, '**')];
  29583. };
  29584. var dirGlob = async (input, options) => {
  29585. options = Object.assign({
  29586. cwd: process.cwd()
  29587. }, options);
  29588. if (typeof options.cwd !== 'string') {
  29589. throw new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof options.cwd}\``);
  29590. }
  29591. const globs = await Promise.all([].concat(input).map(async x => {
  29592. const isDirectory = await pathType.isDirectory(getPath(x, options.cwd));
  29593. return isDirectory ? getGlob(x, options) : x;
  29594. }));
  29595. return [].concat.apply([], globs); // eslint-disable-line prefer-spread
  29596. };
  29597. var sync$7 = (input, options) => {
  29598. options = Object.assign({
  29599. cwd: process.cwd()
  29600. }, options);
  29601. if (typeof options.cwd !== 'string') {
  29602. throw new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof options.cwd}\``);
  29603. }
  29604. const globs = [].concat(input).map(x => pathType.isDirectorySync(getPath(x, options.cwd)) ? getGlob(x, options) : x);
  29605. return [].concat.apply([], globs); // eslint-disable-line prefer-spread
  29606. };
  29607. dirGlob.sync = sync$7;
  29608. // A simple implementation of make-array
  29609. function makeArray(subject) {
  29610. return Array.isArray(subject) ? subject : [subject];
  29611. }
  29612. const EMPTY = '';
  29613. const SPACE = ' ';
  29614. const ESCAPE = '\\';
  29615. const REGEX_TEST_BLANK_LINE = /^\s+$/;
  29616. const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
  29617. const REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
  29618. const REGEX_SPLITALL_CRLF = /\r?\n/g; // /foo,
  29619. // ./foo,
  29620. // ../foo,
  29621. // .
  29622. // ..
  29623. const REGEX_TEST_INVALID_PATH = /^\.*\/|^\.+$/;
  29624. const SLASH$1 = '/';
  29625. const KEY_IGNORE$1 = typeof Symbol !== 'undefined' ? Symbol.for('node-ignore')
  29626. /* istanbul ignore next */
  29627. : 'node-ignore';
  29628. const define$1 = (object, key, value) => Object.defineProperty(object, key, {
  29629. value
  29630. });
  29631. const REGEX_REGEXP_RANGE$1 = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression
  29632. // The cases are complicated, see test cases for details
  29633. const sanitizeRange$1 = range => range.replace(REGEX_REGEXP_RANGE$1, (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match // Invalid range (out of order) which is ok for gitignore rules but
  29634. // fatal for JavaScript regular expression, so eliminate it.
  29635. : EMPTY); // See fixtures #59
  29636. const cleanRangeBackSlash = slashes => {
  29637. const {
  29638. length
  29639. } = slashes;
  29640. return slashes.slice(0, length - length % 2);
  29641. }; // > If the pattern ends with a slash,
  29642. // > it is removed for the purpose of the following description,
  29643. // > but it would only find a match with a directory.
  29644. // > In other words, foo/ will match a directory foo and paths underneath it,
  29645. // > but will not match a regular file or a symbolic link foo
  29646. // > (this is consistent with the way how pathspec works in general in Git).
  29647. // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
  29648. // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
  29649. // you could use option `mark: true` with `glob`
  29650. // '`foo/`' should not continue with the '`..`'
  29651. const REPLACERS = [// > Trailing spaces are ignored unless they are quoted with backslash ("\")
  29652. [// (a\ ) -> (a )
  29653. // (a ) -> (a)
  29654. // (a \ ) -> (a )
  29655. /\\?\s+$/, match => match.indexOf('\\') === 0 ? SPACE : EMPTY], // replace (\ ) with ' '
  29656. [/\\\s/g, () => SPACE], // Escape metacharacters
  29657. // which is written down by users but means special for regular expressions.
  29658. // > There are 12 characters with special meanings:
  29659. // > - the backslash \,
  29660. // > - the caret ^,
  29661. // > - the dollar sign $,
  29662. // > - the period or dot .,
  29663. // > - the vertical bar or pipe symbol |,
  29664. // > - the question mark ?,
  29665. // > - the asterisk or star *,
  29666. // > - the plus sign +,
  29667. // > - the opening parenthesis (,
  29668. // > - the closing parenthesis ),
  29669. // > - and the opening square bracket [,
  29670. // > - the opening curly brace {,
  29671. // > These special characters are often called "metacharacters".
  29672. [/[\\$.|*+(){^]/g, match => `\\${match}`], [// > a question mark (?) matches a single character
  29673. /(?!\\)\?/g, () => '[^/]'], // leading slash
  29674. [// > A leading slash matches the beginning of the pathname.
  29675. // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
  29676. // A leading slash matches the beginning of the pathname
  29677. /^\//, () => '^'], // replace special metacharacter slash after the leading slash
  29678. [/\//g, () => '\\/'], [// > A leading "**" followed by a slash means match in all directories.
  29679. // > For example, "**/foo" matches file or directory "foo" anywhere,
  29680. // > the same as pattern "foo".
  29681. // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
  29682. // > under directory "foo".
  29683. // Notice that the '*'s have been replaced as '\\*'
  29684. /^\^*\\\*\\\*\\\//, // '**/foo' <-> 'foo'
  29685. () => '^(?:.*\\/)?'], // starting
  29686. [// there will be no leading '/'
  29687. // (which has been replaced by section "leading slash")
  29688. // If starts with '**', adding a '^' to the regular expression also works
  29689. /^(?=[^^])/, function startingReplacer() {
  29690. // If has a slash `/` at the beginning or middle
  29691. return !/\/(?!$)/.test(this) // > Prior to 2.22.1
  29692. // > If the pattern does not contain a slash /,
  29693. // > Git treats it as a shell glob pattern
  29694. // Actually, if there is only a trailing slash,
  29695. // git also treats it as a shell glob pattern
  29696. // After 2.22.1 (compatible but clearer)
  29697. // > If there is a separator at the beginning or middle (or both)
  29698. // > of the pattern, then the pattern is relative to the directory
  29699. // > level of the particular .gitignore file itself.
  29700. // > Otherwise the pattern may also match at any level below
  29701. // > the .gitignore level.
  29702. ? '(?:^|\\/)' // > Otherwise, Git treats the pattern as a shell glob suitable for
  29703. // > consumption by fnmatch(3)
  29704. : '^';
  29705. }], // two globstars
  29706. [// Use lookahead assertions so that we could match more than one `'/**'`
  29707. /\\\/\\\*\\\*(?=\\\/|$)/g, // Zero, one or several directories
  29708. // should not use '*', or it will be replaced by the next replacer
  29709. // Check if it is not the last `'/**'`
  29710. (_, index, str) => index + 6 < str.length // case: /**/
  29711. // > A slash followed by two consecutive asterisks then a slash matches
  29712. // > zero or more directories.
  29713. // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
  29714. // '/**/'
  29715. ? '(?:\\/[^\\/]+)*' // case: /**
  29716. // > A trailing `"/**"` matches everything inside.
  29717. // #21: everything inside but it should not include the current folder
  29718. : '\\/.+'], // intermediate wildcards
  29719. [// Never replace escaped '*'
  29720. // ignore rule '\*' will match the path '*'
  29721. // 'abc.*/' -> go
  29722. // 'abc.*' -> skip this rule
  29723. /(^|[^\\]+)\\\*(?=.+)/g, // '*.js' matches '.js'
  29724. // '*.js' doesn't match 'abc'
  29725. (_, p1) => `${p1}[^\\/]*`], [// unescape, revert step 3 except for back slash
  29726. // For example, if a user escape a '\\*',
  29727. // after step 3, the result will be '\\\\\\*'
  29728. /\\\\\\(?=[$.|*+(){^])/g, () => ESCAPE], [// '\\\\' -> '\\'
  29729. /\\\\/g, () => ESCAPE], [// > The range notation, e.g. [a-zA-Z],
  29730. // > can be used to match one of the characters in a range.
  29731. // `\` is escaped by step 3
  29732. /(\\)?\[([^\]/]*?)(\\*)($|\])/g, (match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE // '\\[bar]' -> '\\\\[bar\\]'
  29733. ? `\\[${range}${cleanRangeBackSlash(endEscape)}${close}` : close === ']' ? endEscape.length % 2 === 0 // A normal case, and it is a range notation
  29734. // '[bar]'
  29735. // '[bar\\\\]'
  29736. ? `[${sanitizeRange$1(range)}${endEscape}]` // Invalid range notaton
  29737. // '[bar\\]' -> '[bar\\\\]'
  29738. : '[]' : '[]'], // ending
  29739. [// 'js' will not match 'js.'
  29740. // 'ab' will not match 'abc'
  29741. /(?:[^*])$/, // WTF!
  29742. // https://git-scm.com/docs/gitignore
  29743. // changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
  29744. // which re-fixes #24, #38
  29745. // > If there is a separator at the end of the pattern then the pattern
  29746. // > will only match directories, otherwise the pattern can match both
  29747. // > files and directories.
  29748. // 'js*' will not match 'a.js'
  29749. // 'js/' will not match 'a.js'
  29750. // 'js' will match 'a.js' and 'a.js/'
  29751. match => /\/$/.test(match) // foo/ will not match 'foo'
  29752. ? `${match}$` // foo matches 'foo' and 'foo/'
  29753. : `${match}(?=$|\\/$)`], // trailing wildcard
  29754. [/(\^|\\\/)?\\\*$/, (_, p1) => {
  29755. const prefix = p1 // '\^':
  29756. // '/*' does not match EMPTY
  29757. // '/*' does not match everything
  29758. // '\\\/':
  29759. // 'abc/*' does not match 'abc/'
  29760. ? `${p1}[^/]+` // 'a*' matches 'a'
  29761. // 'a*' matches 'aa'
  29762. : '[^/]*';
  29763. return `${prefix}(?=$|\\/$)`;
  29764. }]]; // A simple cache, because an ignore rule only has only one certain meaning
  29765. const regexCache = Object.create(null); // @param {pattern}
  29766. const makeRegex = (pattern, negative, ignorecase) => {
  29767. const r = regexCache[pattern];
  29768. if (r) {
  29769. return r;
  29770. } // const replacers = negative
  29771. // ? NEGATIVE_REPLACERS
  29772. // : POSITIVE_REPLACERS
  29773. const source = REPLACERS.reduce((prev, current) => prev.replace(current[0], current[1].bind(pattern)), pattern);
  29774. return regexCache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source);
  29775. };
  29776. const isString = subject => typeof subject === 'string'; // > A blank line matches no files, so it can serve as a separator for readability.
  29777. const checkPattern$1 = pattern => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment.
  29778. && pattern.indexOf('#') !== 0;
  29779. const splitPattern = pattern => pattern.split(REGEX_SPLITALL_CRLF);
  29780. class IgnoreRule {
  29781. constructor(origin, pattern, negative, regex) {
  29782. this.origin = origin;
  29783. this.pattern = pattern;
  29784. this.negative = negative;
  29785. this.regex = regex;
  29786. }
  29787. }
  29788. const createRule$1 = (pattern, ignorecase) => {
  29789. const origin = pattern;
  29790. let negative = false; // > An optional prefix "!" which negates the pattern;
  29791. if (pattern.indexOf('!') === 0) {
  29792. negative = true;
  29793. pattern = pattern.substr(1);
  29794. }
  29795. pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that
  29796. // > begin with a literal "!", for example, `"\!important!.txt"`.
  29797. .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that
  29798. // > begin with a hash.
  29799. .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#');
  29800. const regex = makeRegex(pattern, negative, ignorecase);
  29801. return new IgnoreRule(origin, pattern, negative, regex);
  29802. };
  29803. const throwError = (message, Ctor) => {
  29804. throw new Ctor(message);
  29805. };
  29806. const checkPath = (path, originalPath, doThrow) => {
  29807. if (!isString(path)) {
  29808. return doThrow(`path must be a string, but got \`${originalPath}\``, TypeError);
  29809. } // We don't know if we should ignore EMPTY, so throw
  29810. if (!path) {
  29811. return doThrow(`path must not be empty`, TypeError);
  29812. } // Check if it is a relative path
  29813. if (checkPath.isNotRelative(path)) {
  29814. const r = '`path.relative()`d';
  29815. return doThrow(`path should be a ${r} string, but got "${originalPath}"`, RangeError);
  29816. }
  29817. return true;
  29818. };
  29819. const isNotRelative = path => REGEX_TEST_INVALID_PATH.test(path);
  29820. checkPath.isNotRelative = isNotRelative;
  29821. checkPath.convert = p => p;
  29822. class Ignore {
  29823. constructor({
  29824. ignorecase = true
  29825. } = {}) {
  29826. this._rules = [];
  29827. this._ignorecase = ignorecase;
  29828. define$1(this, KEY_IGNORE$1, true);
  29829. this._initCache();
  29830. }
  29831. _initCache() {
  29832. this._ignoreCache = Object.create(null);
  29833. this._testCache = Object.create(null);
  29834. }
  29835. _addPattern(pattern) {
  29836. // #32
  29837. if (pattern && pattern[KEY_IGNORE$1]) {
  29838. this._rules = this._rules.concat(pattern._rules);
  29839. this._added = true;
  29840. return;
  29841. }
  29842. if (checkPattern$1(pattern)) {
  29843. const rule = createRule$1(pattern, this._ignorecase);
  29844. this._added = true;
  29845. this._rules.push(rule);
  29846. }
  29847. } // @param {Array<string> | string | Ignore} pattern
  29848. add(pattern) {
  29849. this._added = false;
  29850. makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore,
  29851. // making the behavior changed.
  29852. if (this._added) {
  29853. this._initCache();
  29854. }
  29855. return this;
  29856. } // legacy
  29857. addPattern(pattern) {
  29858. return this.add(pattern);
  29859. } // | ignored : unignored
  29860. // negative | 0:0 | 0:1 | 1:0 | 1:1
  29861. // -------- | ------- | ------- | ------- | --------
  29862. // 0 | TEST | TEST | SKIP | X
  29863. // 1 | TESTIF | SKIP | TEST | X
  29864. // - SKIP: always skip
  29865. // - TEST: always test
  29866. // - TESTIF: only test if checkUnignored
  29867. // - X: that never happen
  29868. // @param {boolean} whether should check if the path is unignored,
  29869. // setting `checkUnignored` to `false` could reduce additional
  29870. // path matching.
  29871. // @returns {TestResult} true if a file is ignored
  29872. _testOne(path, checkUnignored) {
  29873. let ignored = false;
  29874. let unignored = false;
  29875. this._rules.forEach(rule => {
  29876. const {
  29877. negative
  29878. } = rule;
  29879. if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
  29880. return;
  29881. }
  29882. const matched = rule.regex.test(path);
  29883. if (matched) {
  29884. ignored = !negative;
  29885. unignored = negative;
  29886. }
  29887. });
  29888. return {
  29889. ignored,
  29890. unignored
  29891. };
  29892. } // @returns {TestResult}
  29893. _test(originalPath, cache, checkUnignored, slices) {
  29894. const path = originalPath // Supports nullable path
  29895. && checkPath.convert(originalPath);
  29896. checkPath(path, originalPath, throwError);
  29897. return this._t(path, cache, checkUnignored, slices);
  29898. }
  29899. _t(path, cache, checkUnignored, slices) {
  29900. if (path in cache) {
  29901. return cache[path];
  29902. }
  29903. if (!slices) {
  29904. // path/to/a.js
  29905. // ['path', 'to', 'a.js']
  29906. slices = path.split(SLASH$1);
  29907. }
  29908. slices.pop(); // If the path has no parent directory, just test it
  29909. if (!slices.length) {
  29910. return cache[path] = this._testOne(path, checkUnignored);
  29911. }
  29912. const parent = this._t(slices.join(SLASH$1) + SLASH$1, cache, checkUnignored, slices); // If the path contains a parent directory, check the parent first
  29913. return cache[path] = parent.ignored // > It is not possible to re-include a file if a parent directory of
  29914. // > that file is excluded.
  29915. ? parent : this._testOne(path, checkUnignored);
  29916. }
  29917. ignores(path) {
  29918. return this._test(path, this._ignoreCache, false).ignored;
  29919. }
  29920. createFilter() {
  29921. return path => !this.ignores(path);
  29922. }
  29923. filter(paths) {
  29924. return makeArray(paths).filter(this.createFilter());
  29925. } // @returns {TestResult}
  29926. test(path) {
  29927. return this._test(path, this._testCache, true);
  29928. }
  29929. }
  29930. const factory = options => new Ignore(options);
  29931. const returnFalse = () => false;
  29932. const isPathValid = path => checkPath(path && checkPath.convert(path), path, returnFalse);
  29933. factory.isPathValid = isPathValid; // Fixes typescript
  29934. factory.default = factory;
  29935. var ignore$1 = factory; // Windows
  29936. // --------------------------------------------------------------
  29937. /* istanbul ignore if */
  29938. if ( // Detect `process` so that it can run in browsers.
  29939. typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
  29940. /* eslint no-control-regex: "off" */
  29941. const makePosix = str => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, '/');
  29942. checkPath.convert = makePosix; // 'C:\\foo' <- 'C:\\foo' has been converted to 'C:/'
  29943. // 'd:\\foo'
  29944. const REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
  29945. checkPath.isNotRelative = path => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
  29946. }
  29947. var slash$1 = path => {
  29948. const isExtendedLengthPath = /^\\\\\?\\/.test(path);
  29949. const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex
  29950. if (isExtendedLengthPath || hasNonAscii) {
  29951. return path;
  29952. }
  29953. return path.replace(/\\/g, '/');
  29954. };
  29955. const {
  29956. promisify: promisify$1
  29957. } = util__default['default'];
  29958. const DEFAULT_IGNORE = ['**/node_modules/**', '**/flow-typed/**', '**/coverage/**', '**/.git'];
  29959. const readFileP = promisify$1(fs__default['default'].readFile);
  29960. const mapGitIgnorePatternTo = base => ignore => {
  29961. if (ignore.startsWith('!')) {
  29962. return '!' + path__default['default'].posix.join(base, ignore.slice(1));
  29963. }
  29964. return path__default['default'].posix.join(base, ignore);
  29965. };
  29966. const parseGitIgnore = (content, options) => {
  29967. const base = slash$1(path__default['default'].relative(options.cwd, path__default['default'].dirname(options.fileName)));
  29968. return content.split(/\r?\n/).filter(Boolean).filter(line => !line.startsWith('#')).map(mapGitIgnorePatternTo(base));
  29969. };
  29970. const reduceIgnore = files => {
  29971. return files.reduce((ignores, file) => {
  29972. ignores.add(parseGitIgnore(file.content, {
  29973. cwd: file.cwd,
  29974. fileName: file.filePath
  29975. }));
  29976. return ignores;
  29977. }, ignore$1());
  29978. };
  29979. const ensureAbsolutePathForCwd = (cwd, p) => {
  29980. cwd = slash$1(cwd);
  29981. if (path__default['default'].isAbsolute(p)) {
  29982. if (p.startsWith(cwd)) {
  29983. return p;
  29984. }
  29985. throw new Error(`Path ${p} is not in cwd ${cwd}`);
  29986. }
  29987. return path__default['default'].join(cwd, p);
  29988. };
  29989. const getIsIgnoredPredecate = (ignores, cwd) => {
  29990. return p => ignores.ignores(slash$1(path__default['default'].relative(cwd, ensureAbsolutePathForCwd(cwd, p))));
  29991. };
  29992. const getFile = async (file, cwd) => {
  29993. const filePath = path__default['default'].join(cwd, file);
  29994. const content = await readFileP(filePath, 'utf8');
  29995. return {
  29996. cwd,
  29997. filePath,
  29998. content
  29999. };
  30000. };
  30001. const getFileSync = (file, cwd) => {
  30002. const filePath = path__default['default'].join(cwd, file);
  30003. const content = fs__default['default'].readFileSync(filePath, 'utf8');
  30004. return {
  30005. cwd,
  30006. filePath,
  30007. content
  30008. };
  30009. };
  30010. const normalizeOptions$3 = ({
  30011. ignore = [],
  30012. cwd = slash$1(process.cwd())
  30013. } = {}) => {
  30014. return {
  30015. ignore,
  30016. cwd
  30017. };
  30018. };
  30019. var gitignore = async options => {
  30020. options = normalizeOptions$3(options);
  30021. const paths = await out$3('**/.gitignore', {
  30022. ignore: DEFAULT_IGNORE.concat(options.ignore),
  30023. cwd: options.cwd
  30024. });
  30025. const files = await Promise.all(paths.map(file => getFile(file, options.cwd)));
  30026. const ignores = reduceIgnore(files);
  30027. return getIsIgnoredPredecate(ignores, options.cwd);
  30028. };
  30029. var sync$8 = options => {
  30030. options = normalizeOptions$3(options);
  30031. const paths = out$3.sync('**/.gitignore', {
  30032. ignore: DEFAULT_IGNORE.concat(options.ignore),
  30033. cwd: options.cwd
  30034. });
  30035. const files = paths.map(file => getFileSync(file, options.cwd));
  30036. const ignores = reduceIgnore(files);
  30037. return getIsIgnoredPredecate(ignores, options.cwd);
  30038. };
  30039. gitignore.sync = sync$8;
  30040. const {
  30041. Transform
  30042. } = stream__default['default'];
  30043. class ObjectTransform extends Transform {
  30044. constructor() {
  30045. super({
  30046. objectMode: true
  30047. });
  30048. }
  30049. }
  30050. class FilterStream extends ObjectTransform {
  30051. constructor(filter) {
  30052. super();
  30053. this._filter = filter;
  30054. }
  30055. _transform(data, encoding, callback) {
  30056. if (this._filter(data)) {
  30057. this.push(data);
  30058. }
  30059. callback();
  30060. }
  30061. }
  30062. class UniqueStream extends ObjectTransform {
  30063. constructor() {
  30064. super();
  30065. this._pushed = new Set();
  30066. }
  30067. _transform(data, encoding, callback) {
  30068. if (!this._pushed.has(data)) {
  30069. this.push(data);
  30070. this._pushed.add(data);
  30071. }
  30072. callback();
  30073. }
  30074. }
  30075. var streamUtils = {
  30076. FilterStream,
  30077. UniqueStream
  30078. };
  30079. const {
  30080. FilterStream: FilterStream$1,
  30081. UniqueStream: UniqueStream$1
  30082. } = streamUtils;
  30083. const DEFAULT_FILTER = () => false;
  30084. const isNegative = pattern => pattern[0] === '!';
  30085. const assertPatternsInput$1 = patterns => {
  30086. if (!patterns.every(pattern => typeof pattern === 'string')) {
  30087. throw new TypeError('Patterns must be a string or an array of strings');
  30088. }
  30089. };
  30090. const checkCwdOption = (options = {}) => {
  30091. if (!options.cwd) {
  30092. return;
  30093. }
  30094. let stat;
  30095. try {
  30096. stat = fs__default['default'].statSync(options.cwd);
  30097. } catch (_) {
  30098. return;
  30099. }
  30100. if (!stat.isDirectory()) {
  30101. throw new Error('The `cwd` option must be a path to a directory');
  30102. }
  30103. };
  30104. const getPathString = p => p.stats instanceof fs__default['default'].Stats ? p.path : p;
  30105. const generateGlobTasks = (patterns, taskOptions) => {
  30106. patterns = arrayUnion([].concat(patterns));
  30107. assertPatternsInput$1(patterns);
  30108. checkCwdOption(taskOptions);
  30109. const globTasks = [];
  30110. taskOptions = Object.assign({
  30111. ignore: [],
  30112. expandDirectories: true
  30113. }, taskOptions);
  30114. for (const [index, pattern] of patterns.entries()) {
  30115. if (isNegative(pattern)) {
  30116. continue;
  30117. }
  30118. const ignore = patterns.slice(index).filter(isNegative).map(pattern => pattern.slice(1));
  30119. const options = Object.assign({}, taskOptions, {
  30120. ignore: taskOptions.ignore.concat(ignore)
  30121. });
  30122. globTasks.push({
  30123. pattern,
  30124. options
  30125. });
  30126. }
  30127. return globTasks;
  30128. };
  30129. const globDirs = (task, fn) => {
  30130. let options = {};
  30131. if (task.options.cwd) {
  30132. options.cwd = task.options.cwd;
  30133. }
  30134. if (Array.isArray(task.options.expandDirectories)) {
  30135. options = Object.assign({}, options, {
  30136. files: task.options.expandDirectories
  30137. });
  30138. } else if (typeof task.options.expandDirectories === 'object') {
  30139. options = Object.assign({}, options, task.options.expandDirectories);
  30140. }
  30141. return fn(task.pattern, options);
  30142. };
  30143. const getPattern = (task, fn) => task.options.expandDirectories ? globDirs(task, fn) : [task.pattern];
  30144. const getFilterSync = options => {
  30145. return options && options.gitignore ? gitignore.sync({
  30146. cwd: options.cwd,
  30147. ignore: options.ignore
  30148. }) : DEFAULT_FILTER;
  30149. };
  30150. const globToTask = task => glob => {
  30151. const {
  30152. options
  30153. } = task;
  30154. if (options.ignore && Array.isArray(options.ignore) && options.expandDirectories) {
  30155. options.ignore = dirGlob.sync(options.ignore);
  30156. }
  30157. return {
  30158. pattern: glob,
  30159. options
  30160. };
  30161. };
  30162. var globby$1 = async (patterns, options) => {
  30163. const globTasks = generateGlobTasks(patterns, options);
  30164. const getFilter = async () => {
  30165. return options && options.gitignore ? gitignore({
  30166. cwd: options.cwd,
  30167. ignore: options.ignore
  30168. }) : DEFAULT_FILTER;
  30169. };
  30170. const getTasks = async () => {
  30171. const tasks = await Promise.all(globTasks.map(async task => {
  30172. const globs = await getPattern(task, dirGlob);
  30173. return Promise.all(globs.map(globToTask(task)));
  30174. }));
  30175. return arrayUnion(...tasks);
  30176. };
  30177. const [filter, tasks] = await Promise.all([getFilter(), getTasks()]);
  30178. const paths = await Promise.all(tasks.map(task => out$3(task.pattern, task.options)));
  30179. return arrayUnion(...paths).filter(path_ => !filter(getPathString(path_)));
  30180. };
  30181. var sync$9 = (patterns, options) => {
  30182. const globTasks = generateGlobTasks(patterns, options);
  30183. const tasks = globTasks.reduce((tasks, task) => {
  30184. const newTask = getPattern(task, dirGlob.sync).map(globToTask(task));
  30185. return tasks.concat(newTask);
  30186. }, []);
  30187. const filter = getFilterSync(options);
  30188. return tasks.reduce((matches, task) => arrayUnion(matches, out$3.sync(task.pattern, task.options)), []).filter(path_ => !filter(path_));
  30189. };
  30190. var stream$5 = (patterns, options) => {
  30191. const globTasks = generateGlobTasks(patterns, options);
  30192. const tasks = globTasks.reduce((tasks, task) => {
  30193. const newTask = getPattern(task, dirGlob.sync).map(globToTask(task));
  30194. return tasks.concat(newTask);
  30195. }, []);
  30196. const filter = getFilterSync(options);
  30197. const filterStream = new FilterStream$1(p => !filter(p));
  30198. const uniqueStream = new UniqueStream$1();
  30199. return merge2_1(tasks.map(task => out$3.stream(task.pattern, task.options))).pipe(filterStream).pipe(uniqueStream);
  30200. };
  30201. var generateGlobTasks_1 = generateGlobTasks;
  30202. var hasMagic = (patterns, options) => [].concat(patterns).some(pattern => out$3.isDynamicPattern(pattern, options));
  30203. var gitignore_1 = gitignore;
  30204. globby$1.sync = sync$9;
  30205. globby$1.stream = stream$5;
  30206. globby$1.generateGlobTasks = generateGlobTasks_1;
  30207. globby$1.hasMagic = hasMagic;
  30208. globby$1.gitignore = gitignore_1;
  30209. var createLanguage = function (linguistData, override) {
  30210. const {
  30211. languageId
  30212. } = linguistData,
  30213. rest = _objectWithoutPropertiesLoose(linguistData, ["languageId"]);
  30214. return Object.assign({
  30215. linguistLanguageId: languageId
  30216. }, rest, override(linguistData));
  30217. };
  30218. const {
  30219. getLast: getLast$1,
  30220. hasNewline: hasNewline$3,
  30221. getNextNonSpaceNonCommentCharacterIndexWithStartIndex: getNextNonSpaceNonCommentCharacterIndexWithStartIndex$1,
  30222. getNextNonSpaceNonCommentCharacter: getNextNonSpaceNonCommentCharacter$1,
  30223. hasNewlineInRange: hasNewlineInRange$2,
  30224. isNodeIgnoreComment: isNodeIgnoreComment$1,
  30225. addLeadingComment: addLeadingComment$3,
  30226. addTrailingComment: addTrailingComment$3,
  30227. addDanglingComment: addDanglingComment$3,
  30228. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$2
  30229. } = util;
  30230. function handleOwnLineComment(comment, text, options, ast, isLastComment) {
  30231. const {
  30232. precedingNode,
  30233. enclosingNode,
  30234. followingNode
  30235. } = comment;
  30236. return handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleMemberExpressionComments(enclosingNode, followingNode, comment) || handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) || handleClassComments(enclosingNode, precedingNode, followingNode, comment) || handleImportSpecifierComments(enclosingNode, comment) || handleForComments(enclosingNode, precedingNode, comment) || handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) || handleAssignmentPatternComments(enclosingNode, comment) || handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) || handleLabeledStatementComments(enclosingNode, comment);
  30237. }
  30238. function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
  30239. const {
  30240. precedingNode,
  30241. enclosingNode,
  30242. followingNode
  30243. } = comment;
  30244. return handleClosureTypeCastComments(followingNode, comment) || handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) || handleImportSpecifierComments(enclosingNode, comment) || handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) || handleClassComments(enclosingNode, precedingNode, followingNode, comment) || handleLabeledStatementComments(enclosingNode, comment) || handleCallExpressionComments(precedingNode, enclosingNode, comment) || handlePropertyComments(enclosingNode, comment) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleTypeAliasComments(enclosingNode, followingNode, comment) || handleVariableDeclaratorComments(enclosingNode, followingNode, comment);
  30245. }
  30246. function handleRemainingComment(comment, text, options, ast, isLastComment) {
  30247. const {
  30248. precedingNode,
  30249. enclosingNode,
  30250. followingNode
  30251. } = comment;
  30252. if (handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) || handleCommentInEmptyParens(text, enclosingNode, comment, options) || handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleCommentAfterArrowParams(text, enclosingNode, comment, options) || handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) || handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) || handleBreakAndContinueStatementComments(enclosingNode, comment) || handleTSFunctionTrailingComments(text, enclosingNode, followingNode, comment, options)) {
  30253. return true;
  30254. }
  30255. return false;
  30256. }
  30257. function addBlockStatementFirstComment(node, comment) {
  30258. const body = (node.body || node.properties).filter(n => n.type !== "EmptyStatement");
  30259. if (body.length === 0) {
  30260. addDanglingComment$3(node, comment);
  30261. } else {
  30262. addLeadingComment$3(body[0], comment);
  30263. }
  30264. }
  30265. function addBlockOrNotComment(node, comment) {
  30266. if (node.type === "BlockStatement") {
  30267. addBlockStatementFirstComment(node, comment);
  30268. } else {
  30269. addLeadingComment$3(node, comment);
  30270. }
  30271. }
  30272. function handleClosureTypeCastComments(followingNode, comment) {
  30273. if (followingNode && isTypeCastComment(comment)) {
  30274. addLeadingComment$3(followingNode, comment);
  30275. return true;
  30276. }
  30277. return false;
  30278. } // There are often comments before the else clause of if statements like
  30279. //
  30280. // if (1) { ... }
  30281. // // comment
  30282. // else { ... }
  30283. //
  30284. // They are being attached as leading comments of the BlockExpression which
  30285. // is not well printed. What we want is to instead move the comment inside
  30286. // of the block and make it leadingComment of the first element of the block
  30287. // or dangling comment of the block if there is nothing inside
  30288. //
  30289. // if (1) { ... }
  30290. // else {
  30291. // // comment
  30292. // ...
  30293. // }
  30294. function handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  30295. if (!enclosingNode || enclosingNode.type !== "IfStatement" || !followingNode) {
  30296. return false;
  30297. } // We unfortunately have no way using the AST or location of nodes to know
  30298. // if the comment is positioned before the condition parenthesis:
  30299. // if (a /* comment */) {}
  30300. // The only workaround I found is to look at the next character to see if
  30301. // it is a ).
  30302. const nextCharacter = getNextNonSpaceNonCommentCharacter$1(text, comment, options.locEnd);
  30303. if (nextCharacter === ")") {
  30304. addTrailingComment$3(precedingNode, comment);
  30305. return true;
  30306. } // Comments before `else`:
  30307. // - treat as trailing comments of the consequent, if it's a BlockStatement
  30308. // - treat as a dangling comment otherwise
  30309. if (precedingNode === enclosingNode.consequent && followingNode === enclosingNode.alternate) {
  30310. if (precedingNode.type === "BlockStatement") {
  30311. addTrailingComment$3(precedingNode, comment);
  30312. } else {
  30313. addDanglingComment$3(enclosingNode, comment);
  30314. }
  30315. return true;
  30316. }
  30317. if (followingNode.type === "BlockStatement") {
  30318. addBlockStatementFirstComment(followingNode, comment);
  30319. return true;
  30320. }
  30321. if (followingNode.type === "IfStatement") {
  30322. addBlockOrNotComment(followingNode.consequent, comment);
  30323. return true;
  30324. } // For comments positioned after the condition parenthesis in an if statement
  30325. // before the consequent without brackets on, such as
  30326. // if (a) /* comment */ true,
  30327. // we look at the next character to see if the following node
  30328. // is the consequent for the if statement
  30329. if (enclosingNode.consequent === followingNode) {
  30330. addLeadingComment$3(followingNode, comment);
  30331. return true;
  30332. }
  30333. return false;
  30334. }
  30335. function handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  30336. if (!enclosingNode || enclosingNode.type !== "WhileStatement" || !followingNode) {
  30337. return false;
  30338. } // We unfortunately have no way using the AST or location of nodes to know
  30339. // if the comment is positioned before the condition parenthesis:
  30340. // while (a /* comment */) {}
  30341. // The only workaround I found is to look at the next character to see if
  30342. // it is a ).
  30343. const nextCharacter = getNextNonSpaceNonCommentCharacter$1(text, comment, options.locEnd);
  30344. if (nextCharacter === ")") {
  30345. addTrailingComment$3(precedingNode, comment);
  30346. return true;
  30347. }
  30348. if (followingNode.type === "BlockStatement") {
  30349. addBlockStatementFirstComment(followingNode, comment);
  30350. return true;
  30351. }
  30352. return false;
  30353. } // Same as IfStatement but for TryStatement
  30354. function handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) {
  30355. if (!enclosingNode || enclosingNode.type !== "TryStatement" && enclosingNode.type !== "CatchClause" || !followingNode) {
  30356. return false;
  30357. }
  30358. if (enclosingNode.type === "CatchClause" && precedingNode) {
  30359. addTrailingComment$3(precedingNode, comment);
  30360. return true;
  30361. }
  30362. if (followingNode.type === "BlockStatement") {
  30363. addBlockStatementFirstComment(followingNode, comment);
  30364. return true;
  30365. }
  30366. if (followingNode.type === "TryStatement") {
  30367. addBlockOrNotComment(followingNode.finalizer, comment);
  30368. return true;
  30369. }
  30370. if (followingNode.type === "CatchClause") {
  30371. addBlockOrNotComment(followingNode.body, comment);
  30372. return true;
  30373. }
  30374. return false;
  30375. }
  30376. function handleMemberExpressionComments(enclosingNode, followingNode, comment) {
  30377. if (enclosingNode && (enclosingNode.type === "MemberExpression" || enclosingNode.type === "OptionalMemberExpression") && followingNode && followingNode.type === "Identifier") {
  30378. addLeadingComment$3(enclosingNode, comment);
  30379. return true;
  30380. }
  30381. return false;
  30382. }
  30383. function handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) {
  30384. const isSameLineAsPrecedingNode = precedingNode && !hasNewlineInRange$2(text, options.locEnd(precedingNode), options.locStart(comment));
  30385. if ((!precedingNode || !isSameLineAsPrecedingNode) && enclosingNode && (enclosingNode.type === "ConditionalExpression" || enclosingNode.type === "TSConditionalType") && followingNode) {
  30386. addLeadingComment$3(followingNode, comment);
  30387. return true;
  30388. }
  30389. return false;
  30390. }
  30391. function handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) {
  30392. if (enclosingNode && (enclosingNode.type === "ObjectProperty" || enclosingNode.type === "Property") && enclosingNode.shorthand && enclosingNode.key === precedingNode && enclosingNode.value.type === "AssignmentPattern") {
  30393. addTrailingComment$3(enclosingNode.value.left, comment);
  30394. return true;
  30395. }
  30396. return false;
  30397. }
  30398. function handleClassComments(enclosingNode, precedingNode, followingNode, comment) {
  30399. if (enclosingNode && (enclosingNode.type === "ClassDeclaration" || enclosingNode.type === "ClassExpression" || enclosingNode.type === "DeclareClass" || enclosingNode.type === "DeclareInterface" || enclosingNode.type === "InterfaceDeclaration" || enclosingNode.type === "TSInterfaceDeclaration")) {
  30400. if (enclosingNode.decorators && enclosingNode.decorators.length > 0 && !(followingNode && followingNode.type === "Decorator")) {
  30401. addTrailingComment$3(enclosingNode.decorators[enclosingNode.decorators.length - 1], comment);
  30402. return true;
  30403. }
  30404. if (enclosingNode.body && followingNode === enclosingNode.body) {
  30405. addBlockStatementFirstComment(enclosingNode.body, comment);
  30406. return true;
  30407. } // Don't add leading comments to `implements`, `extends`, `mixins` to
  30408. // avoid printing the comment after the keyword.
  30409. if (followingNode) {
  30410. for (const prop of ["implements", "extends", "mixins"]) {
  30411. if (enclosingNode[prop] && followingNode === enclosingNode[prop][0]) {
  30412. if (precedingNode && (precedingNode === enclosingNode.id || precedingNode === enclosingNode.typeParameters || precedingNode === enclosingNode.superClass)) {
  30413. addTrailingComment$3(precedingNode, comment);
  30414. } else {
  30415. addDanglingComment$3(enclosingNode, comment, prop);
  30416. }
  30417. return true;
  30418. }
  30419. }
  30420. }
  30421. }
  30422. return false;
  30423. }
  30424. function handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) {
  30425. // This is only needed for estree parsers (flow, typescript) to attach
  30426. // after a method name:
  30427. // obj = { fn /*comment*/() {} };
  30428. if (enclosingNode && precedingNode && ( // "MethodDefinition" is handled in getCommentChildNodes
  30429. enclosingNode.type === "Property" || enclosingNode.type === "TSDeclareMethod" || enclosingNode.type === "TSAbstractMethodDefinition") && precedingNode.type === "Identifier" && enclosingNode.key === precedingNode && // special Property case: { key: /*comment*/(value) };
  30430. // comment should be attached to value instead of key
  30431. getNextNonSpaceNonCommentCharacter$1(text, precedingNode, options.locEnd) !== ":") {
  30432. addTrailingComment$3(precedingNode, comment);
  30433. return true;
  30434. } // Print comments between decorators and class methods as a trailing comment
  30435. // on the decorator node instead of the method node
  30436. if (precedingNode && enclosingNode && precedingNode.type === "Decorator" && (enclosingNode.type === "ClassMethod" || enclosingNode.type === "ClassProperty" || enclosingNode.type === "TSAbstractClassProperty" || enclosingNode.type === "TSAbstractMethodDefinition" || enclosingNode.type === "TSDeclareMethod" || enclosingNode.type === "MethodDefinition")) {
  30437. addTrailingComment$3(precedingNode, comment);
  30438. return true;
  30439. }
  30440. return false;
  30441. }
  30442. function handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) {
  30443. if (getNextNonSpaceNonCommentCharacter$1(text, comment, options.locEnd) !== "(") {
  30444. return false;
  30445. }
  30446. if (precedingNode && enclosingNode && (enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "MethodDefinition" || enclosingNode.type === "ObjectMethod")) {
  30447. addTrailingComment$3(precedingNode, comment);
  30448. return true;
  30449. }
  30450. return false;
  30451. }
  30452. function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
  30453. if (!(enclosingNode && enclosingNode.type === "ArrowFunctionExpression")) {
  30454. return false;
  30455. }
  30456. const index = getNextNonSpaceNonCommentCharacterIndex$2(text, comment, options.locEnd);
  30457. if (index !== false && text.slice(index, index + 2) === "=>") {
  30458. addDanglingComment$3(enclosingNode, comment);
  30459. return true;
  30460. }
  30461. return false;
  30462. }
  30463. function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
  30464. if (getNextNonSpaceNonCommentCharacter$1(text, comment, options.locEnd) !== ")") {
  30465. return false;
  30466. } // Only add dangling comments to fix the case when no params are present,
  30467. // i.e. a function without any argument.
  30468. if (enclosingNode && (isRealFunctionLikeNode(enclosingNode) && // `params` vs `parameters` - see https://github.com/babel/babel/issues/9231
  30469. (enclosingNode.params || enclosingNode.parameters).length === 0 || (enclosingNode.type === "CallExpression" || enclosingNode.type === "OptionalCallExpression" || enclosingNode.type === "NewExpression") && enclosingNode.arguments.length === 0)) {
  30470. addDanglingComment$3(enclosingNode, comment);
  30471. return true;
  30472. }
  30473. if (enclosingNode && enclosingNode.type === "MethodDefinition" && enclosingNode.value.params.length === 0) {
  30474. addDanglingComment$3(enclosingNode.value, comment);
  30475. return true;
  30476. }
  30477. return false;
  30478. }
  30479. function handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  30480. // Flow function type definitions
  30481. if (precedingNode && precedingNode.type === "FunctionTypeParam" && enclosingNode && enclosingNode.type === "FunctionTypeAnnotation" && followingNode && followingNode.type !== "FunctionTypeParam") {
  30482. addTrailingComment$3(precedingNode, comment);
  30483. return true;
  30484. } // Real functions and TypeScript function type definitions
  30485. if (precedingNode && (precedingNode.type === "Identifier" || precedingNode.type === "AssignmentPattern") && enclosingNode && isRealFunctionLikeNode(enclosingNode) && getNextNonSpaceNonCommentCharacter$1(text, comment, options.locEnd) === ")") {
  30486. addTrailingComment$3(precedingNode, comment);
  30487. return true;
  30488. }
  30489. if (enclosingNode && enclosingNode.type === "FunctionDeclaration" && followingNode && followingNode.type === "BlockStatement") {
  30490. const functionParamRightParenIndex = (() => {
  30491. if ((enclosingNode.params || enclosingNode.parameters).length !== 0) {
  30492. return getNextNonSpaceNonCommentCharacterIndexWithStartIndex$1(text, options.locEnd(getLast$1(enclosingNode.params || enclosingNode.parameters)));
  30493. }
  30494. const functionParamLeftParenIndex = getNextNonSpaceNonCommentCharacterIndexWithStartIndex$1(text, options.locEnd(enclosingNode.id));
  30495. return functionParamLeftParenIndex !== false && getNextNonSpaceNonCommentCharacterIndexWithStartIndex$1(text, functionParamLeftParenIndex + 1);
  30496. })();
  30497. if (options.locStart(comment) > functionParamRightParenIndex) {
  30498. addBlockStatementFirstComment(followingNode, comment);
  30499. return true;
  30500. }
  30501. }
  30502. return false;
  30503. }
  30504. function handleImportSpecifierComments(enclosingNode, comment) {
  30505. if (enclosingNode && enclosingNode.type === "ImportSpecifier") {
  30506. addLeadingComment$3(enclosingNode, comment);
  30507. return true;
  30508. }
  30509. return false;
  30510. }
  30511. function handleLabeledStatementComments(enclosingNode, comment) {
  30512. if (enclosingNode && enclosingNode.type === "LabeledStatement") {
  30513. addLeadingComment$3(enclosingNode, comment);
  30514. return true;
  30515. }
  30516. return false;
  30517. }
  30518. function handleBreakAndContinueStatementComments(enclosingNode, comment) {
  30519. if (enclosingNode && (enclosingNode.type === "ContinueStatement" || enclosingNode.type === "BreakStatement") && !enclosingNode.label) {
  30520. addTrailingComment$3(enclosingNode, comment);
  30521. return true;
  30522. }
  30523. return false;
  30524. }
  30525. function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
  30526. if (enclosingNode && (enclosingNode.type === "CallExpression" || enclosingNode.type === "OptionalCallExpression") && precedingNode && enclosingNode.callee === precedingNode && enclosingNode.arguments.length > 0) {
  30527. addLeadingComment$3(enclosingNode.arguments[0], comment);
  30528. return true;
  30529. }
  30530. return false;
  30531. }
  30532. function handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) {
  30533. if (enclosingNode && (enclosingNode.type === "UnionTypeAnnotation" || enclosingNode.type === "TSUnionType")) {
  30534. if (isNodeIgnoreComment$1(comment)) {
  30535. followingNode.prettierIgnore = true;
  30536. comment.unignore = true;
  30537. }
  30538. if (precedingNode) {
  30539. addTrailingComment$3(precedingNode, comment);
  30540. return true;
  30541. }
  30542. return false;
  30543. }
  30544. if (followingNode && (followingNode.type === "UnionTypeAnnotation" || followingNode.type === "TSUnionType") && isNodeIgnoreComment$1(comment)) {
  30545. followingNode.types[0].prettierIgnore = true;
  30546. comment.unignore = true;
  30547. }
  30548. return false;
  30549. }
  30550. function handlePropertyComments(enclosingNode, comment) {
  30551. if (enclosingNode && (enclosingNode.type === "Property" || enclosingNode.type === "ObjectProperty")) {
  30552. addLeadingComment$3(enclosingNode, comment);
  30553. return true;
  30554. }
  30555. return false;
  30556. }
  30557. function handleOnlyComments(enclosingNode, ast, comment, isLastComment) {
  30558. // With Flow the enclosingNode is undefined so use the AST instead.
  30559. if (ast && ast.body && ast.body.length === 0) {
  30560. if (isLastComment) {
  30561. addDanglingComment$3(ast, comment);
  30562. } else {
  30563. addLeadingComment$3(ast, comment);
  30564. }
  30565. return true;
  30566. } else if (enclosingNode && enclosingNode.type === "Program" && enclosingNode.body.length === 0 && enclosingNode.directives && enclosingNode.directives.length === 0) {
  30567. if (isLastComment) {
  30568. addDanglingComment$3(enclosingNode, comment);
  30569. } else {
  30570. addLeadingComment$3(enclosingNode, comment);
  30571. }
  30572. return true;
  30573. }
  30574. return false;
  30575. }
  30576. function handleForComments(enclosingNode, precedingNode, comment) {
  30577. if (enclosingNode && (enclosingNode.type === "ForInStatement" || enclosingNode.type === "ForOfStatement")) {
  30578. addLeadingComment$3(enclosingNode, comment);
  30579. return true;
  30580. }
  30581. return false;
  30582. }
  30583. function handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) {
  30584. if (precedingNode && precedingNode.type === "ImportSpecifier" && enclosingNode && enclosingNode.type === "ImportDeclaration" && hasNewline$3(text, options.locEnd(comment))) {
  30585. addTrailingComment$3(precedingNode, comment);
  30586. return true;
  30587. }
  30588. return false;
  30589. }
  30590. function handleAssignmentPatternComments(enclosingNode, comment) {
  30591. if (enclosingNode && enclosingNode.type === "AssignmentPattern") {
  30592. addLeadingComment$3(enclosingNode, comment);
  30593. return true;
  30594. }
  30595. return false;
  30596. }
  30597. function handleTypeAliasComments(enclosingNode, followingNode, comment) {
  30598. if (enclosingNode && enclosingNode.type === "TypeAlias") {
  30599. addLeadingComment$3(enclosingNode, comment);
  30600. return true;
  30601. }
  30602. return false;
  30603. }
  30604. function handleVariableDeclaratorComments(enclosingNode, followingNode, comment) {
  30605. if (enclosingNode && (enclosingNode.type === "VariableDeclarator" || enclosingNode.type === "AssignmentExpression") && followingNode && (followingNode.type === "ObjectExpression" || followingNode.type === "ArrayExpression" || followingNode.type === "TemplateLiteral" || followingNode.type === "TaggedTemplateExpression" || isBlockComment(comment))) {
  30606. addLeadingComment$3(followingNode, comment);
  30607. return true;
  30608. }
  30609. return false;
  30610. }
  30611. function handleTSFunctionTrailingComments(text, enclosingNode, followingNode, comment, options) {
  30612. if (!followingNode && enclosingNode && (enclosingNode.type === "TSMethodSignature" || enclosingNode.type === "TSDeclareFunction" || enclosingNode.type === "TSAbstractMethodDefinition") && getNextNonSpaceNonCommentCharacter$1(text, comment, options.locEnd) === ";") {
  30613. addTrailingComment$3(enclosingNode, comment);
  30614. return true;
  30615. }
  30616. return false;
  30617. }
  30618. function handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) {
  30619. if (!enclosingNode || enclosingNode.type !== "TSMappedType") {
  30620. return false;
  30621. }
  30622. if (followingNode && followingNode.type === "TSTypeParameter" && followingNode.name) {
  30623. addLeadingComment$3(followingNode.name, comment);
  30624. return true;
  30625. }
  30626. if (precedingNode && precedingNode.type === "TSTypeParameter" && precedingNode.constraint) {
  30627. addTrailingComment$3(precedingNode.constraint, comment);
  30628. return true;
  30629. }
  30630. return false;
  30631. }
  30632. function isBlockComment(comment) {
  30633. return comment.type === "Block" || comment.type === "CommentBlock";
  30634. }
  30635. /**
  30636. * @param {any} node
  30637. * @param {(comment: any) => boolean} fn
  30638. * @returns boolean
  30639. */
  30640. function hasLeadingComment(node, fn = () => true) {
  30641. if (node.leadingComments) {
  30642. return node.leadingComments.some(fn);
  30643. }
  30644. if (node.comments) {
  30645. return node.comments.some(comment => comment.leading && fn(comment));
  30646. }
  30647. return false;
  30648. }
  30649. function isRealFunctionLikeNode(node) {
  30650. return node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ObjectMethod" || node.type === "ClassMethod" || node.type === "TSDeclareFunction" || node.type === "TSCallSignatureDeclaration" || node.type === "TSConstructSignatureDeclaration" || node.type === "TSConstructSignatureDeclaration" || node.type === "TSMethodSignature" || node.type === "TSConstructorType" || node.type === "TSFunctionType" || node.type === "TSDeclareMethod";
  30651. }
  30652. function getGapRegex(enclosingNode) {
  30653. if (enclosingNode && enclosingNode.type !== "BinaryExpression" && enclosingNode.type !== "LogicalExpression") {
  30654. // Support degenerate single-element unions and intersections.
  30655. // E.g.: `type A = /* 1 */ & B`
  30656. return /^[\s&(|]*$/;
  30657. }
  30658. }
  30659. function getCommentChildNodes(node, options) {
  30660. // Prevent attaching comments to FunctionExpression in this case:
  30661. // class Foo {
  30662. // bar() // comment
  30663. // {
  30664. // baz();
  30665. // }
  30666. // }
  30667. if ((options.parser === "typescript" || options.parser === "flow") && node.type === "MethodDefinition" && node.value && node.value.type === "FunctionExpression" && node.value.params.length === 0 && !node.value.returnType && (!node.value.typeParameters || node.value.typeParameters.length === 0) && node.value.body) {
  30668. return [...(node.decorators || []), node.key, node.value.body];
  30669. }
  30670. }
  30671. function isTypeCastComment(comment) {
  30672. return isBlockComment(comment) && comment.value[0] === "*" && // TypeScript expects the type to be enclosed in curly brackets, however
  30673. // Closure Compiler accepts types in parens and even without any delimiters at all.
  30674. // That's why we just search for "@type".
  30675. /@type\b/.test(comment.value);
  30676. }
  30677. var comments$1 = {
  30678. handleOwnLineComment,
  30679. handleEndOfLineComment,
  30680. handleRemainingComment,
  30681. hasLeadingComment,
  30682. isBlockComment,
  30683. isTypeCastComment,
  30684. getGapRegex,
  30685. getCommentChildNodes
  30686. };
  30687. const {
  30688. builders: {
  30689. indent: indent$2,
  30690. join: join$2,
  30691. line: line$3,
  30692. hardline: hardline$3,
  30693. softline: softline$1,
  30694. literalline: literalline$2,
  30695. concat: concat$5,
  30696. group: group$1,
  30697. dedentToRoot: dedentToRoot$1
  30698. },
  30699. utils: {
  30700. mapDoc: mapDoc$1,
  30701. replaceNewlinesWithLiterallines: replaceNewlinesWithLiterallines$1
  30702. }
  30703. } = document;
  30704. const {
  30705. isBlockComment: isBlockComment$1,
  30706. hasLeadingComment: hasLeadingComment$1
  30707. } = comments$1;
  30708. function embed(path, print, textToDoc, options) {
  30709. const node = path.getValue();
  30710. const parent = path.getParentNode();
  30711. const parentParent = path.getParentNode(1);
  30712. switch (node.type) {
  30713. case "TemplateLiteral":
  30714. {
  30715. const isCss = [isStyledJsx, isStyledComponents, isCssProp, isAngularComponentStyles].some(isIt => isIt(path));
  30716. if (isCss) {
  30717. // Get full template literal with expressions replaced by placeholders
  30718. const rawQuasis = node.quasis.map(q => q.value.raw);
  30719. let placeholderID = 0;
  30720. const text = rawQuasis.reduce((prevVal, currVal, idx) => {
  30721. return idx === 0 ? currVal : prevVal + "@prettier-placeholder-" + placeholderID++ + "-id" + currVal;
  30722. }, "");
  30723. const doc = textToDoc(text, {
  30724. parser: "scss"
  30725. }, {
  30726. stripTrailingHardline: true
  30727. });
  30728. return transformCssDoc(doc, path, print);
  30729. }
  30730. /*
  30731. * react-relay and graphql-tag
  30732. * graphql`...`
  30733. * graphql.experimental`...`
  30734. * gql`...`
  30735. *
  30736. * This intentionally excludes Relay Classic tags, as Prettier does not
  30737. * support Relay Classic formatting.
  30738. */
  30739. if (isGraphQL(path)) {
  30740. const expressionDocs = node.expressions ? path.map(print, "expressions") : [];
  30741. const numQuasis = node.quasis.length;
  30742. if (numQuasis === 1 && node.quasis[0].value.raw.trim() === "") {
  30743. return "``";
  30744. }
  30745. const parts = [];
  30746. for (let i = 0; i < numQuasis; i++) {
  30747. const templateElement = node.quasis[i];
  30748. const isFirst = i === 0;
  30749. const isLast = i === numQuasis - 1;
  30750. const text = templateElement.value.cooked; // Bail out if any of the quasis have an invalid escape sequence
  30751. // (which would make the `cooked` value be `null` or `undefined`)
  30752. if (typeof text !== "string") {
  30753. return null;
  30754. }
  30755. const lines = text.split("\n");
  30756. const numLines = lines.length;
  30757. const expressionDoc = expressionDocs[i];
  30758. const startsWithBlankLine = numLines > 2 && lines[0].trim() === "" && lines[1].trim() === "";
  30759. const endsWithBlankLine = numLines > 2 && lines[numLines - 1].trim() === "" && lines[numLines - 2].trim() === "";
  30760. const commentsAndWhitespaceOnly = lines.every(line => /^\s*(?:#[^\n\r]*)?$/.test(line)); // Bail out if an interpolation occurs within a comment.
  30761. if (!isLast && /#[^\n\r]*$/.test(lines[numLines - 1])) {
  30762. return null;
  30763. }
  30764. let doc = null;
  30765. if (commentsAndWhitespaceOnly) {
  30766. doc = printGraphqlComments(lines);
  30767. } else {
  30768. doc = textToDoc(text, {
  30769. parser: "graphql"
  30770. }, {
  30771. stripTrailingHardline: true
  30772. });
  30773. }
  30774. if (doc) {
  30775. doc = escapeTemplateCharacters(doc, false);
  30776. if (!isFirst && startsWithBlankLine) {
  30777. parts.push("");
  30778. }
  30779. parts.push(doc);
  30780. if (!isLast && endsWithBlankLine) {
  30781. parts.push("");
  30782. }
  30783. } else if (!isFirst && !isLast && startsWithBlankLine) {
  30784. parts.push("");
  30785. }
  30786. if (expressionDoc) {
  30787. parts.push(concat$5(["${", expressionDoc, "}"]));
  30788. }
  30789. }
  30790. return concat$5(["`", indent$2(concat$5([hardline$3, join$2(hardline$3, parts)])), hardline$3, "`"]);
  30791. }
  30792. const htmlParser = isHtml(path) ? "html" : isAngularComponentTemplate(path) ? "angular" : undefined;
  30793. if (htmlParser) {
  30794. return printHtmlTemplateLiteral(path, print, textToDoc, htmlParser, options);
  30795. }
  30796. break;
  30797. }
  30798. case "TemplateElement":
  30799. {
  30800. /**
  30801. * md`...`
  30802. * markdown`...`
  30803. */
  30804. if (parentParent && parentParent.type === "TaggedTemplateExpression" && parent.quasis.length === 1 && parentParent.tag.type === "Identifier" && (parentParent.tag.name === "md" || parentParent.tag.name === "markdown")) {
  30805. const text = parent.quasis[0].value.raw.replace(/((?:\\\\)*)\\`/g, (_, backslashes) => "\\".repeat(backslashes.length / 2) + "`");
  30806. const indentation = getIndentation(text);
  30807. const hasIndent = indentation !== "";
  30808. return concat$5([hasIndent ? indent$2(concat$5([softline$1, printMarkdown(text.replace(new RegExp(`^${indentation}`, "gm"), ""))])) : concat$5([literalline$2, dedentToRoot$1(printMarkdown(text))]), softline$1]);
  30809. }
  30810. break;
  30811. }
  30812. }
  30813. function printMarkdown(text) {
  30814. const doc = textToDoc(text, {
  30815. parser: "markdown",
  30816. __inJsTemplate: true
  30817. }, {
  30818. stripTrailingHardline: true
  30819. });
  30820. return escapeTemplateCharacters(doc, true);
  30821. }
  30822. }
  30823. function getIndentation(str) {
  30824. const firstMatchedIndent = str.match(/^([^\S\n]*)\S/m);
  30825. return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
  30826. }
  30827. function uncook(cookedValue) {
  30828. return cookedValue.replace(/([\\`]|\${)/g, "\\$1");
  30829. }
  30830. function escapeTemplateCharacters(doc, raw) {
  30831. return mapDoc$1(doc, currentDoc => {
  30832. if (!currentDoc.parts) {
  30833. return currentDoc;
  30834. }
  30835. const parts = currentDoc.parts.map(part => {
  30836. if (typeof part === "string") {
  30837. return raw ? part.replace(/(\\*)`/g, "$1$1\\`") : uncook(part);
  30838. }
  30839. return part;
  30840. });
  30841. return Object.assign({}, currentDoc, {
  30842. parts
  30843. });
  30844. });
  30845. }
  30846. function transformCssDoc(quasisDoc, path, print) {
  30847. const parentNode = path.getValue();
  30848. const isEmpty = parentNode.quasis.length === 1 && !parentNode.quasis[0].value.raw.trim();
  30849. if (isEmpty) {
  30850. return "``";
  30851. }
  30852. const expressionDocs = parentNode.expressions ? path.map(print, "expressions") : [];
  30853. const newDoc = replacePlaceholders(quasisDoc, expressionDocs);
  30854. /* istanbul ignore if */
  30855. if (!newDoc) {
  30856. throw new Error("Couldn't insert all the expressions");
  30857. }
  30858. return concat$5(["`", indent$2(concat$5([hardline$3, newDoc])), softline$1, "`"]);
  30859. } // Search all the placeholders in the quasisDoc tree
  30860. // and replace them with the expression docs one by one
  30861. // returns a new doc with all the placeholders replaced,
  30862. // or null if it couldn't replace any expression
  30863. function replacePlaceholders(quasisDoc, expressionDocs) {
  30864. if (!expressionDocs || !expressionDocs.length) {
  30865. return quasisDoc;
  30866. }
  30867. let replaceCounter = 0;
  30868. const newDoc = mapDoc$1(quasisDoc, doc => {
  30869. if (!doc || !doc.parts || !doc.parts.length) {
  30870. return doc;
  30871. }
  30872. let {
  30873. parts
  30874. } = doc;
  30875. const atIndex = parts.indexOf("@");
  30876. const placeholderIndex = atIndex + 1;
  30877. if (atIndex > -1 && typeof parts[placeholderIndex] === "string" && parts[placeholderIndex].startsWith("prettier-placeholder")) {
  30878. // If placeholder is split, join it
  30879. const at = parts[atIndex];
  30880. const placeholder = parts[placeholderIndex];
  30881. const rest = parts.slice(placeholderIndex + 1);
  30882. parts = parts.slice(0, atIndex).concat([at + placeholder]).concat(rest);
  30883. }
  30884. const replacedParts = [];
  30885. parts.forEach(part => {
  30886. if (typeof part !== "string" || !part.includes("@prettier-placeholder")) {
  30887. replacedParts.push(part);
  30888. return;
  30889. } // When we have multiple placeholders in one line, like:
  30890. // ${Child}${Child2}:not(:first-child)
  30891. part.split(/@prettier-placeholder-(\d+)-id/).forEach((component, idx) => {
  30892. // The placeholder is always at odd indices
  30893. if (idx % 2 === 0) {
  30894. replacedParts.push(replaceNewlinesWithLiterallines$1(component));
  30895. return;
  30896. } // The component will always be a number at odd index
  30897. replacedParts.push("${", expressionDocs[component], "}");
  30898. replaceCounter++;
  30899. });
  30900. });
  30901. return Object.assign({}, doc, {
  30902. parts: replacedParts
  30903. });
  30904. });
  30905. return expressionDocs.length === replaceCounter ? newDoc : null;
  30906. }
  30907. function printGraphqlComments(lines) {
  30908. const parts = [];
  30909. let seenComment = false;
  30910. lines.map(textLine => textLine.trim()).forEach((textLine, i, array) => {
  30911. // Lines are either whitespace only, or a comment (with potential whitespace
  30912. // around it). Drop whitespace-only lines.
  30913. if (textLine === "") {
  30914. return;
  30915. }
  30916. if (array[i - 1] === "" && seenComment) {
  30917. // If a non-first comment is preceded by a blank (whitespace only) line,
  30918. // add in a blank line.
  30919. parts.push(concat$5([hardline$3, textLine]));
  30920. } else {
  30921. parts.push(textLine);
  30922. }
  30923. seenComment = true;
  30924. }); // If `lines` was whitespace only, return `null`.
  30925. return parts.length === 0 ? null : join$2(hardline$3, parts);
  30926. }
  30927. /**
  30928. * Template literal in these contexts:
  30929. * <style jsx>{`div{color:red}`}</style>
  30930. * css``
  30931. * css.global``
  30932. * css.resolve``
  30933. */
  30934. function isStyledJsx(path) {
  30935. const node = path.getValue();
  30936. const parent = path.getParentNode();
  30937. const parentParent = path.getParentNode(1);
  30938. return parentParent && node.quasis && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXElement" && parentParent.openingElement.name.name === "style" && parentParent.openingElement.attributes.some(attribute => attribute.name.name === "jsx") || parent && parent.type === "TaggedTemplateExpression" && parent.tag.type === "Identifier" && parent.tag.name === "css" || parent && parent.type === "TaggedTemplateExpression" && parent.tag.type === "MemberExpression" && parent.tag.object.name === "css" && (parent.tag.property.name === "global" || parent.tag.property.name === "resolve");
  30939. }
  30940. /**
  30941. * Angular Components can have:
  30942. * - Inline HTML template
  30943. * - Inline CSS styles
  30944. *
  30945. * ...which are both within template literals somewhere
  30946. * inside of the Component decorator factory.
  30947. *
  30948. * E.g.
  30949. * @Component({
  30950. * template: `<div>...</div>`,
  30951. * styles: [`h1 { color: blue; }`]
  30952. * })
  30953. */
  30954. function isAngularComponentStyles(path) {
  30955. return path.match(node => node.type === "TemplateLiteral", (node, name) => node.type === "ArrayExpression" && name === "elements", (node, name) => (node.type === "Property" || node.type === "ObjectProperty") && node.key.type === "Identifier" && node.key.name === "styles" && name === "value", ...angularComponentObjectExpressionPredicates);
  30956. }
  30957. function isAngularComponentTemplate(path) {
  30958. return path.match(node => node.type === "TemplateLiteral", (node, name) => (node.type === "Property" || node.type === "ObjectProperty") && node.key.type === "Identifier" && node.key.name === "template" && name === "value", ...angularComponentObjectExpressionPredicates);
  30959. }
  30960. const angularComponentObjectExpressionPredicates = [(node, name) => node.type === "ObjectExpression" && name === "properties", (node, name) => node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "Component" && name === "arguments", (node, name) => node.type === "Decorator" && name === "expression"];
  30961. /**
  30962. * styled-components template literals
  30963. */
  30964. function isStyledComponents(path) {
  30965. const parent = path.getParentNode();
  30966. if (!parent || parent.type !== "TaggedTemplateExpression") {
  30967. return false;
  30968. }
  30969. const {
  30970. tag
  30971. } = parent;
  30972. switch (tag.type) {
  30973. case "MemberExpression":
  30974. return (// styled.foo``
  30975. isStyledIdentifier(tag.object) || // Component.extend``
  30976. isStyledExtend(tag)
  30977. );
  30978. case "CallExpression":
  30979. return (// styled(Component)``
  30980. isStyledIdentifier(tag.callee) || tag.callee.type === "MemberExpression" && (tag.callee.object.type === "MemberExpression" && ( // styled.foo.attrs({})``
  30981. isStyledIdentifier(tag.callee.object.object) || // Component.extend.attrs({})``
  30982. isStyledExtend(tag.callee.object)) || // styled(Component).attrs({})``
  30983. tag.callee.object.type === "CallExpression" && isStyledIdentifier(tag.callee.object.callee))
  30984. );
  30985. case "Identifier":
  30986. // css``
  30987. return tag.name === "css";
  30988. default:
  30989. return false;
  30990. }
  30991. }
  30992. /**
  30993. * JSX element with CSS prop
  30994. */
  30995. function isCssProp(path) {
  30996. const parent = path.getParentNode();
  30997. const parentParent = path.getParentNode(1);
  30998. return parentParent && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" && parentParent.name.type === "JSXIdentifier" && parentParent.name.name === "css";
  30999. }
  31000. function isStyledIdentifier(node) {
  31001. return node.type === "Identifier" && node.name === "styled";
  31002. }
  31003. function isStyledExtend(node) {
  31004. return /^[A-Z]/.test(node.object.name) && node.property.name === "extend";
  31005. }
  31006. /*
  31007. * react-relay and graphql-tag
  31008. * graphql`...`
  31009. * graphql.experimental`...`
  31010. * gql`...`
  31011. * GraphQL comment block
  31012. *
  31013. * This intentionally excludes Relay Classic tags, as Prettier does not
  31014. * support Relay Classic formatting.
  31015. */
  31016. function isGraphQL(path) {
  31017. const node = path.getValue();
  31018. const parent = path.getParentNode();
  31019. return hasLanguageComment(node, "GraphQL") || parent && (parent.type === "TaggedTemplateExpression" && (parent.tag.type === "MemberExpression" && parent.tag.object.name === "graphql" && parent.tag.property.name === "experimental" || parent.tag.type === "Identifier" && (parent.tag.name === "gql" || parent.tag.name === "graphql")) || parent.type === "CallExpression" && parent.callee.type === "Identifier" && parent.callee.name === "graphql");
  31020. }
  31021. function hasLanguageComment(node, languageName) {
  31022. // This checks for a leading comment that is exactly `/* GraphQL */`
  31023. // In order to be in line with other implementations of this comment tag
  31024. // we will not trim the comment value and we will expect exactly one space on
  31025. // either side of the GraphQL string
  31026. // Also see ./clean.js
  31027. return hasLeadingComment$1(node, comment => isBlockComment$1(comment) && comment.value === ` ${languageName} `);
  31028. }
  31029. /**
  31030. * - html`...`
  31031. * - HTML comment block
  31032. */
  31033. function isHtml(path) {
  31034. return hasLanguageComment(path.getValue(), "HTML") || path.match(node => node.type === "TemplateLiteral", (node, name) => node.type === "TaggedTemplateExpression" && node.tag.type === "Identifier" && node.tag.name === "html" && name === "quasi");
  31035. } // The counter is needed to distinguish nested embeds.
  31036. let htmlTemplateLiteralCounter = 0;
  31037. function printHtmlTemplateLiteral(path, print, textToDoc, parser, options) {
  31038. const node = path.getValue();
  31039. const counter = htmlTemplateLiteralCounter;
  31040. htmlTemplateLiteralCounter = htmlTemplateLiteralCounter + 1 >>> 0;
  31041. const composePlaceholder = index => `PRETTIER_HTML_PLACEHOLDER_${index}_${counter}_IN_JS`;
  31042. const text = node.quasis.map((quasi, index, quasis) => index === quasis.length - 1 ? quasi.value.cooked : quasi.value.cooked + composePlaceholder(index)).join("");
  31043. const expressionDocs = path.map(print, "expressions");
  31044. if (expressionDocs.length === 0 && text.trim().length === 0) {
  31045. return "``";
  31046. }
  31047. const placeholderRegex = new RegExp(composePlaceholder("(\\d+)"), "g");
  31048. let topLevelCount = 0;
  31049. const contentDoc = mapDoc$1(textToDoc(text, {
  31050. parser,
  31051. __onHtmlRoot(root) {
  31052. topLevelCount = root.children.length;
  31053. }
  31054. }, {
  31055. stripTrailingHardline: true
  31056. }), doc => {
  31057. if (typeof doc !== "string") {
  31058. return doc;
  31059. }
  31060. const parts = [];
  31061. const components = doc.split(placeholderRegex);
  31062. for (let i = 0; i < components.length; i++) {
  31063. let component = components[i];
  31064. if (i % 2 === 0) {
  31065. if (component) {
  31066. component = uncook(component);
  31067. if (options.embeddedInHtml) {
  31068. component = component.replace(/<\/(script)\b/gi, "<\\/$1");
  31069. }
  31070. parts.push(component);
  31071. }
  31072. continue;
  31073. }
  31074. const placeholderIndex = +component;
  31075. parts.push(concat$5(["${", group$1(expressionDocs[placeholderIndex]), "}"]));
  31076. }
  31077. return concat$5(parts);
  31078. });
  31079. const leadingWhitespace = /^\s/.test(text) ? " " : "";
  31080. const trailingWhitespace = /\s$/.test(text) ? " " : "";
  31081. const linebreak = options.htmlWhitespaceSensitivity === "ignore" ? hardline$3 : leadingWhitespace && trailingWhitespace ? line$3 : null;
  31082. if (linebreak) {
  31083. return group$1(concat$5(["`", indent$2(concat$5([linebreak, group$1(contentDoc)])), linebreak, "`"]));
  31084. }
  31085. return group$1(concat$5(["`", leadingWhitespace, topLevelCount > 1 ? indent$2(group$1(contentDoc)) : group$1(contentDoc), trailingWhitespace, "`"]));
  31086. }
  31087. var embed_1 = embed;
  31088. function clean(ast, newObj, parent) {
  31089. ["range", "raw", "comments", "leadingComments", "trailingComments", "innerComments", "extra", "start", "end", "loc", "flags", "errors", "tokens"].forEach(name => {
  31090. delete newObj[name];
  31091. });
  31092. if (ast.type === "Program") {
  31093. delete newObj.sourceType;
  31094. }
  31095. if (ast.type === "BigIntLiteral") {
  31096. if (newObj.value) {
  31097. newObj.value = newObj.value.toLowerCase();
  31098. }
  31099. if (newObj.bigint) {
  31100. newObj.bigint = newObj.bigint.toLowerCase();
  31101. }
  31102. }
  31103. if (ast.type === "DecimalLiteral") {
  31104. newObj.value = Number(newObj.value);
  31105. } // We remove extra `;` and add them when needed
  31106. if (ast.type === "EmptyStatement") {
  31107. return null;
  31108. } // We move text around, including whitespaces and add {" "}
  31109. if (ast.type === "JSXText") {
  31110. return null;
  31111. }
  31112. if (ast.type === "JSXExpressionContainer" && (ast.expression.type === "Literal" || ast.expression.type === "StringLiteral") && ast.expression.value === " ") {
  31113. return null;
  31114. } // We change {'key': value} into {key: value}.
  31115. // And {key: value} into {'key': value}.
  31116. // Also for (some) number keys.
  31117. if ((ast.type === "Property" || ast.type === "ObjectProperty" || ast.type === "MethodDefinition" || ast.type === "ClassProperty" || ast.type === "ClassMethod" || ast.type === "TSDeclareMethod" || ast.type === "TSPropertySignature" || ast.type === "ObjectTypeProperty") && typeof ast.key === "object" && ast.key && (ast.key.type === "Literal" || ast.key.type === "NumericLiteral" || ast.key.type === "StringLiteral" || ast.key.type === "Identifier")) {
  31118. delete newObj.key;
  31119. }
  31120. if (ast.type === "OptionalMemberExpression" && ast.optional === false) {
  31121. newObj.type = "MemberExpression";
  31122. delete newObj.optional;
  31123. } // Remove raw and cooked values from TemplateElement when it's CSS
  31124. // styled-jsx
  31125. if (ast.type === "JSXElement" && ast.openingElement.name.name === "style" && ast.openingElement.attributes.some(attr => attr.name.name === "jsx")) {
  31126. const templateLiterals = newObj.children.filter(child => child.type === "JSXExpressionContainer" && child.expression.type === "TemplateLiteral").map(container => container.expression);
  31127. const quasis = templateLiterals.reduce((quasis, templateLiteral) => quasis.concat(templateLiteral.quasis), []);
  31128. quasis.forEach(q => delete q.value);
  31129. } // CSS template literals in css prop
  31130. if (ast.type === "JSXAttribute" && ast.name.name === "css" && ast.value.type === "JSXExpressionContainer" && ast.value.expression.type === "TemplateLiteral") {
  31131. newObj.value.expression.quasis.forEach(q => delete q.value);
  31132. } // We change quotes
  31133. if (ast.type === "JSXAttribute" && ast.value && ast.value.type === "Literal" && /["']|&quot;|&apos;/.test(ast.value.value)) {
  31134. newObj.value.value = newObj.value.value.replace(/["']|&quot;|&apos;/g, '"');
  31135. } // Angular Components: Inline HTML template and Inline CSS styles
  31136. const expression = ast.expression || ast.callee;
  31137. if (ast.type === "Decorator" && expression.type === "CallExpression" && expression.callee.name === "Component" && expression.arguments.length === 1) {
  31138. const astProps = ast.expression.arguments[0].properties;
  31139. newObj.expression.arguments[0].properties.forEach((prop, index) => {
  31140. let templateLiteral = null;
  31141. switch (astProps[index].key.name) {
  31142. case "styles":
  31143. if (prop.value.type === "ArrayExpression") {
  31144. templateLiteral = prop.value.elements[0];
  31145. }
  31146. break;
  31147. case "template":
  31148. if (prop.value.type === "TemplateLiteral") {
  31149. templateLiteral = prop.value;
  31150. }
  31151. break;
  31152. }
  31153. if (templateLiteral) {
  31154. templateLiteral.quasis.forEach(q => delete q.value);
  31155. }
  31156. });
  31157. } // styled-components, graphql, markdown
  31158. if (ast.type === "TaggedTemplateExpression" && (ast.tag.type === "MemberExpression" || ast.tag.type === "Identifier" && (ast.tag.name === "gql" || ast.tag.name === "graphql" || ast.tag.name === "css" || ast.tag.name === "md" || ast.tag.name === "markdown" || ast.tag.name === "html") || ast.tag.type === "CallExpression")) {
  31159. newObj.quasi.quasis.forEach(quasi => delete quasi.value);
  31160. }
  31161. if (ast.type === "TemplateLiteral") {
  31162. // This checks for a leading comment that is exactly `/* GraphQL */`
  31163. // In order to be in line with other implementations of this comment tag
  31164. // we will not trim the comment value and we will expect exactly one space on
  31165. // either side of the GraphQL string
  31166. // Also see ./embed.js
  31167. const hasLanguageComment = ast.leadingComments && ast.leadingComments.some(comment => comment.type === "CommentBlock" && ["GraphQL", "HTML"].some(languageName => comment.value === ` ${languageName} `));
  31168. if (hasLanguageComment || parent.type === "CallExpression" && parent.callee.name === "graphql") {
  31169. newObj.quasis.forEach(quasi => delete quasi.value);
  31170. } // TODO: check parser
  31171. // `flow` and `typescript` don't have `leadingComments`
  31172. if (!ast.leadingComments) {
  31173. newObj.quasis.forEach(quasi => {
  31174. if (quasi.value) {
  31175. delete quasi.value.cooked;
  31176. }
  31177. });
  31178. }
  31179. }
  31180. if (ast.type === "InterpreterDirective") {
  31181. newObj.value = newObj.value.trimEnd();
  31182. }
  31183. }
  31184. var clean_1 = clean;
  31185. const detectNewline = string => {
  31186. if (typeof string !== 'string') {
  31187. throw new TypeError('Expected a string');
  31188. }
  31189. const newlines = string.match(/(?:\r?\n)/g) || [];
  31190. if (newlines.length === 0) {
  31191. return;
  31192. }
  31193. const crlf = newlines.filter(newline => newline === '\r\n').length;
  31194. const lf = newlines.length - crlf;
  31195. return crlf > lf ? '\r\n' : '\n';
  31196. };
  31197. var detectNewline_1 = detectNewline;
  31198. var graceful = string => typeof string === 'string' && detectNewline(string) || '\n';
  31199. detectNewline_1.graceful = graceful;
  31200. var build = createCommonjsModule(function (module, exports) {
  31201. Object.defineProperty(exports, '__esModule', {
  31202. value: true
  31203. });
  31204. exports.extract = extract;
  31205. exports.strip = strip;
  31206. exports.parse = parse;
  31207. exports.parseWithComments = parseWithComments;
  31208. exports.print = print;
  31209. function _os() {
  31210. const data = os__default['default'];
  31211. _os = function () {
  31212. return data;
  31213. };
  31214. return data;
  31215. }
  31216. function _detectNewline() {
  31217. const data = _interopRequireDefault(detectNewline_1);
  31218. _detectNewline = function () {
  31219. return data;
  31220. };
  31221. return data;
  31222. }
  31223. function _interopRequireDefault(obj) {
  31224. return obj && obj.__esModule ? obj : {
  31225. default: obj
  31226. };
  31227. }
  31228. /**
  31229. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  31230. *
  31231. * This source code is licensed under the MIT license found in the
  31232. * LICENSE file in the root directory of this source tree.
  31233. */
  31234. const commentEndRe = /\*\/$/;
  31235. const commentStartRe = /^\/\*\*/;
  31236. const docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
  31237. const lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g;
  31238. const ltrimNewlineRe = /^(\r?\n)+/;
  31239. const multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *(?![^@\r\n]*\/\/[^]*)([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
  31240. const propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
  31241. const stringStartRe = /(\r?\n|^) *\* ?/g;
  31242. const STRING_ARRAY = [];
  31243. function extract(contents) {
  31244. const match = contents.match(docblockRe);
  31245. return match ? match[0].trimLeft() : '';
  31246. }
  31247. function strip(contents) {
  31248. const match = contents.match(docblockRe);
  31249. return match && match[0] ? contents.substring(match[0].length) : contents;
  31250. }
  31251. function parse(docblock) {
  31252. return parseWithComments(docblock).pragmas;
  31253. }
  31254. function parseWithComments(docblock) {
  31255. const line = (0, _detectNewline().default)(docblock) || _os().EOL;
  31256. docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(stringStartRe, '$1'); // Normalize multi-line directives
  31257. let prev = '';
  31258. while (prev !== docblock) {
  31259. prev = docblock;
  31260. docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`);
  31261. }
  31262. docblock = docblock.replace(ltrimNewlineRe, '').trimRight();
  31263. const result = Object.create(null);
  31264. const comments = docblock.replace(propertyRe, '').replace(ltrimNewlineRe, '').trimRight();
  31265. let match;
  31266. while (match = propertyRe.exec(docblock)) {
  31267. // strip linecomments from pragmas
  31268. const nextPragma = match[2].replace(lineCommentRe, '');
  31269. if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) {
  31270. result[match[1]] = STRING_ARRAY.concat(result[match[1]], nextPragma);
  31271. } else {
  31272. result[match[1]] = nextPragma;
  31273. }
  31274. }
  31275. return {
  31276. comments,
  31277. pragmas: result
  31278. };
  31279. }
  31280. function print({
  31281. comments = '',
  31282. pragmas = {}
  31283. }) {
  31284. const line = (0, _detectNewline().default)(comments) || _os().EOL;
  31285. const head = '/**';
  31286. const start = ' *';
  31287. const tail = ' */';
  31288. const keys = Object.keys(pragmas);
  31289. const printedObject = keys.map(key => printKeyValues(key, pragmas[key])).reduce((arr, next) => arr.concat(next), []).map(keyValue => start + ' ' + keyValue + line).join('');
  31290. if (!comments) {
  31291. if (keys.length === 0) {
  31292. return '';
  31293. }
  31294. if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) {
  31295. const value = pragmas[keys[0]];
  31296. return `${head} ${printKeyValues(keys[0], value)[0]}${tail}`;
  31297. }
  31298. }
  31299. const printedComments = comments.split(line).map(textLine => `${start} ${textLine}`).join(line) + line;
  31300. return head + line + (comments ? printedComments : '') + (comments && keys.length ? start + line : '') + printedObject + tail;
  31301. }
  31302. function printKeyValues(key, valueOrArray) {
  31303. return STRING_ARRAY.concat(valueOrArray).map(value => `@${key} ${value}`.trim());
  31304. }
  31305. });
  31306. const {
  31307. parseWithComments,
  31308. strip,
  31309. extract,
  31310. print
  31311. } = build;
  31312. const {
  31313. getShebang: getShebang$1
  31314. } = util;
  31315. const {
  31316. normalizeEndOfLine: normalizeEndOfLine$2
  31317. } = endOfLine;
  31318. function parseDocBlock(text) {
  31319. const shebang = getShebang$1(text);
  31320. if (shebang) {
  31321. text = text.slice(shebang.length + 1);
  31322. }
  31323. const docBlock = extract(text);
  31324. const {
  31325. pragmas,
  31326. comments
  31327. } = parseWithComments(docBlock);
  31328. return {
  31329. shebang,
  31330. text,
  31331. pragmas,
  31332. comments
  31333. };
  31334. }
  31335. function hasPragma(text) {
  31336. const pragmas = Object.keys(parseDocBlock(text).pragmas);
  31337. return pragmas.includes("prettier") || pragmas.includes("format");
  31338. }
  31339. function insertPragma(originalText) {
  31340. const {
  31341. shebang,
  31342. text,
  31343. pragmas,
  31344. comments
  31345. } = parseDocBlock(originalText);
  31346. const strippedText = strip(text);
  31347. const docBlock = print({
  31348. pragmas: Object.assign({
  31349. format: ""
  31350. }, pragmas),
  31351. comments: comments.trimStart()
  31352. });
  31353. return (shebang ? `${shebang}\n` : "") + // normalise newlines (mitigate use of os.EOL by jest-docblock)
  31354. normalizeEndOfLine$2(docBlock) + (strippedText.startsWith("\n") ? "\n" : "\n\n") + strippedText;
  31355. }
  31356. var pragma = {
  31357. hasPragma,
  31358. insertPragma
  31359. };
  31360. var ast = createCommonjsModule(function (module) {
  31361. /*
  31362. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  31363. Redistribution and use in source and binary forms, with or without
  31364. modification, are permitted provided that the following conditions are met:
  31365. * Redistributions of source code must retain the above copyright
  31366. notice, this list of conditions and the following disclaimer.
  31367. * Redistributions in binary form must reproduce the above copyright
  31368. notice, this list of conditions and the following disclaimer in the
  31369. documentation and/or other materials provided with the distribution.
  31370. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  31371. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31372. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31373. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  31374. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  31375. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31376. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  31377. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31378. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31379. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31380. */
  31381. (function () {
  31382. function isExpression(node) {
  31383. if (node == null) {
  31384. return false;
  31385. }
  31386. switch (node.type) {
  31387. case 'ArrayExpression':
  31388. case 'AssignmentExpression':
  31389. case 'BinaryExpression':
  31390. case 'CallExpression':
  31391. case 'ConditionalExpression':
  31392. case 'FunctionExpression':
  31393. case 'Identifier':
  31394. case 'Literal':
  31395. case 'LogicalExpression':
  31396. case 'MemberExpression':
  31397. case 'NewExpression':
  31398. case 'ObjectExpression':
  31399. case 'SequenceExpression':
  31400. case 'ThisExpression':
  31401. case 'UnaryExpression':
  31402. case 'UpdateExpression':
  31403. return true;
  31404. }
  31405. return false;
  31406. }
  31407. function isIterationStatement(node) {
  31408. if (node == null) {
  31409. return false;
  31410. }
  31411. switch (node.type) {
  31412. case 'DoWhileStatement':
  31413. case 'ForInStatement':
  31414. case 'ForStatement':
  31415. case 'WhileStatement':
  31416. return true;
  31417. }
  31418. return false;
  31419. }
  31420. function isStatement(node) {
  31421. if (node == null) {
  31422. return false;
  31423. }
  31424. switch (node.type) {
  31425. case 'BlockStatement':
  31426. case 'BreakStatement':
  31427. case 'ContinueStatement':
  31428. case 'DebuggerStatement':
  31429. case 'DoWhileStatement':
  31430. case 'EmptyStatement':
  31431. case 'ExpressionStatement':
  31432. case 'ForInStatement':
  31433. case 'ForStatement':
  31434. case 'IfStatement':
  31435. case 'LabeledStatement':
  31436. case 'ReturnStatement':
  31437. case 'SwitchStatement':
  31438. case 'ThrowStatement':
  31439. case 'TryStatement':
  31440. case 'VariableDeclaration':
  31441. case 'WhileStatement':
  31442. case 'WithStatement':
  31443. return true;
  31444. }
  31445. return false;
  31446. }
  31447. function isSourceElement(node) {
  31448. return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
  31449. }
  31450. function trailingStatement(node) {
  31451. switch (node.type) {
  31452. case 'IfStatement':
  31453. if (node.alternate != null) {
  31454. return node.alternate;
  31455. }
  31456. return node.consequent;
  31457. case 'LabeledStatement':
  31458. case 'ForStatement':
  31459. case 'ForInStatement':
  31460. case 'WhileStatement':
  31461. case 'WithStatement':
  31462. return node.body;
  31463. }
  31464. return null;
  31465. }
  31466. function isProblematicIfStatement(node) {
  31467. var current;
  31468. if (node.type !== 'IfStatement') {
  31469. return false;
  31470. }
  31471. if (node.alternate == null) {
  31472. return false;
  31473. }
  31474. current = node.consequent;
  31475. do {
  31476. if (current.type === 'IfStatement') {
  31477. if (current.alternate == null) {
  31478. return true;
  31479. }
  31480. }
  31481. current = trailingStatement(current);
  31482. } while (current);
  31483. return false;
  31484. }
  31485. module.exports = {
  31486. isExpression: isExpression,
  31487. isStatement: isStatement,
  31488. isIterationStatement: isIterationStatement,
  31489. isSourceElement: isSourceElement,
  31490. isProblematicIfStatement: isProblematicIfStatement,
  31491. trailingStatement: trailingStatement
  31492. };
  31493. })();
  31494. /* vim: set sw=4 ts=4 et tw=80 : */
  31495. });
  31496. var code = createCommonjsModule(function (module) {
  31497. /*
  31498. Copyright (C) 2013-2014 Yusuke Suzuki <utatane.tea@gmail.com>
  31499. Copyright (C) 2014 Ivan Nikulin <ifaaan@gmail.com>
  31500. Redistribution and use in source and binary forms, with or without
  31501. modification, are permitted provided that the following conditions are met:
  31502. * Redistributions of source code must retain the above copyright
  31503. notice, this list of conditions and the following disclaimer.
  31504. * Redistributions in binary form must reproduce the above copyright
  31505. notice, this list of conditions and the following disclaimer in the
  31506. documentation and/or other materials provided with the distribution.
  31507. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  31508. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31509. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31510. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  31511. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  31512. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31513. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  31514. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31515. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31516. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31517. */
  31518. (function () {
  31519. var ES6Regex, ES5Regex, NON_ASCII_WHITESPACES, IDENTIFIER_START, IDENTIFIER_PART, ch; // See `tools/generate-identifier-regex.js`.
  31520. ES5Regex = {
  31521. // ECMAScript 5.1/Unicode v9.0.0 NonAsciiIdentifierStart:
  31522. NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\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-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\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\u0AF9\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-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\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-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\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-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\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]/,
  31523. // ECMAScript 5.1/Unicode v9.0.0 NonAsciiIdentifierPart:
  31524. NonAsciiIdentifierPart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\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\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFB-\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\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\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-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/
  31525. };
  31526. ES6Regex = {
  31527. // ECMAScript 6/Unicode v9.0.0 NonAsciiIdentifierStart:
  31528. NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\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-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\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\u0AF9\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-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\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-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\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\u2118-\u211D\u2124\u2126\u2128\u212A-\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\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\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]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/,
  31529. // ECMAScript 6/Unicode v9.0.0 NonAsciiIdentifierPart:
  31530. NonAsciiIdentifierPart: /[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\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\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFB-\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\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
  31531. };
  31532. function isDecimalDigit(ch) {
  31533. return 0x30 <= ch && ch <= 0x39; // 0..9
  31534. }
  31535. function isHexDigit(ch) {
  31536. return 0x30 <= ch && ch <= 0x39 || // 0..9
  31537. 0x61 <= ch && ch <= 0x66 || // a..f
  31538. 0x41 <= ch && ch <= 0x46; // A..F
  31539. }
  31540. function isOctalDigit(ch) {
  31541. return ch >= 0x30 && ch <= 0x37; // 0..7
  31542. } // 7.2 White Space
  31543. NON_ASCII_WHITESPACES = [0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF];
  31544. function isWhiteSpace(ch) {
  31545. return ch === 0x20 || ch === 0x09 || ch === 0x0B || ch === 0x0C || ch === 0xA0 || ch >= 0x1680 && NON_ASCII_WHITESPACES.indexOf(ch) >= 0;
  31546. } // 7.3 Line Terminators
  31547. function isLineTerminator(ch) {
  31548. return ch === 0x0A || ch === 0x0D || ch === 0x2028 || ch === 0x2029;
  31549. } // 7.6 Identifier Names and Identifiers
  31550. function fromCodePoint(cp) {
  31551. if (cp <= 0xFFFF) {
  31552. return String.fromCharCode(cp);
  31553. }
  31554. var cu1 = String.fromCharCode(Math.floor((cp - 0x10000) / 0x400) + 0xD800);
  31555. var cu2 = String.fromCharCode((cp - 0x10000) % 0x400 + 0xDC00);
  31556. return cu1 + cu2;
  31557. }
  31558. IDENTIFIER_START = new Array(0x80);
  31559. for (ch = 0; ch < 0x80; ++ch) {
  31560. IDENTIFIER_START[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  31561. ch >= 0x41 && ch <= 0x5A || // A..Z
  31562. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  31563. }
  31564. IDENTIFIER_PART = new Array(0x80);
  31565. for (ch = 0; ch < 0x80; ++ch) {
  31566. IDENTIFIER_PART[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  31567. ch >= 0x41 && ch <= 0x5A || // A..Z
  31568. ch >= 0x30 && ch <= 0x39 || // 0..9
  31569. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  31570. }
  31571. function isIdentifierStartES5(ch) {
  31572. return ch < 0x80 ? IDENTIFIER_START[ch] : ES5Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  31573. }
  31574. function isIdentifierPartES5(ch) {
  31575. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES5Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  31576. }
  31577. function isIdentifierStartES6(ch) {
  31578. return ch < 0x80 ? IDENTIFIER_START[ch] : ES6Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  31579. }
  31580. function isIdentifierPartES6(ch) {
  31581. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES6Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  31582. }
  31583. module.exports = {
  31584. isDecimalDigit: isDecimalDigit,
  31585. isHexDigit: isHexDigit,
  31586. isOctalDigit: isOctalDigit,
  31587. isWhiteSpace: isWhiteSpace,
  31588. isLineTerminator: isLineTerminator,
  31589. isIdentifierStartES5: isIdentifierStartES5,
  31590. isIdentifierPartES5: isIdentifierPartES5,
  31591. isIdentifierStartES6: isIdentifierStartES6,
  31592. isIdentifierPartES6: isIdentifierPartES6
  31593. };
  31594. })();
  31595. /* vim: set sw=4 ts=4 et tw=80 : */
  31596. });
  31597. var keyword$1 = createCommonjsModule(function (module) {
  31598. /*
  31599. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  31600. Redistribution and use in source and binary forms, with or without
  31601. modification, are permitted provided that the following conditions are met:
  31602. * Redistributions of source code must retain the above copyright
  31603. notice, this list of conditions and the following disclaimer.
  31604. * Redistributions in binary form must reproduce the above copyright
  31605. notice, this list of conditions and the following disclaimer in the
  31606. documentation and/or other materials provided with the distribution.
  31607. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  31608. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31609. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31610. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  31611. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  31612. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31613. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  31614. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31615. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31616. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31617. */
  31618. (function () {
  31619. var code$1 = code;
  31620. function isStrictModeReservedWordES6(id) {
  31621. switch (id) {
  31622. case 'implements':
  31623. case 'interface':
  31624. case 'package':
  31625. case 'private':
  31626. case 'protected':
  31627. case 'public':
  31628. case 'static':
  31629. case 'let':
  31630. return true;
  31631. default:
  31632. return false;
  31633. }
  31634. }
  31635. function isKeywordES5(id, strict) {
  31636. // yield should not be treated as keyword under non-strict mode.
  31637. if (!strict && id === 'yield') {
  31638. return false;
  31639. }
  31640. return isKeywordES6(id, strict);
  31641. }
  31642. function isKeywordES6(id, strict) {
  31643. if (strict && isStrictModeReservedWordES6(id)) {
  31644. return true;
  31645. }
  31646. switch (id.length) {
  31647. case 2:
  31648. return id === 'if' || id === 'in' || id === 'do';
  31649. case 3:
  31650. return id === 'var' || id === 'for' || id === 'new' || id === 'try';
  31651. case 4:
  31652. return id === 'this' || id === 'else' || id === 'case' || id === 'void' || id === 'with' || id === 'enum';
  31653. case 5:
  31654. return id === 'while' || id === 'break' || id === 'catch' || id === 'throw' || id === 'const' || id === 'yield' || id === 'class' || id === 'super';
  31655. case 6:
  31656. return id === 'return' || id === 'typeof' || id === 'delete' || id === 'switch' || id === 'export' || id === 'import';
  31657. case 7:
  31658. return id === 'default' || id === 'finally' || id === 'extends';
  31659. case 8:
  31660. return id === 'function' || id === 'continue' || id === 'debugger';
  31661. case 10:
  31662. return id === 'instanceof';
  31663. default:
  31664. return false;
  31665. }
  31666. }
  31667. function isReservedWordES5(id, strict) {
  31668. return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
  31669. }
  31670. function isReservedWordES6(id, strict) {
  31671. return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
  31672. }
  31673. function isRestrictedWord(id) {
  31674. return id === 'eval' || id === 'arguments';
  31675. }
  31676. function isIdentifierNameES5(id) {
  31677. var i, iz, ch;
  31678. if (id.length === 0) {
  31679. return false;
  31680. }
  31681. ch = id.charCodeAt(0);
  31682. if (!code$1.isIdentifierStartES5(ch)) {
  31683. return false;
  31684. }
  31685. for (i = 1, iz = id.length; i < iz; ++i) {
  31686. ch = id.charCodeAt(i);
  31687. if (!code$1.isIdentifierPartES5(ch)) {
  31688. return false;
  31689. }
  31690. }
  31691. return true;
  31692. }
  31693. function decodeUtf16(lead, trail) {
  31694. return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  31695. }
  31696. function isIdentifierNameES6(id) {
  31697. var i, iz, ch, lowCh, check;
  31698. if (id.length === 0) {
  31699. return false;
  31700. }
  31701. check = code$1.isIdentifierStartES6;
  31702. for (i = 0, iz = id.length; i < iz; ++i) {
  31703. ch = id.charCodeAt(i);
  31704. if (0xD800 <= ch && ch <= 0xDBFF) {
  31705. ++i;
  31706. if (i >= iz) {
  31707. return false;
  31708. }
  31709. lowCh = id.charCodeAt(i);
  31710. if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {
  31711. return false;
  31712. }
  31713. ch = decodeUtf16(ch, lowCh);
  31714. }
  31715. if (!check(ch)) {
  31716. return false;
  31717. }
  31718. check = code$1.isIdentifierPartES6;
  31719. }
  31720. return true;
  31721. }
  31722. function isIdentifierES5(id, strict) {
  31723. return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);
  31724. }
  31725. function isIdentifierES6(id, strict) {
  31726. return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);
  31727. }
  31728. module.exports = {
  31729. isKeywordES5: isKeywordES5,
  31730. isKeywordES6: isKeywordES6,
  31731. isReservedWordES5: isReservedWordES5,
  31732. isReservedWordES6: isReservedWordES6,
  31733. isRestrictedWord: isRestrictedWord,
  31734. isIdentifierNameES5: isIdentifierNameES5,
  31735. isIdentifierNameES6: isIdentifierNameES6,
  31736. isIdentifierES5: isIdentifierES5,
  31737. isIdentifierES6: isIdentifierES6
  31738. };
  31739. })();
  31740. /* vim: set sw=4 ts=4 et tw=80 : */
  31741. });
  31742. var utils$5 = createCommonjsModule(function (module, exports) {
  31743. /*
  31744. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  31745. Redistribution and use in source and binary forms, with or without
  31746. modification, are permitted provided that the following conditions are met:
  31747. * Redistributions of source code must retain the above copyright
  31748. notice, this list of conditions and the following disclaimer.
  31749. * Redistributions in binary form must reproduce the above copyright
  31750. notice, this list of conditions and the following disclaimer in the
  31751. documentation and/or other materials provided with the distribution.
  31752. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  31753. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31754. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31755. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  31756. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  31757. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31758. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  31759. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31760. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31761. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31762. */
  31763. (function () {
  31764. exports.ast = ast;
  31765. exports.code = code;
  31766. exports.keyword = keyword$1;
  31767. })();
  31768. /* vim: set sw=4 ts=4 et tw=80 : */
  31769. });
  31770. const isIdentifierName = utils$5.keyword.isIdentifierNameES5;
  31771. const {
  31772. getLast: getLast$2,
  31773. hasNewline: hasNewline$4,
  31774. hasNewlineInRange: hasNewlineInRange$3,
  31775. hasIgnoreComment: hasIgnoreComment$1,
  31776. hasNodeIgnoreComment: hasNodeIgnoreComment$1,
  31777. skipWhitespace: skipWhitespace$2
  31778. } = util;
  31779. /**
  31780. * @typedef {import("./types/estree").Node} Node
  31781. * @typedef {import("./types/estree").TemplateLiteral} TemplateLiteral
  31782. * @typedef {import("./types/estree").Comment} Comment
  31783. * @typedef {import("./types/estree").MemberExpression} MemberExpression
  31784. * @typedef {import("./types/estree").OptionalMemberExpression} OptionalMemberExpression
  31785. * @typedef {import("./types/estree").CallExpression} CallExpression
  31786. * @typedef {import("./types/estree").OptionalCallExpression} OptionalCallExpression
  31787. * @typedef {import("./types/estree").Expression} Expression
  31788. * @typedef {import("./types/estree").Property} Property
  31789. * @typedef {import("./types/estree").ObjectTypeProperty} ObjectTypeProperty
  31790. * @typedef {import("./types/estree").JSXElement} JSXElement
  31791. * @typedef {import("./types/estree").TaggedTemplateExpression} TaggedTemplateExpression
  31792. * @typedef {import("./types/estree").Literal} Literal
  31793. *
  31794. * @typedef {import("../common/fast-path")} FastPath
  31795. */
  31796. // We match any whitespace except line terminators because
  31797. // Flow annotation comments cannot be split across lines. For example:
  31798. //
  31799. // (this /*
  31800. // : any */).foo = 5;
  31801. //
  31802. // is not picked up by Flow (see https://github.com/facebook/flow/issues/7050), so
  31803. // removing the newline would create a type annotation that the user did not intend
  31804. // to create.
  31805. const NON_LINE_TERMINATING_WHITE_SPACE = "(?:(?=.)\\s)";
  31806. const FLOW_SHORTHAND_ANNOTATION = new RegExp(`^${NON_LINE_TERMINATING_WHITE_SPACE}*:`);
  31807. const FLOW_ANNOTATION = new RegExp(`^${NON_LINE_TERMINATING_WHITE_SPACE}*::`);
  31808. /**
  31809. * @param {Node} node
  31810. * @returns {boolean}
  31811. */
  31812. function hasFlowShorthandAnnotationComment(node) {
  31813. // https://flow.org/en/docs/types/comments/
  31814. // Syntax example: const r = new (window.Request /*: Class<Request> */)("");
  31815. return node.extra && node.extra.parenthesized && node.trailingComments && FLOW_SHORTHAND_ANNOTATION.test(node.trailingComments[0].value);
  31816. }
  31817. /**
  31818. * @param {Comment[]} comments
  31819. * @returns {boolean}
  31820. */
  31821. function hasFlowAnnotationComment(comments) {
  31822. return comments && FLOW_ANNOTATION.test(comments[0].value);
  31823. }
  31824. /**
  31825. * @param {Node} node
  31826. * @param {(Node) => boolean} fn
  31827. * @returns {boolean}
  31828. */
  31829. function hasNode(node, fn) {
  31830. if (!node || typeof node !== "object") {
  31831. return false;
  31832. }
  31833. if (Array.isArray(node)) {
  31834. return node.some(value => hasNode(value, fn));
  31835. }
  31836. const result = fn(node);
  31837. return typeof result === "boolean" ? result : Object.keys(node).some(key => hasNode(node[key], fn));
  31838. }
  31839. /**
  31840. * @param {Node} node
  31841. * @returns {boolean}
  31842. */
  31843. function hasNakedLeftSide(node) {
  31844. return node.type === "AssignmentExpression" || node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression" || node.type === "ConditionalExpression" || node.type === "CallExpression" || node.type === "OptionalCallExpression" || node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "BindExpression" || node.type === "UpdateExpression" && !node.prefix || node.type === "TSAsExpression" || node.type === "TSNonNullExpression";
  31845. }
  31846. function getLeftSide(node) {
  31847. if (node.expressions) {
  31848. return node.expressions[0];
  31849. }
  31850. return node.left || node.test || node.callee || node.object || node.tag || node.argument || node.expression;
  31851. }
  31852. function getLeftSidePathName(path, node) {
  31853. if (node.expressions) {
  31854. return ["expressions", 0];
  31855. }
  31856. if (node.left) {
  31857. return ["left"];
  31858. }
  31859. if (node.test) {
  31860. return ["test"];
  31861. }
  31862. if (node.object) {
  31863. return ["object"];
  31864. }
  31865. if (node.callee) {
  31866. return ["callee"];
  31867. }
  31868. if (node.tag) {
  31869. return ["tag"];
  31870. }
  31871. if (node.argument) {
  31872. return ["argument"];
  31873. }
  31874. if (node.expression) {
  31875. return ["expression"];
  31876. }
  31877. throw new Error("Unexpected node has no left side.");
  31878. }
  31879. const exportDeclarationTypes = new Set(["ExportDefaultDeclaration", "ExportDefaultSpecifier", "DeclareExportDeclaration", "ExportNamedDeclaration", "ExportAllDeclaration"]);
  31880. /**
  31881. * @param {Node} node
  31882. * @returns {boolean}
  31883. */
  31884. function isExportDeclaration(node) {
  31885. return node && exportDeclarationTypes.has(node.type);
  31886. }
  31887. /**
  31888. * @param {FastPath} path
  31889. * @returns {Node | null}
  31890. */
  31891. function getParentExportDeclaration(path) {
  31892. const parentNode = path.getParentNode();
  31893. if (path.getName() === "declaration" && isExportDeclaration(parentNode)) {
  31894. return parentNode;
  31895. }
  31896. return null;
  31897. }
  31898. /**
  31899. * @param {Node} node
  31900. * @returns {boolean}
  31901. */
  31902. function isLiteral(node) {
  31903. return node.type === "BooleanLiteral" || node.type === "DirectiveLiteral" || node.type === "Literal" || node.type === "NullLiteral" || node.type === "NumericLiteral" || node.type === "BigIntLiteral" || node.type === "DecimalLiteral" || node.type === "RegExpLiteral" || node.type === "StringLiteral" || node.type === "TemplateLiteral" || node.type === "TSTypeLiteral" || node.type === "JSXText";
  31904. }
  31905. /**
  31906. * @param {Node} node
  31907. * @returns {boolean}
  31908. */
  31909. function isNumericLiteral(node) {
  31910. return node.type === "NumericLiteral" || node.type === "Literal" && typeof node.value === "number";
  31911. }
  31912. /**
  31913. * @param {Node} node
  31914. * @returns {boolean}
  31915. */
  31916. function isStringLiteral(node) {
  31917. return node.type === "StringLiteral" || node.type === "Literal" && typeof node.value === "string";
  31918. }
  31919. /**
  31920. * @param {Node} node
  31921. * @returns {boolean}
  31922. */
  31923. function isObjectType(node) {
  31924. return node.type === "ObjectTypeAnnotation" || node.type === "TSTypeLiteral";
  31925. }
  31926. /**
  31927. * @param {Node} node
  31928. * @returns {boolean}
  31929. */
  31930. function isFunctionOrArrowExpression(node) {
  31931. return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
  31932. }
  31933. /**
  31934. * @param {Node} node
  31935. * @returns {boolean}
  31936. */
  31937. function isFunctionOrArrowExpressionWithBody(node) {
  31938. return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" && node.body.type === "BlockStatement";
  31939. }
  31940. /**
  31941. * @param {Node} node
  31942. * @returns {boolean}
  31943. */
  31944. function isTemplateLiteral(node) {
  31945. return node.type === "TemplateLiteral";
  31946. }
  31947. /**
  31948. * Note: `inject` is used in AngularJS 1.x, `async` in Angular 2+
  31949. * example: https://docs.angularjs.org/guide/unit-testing#using-beforeall-
  31950. *
  31951. * @param {Node} node
  31952. * @returns {boolean}
  31953. */
  31954. function isAngularTestWrapper(node) {
  31955. return (node.type === "CallExpression" || node.type === "OptionalCallExpression") && node.callee.type === "Identifier" && (node.callee.name === "async" || node.callee.name === "inject" || node.callee.name === "fakeAsync");
  31956. }
  31957. /**
  31958. * @param {Node} node
  31959. * @returns {boolean}
  31960. */
  31961. function isJSXNode(node) {
  31962. return node.type === "JSXElement" || node.type === "JSXFragment";
  31963. }
  31964. function isTheOnlyJSXElementInMarkdown(options, path) {
  31965. if (options.parentParser !== "markdown" && options.parentParser !== "mdx") {
  31966. return false;
  31967. }
  31968. const node = path.getNode();
  31969. if (!node.expression || !isJSXNode(node.expression)) {
  31970. return false;
  31971. }
  31972. const parent = path.getParentNode();
  31973. return parent.type === "Program" && parent.body.length === 1;
  31974. } // Detect an expression node representing `{" "}`
  31975. function isJSXWhitespaceExpression(node) {
  31976. return node.type === "JSXExpressionContainer" && isLiteral(node.expression) && node.expression.value === " " && !node.expression.comments;
  31977. }
  31978. /**
  31979. * @param {Node} node
  31980. * @returns {boolean}
  31981. */
  31982. function isMemberExpressionChain(node) {
  31983. if (node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression") {
  31984. return false;
  31985. }
  31986. if (node.object.type === "Identifier") {
  31987. return true;
  31988. }
  31989. return isMemberExpressionChain(node.object);
  31990. }
  31991. function isGetterOrSetter(node) {
  31992. return node.kind === "get" || node.kind === "set";
  31993. }
  31994. /**
  31995. * @param {Node} nodeA
  31996. * @param {Node} nodeB
  31997. * @returns {boolean}
  31998. */
  31999. function sameLocStart(nodeA, nodeB, options) {
  32000. return options.locStart(nodeA) === options.locStart(nodeB);
  32001. } // TODO: This is a bad hack and we need a better way to distinguish between
  32002. // arrow functions and otherwise
  32003. function isFunctionNotation(node, options) {
  32004. return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
  32005. } // Hack to differentiate between the following two which have the same ast
  32006. // type T = { method: () => void };
  32007. // type T = { method(): void };
  32008. /**
  32009. * @param {Node} node
  32010. * @returns {boolean}
  32011. */
  32012. function isObjectTypePropertyAFunction(node, options) {
  32013. return (node.type === "ObjectTypeProperty" || node.type === "ObjectTypeInternalSlot") && node.value.type === "FunctionTypeAnnotation" && !node.static && !isFunctionNotation(node, options);
  32014. } // Hack to differentiate between the following two which have the same ast
  32015. // declare function f(a): void;
  32016. // var f: (a) => void;
  32017. function isTypeAnnotationAFunction(node, options) {
  32018. return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
  32019. }
  32020. const binaryishNodeTypes = new Set(["BinaryExpression", "LogicalExpression", "NGPipeExpression"]);
  32021. /**
  32022. * @param {Node} node
  32023. * @returns {boolean}
  32024. */
  32025. function isBinaryish(node) {
  32026. return binaryishNodeTypes.has(node.type);
  32027. }
  32028. /**
  32029. * @param {Node} node
  32030. * @returns {boolean}
  32031. */
  32032. function isMemberish(node) {
  32033. return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "BindExpression" && Boolean(node.object);
  32034. }
  32035. const flowTypeAnnotations = new Set(["AnyTypeAnnotation", "NullLiteralTypeAnnotation", "GenericTypeAnnotation", "ThisTypeAnnotation", "NumberTypeAnnotation", "VoidTypeAnnotation", "EmptyTypeAnnotation", "MixedTypeAnnotation", "BooleanTypeAnnotation", "BooleanLiteralTypeAnnotation", "StringTypeAnnotation"]);
  32036. /**
  32037. * @param {Node} node
  32038. * @returns {boolean}
  32039. */
  32040. function isSimpleFlowType(node) {
  32041. return node && flowTypeAnnotations.has(node.type) && !(node.type === "GenericTypeAnnotation" && node.typeParameters);
  32042. }
  32043. const unitTestRe = /^(skip|[fx]?(it|describe|test))$/;
  32044. /**
  32045. * @param {CallExpression} node
  32046. * @returns {boolean}
  32047. */
  32048. function isSkipOrOnlyBlock(node) {
  32049. return (node.callee.type === "MemberExpression" || node.callee.type === "OptionalMemberExpression") && node.callee.object.type === "Identifier" && node.callee.property.type === "Identifier" && unitTestRe.test(node.callee.object.name) && (node.callee.property.name === "only" || node.callee.property.name === "skip");
  32050. }
  32051. /**
  32052. * @param {CallExpression} node
  32053. * @returns {boolean}
  32054. */
  32055. function isUnitTestSetUp(node) {
  32056. const unitTestSetUpRe = /^(before|after)(Each|All)$/;
  32057. return node.callee.type === "Identifier" && unitTestSetUpRe.test(node.callee.name) && node.arguments.length === 1;
  32058. } // eg; `describe("some string", (done) => {})`
  32059. function isTestCall(n, parent) {
  32060. if (n.type !== "CallExpression") {
  32061. return false;
  32062. }
  32063. if (n.arguments.length === 1) {
  32064. if (isAngularTestWrapper(n) && parent && isTestCall(parent)) {
  32065. return isFunctionOrArrowExpression(n.arguments[0]);
  32066. }
  32067. if (isUnitTestSetUp(n)) {
  32068. return isAngularTestWrapper(n.arguments[0]);
  32069. }
  32070. } else if (n.arguments.length === 2 || n.arguments.length === 3) {
  32071. if ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name) || isSkipOrOnlyBlock(n)) && (isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))) {
  32072. // it("name", () => { ... }, 2500)
  32073. if (n.arguments[2] && !isNumericLiteral(n.arguments[2])) {
  32074. return false;
  32075. }
  32076. return (n.arguments.length === 2 ? isFunctionOrArrowExpression(n.arguments[1]) : isFunctionOrArrowExpressionWithBody(n.arguments[1]) && n.arguments[1].params.length <= 1) || isAngularTestWrapper(n.arguments[1]);
  32077. }
  32078. }
  32079. return false;
  32080. }
  32081. /**
  32082. * @param {Node} node
  32083. * @returns {boolean}
  32084. */
  32085. function hasLeadingComment$2(node) {
  32086. return node.comments && node.comments.some(comment => comment.leading);
  32087. }
  32088. /**
  32089. * @param {Node} node
  32090. * @returns {boolean}
  32091. */
  32092. function hasTrailingComment(node) {
  32093. return node.comments && node.comments.some(comment => comment.trailing);
  32094. }
  32095. /**
  32096. * @param {Node} node
  32097. * @returns {boolean}
  32098. */
  32099. function hasTrailingLineComment(node) {
  32100. return node.comments && node.comments.some(comment => comment.trailing && !comments$1.isBlockComment(comment));
  32101. }
  32102. /**
  32103. * @param {CallExpression | OptionalCallExpression} node
  32104. * @returns {boolean}
  32105. */
  32106. function isCallOrOptionalCallExpression(node) {
  32107. return node.type === "CallExpression" || node.type === "OptionalCallExpression";
  32108. }
  32109. /**
  32110. * @param {Node} node
  32111. * @returns {boolean}
  32112. */
  32113. function hasDanglingComments(node) {
  32114. return node.comments && node.comments.some(comment => !comment.leading && !comment.trailing);
  32115. }
  32116. /** identify if an angular expression seems to have side effects */
  32117. /**
  32118. * @param {FastPath} path
  32119. * @returns {boolean}
  32120. */
  32121. function hasNgSideEffect(path) {
  32122. return hasNode(path.getValue(), node => {
  32123. switch (node.type) {
  32124. case undefined:
  32125. return false;
  32126. case "CallExpression":
  32127. case "OptionalCallExpression":
  32128. case "AssignmentExpression":
  32129. return true;
  32130. }
  32131. });
  32132. }
  32133. function isNgForOf(node, index, parentNode) {
  32134. return node.type === "NGMicrosyntaxKeyedExpression" && node.key.name === "of" && index === 1 && parentNode.body[0].type === "NGMicrosyntaxLet" && parentNode.body[0].value === null;
  32135. }
  32136. /**
  32137. *
  32138. * @param {any} node
  32139. * @returns {boolean}
  32140. */
  32141. function isSimpleTemplateLiteral(node) {
  32142. if (node.expressions.length === 0) {
  32143. return false;
  32144. }
  32145. return node.expressions.every(expr => {
  32146. // Disallow comments since printDocToString can't print them here
  32147. if (expr.comments) {
  32148. return false;
  32149. } // Allow `x` and `this`
  32150. if (expr.type === "Identifier" || expr.type === "ThisExpression") {
  32151. return true;
  32152. } // Allow `a.b.c`, `a.b[c]`, and `this.x.y`
  32153. if (expr.type === "MemberExpression" || expr.type === "OptionalMemberExpression") {
  32154. let head = expr;
  32155. while (head.type === "MemberExpression" || head.type === "OptionalMemberExpression") {
  32156. if (head.property.type !== "Identifier" && head.property.type !== "Literal" && head.property.type !== "StringLiteral" && head.property.type !== "NumericLiteral") {
  32157. return false;
  32158. }
  32159. head = head.object;
  32160. if (head.comments) {
  32161. return false;
  32162. }
  32163. }
  32164. if (head.type === "Identifier" || head.type === "ThisExpression") {
  32165. return true;
  32166. }
  32167. return false;
  32168. }
  32169. return false;
  32170. });
  32171. }
  32172. /**
  32173. * @param {ObjectTypeProperty} node
  32174. */
  32175. function getFlowVariance(node) {
  32176. if (!node.variance) {
  32177. return null;
  32178. } // Babel 7.0 currently uses variance node type, and flow should
  32179. // follow suit soon:
  32180. // https://github.com/babel/babel/issues/4722
  32181. const variance = node.variance.kind || node.variance;
  32182. switch (variance) {
  32183. case "plus":
  32184. return "+";
  32185. case "minus":
  32186. return "-";
  32187. default:
  32188. /* istanbul ignore next */
  32189. return variance;
  32190. }
  32191. }
  32192. /**
  32193. * @param {FastPath} path
  32194. * @returns {boolean}
  32195. */
  32196. function classPropMayCauseASIProblems(path) {
  32197. const node = path.getNode();
  32198. if (node.type !== "ClassProperty") {
  32199. return false;
  32200. }
  32201. const name = node.key && node.key.name; // this isn't actually possible yet with most parsers available today
  32202. // so isn't properly tested yet.
  32203. if ((name === "static" || name === "get" || name === "set") && !node.value && !node.typeAnnotation) {
  32204. return true;
  32205. }
  32206. }
  32207. function classChildNeedsASIProtection(node) {
  32208. if (!node) {
  32209. return;
  32210. }
  32211. if (node.static || node.accessibility // TypeScript
  32212. ) {
  32213. return false;
  32214. }
  32215. if (!node.computed) {
  32216. const name = node.key && node.key.name;
  32217. if (name === "in" || name === "instanceof") {
  32218. return true;
  32219. }
  32220. }
  32221. switch (node.type) {
  32222. case "ClassProperty":
  32223. case "TSAbstractClassProperty":
  32224. return node.computed;
  32225. case "MethodDefinition": // Flow
  32226. case "TSAbstractMethodDefinition": // TypeScript
  32227. case "ClassMethod":
  32228. case "ClassPrivateMethod":
  32229. {
  32230. // Babel
  32231. const isAsync = node.value ? node.value.async : node.async;
  32232. const isGenerator = node.value ? node.value.generator : node.generator;
  32233. if (isAsync || node.kind === "get" || node.kind === "set") {
  32234. return false;
  32235. }
  32236. if (node.computed || isGenerator) {
  32237. return true;
  32238. }
  32239. return false;
  32240. }
  32241. case "TSIndexSignature":
  32242. return true;
  32243. default:
  32244. /* istanbul ignore next */
  32245. return false;
  32246. }
  32247. }
  32248. /**
  32249. * @param {string} tokenNode
  32250. * @param {string} keyword
  32251. * @returns {string}
  32252. */
  32253. function getTypeScriptMappedTypeModifier(tokenNode, keyword) {
  32254. if (tokenNode === "+") {
  32255. return "+" + keyword;
  32256. } else if (tokenNode === "-") {
  32257. return "-" + keyword;
  32258. }
  32259. return keyword;
  32260. }
  32261. function hasNewlineBetweenOrAfterDecorators(node, options) {
  32262. return hasNewlineInRange$3(options.originalText, options.locStart(node.decorators[0]), options.locEnd(getLast$2(node.decorators))) || hasNewline$4(options.originalText, options.locEnd(getLast$2(node.decorators)));
  32263. } // Only space, newline, carriage return, and tab are treated as whitespace
  32264. // inside JSX.
  32265. const jsxWhitespaceChars = " \n\r\t";
  32266. const matchJsxWhitespaceRegex = new RegExp("([" + jsxWhitespaceChars + "]+)");
  32267. const containsNonJsxWhitespaceRegex = new RegExp("[^" + jsxWhitespaceChars + "]"); // Meaningful if it contains non-whitespace characters,
  32268. // or it contains whitespace without a new line.
  32269. /**
  32270. * @param {Node} node
  32271. * @returns {boolean}
  32272. */
  32273. function isMeaningfulJSXText(node) {
  32274. return isLiteral(node) && (containsNonJsxWhitespaceRegex.test(rawText(node)) || !/\n/.test(rawText(node)));
  32275. }
  32276. /**
  32277. * @param {FastPath} path
  32278. * @returns {boolean}
  32279. */
  32280. function hasJsxIgnoreComment(path) {
  32281. const node = path.getValue();
  32282. const parent = path.getParentNode();
  32283. if (!parent || !node || !isJSXNode(node) || !isJSXNode(parent)) {
  32284. return false;
  32285. } // Lookup the previous sibling, ignoring any empty JSXText elements
  32286. const index = parent.children.indexOf(node);
  32287. let prevSibling = null;
  32288. for (let i = index; i > 0; i--) {
  32289. const candidate = parent.children[i - 1];
  32290. if (candidate.type === "JSXText" && !isMeaningfulJSXText(candidate)) {
  32291. continue;
  32292. }
  32293. prevSibling = candidate;
  32294. break;
  32295. }
  32296. return prevSibling && prevSibling.type === "JSXExpressionContainer" && prevSibling.expression.type === "JSXEmptyExpression" && prevSibling.expression.comments && prevSibling.expression.comments.some(comment => comment.value.trim() === "prettier-ignore");
  32297. }
  32298. /**
  32299. * @param {JSXElement} node
  32300. * @returns {boolean}
  32301. */
  32302. function isEmptyJSXElement(node) {
  32303. if (node.children.length === 0) {
  32304. return true;
  32305. }
  32306. if (node.children.length > 1) {
  32307. return false;
  32308. } // if there is one text child and does not contain any meaningful text
  32309. // we can treat the element as empty.
  32310. const child = node.children[0];
  32311. return isLiteral(child) && !isMeaningfulJSXText(child);
  32312. }
  32313. /**
  32314. * @param {FastPath} path
  32315. * @returns {boolean}
  32316. */
  32317. function hasPrettierIgnore(path) {
  32318. return hasIgnoreComment$1(path) || hasJsxIgnoreComment(path);
  32319. }
  32320. /**
  32321. * @param {FastPath} path
  32322. * @returns {boolean}
  32323. */
  32324. function isLastStatement(path) {
  32325. const parent = path.getParentNode();
  32326. if (!parent) {
  32327. return true;
  32328. }
  32329. const node = path.getValue();
  32330. const body = (parent.body || parent.consequent).filter(stmt => stmt.type !== "EmptyStatement");
  32331. return body[body.length - 1] === node;
  32332. }
  32333. /**
  32334. * @param {string} text
  32335. * @param {Node} typeAnnotation
  32336. * @returns {boolean}
  32337. */
  32338. function isFlowAnnotationComment(text, typeAnnotation, options) {
  32339. const start = options.locStart(typeAnnotation);
  32340. const end = skipWhitespace$2(text, options.locEnd(typeAnnotation));
  32341. return end !== false && text.slice(start, start + 2) === "/*" && text.slice(end, end + 2) === "*/";
  32342. }
  32343. /**
  32344. * @param {string} text
  32345. * @param {Node} node
  32346. * @returns {boolean}
  32347. */
  32348. function hasLeadingOwnLineComment(text, node, options) {
  32349. if (isJSXNode(node)) {
  32350. return hasNodeIgnoreComment$1(node);
  32351. }
  32352. const res = node.comments && node.comments.some(comment => comment.leading && hasNewline$4(text, options.locEnd(comment)));
  32353. return res;
  32354. } // This recurses the return argument, looking for the first token
  32355. // (the leftmost leaf node) and, if it (or its parents) has any
  32356. // leadingComments, returns true (so it can be wrapped in parens).
  32357. function returnArgumentHasLeadingComment(options, argument) {
  32358. if (hasLeadingOwnLineComment(options.originalText, argument, options)) {
  32359. return true;
  32360. }
  32361. if (hasNakedLeftSide(argument)) {
  32362. let leftMost = argument;
  32363. let newLeftMost;
  32364. while (newLeftMost = getLeftSide(leftMost)) {
  32365. leftMost = newLeftMost;
  32366. if (hasLeadingOwnLineComment(options.originalText, leftMost, options)) {
  32367. return true;
  32368. }
  32369. }
  32370. }
  32371. return false;
  32372. } // Note: Quoting/unquoting numbers in TypeScript is not safe.
  32373. //
  32374. // let a = { 1: 1, 2: 2 }
  32375. // let b = { '1': 1, '2': 2 }
  32376. //
  32377. // declare let aa: keyof typeof a;
  32378. // declare let bb: keyof typeof b;
  32379. //
  32380. // aa = bb;
  32381. // ^^
  32382. // Type '"1" | "2"' is not assignable to type '1 | 2'.
  32383. // Type '"1"' is not assignable to type '1 | 2'.(2322)
  32384. //
  32385. // And in Flow, you get:
  32386. //
  32387. // const x = {
  32388. // 0: 1
  32389. // ^ Non-string literal property keys not supported. [unsupported-syntax]
  32390. // }
  32391. //
  32392. // Angular does not support unquoted numbers in expressions.
  32393. //
  32394. // So we play it safe and only unquote numbers for the "babel" parser.
  32395. // (Vue supports unquoted numbers in expressions, but let’s keep it simple.)
  32396. //
  32397. // Identifiers can be unquoted in more circumstances, though.
  32398. function isStringPropSafeToUnquote(node, options) {
  32399. return options.parser !== "json" && isStringLiteral(node.key) && rawText(node.key).slice(1, -1) === node.key.value && (isIdentifierName(node.key.value) && // With `--strictPropertyInitialization`, TS treats properties with quoted names differently than unquoted ones.
  32400. // See https://github.com/microsoft/TypeScript/pull/20075
  32401. !((options.parser === "typescript" || options.parser === "babel-ts") && node.type === "ClassProperty") || isSimpleNumber(node.key.value) && String(Number(node.key.value)) === node.key.value && options.parser === "babel");
  32402. } // Matches “simple” numbers like `123` and `2.5` but not `1_000`, `1e+100` or `0b10`.
  32403. function isSimpleNumber(numberString) {
  32404. return /^(\d+|\d+\.\d+)$/.test(numberString);
  32405. }
  32406. /**
  32407. * @param {Node} node
  32408. * @param {Node} parentNode
  32409. * @returns {boolean}
  32410. */
  32411. function isJestEachTemplateLiteral(node, parentNode) {
  32412. /**
  32413. * describe.each`table`(name, fn)
  32414. * describe.only.each`table`(name, fn)
  32415. * describe.skip.each`table`(name, fn)
  32416. * test.each`table`(name, fn)
  32417. * test.only.each`table`(name, fn)
  32418. * test.skip.each`table`(name, fn)
  32419. *
  32420. * Ref: https://github.com/facebook/jest/pull/6102
  32421. */
  32422. const jestEachTriggerRegex = /^[fx]?(describe|it|test)$/;
  32423. return parentNode.type === "TaggedTemplateExpression" && parentNode.quasi === node && parentNode.tag.type === "MemberExpression" && parentNode.tag.property.type === "Identifier" && parentNode.tag.property.name === "each" && (parentNode.tag.object.type === "Identifier" && jestEachTriggerRegex.test(parentNode.tag.object.name) || parentNode.tag.object.type === "MemberExpression" && parentNode.tag.object.property.type === "Identifier" && (parentNode.tag.object.property.name === "only" || parentNode.tag.object.property.name === "skip") && parentNode.tag.object.object.type === "Identifier" && jestEachTriggerRegex.test(parentNode.tag.object.object.name));
  32424. }
  32425. /**
  32426. * @param {TemplateLiteral} template
  32427. * @returns {boolean}
  32428. */
  32429. function templateLiteralHasNewLines(template) {
  32430. return template.quasis.some(quasi => quasi.value.raw.includes("\n"));
  32431. }
  32432. /**
  32433. * @param {TemplateLiteral | TaggedTemplateExpression} n
  32434. * @param {string} text
  32435. * @returns {boolean}
  32436. */
  32437. function isTemplateOnItsOwnLine(n, text, options) {
  32438. return (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && !hasNewline$4(text, options.locStart(n), {
  32439. backwards: true
  32440. });
  32441. }
  32442. /**
  32443. * @param {Node} node
  32444. * @returns {boolean}
  32445. */
  32446. function needsHardlineAfterDanglingComment(node) {
  32447. if (!node.comments) {
  32448. return false;
  32449. }
  32450. const lastDanglingComment = getLast$2(node.comments.filter(comment => !comment.leading && !comment.trailing));
  32451. return lastDanglingComment && !comments$1.isBlockComment(lastDanglingComment);
  32452. } // Logic to check for args with multiple anonymous functions. For instance,
  32453. // the following call should be split on multiple lines for readability:
  32454. // source.pipe(map((x) => x + x), filter((x) => x % 2 === 0))
  32455. function isFunctionCompositionArgs(args) {
  32456. if (args.length <= 1) {
  32457. return false;
  32458. }
  32459. let count = 0;
  32460. for (const arg of args) {
  32461. if (isFunctionOrArrowExpression(arg)) {
  32462. count += 1;
  32463. if (count > 1) {
  32464. return true;
  32465. }
  32466. } else if (isCallOrOptionalCallExpression(arg)) {
  32467. for (const childArg of arg.arguments) {
  32468. if (isFunctionOrArrowExpression(childArg)) {
  32469. return true;
  32470. }
  32471. }
  32472. }
  32473. }
  32474. return false;
  32475. } // Logic to determine if a call is a “long curried function call”.
  32476. // See https://github.com/prettier/prettier/issues/1420.
  32477. //
  32478. // `connect(a, b, c)(d)`
  32479. // In the above call expression, the second call is the parent node and the
  32480. // first call is the current node.
  32481. /**
  32482. * @param {FastPath} path
  32483. * @returns {boolean}
  32484. */
  32485. function isLongCurriedCallExpression(path) {
  32486. const node = path.getValue();
  32487. const parent = path.getParentNode();
  32488. return isCallOrOptionalCallExpression(node) && isCallOrOptionalCallExpression(parent) && parent.callee === node && node.arguments.length > parent.arguments.length && parent.arguments.length > 0;
  32489. }
  32490. /**
  32491. * @param {any} node
  32492. * @param {number} depth
  32493. * @returns {boolean}
  32494. */
  32495. function isSimpleCallArgument(node, depth) {
  32496. if (depth >= 2) {
  32497. return false;
  32498. }
  32499. const isChildSimple = child => isSimpleCallArgument(child, depth + 1);
  32500. const regexpPattern = node.type === "Literal" && "regex" in node && node.regex.pattern || node.type === "RegExpLiteral" && node.pattern;
  32501. if (regexpPattern && regexpPattern.length > 5) {
  32502. return false;
  32503. }
  32504. if (node.type === "Literal" || node.type === "BigIntLiteral" || node.type === "DecimalLiteral" || node.type === "BooleanLiteral" || node.type === "NullLiteral" || node.type === "NumericLiteral" || node.type === "RegExpLiteral" || node.type === "StringLiteral" || node.type === "Identifier" || node.type === "ThisExpression" || node.type === "Super" || node.type === "PrivateName" || node.type === "ArgumentPlaceholder" || node.type === "Import") {
  32505. return true;
  32506. }
  32507. if (node.type === "TemplateLiteral") {
  32508. return node.expressions.every(isChildSimple);
  32509. }
  32510. if (node.type === "ObjectExpression") {
  32511. return node.properties.every(p => !p.computed && (p.shorthand || p.value && isChildSimple(p.value)));
  32512. }
  32513. if (node.type === "ArrayExpression") {
  32514. return node.elements.every(x => x === null || isChildSimple(x));
  32515. }
  32516. if (node.type === "ImportExpression") {
  32517. return isChildSimple(node.source);
  32518. }
  32519. if (node.type === "CallExpression" || node.type === "OptionalCallExpression" || node.type === "NewExpression") {
  32520. return isSimpleCallArgument(node.callee, depth) && node.arguments.every(isChildSimple);
  32521. }
  32522. if (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") {
  32523. return isSimpleCallArgument(node.object, depth) && isSimpleCallArgument(node.property, depth);
  32524. }
  32525. if (node.type === "UnaryExpression" && (node.operator === "!" || node.operator === "-")) {
  32526. return isSimpleCallArgument(node.argument, depth);
  32527. }
  32528. if (node.type === "TSNonNullExpression") {
  32529. return isSimpleCallArgument(node.expression, depth);
  32530. }
  32531. return false;
  32532. }
  32533. function rawText(node) {
  32534. return node.extra ? node.extra.raw : node.raw;
  32535. }
  32536. function identity$1(x) {
  32537. return x;
  32538. }
  32539. function isTSXFile(options) {
  32540. return options.filepath && /\.tsx$/i.test(options.filepath);
  32541. }
  32542. /**
  32543. * @param {any} options
  32544. * @param {("es5" | "all")} [level]
  32545. * @returns {boolean}
  32546. */
  32547. function shouldPrintComma(options, level = "es5") {
  32548. return options.trailingComma === "es5" && level === "es5" || options.trailingComma === "all" && (level === "all" || level === "es5");
  32549. }
  32550. /**
  32551. * Tests if an expression starts with `{`, or (if forbidFunctionClassAndDoExpr
  32552. * holds) `function`, `class`, or `do {}`. Will be overzealous if there's
  32553. * already necessary grouping parentheses.
  32554. *
  32555. * @param {Node} node
  32556. * @param {boolean} forbidFunctionClassAndDoExpr
  32557. * @returns {boolean}
  32558. */
  32559. function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) {
  32560. node = getLeftMost(node);
  32561. switch (node.type) {
  32562. case "FunctionExpression":
  32563. case "ClassExpression":
  32564. case "DoExpression":
  32565. return forbidFunctionClassAndDoExpr;
  32566. case "ObjectExpression":
  32567. return true;
  32568. case "MemberExpression":
  32569. case "OptionalMemberExpression":
  32570. return startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  32571. case "TaggedTemplateExpression":
  32572. if (node.tag.type === "FunctionExpression") {
  32573. // IIFEs are always already parenthesized
  32574. return false;
  32575. }
  32576. return startsWithNoLookaheadToken(node.tag, forbidFunctionClassAndDoExpr);
  32577. case "CallExpression":
  32578. case "OptionalCallExpression":
  32579. if (node.callee.type === "FunctionExpression") {
  32580. // IIFEs are always already parenthesized
  32581. return false;
  32582. }
  32583. return startsWithNoLookaheadToken(node.callee, forbidFunctionClassAndDoExpr);
  32584. case "ConditionalExpression":
  32585. return startsWithNoLookaheadToken(node.test, forbidFunctionClassAndDoExpr);
  32586. case "UpdateExpression":
  32587. return !node.prefix && startsWithNoLookaheadToken(node.argument, forbidFunctionClassAndDoExpr);
  32588. case "BindExpression":
  32589. return node.object && startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  32590. case "SequenceExpression":
  32591. return startsWithNoLookaheadToken(node.expressions[0], forbidFunctionClassAndDoExpr);
  32592. case "TSAsExpression":
  32593. return startsWithNoLookaheadToken(node.expression, forbidFunctionClassAndDoExpr);
  32594. default:
  32595. return false;
  32596. }
  32597. }
  32598. const equalityOperators = {
  32599. "==": true,
  32600. "!=": true,
  32601. "===": true,
  32602. "!==": true
  32603. };
  32604. const multiplicativeOperators = {
  32605. "*": true,
  32606. "/": true,
  32607. "%": true
  32608. };
  32609. const bitshiftOperators = {
  32610. ">>": true,
  32611. ">>>": true,
  32612. "<<": true
  32613. };
  32614. function shouldFlatten(parentOp, nodeOp) {
  32615. if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
  32616. return false;
  32617. } // ** is right-associative
  32618. // x ** y ** z --> x ** (y ** z)
  32619. if (parentOp === "**") {
  32620. return false;
  32621. } // x == y == z --> (x == y) == z
  32622. if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
  32623. return false;
  32624. } // x * y % z --> (x * y) % z
  32625. if (nodeOp === "%" && multiplicativeOperators[parentOp] || parentOp === "%" && multiplicativeOperators[nodeOp]) {
  32626. return false;
  32627. } // x * y / z --> (x * y) / z
  32628. // x / y * z --> (x / y) * z
  32629. if (nodeOp !== parentOp && multiplicativeOperators[nodeOp] && multiplicativeOperators[parentOp]) {
  32630. return false;
  32631. } // x << y << z --> (x << y) << z
  32632. if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
  32633. return false;
  32634. }
  32635. return true;
  32636. }
  32637. const PRECEDENCE = {};
  32638. [["|>"], ["??"], ["||"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]].forEach((tier, i) => {
  32639. tier.forEach(op => {
  32640. PRECEDENCE[op] = i;
  32641. });
  32642. });
  32643. function getPrecedence(op) {
  32644. return PRECEDENCE[op];
  32645. }
  32646. function getLeftMost(node) {
  32647. while (node.left) {
  32648. node = node.left;
  32649. }
  32650. return node;
  32651. }
  32652. function isBitwiseOperator(operator) {
  32653. return !!bitshiftOperators[operator] || operator === "|" || operator === "^" || operator === "&";
  32654. }
  32655. var utils$6 = {
  32656. classChildNeedsASIProtection,
  32657. classPropMayCauseASIProblems,
  32658. getFlowVariance,
  32659. getLeftSidePathName,
  32660. getParentExportDeclaration,
  32661. getTypeScriptMappedTypeModifier,
  32662. hasDanglingComments,
  32663. hasFlowAnnotationComment,
  32664. hasFlowShorthandAnnotationComment,
  32665. hasLeadingComment: hasLeadingComment$2,
  32666. hasLeadingOwnLineComment,
  32667. hasNakedLeftSide,
  32668. hasNewlineBetweenOrAfterDecorators,
  32669. hasNgSideEffect,
  32670. hasNode,
  32671. hasPrettierIgnore,
  32672. hasTrailingComment,
  32673. hasTrailingLineComment,
  32674. identity: identity$1,
  32675. isBinaryish,
  32676. isCallOrOptionalCallExpression,
  32677. isEmptyJSXElement,
  32678. isExportDeclaration,
  32679. isFlowAnnotationComment,
  32680. isFunctionCompositionArgs,
  32681. isFunctionNotation,
  32682. isFunctionOrArrowExpression,
  32683. isGetterOrSetter,
  32684. isJestEachTemplateLiteral,
  32685. isJSXNode,
  32686. isJSXWhitespaceExpression,
  32687. isLastStatement,
  32688. isLiteral,
  32689. isLongCurriedCallExpression,
  32690. isSimpleCallArgument,
  32691. isMeaningfulJSXText,
  32692. isMemberExpressionChain,
  32693. isMemberish,
  32694. isNgForOf,
  32695. isNumericLiteral,
  32696. isObjectType,
  32697. isObjectTypePropertyAFunction,
  32698. isSimpleFlowType,
  32699. isSimpleNumber,
  32700. isSimpleTemplateLiteral,
  32701. isStringLiteral,
  32702. isStringPropSafeToUnquote,
  32703. isTemplateOnItsOwnLine,
  32704. isTestCall,
  32705. isTheOnlyJSXElementInMarkdown,
  32706. isTSXFile,
  32707. isTypeAnnotationAFunction,
  32708. matchJsxWhitespaceRegex,
  32709. needsHardlineAfterDanglingComment,
  32710. rawText,
  32711. returnArgumentHasLeadingComment,
  32712. shouldPrintComma,
  32713. isBitwiseOperator,
  32714. shouldFlatten,
  32715. startsWithNoLookaheadToken,
  32716. getPrecedence
  32717. };
  32718. /** @type {import("assert")} */
  32719. const {
  32720. getLeftSidePathName: getLeftSidePathName$1,
  32721. hasFlowShorthandAnnotationComment: hasFlowShorthandAnnotationComment$1,
  32722. hasNakedLeftSide: hasNakedLeftSide$1,
  32723. hasNode: hasNode$1,
  32724. isBitwiseOperator: isBitwiseOperator$1,
  32725. startsWithNoLookaheadToken: startsWithNoLookaheadToken$1,
  32726. shouldFlatten: shouldFlatten$1,
  32727. getPrecedence: getPrecedence$1
  32728. } = utils$6;
  32729. function needsParens(path, options) {
  32730. const parent = path.getParentNode();
  32731. if (!parent) {
  32732. return false;
  32733. }
  32734. const name = path.getName();
  32735. const node = path.getNode(); // If the value of this path is some child of a Node and not a Node
  32736. // itself, then it doesn't need parentheses. Only Node objects (in
  32737. // fact, only Expression nodes) need parentheses.
  32738. if (path.getValue() !== node) {
  32739. return false;
  32740. } // to avoid unexpected `}}` in HTML interpolations
  32741. if (options.__isInHtmlInterpolation && !options.bracketSpacing && endsWithRightBracket(node) && isFollowedByRightBracket(path)) {
  32742. return true;
  32743. } // Only statements don't need parentheses.
  32744. if (isStatement(node)) {
  32745. return false;
  32746. }
  32747. if ( // Preserve parens if we have a Flow annotation comment, unless we're using the Flow
  32748. // parser. The Flow parser turns Flow comments into type annotation nodes in its
  32749. // AST, which we handle separately.
  32750. options.parser !== "flow" && hasFlowShorthandAnnotationComment$1(path.getValue())) {
  32751. return true;
  32752. } // Identifiers never need parentheses.
  32753. if (node.type === "Identifier") {
  32754. // ...unless those identifiers are embed placeholders. They might be substituted by complex
  32755. // expressions, so the parens around them should not be dropped. Example (JS-in-HTML-in-JS):
  32756. // let tpl = html`<script> f((${expr}) / 2); </script>`;
  32757. // If the inner JS formatter removes the parens, the expression might change its meaning:
  32758. // f((a + b) / 2) vs f(a + b / 2)
  32759. if (node.extra && node.extra.parenthesized && /^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(node.name)) {
  32760. return true;
  32761. }
  32762. return false;
  32763. }
  32764. if (parent.type === "ParenthesizedExpression") {
  32765. return false;
  32766. } // Add parens around the extends clause of a class. It is needed for almost
  32767. // all expressions.
  32768. if ((parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node && (node.type === "ArrowFunctionExpression" || node.type === "AssignmentExpression" || node.type === "AwaitExpression" || node.type === "BinaryExpression" || node.type === "ConditionalExpression" || node.type === "LogicalExpression" || node.type === "NewExpression" || node.type === "ObjectExpression" || node.type === "ParenthesizedExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "UnaryExpression" || node.type === "UpdateExpression" || node.type === "YieldExpression")) {
  32769. return true;
  32770. }
  32771. if (parent.type === "ExportDefaultDeclaration") {
  32772. return (// `export default function` or `export default class` can't be followed by
  32773. // anything after. So an expression like `export default (function(){}).toString()`
  32774. // needs to be followed by a parentheses
  32775. shouldWrapFunctionForExportDefault(path, options) || // `export default (foo, bar)` also needs parentheses
  32776. node.type === "SequenceExpression"
  32777. );
  32778. }
  32779. if (parent.type === "Decorator" && parent.expression === node) {
  32780. let hasCallExpression = false;
  32781. let hasMemberExpression = false;
  32782. let current = node;
  32783. while (current) {
  32784. switch (current.type) {
  32785. case "MemberExpression":
  32786. hasMemberExpression = true;
  32787. current = current.object;
  32788. break;
  32789. case "CallExpression":
  32790. if (
  32791. /** @(x().y) */
  32792. hasMemberExpression ||
  32793. /** @(x().y()) */
  32794. hasCallExpression) {
  32795. return true;
  32796. }
  32797. hasCallExpression = true;
  32798. current = current.callee;
  32799. break;
  32800. case "Identifier":
  32801. return false;
  32802. default:
  32803. return true;
  32804. }
  32805. }
  32806. return true;
  32807. }
  32808. if (parent.type === "ArrowFunctionExpression" && parent.body === node && node.type !== "SequenceExpression" && // these have parens added anyway
  32809. startsWithNoLookaheadToken$1(node,
  32810. /* forbidFunctionClassAndDoExpr */
  32811. false) || parent.type === "ExpressionStatement" && startsWithNoLookaheadToken$1(node,
  32812. /* forbidFunctionClassAndDoExpr */
  32813. true)) {
  32814. return true;
  32815. }
  32816. switch (node.type) {
  32817. case "SpreadElement":
  32818. case "SpreadProperty":
  32819. return parent.type === "MemberExpression" && name === "object" && parent.object === node;
  32820. case "UpdateExpression":
  32821. if (parent.type === "UnaryExpression") {
  32822. return node.prefix && (node.operator === "++" && parent.operator === "+" || node.operator === "--" && parent.operator === "-");
  32823. }
  32824. // else fallthrough
  32825. case "UnaryExpression":
  32826. switch (parent.type) {
  32827. case "UnaryExpression":
  32828. return node.operator === parent.operator && (node.operator === "+" || node.operator === "-");
  32829. case "BindExpression":
  32830. return true;
  32831. case "MemberExpression":
  32832. case "OptionalMemberExpression":
  32833. return name === "object";
  32834. case "TaggedTemplateExpression":
  32835. return true;
  32836. case "NewExpression":
  32837. case "CallExpression":
  32838. case "OptionalCallExpression":
  32839. return name === "callee";
  32840. case "BinaryExpression":
  32841. return parent.operator === "**" && name === "left";
  32842. case "TSNonNullExpression":
  32843. return true;
  32844. default:
  32845. return false;
  32846. }
  32847. case "BinaryExpression":
  32848. {
  32849. if (parent.type === "UpdateExpression" || parent.type === "PipelineTopicExpression" && node.operator === "|>") {
  32850. return true;
  32851. }
  32852. const isLeftOfAForStatement = node => {
  32853. let i = 0;
  32854. while (node) {
  32855. const parent = path.getParentNode(i++);
  32856. if (!parent) {
  32857. return false;
  32858. }
  32859. if (parent.type === "ForStatement" && parent.init === node) {
  32860. return true;
  32861. }
  32862. node = parent;
  32863. }
  32864. return false;
  32865. };
  32866. if (node.operator === "in" && isLeftOfAForStatement(node)) {
  32867. return true;
  32868. }
  32869. if (node.operator === "|>" && node.extra && node.extra.parenthesized) {
  32870. const grandParent = path.getParentNode(1);
  32871. if (grandParent.type === "BinaryExpression" && grandParent.operator === "|>") {
  32872. return true;
  32873. }
  32874. }
  32875. }
  32876. // fallthrough
  32877. case "TSTypeAssertion":
  32878. case "TSAsExpression":
  32879. case "LogicalExpression":
  32880. switch (parent.type) {
  32881. case "ConditionalExpression":
  32882. return node.type === "TSAsExpression";
  32883. case "CallExpression":
  32884. case "NewExpression":
  32885. case "OptionalCallExpression":
  32886. return name === "callee";
  32887. case "ClassExpression":
  32888. case "ClassDeclaration":
  32889. return name === "superClass" && parent.superClass === node;
  32890. case "TSTypeAssertion":
  32891. case "TaggedTemplateExpression":
  32892. case "UnaryExpression":
  32893. case "JSXSpreadAttribute":
  32894. case "SpreadElement":
  32895. case "SpreadProperty":
  32896. case "BindExpression":
  32897. case "AwaitExpression":
  32898. case "TSAsExpression":
  32899. case "TSNonNullExpression":
  32900. case "UpdateExpression":
  32901. return true;
  32902. case "MemberExpression":
  32903. case "OptionalMemberExpression":
  32904. return name === "object";
  32905. case "AssignmentExpression":
  32906. return parent.left === node && (node.type === "TSTypeAssertion" || node.type === "TSAsExpression");
  32907. case "LogicalExpression":
  32908. if (node.type === "LogicalExpression") {
  32909. return parent.operator !== node.operator;
  32910. }
  32911. // else fallthrough
  32912. case "BinaryExpression":
  32913. {
  32914. if (!node.operator && node.type !== "TSTypeAssertion") {
  32915. return true;
  32916. }
  32917. const po = parent.operator;
  32918. const pp = getPrecedence$1(po);
  32919. const no = node.operator;
  32920. const np = getPrecedence$1(no);
  32921. if (pp > np) {
  32922. return true;
  32923. }
  32924. if (pp === np && name === "right") {
  32925. assert__default['default'].strictEqual(parent.right, node);
  32926. return true;
  32927. }
  32928. if (pp === np && !shouldFlatten$1(po, no)) {
  32929. return true;
  32930. }
  32931. if (pp < np && no === "%") {
  32932. return po === "+" || po === "-";
  32933. } // Add parenthesis when working with bitwise operators
  32934. // It's not strictly needed but helps with code understanding
  32935. if (isBitwiseOperator$1(po)) {
  32936. return true;
  32937. }
  32938. return false;
  32939. }
  32940. default:
  32941. return false;
  32942. }
  32943. case "SequenceExpression":
  32944. switch (parent.type) {
  32945. case "ReturnStatement":
  32946. return false;
  32947. case "ForStatement":
  32948. // Although parentheses wouldn't hurt around sequence
  32949. // expressions in the head of for loops, traditional style
  32950. // dictates that e.g. i++, j++ should not be wrapped with
  32951. // parentheses.
  32952. return false;
  32953. case "ExpressionStatement":
  32954. return name !== "expression";
  32955. case "ArrowFunctionExpression":
  32956. // We do need parentheses, but SequenceExpressions are handled
  32957. // specially when printing bodies of arrow functions.
  32958. return name !== "body";
  32959. default:
  32960. // Otherwise err on the side of overparenthesization, adding
  32961. // explicit exceptions above if this proves overzealous.
  32962. return true;
  32963. }
  32964. case "YieldExpression":
  32965. if (parent.type === "UnaryExpression" || parent.type === "AwaitExpression" || parent.type === "TSAsExpression" || parent.type === "TSNonNullExpression") {
  32966. return true;
  32967. }
  32968. // else fallthrough
  32969. case "AwaitExpression":
  32970. switch (parent.type) {
  32971. case "TaggedTemplateExpression":
  32972. case "UnaryExpression":
  32973. case "LogicalExpression":
  32974. case "SpreadElement":
  32975. case "SpreadProperty":
  32976. case "TSAsExpression":
  32977. case "TSNonNullExpression":
  32978. case "BindExpression":
  32979. return true;
  32980. case "MemberExpression":
  32981. case "OptionalMemberExpression":
  32982. return name === "object";
  32983. case "NewExpression":
  32984. case "CallExpression":
  32985. case "OptionalCallExpression":
  32986. return name === "callee";
  32987. case "ConditionalExpression":
  32988. return parent.test === node;
  32989. case "BinaryExpression":
  32990. {
  32991. if (!node.argument && parent.operator === "|>") {
  32992. return false;
  32993. }
  32994. return true;
  32995. }
  32996. default:
  32997. return false;
  32998. }
  32999. case "TSJSDocFunctionType":
  33000. case "TSConditionalType":
  33001. if (parent.type === "TSConditionalType" && node === parent.extendsType) {
  33002. return true;
  33003. }
  33004. // fallthrough
  33005. case "TSFunctionType":
  33006. case "TSConstructorType":
  33007. if (parent.type === "TSConditionalType" && node === parent.checkType) {
  33008. return true;
  33009. }
  33010. // fallthrough
  33011. case "TSUnionType":
  33012. case "TSIntersectionType":
  33013. if (parent.type === "TSUnionType" || parent.type === "TSIntersectionType") {
  33014. return true;
  33015. }
  33016. // fallthrough
  33017. case "TSInferType":
  33018. if (node.type === "TSInferType" && parent.type === "TSRestType") {
  33019. return false;
  33020. }
  33021. // fallthrough
  33022. case "TSTypeOperator":
  33023. return parent.type === "TSArrayType" || parent.type === "TSOptionalType" || parent.type === "TSRestType" || parent.type === "TSIndexedAccessType" && node === parent.objectType || parent.type === "TSTypeOperator" || parent.type === "TSTypeAnnotation" && /^TSJSDoc/.test(path.getParentNode(1).type);
  33024. case "ArrayTypeAnnotation":
  33025. return parent.type === "NullableTypeAnnotation";
  33026. case "IntersectionTypeAnnotation":
  33027. case "UnionTypeAnnotation":
  33028. return parent.type === "ArrayTypeAnnotation" || parent.type === "NullableTypeAnnotation" || parent.type === "IntersectionTypeAnnotation" || parent.type === "UnionTypeAnnotation";
  33029. case "NullableTypeAnnotation":
  33030. return parent.type === "ArrayTypeAnnotation";
  33031. case "FunctionTypeAnnotation":
  33032. {
  33033. const ancestor = parent.type === "NullableTypeAnnotation" ? path.getParentNode(1) : parent;
  33034. return ancestor.type === "UnionTypeAnnotation" || ancestor.type === "IntersectionTypeAnnotation" || ancestor.type === "ArrayTypeAnnotation" || // We should check ancestor's parent to know whether the parentheses
  33035. // are really needed, but since ??T doesn't make sense this check
  33036. // will almost never be true.
  33037. ancestor.type === "NullableTypeAnnotation" || // See #5283
  33038. parent.type === "FunctionTypeParam" && parent.name === null && node.params && node.params.some(param => param.typeAnnotation && param.typeAnnotation.type === "NullableTypeAnnotation");
  33039. }
  33040. case "StringLiteral":
  33041. case "NumericLiteral":
  33042. case "Literal":
  33043. if (typeof node.value === "string" && parent.type === "ExpressionStatement" && !parent.directive) {
  33044. // To avoid becoming a directive
  33045. const grandParent = path.getParentNode(1);
  33046. return grandParent.type === "Program" || grandParent.type === "BlockStatement";
  33047. }
  33048. return parent.type === "MemberExpression" && typeof node.value === "number" && name === "object" && parent.object === node;
  33049. case "AssignmentExpression":
  33050. {
  33051. const grandParent = path.getParentNode(1);
  33052. if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
  33053. return true;
  33054. } else if (parent.type === "ClassProperty" && parent.key === node && parent.computed) {
  33055. return false;
  33056. } else if (parent.type === "TSPropertySignature" && parent.name === node) {
  33057. return false;
  33058. } else if (parent.type === "ForStatement" && (parent.init === node || parent.update === node)) {
  33059. return false;
  33060. } else if (parent.type === "ExpressionStatement") {
  33061. return node.left.type === "ObjectPattern";
  33062. } else if (parent.type === "TSPropertySignature" && parent.key === node) {
  33063. return false;
  33064. } else if (parent.type === "AssignmentExpression") {
  33065. return false;
  33066. } else if (parent.type === "SequenceExpression" && grandParent && grandParent.type === "ForStatement" && (grandParent.init === parent || grandParent.update === parent)) {
  33067. return false;
  33068. } else if (parent.type === "Property" && parent.value === node) {
  33069. return false;
  33070. } else if (parent.type === "NGChainedExpression") {
  33071. return false;
  33072. }
  33073. return true;
  33074. }
  33075. case "ConditionalExpression":
  33076. switch (parent.type) {
  33077. case "TaggedTemplateExpression":
  33078. case "UnaryExpression":
  33079. case "SpreadElement":
  33080. case "SpreadProperty":
  33081. case "BinaryExpression":
  33082. case "LogicalExpression":
  33083. case "NGPipeExpression":
  33084. case "ExportDefaultDeclaration":
  33085. case "AwaitExpression":
  33086. case "JSXSpreadAttribute":
  33087. case "TSTypeAssertion":
  33088. case "TypeCastExpression":
  33089. case "TSAsExpression":
  33090. case "TSNonNullExpression":
  33091. return true;
  33092. case "NewExpression":
  33093. case "CallExpression":
  33094. case "OptionalCallExpression":
  33095. return name === "callee";
  33096. case "ConditionalExpression":
  33097. return name === "test" && parent.test === node;
  33098. case "MemberExpression":
  33099. case "OptionalMemberExpression":
  33100. return name === "object";
  33101. default:
  33102. return false;
  33103. }
  33104. case "FunctionExpression":
  33105. switch (parent.type) {
  33106. case "NewExpression":
  33107. case "CallExpression":
  33108. case "OptionalCallExpression":
  33109. // Not always necessary, but it's clearer to the reader if IIFEs are wrapped in parentheses.
  33110. // Is necessary if it is `expression` of `ExpressionStatement`.
  33111. return name === "callee";
  33112. case "TaggedTemplateExpression":
  33113. return true;
  33114. // This is basically a kind of IIFE.
  33115. default:
  33116. return false;
  33117. }
  33118. case "ArrowFunctionExpression":
  33119. switch (parent.type) {
  33120. case "PipelineTopicExpression":
  33121. return !!(node.extra && node.extra.parenthesized);
  33122. case "BinaryExpression":
  33123. return parent.operator !== "|>" || node.extra && node.extra.parenthesized;
  33124. case "NewExpression":
  33125. case "CallExpression":
  33126. case "OptionalCallExpression":
  33127. return name === "callee";
  33128. case "MemberExpression":
  33129. case "OptionalMemberExpression":
  33130. return name === "object";
  33131. case "TSAsExpression":
  33132. case "BindExpression":
  33133. case "TaggedTemplateExpression":
  33134. case "UnaryExpression":
  33135. case "LogicalExpression":
  33136. case "AwaitExpression":
  33137. case "TSTypeAssertion":
  33138. return true;
  33139. case "ConditionalExpression":
  33140. return name === "test";
  33141. default:
  33142. return false;
  33143. }
  33144. case "ClassExpression":
  33145. switch (parent.type) {
  33146. case "NewExpression":
  33147. return name === "callee" && parent.callee === node;
  33148. default:
  33149. return false;
  33150. }
  33151. case "OptionalMemberExpression":
  33152. case "OptionalCallExpression":
  33153. {
  33154. const parentParent = path.getParentNode(1);
  33155. if (parent.type === "MemberExpression" && name === "object" || (parent.type === "CallExpression" || parent.type === "NewExpression") && name === "callee" || parent.type === "TSNonNullExpression" && parentParent.type === "MemberExpression" && parentParent.object === parent) {
  33156. return true;
  33157. }
  33158. }
  33159. // fallthrough
  33160. case "CallExpression":
  33161. case "MemberExpression":
  33162. case "TaggedTemplateExpression":
  33163. case "TSNonNullExpression":
  33164. if ((parent.type === "BindExpression" || parent.type === "NewExpression") && name === "callee") {
  33165. let object = node;
  33166. while (object) {
  33167. switch (object.type) {
  33168. case "CallExpression":
  33169. case "OptionalCallExpression":
  33170. return true;
  33171. case "MemberExpression":
  33172. case "OptionalMemberExpression":
  33173. case "BindExpression":
  33174. object = object.object;
  33175. break;
  33176. // tagged templates are basically member expressions from a grammar perspective
  33177. // see https://tc39.github.io/ecma262/#prod-MemberExpression
  33178. case "TaggedTemplateExpression":
  33179. object = object.tag;
  33180. break;
  33181. case "TSNonNullExpression":
  33182. object = object.expression;
  33183. break;
  33184. default:
  33185. return false;
  33186. }
  33187. }
  33188. }
  33189. return false;
  33190. case "BindExpression":
  33191. return (parent.type === "BindExpression" || parent.type === "NewExpression") && name === "callee" || (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && name === "object";
  33192. case "NGPipeExpression":
  33193. if (parent.type === "NGRoot" || parent.type === "NGMicrosyntaxExpression" || parent.type === "ObjectProperty" && // Preserve parens for compatibility with AngularJS expressions
  33194. !(node.extra && node.extra.parenthesized) || parent.type === "ArrayExpression" || (parent.type === "CallExpression" || parent.type === "OptionalCallExpression") && parent.arguments[name] === node || parent.type === "NGPipeExpression" && name === "right" || parent.type === "MemberExpression" && name === "property" || parent.type === "AssignmentExpression") {
  33195. return false;
  33196. }
  33197. return true;
  33198. case "JSXFragment":
  33199. case "JSXElement":
  33200. return name === "callee" || parent.type === "BinaryExpression" && parent.operator === "<" && name === "left" || parent.type !== "ArrayExpression" && parent.type !== "ArrowFunctionExpression" && parent.type !== "AssignmentExpression" && parent.type !== "AssignmentPattern" && parent.type !== "BinaryExpression" && parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "ConditionalExpression" && parent.type !== "ExpressionStatement" && parent.type !== "JsExpressionRoot" && parent.type !== "JSXAttribute" && parent.type !== "JSXElement" && parent.type !== "JSXExpressionContainer" && parent.type !== "JSXFragment" && parent.type !== "LogicalExpression" && parent.type !== "ObjectProperty" && parent.type !== "OptionalCallExpression" && parent.type !== "Property" && parent.type !== "ReturnStatement" && parent.type !== "ThrowStatement" && parent.type !== "TypeCastExpression" && parent.type !== "VariableDeclarator";
  33201. case "TypeAnnotation":
  33202. return name === "returnType" && parent.type === "ArrowFunctionExpression" && includesFunctionTypeInObjectType(node);
  33203. }
  33204. return false;
  33205. }
  33206. function isStatement(node) {
  33207. return node.type === "BlockStatement" || node.type === "BreakStatement" || node.type === "ClassBody" || node.type === "ClassDeclaration" || node.type === "ClassMethod" || node.type === "ClassProperty" || node.type === "ClassPrivateProperty" || node.type === "ContinueStatement" || node.type === "DebuggerStatement" || node.type === "DeclareClass" || node.type === "DeclareExportAllDeclaration" || node.type === "DeclareExportDeclaration" || node.type === "DeclareFunction" || node.type === "DeclareInterface" || node.type === "DeclareModule" || node.type === "DeclareModuleExports" || node.type === "DeclareVariable" || node.type === "DoWhileStatement" || node.type === "EnumDeclaration" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExpressionStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement" || node.type === "ForStatement" || node.type === "FunctionDeclaration" || node.type === "IfStatement" || node.type === "ImportDeclaration" || node.type === "InterfaceDeclaration" || node.type === "LabeledStatement" || node.type === "MethodDefinition" || node.type === "ReturnStatement" || node.type === "SwitchStatement" || node.type === "ThrowStatement" || node.type === "TryStatement" || node.type === "TSDeclareFunction" || node.type === "TSEnumDeclaration" || node.type === "TSImportEqualsDeclaration" || node.type === "TSInterfaceDeclaration" || node.type === "TSModuleDeclaration" || node.type === "TSNamespaceExportDeclaration" || node.type === "TypeAlias" || node.type === "VariableDeclaration" || node.type === "WhileStatement" || node.type === "WithStatement";
  33208. }
  33209. function includesFunctionTypeInObjectType(node) {
  33210. return hasNode$1(node, n1 => n1.type === "ObjectTypeAnnotation" && hasNode$1(n1, n2 => n2.type === "FunctionTypeAnnotation" || undefined) || undefined);
  33211. }
  33212. function endsWithRightBracket(node) {
  33213. switch (node.type) {
  33214. case "ObjectExpression":
  33215. return true;
  33216. default:
  33217. return false;
  33218. }
  33219. }
  33220. function isFollowedByRightBracket(path) {
  33221. const node = path.getValue();
  33222. const parent = path.getParentNode();
  33223. const name = path.getName();
  33224. switch (parent.type) {
  33225. case "NGPipeExpression":
  33226. if (typeof name === "number" && parent.arguments[name] === node && parent.arguments.length - 1 === name) {
  33227. return path.callParent(isFollowedByRightBracket);
  33228. }
  33229. break;
  33230. case "ObjectProperty":
  33231. if (name === "value") {
  33232. const parentParent = path.getParentNode(1);
  33233. return parentParent.properties[parentParent.properties.length - 1] === parent;
  33234. }
  33235. break;
  33236. case "BinaryExpression":
  33237. case "LogicalExpression":
  33238. if (name === "right") {
  33239. return path.callParent(isFollowedByRightBracket);
  33240. }
  33241. break;
  33242. case "ConditionalExpression":
  33243. if (name === "alternate") {
  33244. return path.callParent(isFollowedByRightBracket);
  33245. }
  33246. break;
  33247. case "UnaryExpression":
  33248. if (parent.prefix) {
  33249. return path.callParent(isFollowedByRightBracket);
  33250. }
  33251. break;
  33252. }
  33253. return false;
  33254. }
  33255. function shouldWrapFunctionForExportDefault(path, options) {
  33256. const node = path.getValue();
  33257. const parent = path.getParentNode();
  33258. if (node.type === "FunctionExpression" || node.type === "ClassExpression") {
  33259. return parent.type === "ExportDefaultDeclaration" || // in some cases the function is already wrapped
  33260. // (e.g. `export default (function() {})();`)
  33261. // in this case we don't need to add extra parens
  33262. !needsParens(path, options);
  33263. }
  33264. if (!hasNakedLeftSide$1(node) || parent.type !== "ExportDefaultDeclaration" && needsParens(path, options)) {
  33265. return false;
  33266. }
  33267. return path.call(childPath => shouldWrapFunctionForExportDefault(childPath, options), ...getLeftSidePathName$1(path, node));
  33268. }
  33269. var needsParens_1 = needsParens;
  33270. const {
  33271. builders: {
  33272. concat: concat$6,
  33273. join: join$3,
  33274. line: line$4
  33275. }
  33276. } = document;
  33277. function printHtmlBinding(path, options, print) {
  33278. const node = path.getValue();
  33279. if (options.__onHtmlBindingRoot && path.getName() === null) {
  33280. options.__onHtmlBindingRoot(node, options);
  33281. }
  33282. if (node.type !== "File") {
  33283. return;
  33284. }
  33285. if (options.__isVueForBindingLeft) {
  33286. return path.call(functionDeclarationPath => {
  33287. const {
  33288. params
  33289. } = functionDeclarationPath.getValue();
  33290. return concat$6([params.length > 1 ? "(" : "", join$3(concat$6([",", line$4]), functionDeclarationPath.map(print, "params")), params.length > 1 ? ")" : ""]);
  33291. }, "program", "body", 0);
  33292. }
  33293. if (options.__isVueSlotScope) {
  33294. return path.call(functionDeclarationPath => join$3(concat$6([",", line$4]), functionDeclarationPath.map(print, "params")), "program", "body", 0);
  33295. }
  33296. } // based on https://github.com/prettier/prettier/blob/master/src/language-html/syntax-vue.js isVueEventBindingExpression()
  33297. function isVueEventBindingExpression(node) {
  33298. switch (node.type) {
  33299. case "MemberExpression":
  33300. switch (node.property.type) {
  33301. case "Identifier":
  33302. case "NumericLiteral":
  33303. case "StringLiteral":
  33304. return isVueEventBindingExpression(node.object);
  33305. }
  33306. return false;
  33307. case "Identifier":
  33308. return true;
  33309. default:
  33310. return false;
  33311. }
  33312. }
  33313. var htmlBinding = {
  33314. isVueEventBindingExpression,
  33315. printHtmlBinding
  33316. };
  33317. function preprocess(ast, options) {
  33318. switch (options.parser) {
  33319. case "json":
  33320. case "json5":
  33321. case "json-stringify":
  33322. case "__js_expression":
  33323. case "__vue_expression":
  33324. return Object.assign({}, ast, {
  33325. type: options.parser.startsWith("__") ? "JsExpressionRoot" : "JsonRoot",
  33326. node: ast,
  33327. comments: [],
  33328. rootMarker: options.rootMarker
  33329. });
  33330. default:
  33331. return ast;
  33332. }
  33333. }
  33334. var preprocess_1 = preprocess;
  33335. const {
  33336. getLast: getLast$3,
  33337. getPenultimate: getPenultimate$1,
  33338. isNextLineEmpty: isNextLineEmpty$2
  33339. } = util;
  33340. const {
  33341. hasLeadingComment: hasLeadingComment$3,
  33342. hasTrailingComment: hasTrailingComment$1,
  33343. isFunctionCompositionArgs: isFunctionCompositionArgs$1,
  33344. isJSXNode: isJSXNode$1,
  33345. isLongCurriedCallExpression: isLongCurriedCallExpression$1,
  33346. shouldPrintComma: shouldPrintComma$1
  33347. } = utils$6;
  33348. const {
  33349. builders: {
  33350. concat: concat$7,
  33351. line: line$5,
  33352. hardline: hardline$4,
  33353. softline: softline$2,
  33354. group: group$2,
  33355. indent: indent$3,
  33356. conditionalGroup: conditionalGroup$1,
  33357. ifBreak: ifBreak$1,
  33358. breakParent: breakParent$2
  33359. },
  33360. utils: {
  33361. willBreak: willBreak$1
  33362. }
  33363. } = document;
  33364. function printCallArguments(path, options, print) {
  33365. const node = path.getValue();
  33366. const isDynamicImport = node.type === "ImportExpression";
  33367. const args = isDynamicImport ? [node.source] : node.arguments;
  33368. if (args.length === 0) {
  33369. return concat$7(["(", comments.printDanglingComments(path, options,
  33370. /* sameIndent */
  33371. true), ")"]);
  33372. } // useEffect(() => { ... }, [foo, bar, baz])
  33373. if (args.length === 2 && args[0].type === "ArrowFunctionExpression" && args[0].params.length === 0 && args[0].body.type === "BlockStatement" && args[1].type === "ArrayExpression" && !args.some(arg => arg.comments)) {
  33374. return concat$7(["(", path.call(print, "arguments", 0), ", ", path.call(print, "arguments", 1), ")"]);
  33375. } // func(
  33376. // ({
  33377. // a,
  33378. //
  33379. // b
  33380. // }) => {}
  33381. // );
  33382. function shouldBreakForArrowFunctionInArguments(arg, argPath) {
  33383. if (!arg || arg.type !== "ArrowFunctionExpression" || !arg.body || arg.body.type !== "BlockStatement" || !arg.params || arg.params.length < 1) {
  33384. return false;
  33385. }
  33386. let shouldBreak = false;
  33387. argPath.each(paramPath => {
  33388. const printed = concat$7([print(paramPath)]);
  33389. shouldBreak = shouldBreak || willBreak$1(printed);
  33390. }, "params");
  33391. return shouldBreak;
  33392. }
  33393. let anyArgEmptyLine = false;
  33394. let shouldBreakForArrowFunction = false;
  33395. let hasEmptyLineFollowingFirstArg = false;
  33396. const lastArgIndex = args.length - 1;
  33397. const printArgument = (argPath, index) => {
  33398. const arg = argPath.getNode();
  33399. const parts = [print(argPath)];
  33400. if (index === lastArgIndex) ; else if (isNextLineEmpty$2(options.originalText, arg, options.locEnd)) {
  33401. if (index === 0) {
  33402. hasEmptyLineFollowingFirstArg = true;
  33403. }
  33404. anyArgEmptyLine = true;
  33405. parts.push(",", hardline$4, hardline$4);
  33406. } else {
  33407. parts.push(",", line$5);
  33408. }
  33409. shouldBreakForArrowFunction = shouldBreakForArrowFunctionInArguments(arg, argPath);
  33410. return concat$7(parts);
  33411. };
  33412. const printedArguments = isDynamicImport ? [path.call(path => printArgument(path, 0), "source")] : path.map(printArgument, "arguments");
  33413. const maybeTrailingComma = // Dynamic imports cannot have trailing commas
  33414. !(isDynamicImport || node.callee && node.callee.type === "Import") && shouldPrintComma$1(options, "all") ? "," : "";
  33415. function allArgsBrokenOut() {
  33416. return group$2(concat$7(["(", indent$3(concat$7([line$5, concat$7(printedArguments)])), maybeTrailingComma, line$5, ")"]), {
  33417. shouldBreak: true
  33418. });
  33419. }
  33420. if (path.getParentNode().type !== "Decorator" && isFunctionCompositionArgs$1(args)) {
  33421. return allArgsBrokenOut();
  33422. }
  33423. const shouldGroupFirst = shouldGroupFirstArg(args);
  33424. const shouldGroupLast = shouldGroupLastArg(args);
  33425. if (shouldGroupFirst || shouldGroupLast) {
  33426. const shouldBreak = (shouldGroupFirst ? printedArguments.slice(1).some(willBreak$1) : printedArguments.slice(0, -1).some(willBreak$1)) || anyArgEmptyLine || shouldBreakForArrowFunction; // We want to print the last argument with a special flag
  33427. let printedExpanded = [];
  33428. let i = 0;
  33429. const printArgument = argPath => {
  33430. if (shouldGroupFirst && i === 0) {
  33431. printedExpanded = [concat$7([argPath.call(p => print(p, {
  33432. expandFirstArg: true
  33433. })), printedArguments.length > 1 ? "," : "", hasEmptyLineFollowingFirstArg ? hardline$4 : line$5, hasEmptyLineFollowingFirstArg ? hardline$4 : ""])].concat(printedArguments.slice(1));
  33434. }
  33435. if (shouldGroupLast && i === args.length - 1) {
  33436. printedExpanded = printedArguments.slice(0, -1).concat(argPath.call(p => print(p, {
  33437. expandLastArg: true
  33438. })));
  33439. }
  33440. i++;
  33441. };
  33442. if (isDynamicImport) {
  33443. path.call(printArgument, "source");
  33444. } else {
  33445. path.each(printArgument, "arguments");
  33446. }
  33447. const somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1);
  33448. const simpleConcat = concat$7(["(", concat$7(printedExpanded), ")"]);
  33449. return concat$7([somePrintedArgumentsWillBreak ? breakParent$2 : "", conditionalGroup$1([!somePrintedArgumentsWillBreak && !node.typeArguments && !node.typeParameters ? simpleConcat : ifBreak$1(allArgsBrokenOut(), simpleConcat), shouldGroupFirst ? concat$7(["(", group$2(printedExpanded[0], {
  33450. shouldBreak: true
  33451. }), concat$7(printedExpanded.slice(1)), ")"]) : concat$7(["(", concat$7(printedArguments.slice(0, -1)), group$2(getLast$3(printedExpanded), {
  33452. shouldBreak: true
  33453. }), ")"]), allArgsBrokenOut()], {
  33454. shouldBreak
  33455. })]);
  33456. }
  33457. const contents = concat$7(["(", indent$3(concat$7([softline$2, concat$7(printedArguments)])), ifBreak$1(maybeTrailingComma), softline$2, ")"]);
  33458. if (isLongCurriedCallExpression$1(path)) {
  33459. // By not wrapping the arguments in a group, the printer prioritizes
  33460. // breaking up these arguments rather than the args of the parent call.
  33461. return contents;
  33462. }
  33463. return group$2(contents, {
  33464. shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine
  33465. });
  33466. }
  33467. function couldGroupArg(arg) {
  33468. return arg.type === "ObjectExpression" && (arg.properties.length > 0 || arg.comments) || arg.type === "ArrayExpression" && (arg.elements.length > 0 || arg.comments) || arg.type === "TSTypeAssertion" && couldGroupArg(arg.expression) || arg.type === "TSAsExpression" && couldGroupArg(arg.expression) || arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression" && ( // we want to avoid breaking inside composite return types but not simple keywords
  33469. // https://github.com/prettier/prettier/issues/4070
  33470. // export class Thing implements OtherThing {
  33471. // do: (type: Type) => Provider<Prop> = memoize(
  33472. // (type: ObjectType): Provider<Opts> => {}
  33473. // );
  33474. // }
  33475. // https://github.com/prettier/prettier/issues/6099
  33476. // app.get("/", (req, res): void => {
  33477. // res.send("Hello World!");
  33478. // });
  33479. !arg.returnType || !arg.returnType.typeAnnotation || arg.returnType.typeAnnotation.type !== "TSTypeReference") && (arg.body.type === "BlockStatement" || arg.body.type === "ArrowFunctionExpression" || arg.body.type === "ObjectExpression" || arg.body.type === "ArrayExpression" || arg.body.type === "CallExpression" || arg.body.type === "OptionalCallExpression" || arg.body.type === "ConditionalExpression" || isJSXNode$1(arg.body));
  33480. }
  33481. function shouldGroupLastArg(args) {
  33482. const lastArg = getLast$3(args);
  33483. const penultimateArg = getPenultimate$1(args);
  33484. return !hasLeadingComment$3(lastArg) && !hasTrailingComment$1(lastArg) && couldGroupArg(lastArg) && ( // If the last two arguments are of the same type,
  33485. // disable last element expansion.
  33486. !penultimateArg || penultimateArg.type !== lastArg.type);
  33487. }
  33488. function shouldGroupFirstArg(args) {
  33489. if (args.length !== 2) {
  33490. return false;
  33491. }
  33492. const [firstArg, secondArg] = args;
  33493. return (!firstArg.comments || !firstArg.comments.length) && (firstArg.type === "FunctionExpression" || firstArg.type === "ArrowFunctionExpression" && firstArg.body.type === "BlockStatement") && secondArg.type !== "FunctionExpression" && secondArg.type !== "ArrowFunctionExpression" && secondArg.type !== "ConditionalExpression" && !couldGroupArg(secondArg);
  33494. }
  33495. var callArguments = printCallArguments;
  33496. const {
  33497. isNumericLiteral: isNumericLiteral$1
  33498. } = utils$6;
  33499. const {
  33500. builders: {
  33501. concat: concat$8,
  33502. softline: softline$3,
  33503. group: group$3,
  33504. indent: indent$4
  33505. }
  33506. } = document;
  33507. function printOptionalToken(path) {
  33508. const node = path.getValue();
  33509. if (!node.optional || // It's an optional computed method parsed by typescript-estree.
  33510. // "?" is printed in `printMethod`.
  33511. node.type === "Identifier" && node === path.getParentNode().key) {
  33512. return "";
  33513. }
  33514. if (node.type === "OptionalCallExpression" || node.type === "OptionalMemberExpression" && node.computed) {
  33515. return "?.";
  33516. }
  33517. return "?";
  33518. }
  33519. function printFunctionTypeParameters(path, options, print) {
  33520. const fun = path.getValue();
  33521. if (fun.typeArguments) {
  33522. return path.call(print, "typeArguments");
  33523. }
  33524. if (fun.typeParameters) {
  33525. return path.call(print, "typeParameters");
  33526. }
  33527. return "";
  33528. }
  33529. function printMemberLookup(path, options, print) {
  33530. const property = path.call(print, "property");
  33531. const n = path.getValue();
  33532. const optional = printOptionalToken(path);
  33533. if (!n.computed) {
  33534. return concat$8([optional, ".", property]);
  33535. }
  33536. if (!n.property || isNumericLiteral$1(n.property)) {
  33537. return concat$8([optional, "[", property, "]"]);
  33538. }
  33539. return group$3(concat$8([optional, "[", indent$4(concat$8([softline$3, property])), softline$3, "]"]));
  33540. }
  33541. function printBindExpressionCallee(path, options, print) {
  33542. return concat$8(["::", path.call(print, "callee")]);
  33543. }
  33544. var misc = {
  33545. printOptionalToken,
  33546. printFunctionTypeParameters,
  33547. printMemberLookup,
  33548. printBindExpressionCallee
  33549. };
  33550. const {
  33551. getLast: getLast$4,
  33552. isNextLineEmpty: isNextLineEmpty$3,
  33553. isNextLineEmptyAfterIndex: isNextLineEmptyAfterIndex$2,
  33554. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$3
  33555. } = util;
  33556. const {
  33557. hasLeadingComment: hasLeadingComment$4,
  33558. hasTrailingComment: hasTrailingComment$2,
  33559. isCallOrOptionalCallExpression: isCallOrOptionalCallExpression$1,
  33560. isFunctionOrArrowExpression: isFunctionOrArrowExpression$1,
  33561. isLongCurriedCallExpression: isLongCurriedCallExpression$2,
  33562. isMemberish: isMemberish$1,
  33563. isNumericLiteral: isNumericLiteral$2,
  33564. isSimpleCallArgument: isSimpleCallArgument$1
  33565. } = utils$6;
  33566. const {
  33567. builders: {
  33568. concat: concat$9,
  33569. join: join$4,
  33570. hardline: hardline$5,
  33571. group: group$4,
  33572. indent: indent$5,
  33573. conditionalGroup: conditionalGroup$2,
  33574. breakParent: breakParent$3
  33575. },
  33576. utils: {
  33577. willBreak: willBreak$2
  33578. }
  33579. } = document;
  33580. const {
  33581. printOptionalToken: printOptionalToken$1,
  33582. printFunctionTypeParameters: printFunctionTypeParameters$1,
  33583. printMemberLookup: printMemberLookup$1,
  33584. printBindExpressionCallee: printBindExpressionCallee$1
  33585. } = misc; // We detect calls on member expressions specially to format a
  33586. // common pattern better. The pattern we are looking for is this:
  33587. //
  33588. // arr
  33589. // .map(x => x + 1)
  33590. // .filter(x => x > 10)
  33591. // .some(x => x % 2)
  33592. //
  33593. // The way it is structured in the AST is via a nested sequence of
  33594. // MemberExpression and CallExpression. We need to traverse the AST
  33595. // and make groups out of it to print it in the desired way.
  33596. function printMemberChain(path, options, print) {
  33597. const parent = path.getParentNode();
  33598. const isExpressionStatement = !parent || parent.type === "ExpressionStatement"; // The first phase is to linearize the AST by traversing it down.
  33599. //
  33600. // a().b()
  33601. // has the following AST structure:
  33602. // CallExpression(MemberExpression(CallExpression(Identifier)))
  33603. // and we transform it into
  33604. // [Identifier, CallExpression, MemberExpression, CallExpression]
  33605. const printedNodes = []; // Here we try to retain one typed empty line after each call expression or
  33606. // the first group whether it is in parentheses or not
  33607. function shouldInsertEmptyLineAfter(node) {
  33608. const {
  33609. originalText
  33610. } = options;
  33611. const nextCharIndex = getNextNonSpaceNonCommentCharacterIndex$3(originalText, node, options.locEnd);
  33612. const nextChar = originalText.charAt(nextCharIndex); // if it is cut off by a parenthesis, we only account for one typed empty
  33613. // line after that parenthesis
  33614. if (nextChar === ")") {
  33615. return nextCharIndex !== false && isNextLineEmptyAfterIndex$2(originalText, nextCharIndex + 1);
  33616. }
  33617. return isNextLineEmpty$3(originalText, node, options.locEnd);
  33618. }
  33619. function rec(path) {
  33620. const node = path.getValue();
  33621. if (isCallOrOptionalCallExpression$1(node) && (isMemberish$1(node.callee) || isCallOrOptionalCallExpression$1(node.callee))) {
  33622. printedNodes.unshift({
  33623. node,
  33624. printed: concat$9([comments.printComments(path, () => concat$9([printOptionalToken$1(path), printFunctionTypeParameters$1(path, options, print), callArguments(path, options, print)]), options), shouldInsertEmptyLineAfter(node) ? hardline$5 : ""])
  33625. });
  33626. path.call(callee => rec(callee), "callee");
  33627. } else if (isMemberish$1(node)) {
  33628. printedNodes.unshift({
  33629. node,
  33630. needsParens: needsParens_1(path, options),
  33631. printed: comments.printComments(path, () => node.type === "OptionalMemberExpression" || node.type === "MemberExpression" ? printMemberLookup$1(path, options, print) : printBindExpressionCallee$1(path, options, print), options)
  33632. });
  33633. path.call(object => rec(object), "object");
  33634. } else if (node.type === "TSNonNullExpression") {
  33635. printedNodes.unshift({
  33636. node,
  33637. printed: comments.printComments(path, () => "!", options)
  33638. });
  33639. path.call(expression => rec(expression), "expression");
  33640. } else {
  33641. printedNodes.unshift({
  33642. node,
  33643. printed: path.call(print)
  33644. });
  33645. }
  33646. } // Note: the comments of the root node have already been printed, so we
  33647. // need to extract this first call without printing them as they would
  33648. // if handled inside of the recursive call.
  33649. const node = path.getValue();
  33650. printedNodes.unshift({
  33651. node,
  33652. printed: concat$9([printOptionalToken$1(path), printFunctionTypeParameters$1(path, options, print), callArguments(path, options, print)])
  33653. });
  33654. if (node.callee) {
  33655. path.call(callee => rec(callee), "callee");
  33656. } // Once we have a linear list of printed nodes, we want to create groups out
  33657. // of it.
  33658. //
  33659. // a().b.c().d().e
  33660. // will be grouped as
  33661. // [
  33662. // [Identifier, CallExpression],
  33663. // [MemberExpression, MemberExpression, CallExpression],
  33664. // [MemberExpression, CallExpression],
  33665. // [MemberExpression],
  33666. // ]
  33667. // so that we can print it as
  33668. // a()
  33669. // .b.c()
  33670. // .d()
  33671. // .e
  33672. // The first group is the first node followed by
  33673. // - as many CallExpression as possible
  33674. // < fn()()() >.something()
  33675. // - as many array accessors as possible
  33676. // < fn()[0][1][2] >.something()
  33677. // - then, as many MemberExpression as possible but the last one
  33678. // < this.items >.something()
  33679. const groups = [];
  33680. let currentGroup = [printedNodes[0]];
  33681. let i = 1;
  33682. for (; i < printedNodes.length; ++i) {
  33683. if (printedNodes[i].node.type === "TSNonNullExpression" || isCallOrOptionalCallExpression$1(printedNodes[i].node) || (printedNodes[i].node.type === "MemberExpression" || printedNodes[i].node.type === "OptionalMemberExpression") && printedNodes[i].node.computed && isNumericLiteral$2(printedNodes[i].node.property)) {
  33684. currentGroup.push(printedNodes[i]);
  33685. } else {
  33686. break;
  33687. }
  33688. }
  33689. if (!isCallOrOptionalCallExpression$1(printedNodes[0].node)) {
  33690. for (; i + 1 < printedNodes.length; ++i) {
  33691. if (isMemberish$1(printedNodes[i].node) && isMemberish$1(printedNodes[i + 1].node)) {
  33692. currentGroup.push(printedNodes[i]);
  33693. } else {
  33694. break;
  33695. }
  33696. }
  33697. }
  33698. groups.push(currentGroup);
  33699. currentGroup = []; // Then, each following group is a sequence of MemberExpression followed by
  33700. // a sequence of CallExpression. To compute it, we keep adding things to the
  33701. // group until we has seen a CallExpression in the past and reach a
  33702. // MemberExpression
  33703. let hasSeenCallExpression = false;
  33704. for (; i < printedNodes.length; ++i) {
  33705. if (hasSeenCallExpression && isMemberish$1(printedNodes[i].node)) {
  33706. // [0] should be appended at the end of the group instead of the
  33707. // beginning of the next one
  33708. if (printedNodes[i].node.computed && isNumericLiteral$2(printedNodes[i].node.property)) {
  33709. currentGroup.push(printedNodes[i]);
  33710. continue;
  33711. }
  33712. groups.push(currentGroup);
  33713. currentGroup = [];
  33714. hasSeenCallExpression = false;
  33715. }
  33716. if (isCallOrOptionalCallExpression$1(printedNodes[i].node) || printedNodes[i].node.type === "ImportExpression") {
  33717. hasSeenCallExpression = true;
  33718. }
  33719. currentGroup.push(printedNodes[i]);
  33720. if (printedNodes[i].node.comments && printedNodes[i].node.comments.some(comment => comment.trailing)) {
  33721. groups.push(currentGroup);
  33722. currentGroup = [];
  33723. hasSeenCallExpression = false;
  33724. }
  33725. }
  33726. if (currentGroup.length > 0) {
  33727. groups.push(currentGroup);
  33728. } // There are cases like Object.keys(), Observable.of(), _.values() where
  33729. // they are the subject of all the chained calls and therefore should
  33730. // be kept on the same line:
  33731. //
  33732. // Object.keys(items)
  33733. // .filter(x => x)
  33734. // .map(x => x)
  33735. //
  33736. // In order to detect those cases, we use an heuristic: if the first
  33737. // node is an identifier with the name starting with a capital
  33738. // letter or just a sequence of _$. The rationale is that they are
  33739. // likely to be factories.
  33740. function isFactory(name) {
  33741. return /^[A-Z]|^[$_]+$/.test(name);
  33742. } // In case the Identifier is shorter than tab width, we can keep the
  33743. // first call in a single line, if it's an ExpressionStatement.
  33744. //
  33745. // d3.scaleLinear()
  33746. // .domain([0, 100])
  33747. // .range([0, width]);
  33748. //
  33749. function isShort(name) {
  33750. return name.length <= options.tabWidth;
  33751. }
  33752. function shouldNotWrap(groups) {
  33753. const hasComputed = groups[1].length && groups[1][0].node.computed;
  33754. if (groups[0].length === 1) {
  33755. const firstNode = groups[0][0].node;
  33756. return firstNode.type === "ThisExpression" || firstNode.type === "Identifier" && (isFactory(firstNode.name) || isExpressionStatement && isShort(firstNode.name) || hasComputed);
  33757. }
  33758. const lastNode = getLast$4(groups[0]).node;
  33759. return (lastNode.type === "MemberExpression" || lastNode.type === "OptionalMemberExpression") && lastNode.property.type === "Identifier" && (isFactory(lastNode.property.name) || hasComputed);
  33760. }
  33761. const shouldMerge = groups.length >= 2 && !groups[1][0].node.comments && shouldNotWrap(groups);
  33762. function printGroup(printedGroup) {
  33763. const printed = printedGroup.map(tuple => tuple.printed); // Checks if the last node (i.e. the parent node) needs parens and print
  33764. // accordingly
  33765. if (printedGroup.length > 0 && printedGroup[printedGroup.length - 1].needsParens) {
  33766. return concat$9(["(", ...printed, ")"]);
  33767. }
  33768. return concat$9(printed);
  33769. }
  33770. function printIndentedGroup(groups) {
  33771. /* istanbul ignore next */
  33772. if (groups.length === 0) {
  33773. return "";
  33774. }
  33775. return indent$5(group$4(concat$9([hardline$5, join$4(hardline$5, groups.map(printGroup))])));
  33776. }
  33777. const printedGroups = groups.map(printGroup);
  33778. const oneLine = concat$9(printedGroups);
  33779. const cutoff = shouldMerge ? 3 : 2;
  33780. const flatGroups = flatten_1(groups);
  33781. const hasComment = flatGroups.slice(1, -1).some(node => hasLeadingComment$4(node.node)) || flatGroups.slice(0, -1).some(node => hasTrailingComment$2(node.node)) || groups[cutoff] && hasLeadingComment$4(groups[cutoff][0].node); // If we only have a single `.`, we shouldn't do anything fancy and just
  33782. // render everything concatenated together.
  33783. if (groups.length <= cutoff && !hasComment) {
  33784. if (isLongCurriedCallExpression$2(path)) {
  33785. return oneLine;
  33786. }
  33787. return group$4(oneLine);
  33788. } // Find out the last node in the first group and check if it has an
  33789. // empty line after
  33790. const lastNodeBeforeIndent = getLast$4(groups[shouldMerge ? 1 : 0]).node;
  33791. const shouldHaveEmptyLineBeforeIndent = !isCallOrOptionalCallExpression$1(lastNodeBeforeIndent) && shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
  33792. const expanded = concat$9([printGroup(groups[0]), shouldMerge ? concat$9(groups.slice(1, 2).map(printGroup)) : "", shouldHaveEmptyLineBeforeIndent ? hardline$5 : "", printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))]);
  33793. const callExpressions = printedNodes.map(({
  33794. node
  33795. }) => node).filter(isCallOrOptionalCallExpression$1);
  33796. function lastGroupWillBreakAndOtherCallsHaveFunctionArguments() {
  33797. const lastGroupNode = getLast$4(getLast$4(groups)).node;
  33798. const lastGroupDoc = getLast$4(printedGroups);
  33799. return isCallOrOptionalCallExpression$1(lastGroupNode) && willBreak$2(lastGroupDoc) && callExpressions.slice(0, -1).some(n => n.arguments.some(isFunctionOrArrowExpression$1));
  33800. } // We don't want to print in one line if at least one of these conditions occurs:
  33801. // * the chain has comments,
  33802. // * the chain is an expression statement and all the arguments are literal-like ("fluent configuration" pattern),
  33803. // * the chain is longer than 2 calls and has non-trivial arguments or more than 2 arguments in any call but the first one,
  33804. // * any group but the last one has a hard line,
  33805. // * the last call's arguments have a hard line and other calls have non-trivial arguments.
  33806. if (hasComment || callExpressions.length > 2 && callExpressions.some(expr => !expr.arguments.every(arg => isSimpleCallArgument$1(arg, 0))) || printedGroups.slice(0, -1).some(willBreak$2) || lastGroupWillBreakAndOtherCallsHaveFunctionArguments()) {
  33807. return group$4(expanded);
  33808. }
  33809. return concat$9([// We only need to check `oneLine` because if `expanded` is chosen
  33810. // that means that the parent group has already been broken
  33811. // naturally
  33812. willBreak$2(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent$3 : "", conditionalGroup$2([oneLine, expanded])]);
  33813. }
  33814. var memberChain = printMemberChain;
  33815. const {
  33816. builders: {
  33817. concat: concat$a,
  33818. softline: softline$4,
  33819. group: group$5,
  33820. indent: indent$6,
  33821. join: join$5,
  33822. line: line$6,
  33823. ifBreak: ifBreak$2
  33824. }
  33825. } = document;
  33826. const {
  33827. shouldPrintComma: shouldPrintComma$2
  33828. } = utils$6;
  33829. /**
  33830. * @typedef {import("../../document").Doc} Doc
  33831. */
  33832. function printModuleSource(path, options, print) {
  33833. const node = path.getValue();
  33834. return node.source ? concat$a([" from ", path.call(print, "source")]) : "";
  33835. }
  33836. function printModuleSpecifiers(path, options, print) {
  33837. const node = path.getValue();
  33838. /** @type{Doc[]} */
  33839. const parts = [node.type === "ImportDeclaration" ? " " : ""];
  33840. if (node.specifiers && node.specifiers.length > 0) {
  33841. const standalonesSpecifiers = [];
  33842. const groupedSpecifiers = [];
  33843. path.each(specifierPath => {
  33844. const specifierType = path.getValue().type;
  33845. if (specifierType === "ExportNamespaceSpecifier" || specifierType === "ExportDefaultSpecifier" || specifierType === "ImportNamespaceSpecifier" || specifierType === "ImportDefaultSpecifier") {
  33846. standalonesSpecifiers.push(print(specifierPath));
  33847. } else if (specifierType === "ExportSpecifier" || specifierType === "ImportSpecifier") {
  33848. groupedSpecifiers.push(print(specifierPath));
  33849. } else {
  33850. /* istanbul ignore next */
  33851. throw new Error(`Unknown specifier type ${JSON.stringify(specifierType)}`);
  33852. }
  33853. }, "specifiers");
  33854. parts.push(join$5(", ", standalonesSpecifiers));
  33855. if (groupedSpecifiers.length !== 0) {
  33856. if (standalonesSpecifiers.length !== 0) {
  33857. parts.push(", ");
  33858. }
  33859. const canBreak = groupedSpecifiers.length > 1 || standalonesSpecifiers.length > 0 || node.specifiers.some(node => node.comments);
  33860. if (canBreak) {
  33861. parts.push(group$5(concat$a(["{", indent$6(concat$a([options.bracketSpacing ? line$6 : softline$4, join$5(concat$a([",", line$6]), groupedSpecifiers)])), ifBreak$2(shouldPrintComma$2(options) ? "," : ""), options.bracketSpacing ? line$6 : softline$4, "}"])));
  33862. } else {
  33863. parts.push(concat$a(["{", options.bracketSpacing ? " " : "", concat$a(groupedSpecifiers), options.bracketSpacing ? " " : "", "}"]));
  33864. }
  33865. }
  33866. } else {
  33867. parts.push("{}");
  33868. }
  33869. return concat$a(parts);
  33870. }
  33871. var module$2 = {
  33872. printModuleSource,
  33873. printModuleSpecifiers
  33874. };
  33875. const {
  33876. isJSXNode: isJSXNode$2
  33877. } = utils$6;
  33878. const {
  33879. hasNewlineInRange: hasNewlineInRange$4
  33880. } = util;
  33881. const {
  33882. builders: {
  33883. concat: concat$b,
  33884. line: line$7,
  33885. softline: softline$5,
  33886. group: group$6,
  33887. indent: indent$7,
  33888. align: align$1,
  33889. ifBreak: ifBreak$3,
  33890. dedent: dedent$1,
  33891. breakParent: breakParent$4
  33892. }
  33893. } = document;
  33894. /**
  33895. * @typedef {import("../../document").Doc} Doc
  33896. * @typedef {import("../../common/fast-path")} FastPath
  33897. *
  33898. * @typedef {any} Options - Prettier options (TBD ...)
  33899. *
  33900. * @typedef {Object} OperatorOptions
  33901. * @property {() => Array<string | Doc>} beforeParts - Parts to print before the `?`.
  33902. * @property {(breakClosingParen: boolean) => Array<string | Doc>} afterParts - Parts to print after the conditional expression.
  33903. * @property {boolean} shouldCheckJsx - Whether to check for and print in JSX mode.
  33904. * @property {string} conditionalNodeType - The type of the conditional expression node, ie "ConditionalExpression" or "TSConditionalType".
  33905. * @property {string} consequentNodePropertyName - The property at which the consequent node can be found on the main node, eg "consequent".
  33906. * @property {string} alternateNodePropertyName - The property at which the alternate node can be found on the main node, eg "alternate".
  33907. * @property {string[]} testNodePropertyNames - The properties at which the test nodes can be found on the main node, eg "test".
  33908. */
  33909. // If we have nested conditional expressions, we want to print them in JSX mode
  33910. // if there's at least one JSXElement somewhere in the tree.
  33911. //
  33912. // A conditional expression chain like this should be printed in normal mode,
  33913. // because there aren't JSXElements anywhere in it:
  33914. //
  33915. // isA ? "A" : isB ? "B" : isC ? "C" : "Unknown";
  33916. //
  33917. // But a conditional expression chain like this should be printed in JSX mode,
  33918. // because there is a JSXElement in the last ConditionalExpression:
  33919. //
  33920. // isA ? "A" : isB ? "B" : isC ? "C" : <span className="warning">Unknown</span>;
  33921. //
  33922. // This type of ConditionalExpression chain is structured like this in the AST:
  33923. //
  33924. // ConditionalExpression {
  33925. // test: ...,
  33926. // consequent: ...,
  33927. // alternate: ConditionalExpression {
  33928. // test: ...,
  33929. // consequent: ...,
  33930. // alternate: ConditionalExpression {
  33931. // test: ...,
  33932. // consequent: ...,
  33933. // alternate: ...,
  33934. // }
  33935. // }
  33936. // }
  33937. //
  33938. // We want to traverse over that shape and convert it into a flat structure so
  33939. // that we can find if there's a JSXElement somewhere inside.
  33940. function getConditionalChainContents(node) {
  33941. // Given this code:
  33942. //
  33943. // // Using a ConditionalExpression as the consequent is uncommon, but should
  33944. // // be handled.
  33945. // A ? B : C ? D : E ? F ? G : H : I
  33946. //
  33947. // which has this AST:
  33948. //
  33949. // ConditionalExpression {
  33950. // test: Identifier(A),
  33951. // consequent: Identifier(B),
  33952. // alternate: ConditionalExpression {
  33953. // test: Identifier(C),
  33954. // consequent: Identifier(D),
  33955. // alternate: ConditionalExpression {
  33956. // test: Identifier(E),
  33957. // consequent: ConditionalExpression {
  33958. // test: Identifier(F),
  33959. // consequent: Identifier(G),
  33960. // alternate: Identifier(H),
  33961. // },
  33962. // alternate: Identifier(I),
  33963. // }
  33964. // }
  33965. // }
  33966. //
  33967. // we should return this Array:
  33968. //
  33969. // [
  33970. // Identifier(A),
  33971. // Identifier(B),
  33972. // Identifier(C),
  33973. // Identifier(D),
  33974. // Identifier(E),
  33975. // Identifier(F),
  33976. // Identifier(G),
  33977. // Identifier(H),
  33978. // Identifier(I)
  33979. // ];
  33980. //
  33981. // This loses the information about whether each node was the test,
  33982. // consequent, or alternate, but we don't care about that here- we are only
  33983. // flattening this structure to find if there's any JSXElements inside.
  33984. const nonConditionalExpressions = [];
  33985. function recurse(node) {
  33986. if (node.type === "ConditionalExpression") {
  33987. recurse(node.test);
  33988. recurse(node.consequent);
  33989. recurse(node.alternate);
  33990. } else {
  33991. nonConditionalExpressions.push(node);
  33992. }
  33993. }
  33994. recurse(node);
  33995. return nonConditionalExpressions;
  33996. }
  33997. function conditionalExpressionChainContainsJSX(node) {
  33998. return getConditionalChainContents(node).some(isJSXNode$2);
  33999. }
  34000. /**
  34001. * The following is the shared logic for
  34002. * ternary operators, namely ConditionalExpression
  34003. * and TSConditionalType
  34004. * @param {FastPath} path - The path to the ConditionalExpression/TSConditionalType node.
  34005. * @param {Options} options - Prettier options
  34006. * @param {Function} print - Print function to call recursively
  34007. * @param {OperatorOptions} operatorOptions
  34008. * @returns {Doc}
  34009. */
  34010. function printTernaryOperator(path, options, print, operatorOptions) {
  34011. const node = path.getValue();
  34012. const consequentNode = node[operatorOptions.consequentNodePropertyName];
  34013. const alternateNode = node[operatorOptions.alternateNodePropertyName];
  34014. const parts = []; // We print a ConditionalExpression in either "JSX mode" or "normal mode".
  34015. // See tests/jsx/conditional-expression.js for more info.
  34016. let jsxMode = false;
  34017. const parent = path.getParentNode();
  34018. const isParentTest = parent.type === operatorOptions.conditionalNodeType && operatorOptions.testNodePropertyNames.some(prop => parent[prop] === node);
  34019. let forceNoIndent = parent.type === operatorOptions.conditionalNodeType && !isParentTest; // Find the outermost non-ConditionalExpression parent, and the outermost
  34020. // ConditionalExpression parent. We'll use these to determine if we should
  34021. // print in JSX mode.
  34022. let currentParent;
  34023. let previousParent;
  34024. let i = 0;
  34025. do {
  34026. previousParent = currentParent || node;
  34027. currentParent = path.getParentNode(i);
  34028. i++;
  34029. } while (currentParent && currentParent.type === operatorOptions.conditionalNodeType && operatorOptions.testNodePropertyNames.every(prop => currentParent[prop] !== previousParent));
  34030. const firstNonConditionalParent = currentParent || parent;
  34031. const lastConditionalParent = previousParent;
  34032. if (operatorOptions.shouldCheckJsx && (isJSXNode$2(node[operatorOptions.testNodePropertyNames[0]]) || isJSXNode$2(consequentNode) || isJSXNode$2(alternateNode) || conditionalExpressionChainContainsJSX(lastConditionalParent))) {
  34033. jsxMode = true;
  34034. forceNoIndent = true; // Even though they don't need parens, we wrap (almost) everything in
  34035. // parens when using ?: within JSX, because the parens are analogous to
  34036. // curly braces in an if statement.
  34037. const wrap = doc => concat$b([ifBreak$3("(", ""), indent$7(concat$b([softline$5, doc])), softline$5, ifBreak$3(")", "")]); // The only things we don't wrap are:
  34038. // * Nested conditional expressions in alternates
  34039. // * null
  34040. // * undefined
  34041. const isNil = node => node.type === "NullLiteral" || node.type === "Literal" && node.value === null || node.type === "Identifier" && node.name === "undefined";
  34042. parts.push(" ? ", isNil(consequentNode) ? path.call(print, operatorOptions.consequentNodePropertyName) : wrap(path.call(print, operatorOptions.consequentNodePropertyName)), " : ", alternateNode.type === operatorOptions.conditionalNodeType || isNil(alternateNode) ? path.call(print, operatorOptions.alternateNodePropertyName) : wrap(path.call(print, operatorOptions.alternateNodePropertyName)));
  34043. } else {
  34044. // normal mode
  34045. const part = concat$b([line$7, "? ", consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$3("", "(") : "", align$1(2, path.call(print, operatorOptions.consequentNodePropertyName)), consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$3("", ")") : "", line$7, ": ", alternateNode.type === operatorOptions.conditionalNodeType ? path.call(print, operatorOptions.alternateNodePropertyName) : align$1(2, path.call(print, operatorOptions.alternateNodePropertyName))]);
  34046. parts.push(parent.type !== operatorOptions.conditionalNodeType || parent[operatorOptions.alternateNodePropertyName] === node || isParentTest ? part : options.useTabs ? dedent$1(indent$7(part)) : align$1(Math.max(0, options.tabWidth - 2), part));
  34047. } // We want a whole chain of ConditionalExpressions to all
  34048. // break if any of them break. That means we should only group around the
  34049. // outer-most ConditionalExpression.
  34050. const comments = flatten_1([...operatorOptions.testNodePropertyNames.map(propertyName => node[propertyName].comments), consequentNode.comments, alternateNode.comments]).filter(Boolean);
  34051. const shouldBreak = comments.some(comment => comments$1.isBlockComment(comment) && hasNewlineInRange$4(options.originalText, options.locStart(comment), options.locEnd(comment)));
  34052. const maybeGroup = doc => parent === firstNonConditionalParent ? group$6(doc, {
  34053. shouldBreak
  34054. }) : shouldBreak ? concat$b([doc, breakParent$4]) : doc; // Break the closing paren to keep the chain right after it:
  34055. // (a
  34056. // ? b
  34057. // : c
  34058. // ).call()
  34059. const breakClosingParen = !jsxMode && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression" || parent.type === "NGPipeExpression" && parent.left === node) && !parent.computed;
  34060. const result = maybeGroup(concat$b([].concat((testDoc =>
  34061. /**
  34062. * a
  34063. * ? b
  34064. * : multiline
  34065. * test
  34066. * node
  34067. * ^^ align(2)
  34068. * ? d
  34069. * : e
  34070. */
  34071. parent.type === operatorOptions.conditionalNodeType && parent[operatorOptions.alternateNodePropertyName] === node ? align$1(2, testDoc) : testDoc)(concat$b(operatorOptions.beforeParts())), forceNoIndent ? concat$b(parts) : indent$7(concat$b(parts)), operatorOptions.afterParts(breakClosingParen))));
  34072. return isParentTest ? group$6(concat$b([indent$7(concat$b([softline$5, result])), softline$5])) : result;
  34073. }
  34074. var ternary = printTernaryOperator;
  34075. /** @typedef {import("../document").Doc} Doc */
  34076. /** @type {import("assert")} */
  34077. // TODO(azz): anything that imports from main shouldn't be in a `language-*` dir.
  34078. const {
  34079. getNextNonSpaceNonCommentCharacter: getNextNonSpaceNonCommentCharacter$2,
  34080. hasNewline: hasNewline$5,
  34081. hasNewlineInRange: hasNewlineInRange$5,
  34082. getLast: getLast$5,
  34083. getStringWidth: getStringWidth$3,
  34084. printString: printString$1,
  34085. printNumber: printNumber$1,
  34086. hasIgnoreComment: hasIgnoreComment$2,
  34087. hasNodeIgnoreComment: hasNodeIgnoreComment$2,
  34088. getIndentSize: getIndentSize$2,
  34089. getPreferredQuote: getPreferredQuote$1
  34090. } = util;
  34091. const {
  34092. isNextLineEmpty: isNextLineEmpty$4,
  34093. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$4
  34094. } = utilShared;
  34095. const {
  34096. builders: {
  34097. concat: concat$c,
  34098. join: join$6,
  34099. line: line$8,
  34100. hardline: hardline$6,
  34101. softline: softline$6,
  34102. literalline: literalline$3,
  34103. group: group$7,
  34104. indent: indent$8,
  34105. align: align$2,
  34106. conditionalGroup: conditionalGroup$3,
  34107. fill: fill$3,
  34108. ifBreak: ifBreak$4,
  34109. lineSuffixBoundary: lineSuffixBoundary$1,
  34110. addAlignmentToDoc: addAlignmentToDoc$2
  34111. },
  34112. utils: {
  34113. willBreak: willBreak$3,
  34114. isLineNext: isLineNext$1,
  34115. isEmpty: isEmpty$1,
  34116. removeLines: removeLines$1,
  34117. normalizeParts: normalizeParts$1
  34118. },
  34119. printer: {
  34120. printDocToString: printDocToString$2
  34121. }
  34122. } = document;
  34123. const {
  34124. insertPragma: insertPragma$1
  34125. } = pragma;
  34126. const {
  34127. printHtmlBinding: printHtmlBinding$1,
  34128. isVueEventBindingExpression: isVueEventBindingExpression$1
  34129. } = htmlBinding;
  34130. const {
  34131. classChildNeedsASIProtection: classChildNeedsASIProtection$1,
  34132. classPropMayCauseASIProblems: classPropMayCauseASIProblems$1,
  34133. getFlowVariance: getFlowVariance$1,
  34134. getLeftSidePathName: getLeftSidePathName$2,
  34135. getParentExportDeclaration: getParentExportDeclaration$1,
  34136. getTypeScriptMappedTypeModifier: getTypeScriptMappedTypeModifier$1,
  34137. hasDanglingComments: hasDanglingComments$1,
  34138. hasFlowAnnotationComment: hasFlowAnnotationComment$1,
  34139. hasFlowShorthandAnnotationComment: hasFlowShorthandAnnotationComment$2,
  34140. hasLeadingOwnLineComment: hasLeadingOwnLineComment$1,
  34141. hasNakedLeftSide: hasNakedLeftSide$2,
  34142. hasNewlineBetweenOrAfterDecorators: hasNewlineBetweenOrAfterDecorators$1,
  34143. hasNgSideEffect: hasNgSideEffect$1,
  34144. hasPrettierIgnore: hasPrettierIgnore$1,
  34145. hasTrailingComment: hasTrailingComment$3,
  34146. hasTrailingLineComment: hasTrailingLineComment$1,
  34147. identity: identity$2,
  34148. isBinaryish: isBinaryish$1,
  34149. isCallOrOptionalCallExpression: isCallOrOptionalCallExpression$2,
  34150. isEmptyJSXElement: isEmptyJSXElement$1,
  34151. isExportDeclaration: isExportDeclaration$1,
  34152. isFlowAnnotationComment: isFlowAnnotationComment$1,
  34153. isFunctionNotation: isFunctionNotation$1,
  34154. isGetterOrSetter: isGetterOrSetter$1,
  34155. isJestEachTemplateLiteral: isJestEachTemplateLiteral$1,
  34156. isJSXNode: isJSXNode$3,
  34157. isJSXWhitespaceExpression: isJSXWhitespaceExpression$1,
  34158. isLastStatement: isLastStatement$1,
  34159. isLiteral: isLiteral$1,
  34160. isMeaningfulJSXText: isMeaningfulJSXText$1,
  34161. isMemberExpressionChain: isMemberExpressionChain$1,
  34162. isMemberish: isMemberish$2,
  34163. isNgForOf: isNgForOf$1,
  34164. isNumericLiteral: isNumericLiteral$3,
  34165. isObjectType: isObjectType$1,
  34166. isObjectTypePropertyAFunction: isObjectTypePropertyAFunction$1,
  34167. isSimpleFlowType: isSimpleFlowType$1,
  34168. isSimpleNumber: isSimpleNumber$1,
  34169. isSimpleTemplateLiteral: isSimpleTemplateLiteral$1,
  34170. isStringLiteral: isStringLiteral$1,
  34171. isStringPropSafeToUnquote: isStringPropSafeToUnquote$1,
  34172. isTemplateOnItsOwnLine: isTemplateOnItsOwnLine$1,
  34173. isTestCall: isTestCall$1,
  34174. isTheOnlyJSXElementInMarkdown: isTheOnlyJSXElementInMarkdown$1,
  34175. isTSXFile: isTSXFile$1,
  34176. isTypeAnnotationAFunction: isTypeAnnotationAFunction$1,
  34177. matchJsxWhitespaceRegex: matchJsxWhitespaceRegex$1,
  34178. needsHardlineAfterDanglingComment: needsHardlineAfterDanglingComment$1,
  34179. rawText: rawText$1,
  34180. returnArgumentHasLeadingComment: returnArgumentHasLeadingComment$1,
  34181. shouldPrintComma: shouldPrintComma$3,
  34182. shouldFlatten: shouldFlatten$2,
  34183. startsWithNoLookaheadToken: startsWithNoLookaheadToken$2
  34184. } = utils$6;
  34185. const {
  34186. printOptionalToken: printOptionalToken$2,
  34187. printFunctionTypeParameters: printFunctionTypeParameters$2,
  34188. printMemberLookup: printMemberLookup$2,
  34189. printBindExpressionCallee: printBindExpressionCallee$2
  34190. } = misc;
  34191. const {
  34192. printModuleSource: printModuleSource$1,
  34193. printModuleSpecifiers: printModuleSpecifiers$1
  34194. } = module$2;
  34195. const needsQuoteProps = new WeakMap();
  34196. let uid = 0;
  34197. function genericPrint(path, options, printPath, args) {
  34198. const node = path.getValue();
  34199. let needsParens = false;
  34200. const linesWithoutParens = printPathNoParens(path, options, printPath, args);
  34201. if (!node || isEmpty$1(linesWithoutParens)) {
  34202. return linesWithoutParens;
  34203. }
  34204. const parentExportDecl = getParentExportDeclaration$1(path);
  34205. const decorators = [];
  34206. if (node.type === "ClassMethod" || node.type === "ClassPrivateMethod" || node.type === "ClassProperty" || node.type === "TSAbstractClassProperty" || node.type === "ClassPrivateProperty" || node.type === "MethodDefinition" || node.type === "TSAbstractMethodDefinition" || node.type === "TSDeclareMethod") ; else if (node.decorators && node.decorators.length > 0 && // If the parent node is an export declaration and the decorator
  34207. // was written before the export, the export will be responsible
  34208. // for printing the decorators.
  34209. !(parentExportDecl && options.locStart(parentExportDecl, {
  34210. ignoreDecorators: true
  34211. }) > options.locStart(node.decorators[0]))) {
  34212. const shouldBreak = node.type === "ClassExpression" || node.type === "ClassDeclaration" || hasNewlineBetweenOrAfterDecorators$1(node, options);
  34213. const separator = shouldBreak ? hardline$6 : line$8;
  34214. path.each(decoratorPath => {
  34215. let decorator = decoratorPath.getValue();
  34216. if (decorator.expression) {
  34217. decorator = decorator.expression;
  34218. } else {
  34219. decorator = decorator.callee;
  34220. }
  34221. decorators.push(printPath(decoratorPath), separator);
  34222. }, "decorators");
  34223. if (parentExportDecl) {
  34224. decorators.unshift(hardline$6);
  34225. }
  34226. } else if (isExportDeclaration$1(node) && node.declaration && node.declaration.decorators && node.declaration.decorators.length > 0 && // Only print decorators here if they were written before the export,
  34227. // otherwise they are printed by the node.declaration
  34228. options.locStart(node, {
  34229. ignoreDecorators: true
  34230. }) > options.locStart(node.declaration.decorators[0])) {
  34231. // Export declarations are responsible for printing any decorators
  34232. // that logically apply to node.declaration.
  34233. path.each(decoratorPath => {
  34234. const decorator = decoratorPath.getValue();
  34235. const prefix = decorator.type === "Decorator" ? "" : "@";
  34236. decorators.push(prefix, printPath(decoratorPath), hardline$6);
  34237. }, "declaration", "decorators");
  34238. } else {
  34239. // Nodes with decorators can't have parentheses, so we can avoid
  34240. // computing pathNeedsParens() except in this case.
  34241. needsParens = needsParens_1(path, options);
  34242. }
  34243. const parts = [];
  34244. if (needsParens) {
  34245. parts.unshift("(");
  34246. }
  34247. parts.push(linesWithoutParens);
  34248. if (needsParens) {
  34249. const node = path.getValue();
  34250. if (hasFlowShorthandAnnotationComment$2(node)) {
  34251. parts.push(" /*");
  34252. parts.push(node.trailingComments[0].value.trimStart());
  34253. parts.push("*/");
  34254. node.trailingComments[0].printed = true;
  34255. }
  34256. parts.push(")");
  34257. }
  34258. if (decorators.length > 0) {
  34259. return group$7(concat$c(decorators.concat(parts)));
  34260. }
  34261. return concat$c(parts);
  34262. }
  34263. function printDecorators(path, options, print) {
  34264. const node = path.getValue();
  34265. return group$7(concat$c([join$6(line$8, path.map(print, "decorators")), hasNewlineBetweenOrAfterDecorators$1(node, options) ? hardline$6 : line$8]));
  34266. }
  34267. function printPathNoParens(path, options, print, args) {
  34268. const n = path.getValue();
  34269. const semi = options.semi ? ";" : "";
  34270. if (!n) {
  34271. return "";
  34272. }
  34273. if (typeof n === "string") {
  34274. return n;
  34275. }
  34276. const htmlBinding = printHtmlBinding$1(path, options, print);
  34277. if (htmlBinding) {
  34278. return htmlBinding;
  34279. }
  34280. /** @type{Doc[]} */
  34281. let parts = [];
  34282. switch (n.type) {
  34283. case "JsExpressionRoot":
  34284. return path.call(print, "node");
  34285. case "JsonRoot":
  34286. return concat$c([path.call(print, "node"), hardline$6]);
  34287. case "File":
  34288. // Print @babel/parser's InterpreterDirective here so that
  34289. // leading comments on the `Program` node get printed after the hashbang.
  34290. if (n.program && n.program.interpreter) {
  34291. parts.push(path.call(programPath => programPath.call(print, "interpreter"), "program"));
  34292. }
  34293. parts.push(path.call(print, "program"));
  34294. return concat$c(parts);
  34295. case "Program":
  34296. {
  34297. const hasContents = !n.body.every(({
  34298. type
  34299. }) => type === "EmptyStatement") || n.comments; // Babel 6
  34300. if (n.directives) {
  34301. const directivesCount = n.directives.length;
  34302. path.map((childPath, index) => {
  34303. parts.push(print(childPath), semi, hardline$6);
  34304. if ((index < directivesCount - 1 || hasContents) && isNextLineEmpty$4(options.originalText, childPath.getValue(), options.locEnd)) {
  34305. parts.push(hardline$6);
  34306. }
  34307. }, "directives");
  34308. }
  34309. parts.push(path.call(bodyPath => {
  34310. return printStatementSequence(bodyPath, options, print);
  34311. }, "body"));
  34312. parts.push(comments.printDanglingComments(path, options,
  34313. /* sameIndent */
  34314. true)); // Only force a trailing newline if there were any contents.
  34315. if (hasContents) {
  34316. parts.push(hardline$6);
  34317. }
  34318. return concat$c(parts);
  34319. }
  34320. // Babel extension.
  34321. case "EmptyStatement":
  34322. return "";
  34323. case "ExpressionStatement":
  34324. // Detect Flow and TypeScript directives
  34325. if (n.directive) {
  34326. return concat$c([nodeStr(n.expression, options, true), semi]);
  34327. }
  34328. if (options.parser === "__vue_event_binding") {
  34329. const parent = path.getParentNode();
  34330. if (parent.type === "Program" && parent.body.length === 1 && parent.body[0] === n) {
  34331. return concat$c([path.call(print, "expression"), isVueEventBindingExpression$1(n.expression) ? ";" : ""]);
  34332. }
  34333. } // Do not append semicolon after the only JSX element in a program
  34334. return concat$c([path.call(print, "expression"), isTheOnlyJSXElementInMarkdown$1(options, path) ? "" : semi]);
  34335. // Babel non-standard node. Used for Closure-style type casts. See postprocess.js.
  34336. case "ParenthesizedExpression":
  34337. {
  34338. const shouldHug = !n.expression.comments;
  34339. if (shouldHug) {
  34340. return concat$c(["(", path.call(print, "expression"), ")"]);
  34341. }
  34342. return group$7(concat$c(["(", indent$8(concat$c([softline$6, path.call(print, "expression")])), softline$6, ")"]));
  34343. }
  34344. case "AssignmentExpression":
  34345. return printAssignment(n.left, path.call(print, "left"), concat$c([" ", n.operator]), n.right, path.call(print, "right"), options);
  34346. case "BinaryExpression":
  34347. case "LogicalExpression":
  34348. case "NGPipeExpression":
  34349. {
  34350. const parent = path.getParentNode();
  34351. const parentParent = path.getParentNode(1);
  34352. const isInsideParenthesis = n !== parent.body && (parent.type === "IfStatement" || parent.type === "WhileStatement" || parent.type === "SwitchStatement" || parent.type === "DoWhileStatement");
  34353. const parts = printBinaryishExpressions(path, print, options,
  34354. /* isNested */
  34355. false, isInsideParenthesis); // if (
  34356. // this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
  34357. // ) {
  34358. //
  34359. // looks super weird, we want to break the children if the parent breaks
  34360. //
  34361. // if (
  34362. // this.hasPlugin("dynamicImports") &&
  34363. // this.lookahead().type === tt.parenLeft
  34364. // ) {
  34365. if (isInsideParenthesis) {
  34366. return concat$c(parts);
  34367. } // Break between the parens in
  34368. // unaries or in a member or specific call expression, i.e.
  34369. //
  34370. // (
  34371. // a &&
  34372. // b &&
  34373. // c
  34374. // ).call()
  34375. if ((parent.type === "CallExpression" || parent.type === "OptionalCallExpression") && parent.callee === n || parent.type === "UnaryExpression" || (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && !parent.computed) {
  34376. return group$7(concat$c([indent$8(concat$c([softline$6, concat$c(parts)])), softline$6]));
  34377. } // Avoid indenting sub-expressions in some cases where the first sub-expression is already
  34378. // indented accordingly. We should indent sub-expressions where the first case isn't indented.
  34379. const shouldNotIndent = parent.type === "ReturnStatement" || parent.type === "ThrowStatement" || parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" || n.operator !== "|" && parent.type === "JsExpressionRoot" || n.type !== "NGPipeExpression" && (parent.type === "NGRoot" && options.parser === "__ng_binding" || parent.type === "NGMicrosyntaxExpression" && parentParent.type === "NGMicrosyntax" && parentParent.body.length === 1) || n === parent.body && parent.type === "ArrowFunctionExpression" || n !== parent.body && parent.type === "ForStatement" || parent.type === "ConditionalExpression" && parentParent.type !== "ReturnStatement" && parentParent.type !== "ThrowStatement" && parentParent.type !== "CallExpression" && parentParent.type !== "OptionalCallExpression" || parent.type === "TemplateLiteral";
  34380. const shouldIndentIfInlining = parent.type === "AssignmentExpression" || parent.type === "VariableDeclarator" || parent.type === "ClassProperty" || parent.type === "TSAbstractClassProperty" || parent.type === "ClassPrivateProperty" || parent.type === "ObjectProperty" || parent.type === "Property";
  34381. const samePrecedenceSubExpression = isBinaryish$1(n.left) && shouldFlatten$2(n.operator, n.left.operator);
  34382. if (shouldNotIndent || shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression || !shouldInlineLogicalExpression(n) && shouldIndentIfInlining) {
  34383. return group$7(concat$c(parts));
  34384. }
  34385. if (parts.length === 0) {
  34386. return "";
  34387. } // If the right part is a JSX node, we include it in a separate group to
  34388. // prevent it breaking the whole chain, so we can print the expression like:
  34389. //
  34390. // foo && bar && (
  34391. // <Foo>
  34392. // <Bar />
  34393. // </Foo>
  34394. // )
  34395. const hasJSX = isJSXNode$3(n.right);
  34396. const firstGroupIndex = parts.findIndex(part => typeof part !== "string" && part.type === "group"); // Separate the leftmost expression, possibly with its leading comments.
  34397. const headParts = parts.slice(0, firstGroupIndex === -1 ? 1 : firstGroupIndex + 1);
  34398. const rest = concat$c(parts.slice(headParts.length, hasJSX ? -1 : undefined));
  34399. const groupId = Symbol("logicalChain-" + ++uid);
  34400. const chain = group$7(concat$c([// Don't include the initial expression in the indentation
  34401. // level. The first item is guaranteed to be the first
  34402. // left-most expression.
  34403. ...headParts, indent$8(rest)]), {
  34404. id: groupId
  34405. });
  34406. if (!hasJSX) {
  34407. return chain;
  34408. }
  34409. const jsxPart = getLast$5(parts);
  34410. return group$7(concat$c([chain, ifBreak$4(indent$8(jsxPart), jsxPart, {
  34411. groupId
  34412. })]));
  34413. }
  34414. case "AssignmentPattern":
  34415. return concat$c([path.call(print, "left"), " = ", path.call(print, "right")]);
  34416. case "TSTypeAssertion":
  34417. {
  34418. const shouldBreakAfterCast = !(n.expression.type === "ArrayExpression" || n.expression.type === "ObjectExpression");
  34419. const castGroup = group$7(concat$c(["<", indent$8(concat$c([softline$6, path.call(print, "typeAnnotation")])), softline$6, ">"]));
  34420. const exprContents = concat$c([ifBreak$4("("), indent$8(concat$c([softline$6, path.call(print, "expression")])), softline$6, ifBreak$4(")")]);
  34421. if (shouldBreakAfterCast) {
  34422. return conditionalGroup$3([concat$c([castGroup, path.call(print, "expression")]), concat$c([castGroup, group$7(exprContents, {
  34423. shouldBreak: true
  34424. })]), concat$c([castGroup, path.call(print, "expression")])]);
  34425. }
  34426. return group$7(concat$c([castGroup, path.call(print, "expression")]));
  34427. }
  34428. case "OptionalMemberExpression":
  34429. case "MemberExpression":
  34430. {
  34431. const parent = path.getParentNode();
  34432. let firstNonMemberParent;
  34433. let i = 0;
  34434. do {
  34435. firstNonMemberParent = path.getParentNode(i);
  34436. i++;
  34437. } while (firstNonMemberParent && (firstNonMemberParent.type === "MemberExpression" || firstNonMemberParent.type === "OptionalMemberExpression" || firstNonMemberParent.type === "TSNonNullExpression"));
  34438. const shouldInline = firstNonMemberParent && (firstNonMemberParent.type === "NewExpression" || firstNonMemberParent.type === "BindExpression" || firstNonMemberParent.type === "VariableDeclarator" && firstNonMemberParent.id.type !== "Identifier" || firstNonMemberParent.type === "AssignmentExpression" && firstNonMemberParent.left.type !== "Identifier") || n.computed || n.object.type === "Identifier" && n.property.type === "Identifier" && parent.type !== "MemberExpression" && parent.type !== "OptionalMemberExpression";
  34439. return concat$c([path.call(print, "object"), shouldInline ? printMemberLookup$2(path, options, print) : group$7(indent$8(concat$c([softline$6, printMemberLookup$2(path, options, print)])))]);
  34440. }
  34441. case "MetaProperty":
  34442. return concat$c([path.call(print, "meta"), ".", path.call(print, "property")]);
  34443. case "BindExpression":
  34444. if (n.object) {
  34445. parts.push(path.call(print, "object"));
  34446. }
  34447. parts.push(group$7(indent$8(concat$c([softline$6, printBindExpressionCallee$2(path, options, print)]))));
  34448. return concat$c(parts);
  34449. case "Identifier":
  34450. {
  34451. return concat$c([n.name, printOptionalToken$2(path), printTypeAnnotation(path, options, print)]);
  34452. }
  34453. case "V8IntrinsicIdentifier":
  34454. return concat$c(["%", n.name]);
  34455. case "SpreadElement":
  34456. case "SpreadElementPattern":
  34457. case "SpreadProperty":
  34458. case "SpreadPropertyPattern":
  34459. case "RestElement":
  34460. case "ObjectTypeSpreadProperty":
  34461. return concat$c(["...", path.call(print, "argument"), printTypeAnnotation(path, options, print)]);
  34462. case "FunctionDeclaration":
  34463. case "FunctionExpression":
  34464. parts.push(printFunctionDeclaration(path, print, options));
  34465. if (!n.body) {
  34466. parts.push(semi);
  34467. }
  34468. return concat$c(parts);
  34469. case "ArrowFunctionExpression":
  34470. {
  34471. if (n.async) {
  34472. parts.push("async ");
  34473. }
  34474. if (shouldPrintParamsWithoutParens(path, options)) {
  34475. parts.push(path.call(print, "params", 0));
  34476. } else {
  34477. parts.push(group$7(concat$c([printFunctionParams(path, print, options,
  34478. /* expandLast */
  34479. args && (args.expandLastArg || args.expandFirstArg),
  34480. /* printTypeParams */
  34481. true), printReturnType(path, print, options)])));
  34482. }
  34483. const dangling = comments.printDanglingComments(path, options,
  34484. /* sameIndent */
  34485. true, comment => {
  34486. const nextCharacter = getNextNonSpaceNonCommentCharacterIndex$4(options.originalText, comment, options.locEnd);
  34487. return nextCharacter !== false && options.originalText.slice(nextCharacter, nextCharacter + 2) === "=>";
  34488. });
  34489. if (dangling) {
  34490. parts.push(" ", dangling);
  34491. }
  34492. parts.push(" =>");
  34493. const body = path.call(bodyPath => print(bodyPath, args), "body"); // We want to always keep these types of nodes on the same line
  34494. // as the arrow.
  34495. if (!hasLeadingOwnLineComment$1(options.originalText, n.body, options) && (n.body.type === "ArrayExpression" || n.body.type === "ObjectExpression" || n.body.type === "BlockStatement" || isJSXNode$3(n.body) || isTemplateOnItsOwnLine$1(n.body, options.originalText, options) || n.body.type === "ArrowFunctionExpression" || n.body.type === "DoExpression")) {
  34496. return group$7(concat$c([concat$c(parts), " ", body]));
  34497. } // We handle sequence expressions as the body of arrows specially,
  34498. // so that the required parentheses end up on their own lines.
  34499. if (n.body.type === "SequenceExpression") {
  34500. return group$7(concat$c([concat$c(parts), group$7(concat$c([" (", indent$8(concat$c([softline$6, body])), softline$6, ")"]))]));
  34501. } // if the arrow function is expanded as last argument, we are adding a
  34502. // level of indentation and need to add a softline to align the closing )
  34503. // with the opening (, or if it's inside a JSXExpression (e.g. an attribute)
  34504. // we should align the expression's closing } with the line with the opening {.
  34505. const shouldAddSoftLine = (args && args.expandLastArg || path.getParentNode().type === "JSXExpressionContainer") && !(n.comments && n.comments.length);
  34506. const printTrailingComma = args && args.expandLastArg && shouldPrintComma$3(options, "all"); // In order to avoid confusion between
  34507. // a => a ? a : a
  34508. // a <= a ? a : a
  34509. const shouldAddParens = n.body.type === "ConditionalExpression" && !startsWithNoLookaheadToken$2(n.body,
  34510. /* forbidFunctionAndClass */
  34511. false);
  34512. return group$7(concat$c([concat$c(parts), group$7(concat$c([indent$8(concat$c([line$8, shouldAddParens ? ifBreak$4("", "(") : "", body, shouldAddParens ? ifBreak$4("", ")") : ""])), shouldAddSoftLine ? concat$c([ifBreak$4(printTrailingComma ? "," : ""), softline$6]) : ""]))]));
  34513. }
  34514. case "YieldExpression":
  34515. parts.push("yield");
  34516. if (n.delegate) {
  34517. parts.push("*");
  34518. }
  34519. if (n.argument) {
  34520. parts.push(" ", path.call(print, "argument"));
  34521. }
  34522. return concat$c(parts);
  34523. case "AwaitExpression":
  34524. {
  34525. parts.push("await");
  34526. if (n.argument) {
  34527. parts.push(" ", path.call(print, "argument"));
  34528. }
  34529. const parent = path.getParentNode();
  34530. if ((parent.type === "CallExpression" || parent.type === "OptionalCallExpression") && parent.callee === n || (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && parent.object === n) {
  34531. return group$7(concat$c([indent$8(concat$c([softline$6, concat$c(parts)])), softline$6]));
  34532. }
  34533. return concat$c(parts);
  34534. }
  34535. case "ImportSpecifier":
  34536. if (n.importKind) {
  34537. parts.push(path.call(print, "importKind"), " ");
  34538. }
  34539. parts.push(path.call(print, "imported"));
  34540. if (n.local && n.local.name !== n.imported.name) {
  34541. parts.push(" as ", path.call(print, "local"));
  34542. }
  34543. return concat$c(parts);
  34544. case "ExportSpecifier":
  34545. parts.push(path.call(print, "local"));
  34546. if (n.exported && n.exported.name !== n.local.name) {
  34547. parts.push(" as ", path.call(print, "exported"));
  34548. }
  34549. return concat$c(parts);
  34550. case "ImportNamespaceSpecifier":
  34551. parts.push("* as ");
  34552. parts.push(path.call(print, "local"));
  34553. return concat$c(parts);
  34554. case "ImportDefaultSpecifier":
  34555. return path.call(print, "local");
  34556. case "TSExportAssignment":
  34557. return concat$c(["export = ", path.call(print, "expression"), semi]);
  34558. case "ExportDefaultDeclaration":
  34559. case "ExportNamedDeclaration":
  34560. return printExportDeclaration(path, options, print);
  34561. case "DeclareExportDeclaration":
  34562. return concat$c(["declare ", printExportDeclaration(path, options, print)]);
  34563. case "ExportAllDeclaration":
  34564. parts.push("export");
  34565. if (n.exportKind === "type") {
  34566. parts.push(" type");
  34567. }
  34568. parts.push(" *");
  34569. if (n.exported) {
  34570. parts.push(" as ", path.call(print, "exported"));
  34571. }
  34572. parts.push(printModuleSource$1(path, options, print), semi);
  34573. return concat$c(parts);
  34574. case "ExportNamespaceSpecifier":
  34575. return concat$c(["* as ", path.call(print, "exported")]);
  34576. case "ExportDefaultSpecifier":
  34577. return path.call(print, "exported");
  34578. case "ImportDeclaration":
  34579. {
  34580. parts.push("import");
  34581. if (n.importKind && n.importKind !== "value") {
  34582. parts.push(" ", n.importKind);
  34583. }
  34584. if (n.specifiers && n.specifiers.length > 0) {
  34585. parts.push(printModuleSpecifiers$1(path, options, print));
  34586. parts.push(printModuleSource$1(path, options, print));
  34587. } else if (n.importKind && n.importKind === "type" || // import {} from 'x'
  34588. /{\s*}/.test(options.originalText.slice(options.locStart(n), options.locStart(n.source)))) {
  34589. parts.push(" {}", printModuleSource$1(path, options, print));
  34590. } else {
  34591. parts.push(" ", path.call(print, "source"));
  34592. }
  34593. if (Array.isArray(n.attributes) && n.attributes.length !== 0) {
  34594. parts.push(" with ", concat$c(path.map(print, "attributes")));
  34595. }
  34596. parts.push(semi);
  34597. return concat$c(parts);
  34598. }
  34599. case "ImportAttribute":
  34600. return concat$c([path.call(print, "key"), ": ", path.call(print, "value")]);
  34601. case "Import":
  34602. return "import";
  34603. case "TSModuleBlock":
  34604. case "BlockStatement":
  34605. {
  34606. const naked = path.call(bodyPath => {
  34607. return printStatementSequence(bodyPath, options, print);
  34608. }, "body");
  34609. const hasContent = n.body.some(node => node.type !== "EmptyStatement");
  34610. const hasDirectives = n.directives && n.directives.length > 0;
  34611. const parent = path.getParentNode();
  34612. const parentParent = path.getParentNode(1);
  34613. if (!hasContent && !hasDirectives && !hasDanglingComments$1(n) && (parent.type === "ArrowFunctionExpression" || parent.type === "FunctionExpression" || parent.type === "FunctionDeclaration" || parent.type === "ObjectMethod" || parent.type === "ClassMethod" || parent.type === "ClassPrivateMethod" || parent.type === "ForStatement" || parent.type === "WhileStatement" || parent.type === "DoWhileStatement" || parent.type === "DoExpression" || parent.type === "CatchClause" && !parentParent.finalizer || parent.type === "TSModuleDeclaration")) {
  34614. return "{}";
  34615. }
  34616. parts.push("{"); // Babel 6
  34617. if (hasDirectives) {
  34618. path.each(childPath => {
  34619. parts.push(indent$8(concat$c([hardline$6, print(childPath), semi])));
  34620. if (isNextLineEmpty$4(options.originalText, childPath.getValue(), options.locEnd)) {
  34621. parts.push(hardline$6);
  34622. }
  34623. }, "directives");
  34624. }
  34625. if (hasContent) {
  34626. parts.push(indent$8(concat$c([hardline$6, naked])));
  34627. }
  34628. parts.push(comments.printDanglingComments(path, options));
  34629. parts.push(hardline$6, "}");
  34630. return concat$c(parts);
  34631. }
  34632. case "ReturnStatement":
  34633. return concat$c(["return", printReturnAndThrowArgument(path, options, print)]);
  34634. case "NewExpression":
  34635. case "ImportExpression":
  34636. case "OptionalCallExpression":
  34637. case "CallExpression":
  34638. {
  34639. const isNew = n.type === "NewExpression";
  34640. const isDynamicImport = n.type === "ImportExpression";
  34641. const optional = printOptionalToken$2(path);
  34642. const args = isDynamicImport ? [n.source] : n.arguments;
  34643. if ( // We want to keep CommonJS- and AMD-style require calls, and AMD-style
  34644. // define calls, as a unit.
  34645. // e.g. `define(["some/lib", (lib) => {`
  34646. !isDynamicImport && !isNew && n.callee.type === "Identifier" && (n.callee.name === "require" || n.callee.name === "define") || // Template literals as single arguments
  34647. args.length === 1 && isTemplateOnItsOwnLine$1(args[0], options.originalText, options) || // Keep test declarations on a single line
  34648. // e.g. `it('long name', () => {`
  34649. !isNew && isTestCall$1(n, path.getParentNode())) {
  34650. return concat$c([isNew ? "new " : "", path.call(print, "callee"), optional, printFunctionTypeParameters$2(path, options, print), concat$c(["(", isDynamicImport ? path.call(print, "source") : join$6(", ", path.map(print, "arguments")), ")"])]);
  34651. } // Inline Flow annotation comments following Identifiers in Call nodes need to
  34652. // stay with the Identifier. For example:
  34653. //
  34654. // foo /*:: <SomeGeneric> */(bar);
  34655. //
  34656. // Here, we ensure that such comments stay between the Identifier and the Callee.
  34657. const isIdentifierWithFlowAnnotation = n.callee && n.callee.type === "Identifier" && hasFlowAnnotationComment$1(n.callee.trailingComments);
  34658. if (isIdentifierWithFlowAnnotation) {
  34659. n.callee.trailingComments[0].printed = true;
  34660. } // We detect calls on member lookups and possibly print them in a
  34661. // special chain format. See `printMemberChain` for more info.
  34662. if (!isDynamicImport && !isNew && isMemberish$2(n.callee) && !path.call(path => needsParens_1(path, options), "callee")) {
  34663. return memberChain(path, options, print);
  34664. }
  34665. const contents = concat$c([isNew ? "new " : "", isDynamicImport ? "import" : path.call(print, "callee"), optional, isIdentifierWithFlowAnnotation ? `/*:: ${n.callee.trailingComments[0].value.slice(2).trim()} */` : "", printFunctionTypeParameters$2(path, options, print), callArguments(path, options, print)]); // We group here when the callee is itself a call expression.
  34666. // See `isLongCurriedCallExpression` for more info.
  34667. if (isDynamicImport || isCallOrOptionalCallExpression$2(n.callee)) {
  34668. return group$7(contents);
  34669. }
  34670. return contents;
  34671. }
  34672. case "ObjectTypeInternalSlot":
  34673. return concat$c([n.static ? "static " : "", "[[", path.call(print, "id"), "]]", printOptionalToken$2(path), n.method ? "" : ": ", path.call(print, "value")]);
  34674. case "ObjectExpression":
  34675. case "ObjectPattern":
  34676. case "ObjectTypeAnnotation":
  34677. case "TSInterfaceBody":
  34678. case "TSTypeLiteral":
  34679. case "RecordExpression":
  34680. {
  34681. let propertiesField;
  34682. if (n.type === "TSTypeLiteral") {
  34683. propertiesField = "members";
  34684. } else if (n.type === "TSInterfaceBody") {
  34685. propertiesField = "body";
  34686. } else {
  34687. propertiesField = "properties";
  34688. }
  34689. const isTypeAnnotation = n.type === "ObjectTypeAnnotation";
  34690. const fields = [];
  34691. if (isTypeAnnotation) {
  34692. fields.push("indexers", "callProperties", "internalSlots");
  34693. }
  34694. fields.push(propertiesField);
  34695. const firstProperty = fields.map(field => n[field][0]).sort((a, b) => options.locStart(a) - options.locStart(b))[0];
  34696. const parent = path.getParentNode(0);
  34697. const isFlowInterfaceLikeBody = isTypeAnnotation && parent && (parent.type === "InterfaceDeclaration" || parent.type === "DeclareInterface" || parent.type === "DeclareClass") && path.getName() === "body";
  34698. const shouldBreak = n.type === "TSInterfaceBody" || isFlowInterfaceLikeBody || n.type === "ObjectPattern" && parent.type !== "FunctionDeclaration" && parent.type !== "FunctionExpression" && parent.type !== "ArrowFunctionExpression" && parent.type !== "ObjectMethod" && parent.type !== "ClassMethod" && parent.type !== "ClassPrivateMethod" && parent.type !== "AssignmentPattern" && parent.type !== "CatchClause" && n.properties.some(property => property.value && (property.value.type === "ObjectPattern" || property.value.type === "ArrayPattern")) || n.type !== "ObjectPattern" && firstProperty && hasNewlineInRange$5(options.originalText, options.locStart(n), options.locStart(firstProperty));
  34699. const separator = isFlowInterfaceLikeBody ? ";" : n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral" ? ifBreak$4(semi, ";") : ",";
  34700. const leftBrace = n.type === "RecordExpression" ? "#{" : n.exact ? "{|" : "{";
  34701. const rightBrace = n.exact ? "|}" : "}"; // Unfortunately, things are grouped together in the ast can be
  34702. // interleaved in the source code. So we need to reorder them before
  34703. // printing them.
  34704. const propsAndLoc = [];
  34705. fields.forEach(field => {
  34706. path.each(childPath => {
  34707. const node = childPath.getValue();
  34708. propsAndLoc.push({
  34709. node,
  34710. printed: print(childPath),
  34711. loc: options.locStart(node)
  34712. });
  34713. }, field);
  34714. });
  34715. let separatorParts = [];
  34716. const props = propsAndLoc.sort((a, b) => a.loc - b.loc).map(prop => {
  34717. const result = concat$c(separatorParts.concat(group$7(prop.printed)));
  34718. separatorParts = [separator, line$8];
  34719. if ((prop.node.type === "TSPropertySignature" || prop.node.type === "TSMethodSignature" || prop.node.type === "TSConstructSignatureDeclaration") && hasNodeIgnoreComment$2(prop.node)) {
  34720. separatorParts.shift();
  34721. }
  34722. if (isNextLineEmpty$4(options.originalText, prop.node, options.locEnd)) {
  34723. separatorParts.push(hardline$6);
  34724. }
  34725. return result;
  34726. });
  34727. if (n.inexact) {
  34728. let printed;
  34729. if (hasDanglingComments$1(n)) {
  34730. const hasLineComments = !n.comments.every(comments$1.isBlockComment);
  34731. const printedDanglingComments = comments.printDanglingComments(path, options,
  34732. /* sameIndent */
  34733. true);
  34734. printed = concat$c([printedDanglingComments, hasLineComments || hasNewline$5(options.originalText, options.locEnd(n.comments[n.comments.length - 1])) ? hardline$6 : line$8, "..."]);
  34735. } else {
  34736. printed = "...";
  34737. }
  34738. props.push(concat$c(separatorParts.concat(printed)));
  34739. }
  34740. const lastElem = getLast$5(n[propertiesField]);
  34741. const canHaveTrailingSeparator = !(n.inexact || lastElem && lastElem.type === "RestElement");
  34742. let content;
  34743. if (props.length === 0) {
  34744. if (!hasDanglingComments$1(n)) {
  34745. return concat$c([leftBrace, rightBrace, printTypeAnnotation(path, options, print)]);
  34746. }
  34747. content = group$7(concat$c([leftBrace, comments.printDanglingComments(path, options), softline$6, rightBrace, printOptionalToken$2(path), printTypeAnnotation(path, options, print)]));
  34748. } else {
  34749. content = concat$c([leftBrace, indent$8(concat$c([options.bracketSpacing ? line$8 : softline$6, concat$c(props)])), ifBreak$4(canHaveTrailingSeparator && (separator !== "," || shouldPrintComma$3(options)) ? separator : ""), concat$c([options.bracketSpacing ? line$8 : softline$6, rightBrace]), printOptionalToken$2(path), printTypeAnnotation(path, options, print)]);
  34750. } // If we inline the object as first argument of the parent, we don't want
  34751. // to create another group so that the object breaks before the return
  34752. // type
  34753. if (path.match(node => node.type === "ObjectPattern" && !node.decorators, (node, name, number) => shouldHugArguments(node) && (name === "params" || name === "parameters") && number === 0) || path.match(shouldHugType, (node, name) => name === "typeAnnotation", (node, name) => name === "typeAnnotation", (node, name, number) => shouldHugArguments(node) && (name === "params" || name === "parameters") && number === 0)) {
  34754. return content;
  34755. }
  34756. return group$7(content, {
  34757. shouldBreak
  34758. });
  34759. }
  34760. // Babel 6
  34761. case "ObjectProperty": // Non-standard AST node type.
  34762. case "Property":
  34763. if (n.method || n.kind === "get" || n.kind === "set") {
  34764. return printMethod(path, options, print);
  34765. }
  34766. if (n.shorthand) {
  34767. parts.push(path.call(print, "value"));
  34768. } else {
  34769. parts.push(printAssignment(n.key, printPropertyKey(path, options, print), ":", n.value, path.call(print, "value"), options));
  34770. }
  34771. return concat$c(parts);
  34772. // Babel 6
  34773. case "ClassMethod":
  34774. case "ClassPrivateMethod":
  34775. case "MethodDefinition":
  34776. case "TSAbstractMethodDefinition":
  34777. case "TSDeclareMethod":
  34778. if (n.decorators && n.decorators.length !== 0) {
  34779. parts.push(printDecorators(path, options, print));
  34780. }
  34781. if (n.accessibility) {
  34782. parts.push(n.accessibility + " ");
  34783. }
  34784. if (n.static) {
  34785. parts.push("static ");
  34786. }
  34787. if (n.type === "TSAbstractMethodDefinition" || n.abstract) {
  34788. parts.push("abstract ");
  34789. }
  34790. parts.push(printMethod(path, options, print));
  34791. return concat$c(parts);
  34792. case "ObjectMethod":
  34793. return printMethod(path, options, print);
  34794. case "Decorator":
  34795. return concat$c(["@", path.call(print, "expression"), path.call(print, "callee")]);
  34796. case "ArrayExpression":
  34797. case "ArrayPattern":
  34798. case "TupleExpression":
  34799. {
  34800. const openBracket = n.type === "TupleExpression" ? "#[" : "[";
  34801. const closeBracket = "]";
  34802. if (n.elements.length === 0) {
  34803. if (!hasDanglingComments$1(n)) {
  34804. parts.push(openBracket, closeBracket);
  34805. } else {
  34806. parts.push(group$7(concat$c([openBracket, comments.printDanglingComments(path, options), softline$6, closeBracket])));
  34807. }
  34808. } else {
  34809. const lastElem = getLast$5(n.elements);
  34810. const canHaveTrailingComma = !(lastElem && lastElem.type === "RestElement"); // JavaScript allows you to have empty elements in an array which
  34811. // changes its length based on the number of commas. The algorithm
  34812. // is that if the last argument is null, we need to force insert
  34813. // a comma to ensure JavaScript recognizes it.
  34814. // [,].length === 1
  34815. // [1,].length === 1
  34816. // [1,,].length === 2
  34817. //
  34818. // Note that getLast returns null if the array is empty, but
  34819. // we already check for an empty array just above so we are safe
  34820. const needsForcedTrailingComma = canHaveTrailingComma && lastElem === null;
  34821. const shouldBreak = !options.__inJestEach && n.elements.length > 1 && n.elements.every((element, i, elements) => {
  34822. const elementType = element && element.type;
  34823. if (elementType !== "ArrayExpression" && elementType !== "ObjectExpression") {
  34824. return false;
  34825. }
  34826. const nextElement = elements[i + 1];
  34827. if (nextElement && elementType !== nextElement.type) {
  34828. return false;
  34829. }
  34830. const itemsKey = elementType === "ArrayExpression" ? "elements" : "properties";
  34831. return element[itemsKey] && element[itemsKey].length > 1;
  34832. });
  34833. parts.push(group$7(concat$c([openBracket, indent$8(concat$c([softline$6, printArrayItems(path, options, "elements", print)])), needsForcedTrailingComma ? "," : "", ifBreak$4(canHaveTrailingComma && !needsForcedTrailingComma && shouldPrintComma$3(options) ? "," : ""), comments.printDanglingComments(path, options,
  34834. /* sameIndent */
  34835. true), softline$6, closeBracket]), {
  34836. shouldBreak
  34837. }));
  34838. }
  34839. parts.push(printOptionalToken$2(path), printTypeAnnotation(path, options, print));
  34840. return concat$c(parts);
  34841. }
  34842. case "SequenceExpression":
  34843. {
  34844. const parent = path.getParentNode(0);
  34845. if (parent.type === "ExpressionStatement" || parent.type === "ForStatement") {
  34846. // For ExpressionStatements and for-loop heads, which are among
  34847. // the few places a SequenceExpression appears unparenthesized, we want
  34848. // to indent expressions after the first.
  34849. const parts = [];
  34850. path.each(p => {
  34851. if (p.getName() === 0) {
  34852. parts.push(print(p));
  34853. } else {
  34854. parts.push(",", indent$8(concat$c([line$8, print(p)])));
  34855. }
  34856. }, "expressions");
  34857. return group$7(concat$c(parts));
  34858. }
  34859. return group$7(concat$c([join$6(concat$c([",", line$8]), path.map(print, "expressions"))]));
  34860. }
  34861. case "ThisExpression":
  34862. return "this";
  34863. case "Super":
  34864. return "super";
  34865. case "NullLiteral":
  34866. // Babel 6 Literal split
  34867. return "null";
  34868. case "RegExpLiteral":
  34869. // Babel 6 Literal split
  34870. return printRegex(n);
  34871. case "NumericLiteral":
  34872. // Babel 6 Literal split
  34873. return printNumber$1(n.extra.raw);
  34874. case "DecimalLiteral":
  34875. return printNumber$1(n.value) + "m";
  34876. case "BigIntLiteral":
  34877. // babel: n.extra.raw, flow: n.bigint
  34878. return (n.bigint || n.extra.raw).toLowerCase();
  34879. case "BooleanLiteral": // Babel 6 Literal split
  34880. case "StringLiteral": // Babel 6 Literal split
  34881. case "Literal":
  34882. if (n.regex) {
  34883. return printRegex(n.regex);
  34884. } // typescript
  34885. if (n.bigint) {
  34886. return n.raw.toLowerCase();
  34887. }
  34888. if (typeof n.value === "number") {
  34889. return printNumber$1(n.raw);
  34890. }
  34891. if (typeof n.value !== "string") {
  34892. return "" + n.value;
  34893. }
  34894. return nodeStr(n, options);
  34895. case "Directive":
  34896. return path.call(print, "value");
  34897. // Babel 6
  34898. case "DirectiveLiteral":
  34899. return nodeStr(n, options);
  34900. case "UnaryExpression":
  34901. parts.push(n.operator);
  34902. if (/[a-z]$/.test(n.operator)) {
  34903. parts.push(" ");
  34904. }
  34905. if (n.argument.comments && n.argument.comments.length > 0) {
  34906. parts.push(group$7(concat$c(["(", indent$8(concat$c([softline$6, path.call(print, "argument")])), softline$6, ")"])));
  34907. } else {
  34908. parts.push(path.call(print, "argument"));
  34909. }
  34910. return concat$c(parts);
  34911. case "UpdateExpression":
  34912. parts.push(path.call(print, "argument"), n.operator);
  34913. if (n.prefix) {
  34914. parts.reverse();
  34915. }
  34916. return concat$c(parts);
  34917. case "ConditionalExpression":
  34918. return ternary(path, options, print, {
  34919. beforeParts: () => [path.call(print, "test")],
  34920. afterParts: breakClosingParen => [breakClosingParen ? softline$6 : ""],
  34921. shouldCheckJsx: true,
  34922. conditionalNodeType: "ConditionalExpression",
  34923. consequentNodePropertyName: "consequent",
  34924. alternateNodePropertyName: "alternate",
  34925. testNodePropertyNames: ["test"]
  34926. });
  34927. case "VariableDeclaration":
  34928. {
  34929. const printed = path.map(childPath => {
  34930. return print(childPath);
  34931. }, "declarations"); // We generally want to terminate all variable declarations with a
  34932. // semicolon, except when they in the () part of for loops.
  34933. const parentNode = path.getParentNode();
  34934. const isParentForLoop = parentNode.type === "ForStatement" || parentNode.type === "ForInStatement" || parentNode.type === "ForOfStatement";
  34935. const hasValue = n.declarations.some(decl => decl.init);
  34936. let firstVariable;
  34937. if (printed.length === 1 && !n.declarations[0].comments) {
  34938. firstVariable = printed[0];
  34939. } else if (printed.length > 0) {
  34940. // Indent first var to comply with eslint one-var rule
  34941. firstVariable = indent$8(printed[0]);
  34942. }
  34943. parts = [n.declare ? "declare " : "", n.kind, firstVariable ? concat$c([" ", firstVariable]) : "", indent$8(concat$c(printed.slice(1).map(p => concat$c([",", hasValue && !isParentForLoop ? hardline$6 : line$8, p]))))];
  34944. if (!(isParentForLoop && parentNode.body !== n)) {
  34945. parts.push(semi);
  34946. }
  34947. return group$7(concat$c(parts));
  34948. }
  34949. case "TSTypeAliasDeclaration":
  34950. {
  34951. if (n.declare) {
  34952. parts.push("declare ");
  34953. }
  34954. const printed = printAssignmentRight(n.id, n.typeAnnotation, n.typeAnnotation && path.call(print, "typeAnnotation"), options);
  34955. parts.push("type ", path.call(print, "id"), path.call(print, "typeParameters"), " =", printed, semi);
  34956. return group$7(concat$c(parts));
  34957. }
  34958. case "VariableDeclarator":
  34959. return printAssignment(n.id, path.call(print, "id"), " =", n.init, n.init && path.call(print, "init"), options);
  34960. case "WithStatement":
  34961. return group$7(concat$c(["with (", path.call(print, "object"), ")", adjustClause(n.body, path.call(print, "body"))]));
  34962. case "IfStatement":
  34963. {
  34964. const con = adjustClause(n.consequent, path.call(print, "consequent"));
  34965. const opening = group$7(concat$c(["if (", group$7(concat$c([indent$8(concat$c([softline$6, path.call(print, "test")])), softline$6])), ")", con]));
  34966. parts.push(opening);
  34967. if (n.alternate) {
  34968. const commentOnOwnLine = hasTrailingComment$3(n.consequent) && n.consequent.comments.some(comment => comment.trailing && !comments$1.isBlockComment(comment)) || needsHardlineAfterDanglingComment$1(n);
  34969. const elseOnSameLine = n.consequent.type === "BlockStatement" && !commentOnOwnLine;
  34970. parts.push(elseOnSameLine ? " " : hardline$6);
  34971. if (hasDanglingComments$1(n)) {
  34972. parts.push(comments.printDanglingComments(path, options, true), commentOnOwnLine ? hardline$6 : " ");
  34973. }
  34974. parts.push("else", group$7(adjustClause(n.alternate, path.call(print, "alternate"), n.alternate.type === "IfStatement")));
  34975. }
  34976. return concat$c(parts);
  34977. }
  34978. case "ForStatement":
  34979. {
  34980. const body = adjustClause(n.body, path.call(print, "body")); // We want to keep dangling comments above the loop to stay consistent.
  34981. // Any comment positioned between the for statement and the parentheses
  34982. // is going to be printed before the statement.
  34983. const dangling = comments.printDanglingComments(path, options,
  34984. /* sameLine */
  34985. true);
  34986. const printedComments = dangling ? concat$c([dangling, softline$6]) : "";
  34987. if (!n.init && !n.test && !n.update) {
  34988. return concat$c([printedComments, group$7(concat$c(["for (;;)", body]))]);
  34989. }
  34990. return concat$c([printedComments, group$7(concat$c(["for (", group$7(concat$c([indent$8(concat$c([softline$6, path.call(print, "init"), ";", line$8, path.call(print, "test"), ";", line$8, path.call(print, "update")])), softline$6])), ")", body]))]);
  34991. }
  34992. case "WhileStatement":
  34993. return group$7(concat$c(["while (", group$7(concat$c([indent$8(concat$c([softline$6, path.call(print, "test")])), softline$6])), ")", adjustClause(n.body, path.call(print, "body"))]));
  34994. case "ForInStatement":
  34995. // Note: esprima can't actually parse "for each (".
  34996. return group$7(concat$c([n.each ? "for each (" : "for (", path.call(print, "left"), " in ", path.call(print, "right"), ")", adjustClause(n.body, path.call(print, "body"))]));
  34997. case "ForOfStatement":
  34998. return group$7(concat$c(["for", n.await ? " await" : "", " (", path.call(print, "left"), " of ", path.call(print, "right"), ")", adjustClause(n.body, path.call(print, "body"))]));
  34999. case "DoWhileStatement":
  35000. {
  35001. const clause = adjustClause(n.body, path.call(print, "body"));
  35002. const doBody = group$7(concat$c(["do", clause]));
  35003. parts = [doBody];
  35004. if (n.body.type === "BlockStatement") {
  35005. parts.push(" ");
  35006. } else {
  35007. parts.push(hardline$6);
  35008. }
  35009. parts.push("while (");
  35010. parts.push(group$7(concat$c([indent$8(concat$c([softline$6, path.call(print, "test")])), softline$6])), ")", semi);
  35011. return concat$c(parts);
  35012. }
  35013. case "DoExpression":
  35014. return concat$c(["do ", path.call(print, "body")]);
  35015. case "BreakStatement":
  35016. parts.push("break");
  35017. if (n.label) {
  35018. parts.push(" ", path.call(print, "label"));
  35019. }
  35020. parts.push(semi);
  35021. return concat$c(parts);
  35022. case "ContinueStatement":
  35023. parts.push("continue");
  35024. if (n.label) {
  35025. parts.push(" ", path.call(print, "label"));
  35026. }
  35027. parts.push(semi);
  35028. return concat$c(parts);
  35029. case "LabeledStatement":
  35030. if (n.body.type === "EmptyStatement") {
  35031. return concat$c([path.call(print, "label"), ":;"]);
  35032. }
  35033. return concat$c([path.call(print, "label"), ": ", path.call(print, "body")]);
  35034. case "TryStatement":
  35035. return concat$c(["try ", path.call(print, "block"), n.handler ? concat$c([" ", path.call(print, "handler")]) : "", n.finalizer ? concat$c([" finally ", path.call(print, "finalizer")]) : ""]);
  35036. case "CatchClause":
  35037. if (n.param) {
  35038. const hasComments = n.param.comments && n.param.comments.some(comment => !comments$1.isBlockComment(comment) || comment.leading && hasNewline$5(options.originalText, options.locEnd(comment)) || comment.trailing && hasNewline$5(options.originalText, options.locStart(comment), {
  35039. backwards: true
  35040. }));
  35041. const param = path.call(print, "param");
  35042. return concat$c(["catch ", hasComments ? concat$c(["(", indent$8(concat$c([softline$6, param])), softline$6, ") "]) : concat$c(["(", param, ") "]), path.call(print, "body")]);
  35043. }
  35044. return concat$c(["catch ", path.call(print, "body")]);
  35045. case "ThrowStatement":
  35046. return concat$c(["throw", printReturnAndThrowArgument(path, options, print)]);
  35047. // Note: ignoring n.lexical because it has no printing consequences.
  35048. case "SwitchStatement":
  35049. return concat$c([group$7(concat$c(["switch (", indent$8(concat$c([softline$6, path.call(print, "discriminant")])), softline$6, ")"])), " {", n.cases.length > 0 ? indent$8(concat$c([hardline$6, join$6(hardline$6, path.map(casePath => {
  35050. const caseNode = casePath.getValue();
  35051. return concat$c([casePath.call(print), n.cases.indexOf(caseNode) !== n.cases.length - 1 && isNextLineEmpty$4(options.originalText, caseNode, options.locEnd) ? hardline$6 : ""]);
  35052. }, "cases"))])) : "", hardline$6, "}"]);
  35053. case "SwitchCase":
  35054. {
  35055. if (n.test) {
  35056. parts.push("case ", path.call(print, "test"), ":");
  35057. } else {
  35058. parts.push("default:");
  35059. }
  35060. const consequent = n.consequent.filter(node => node.type !== "EmptyStatement");
  35061. if (consequent.length > 0) {
  35062. const cons = path.call(consequentPath => {
  35063. return printStatementSequence(consequentPath, options, print);
  35064. }, "consequent");
  35065. parts.push(consequent.length === 1 && consequent[0].type === "BlockStatement" ? concat$c([" ", cons]) : indent$8(concat$c([hardline$6, cons])));
  35066. }
  35067. return concat$c(parts);
  35068. }
  35069. // JSX extensions below.
  35070. case "DebuggerStatement":
  35071. return concat$c(["debugger", semi]);
  35072. case "JSXAttribute":
  35073. parts.push(path.call(print, "name"));
  35074. if (n.value) {
  35075. let res;
  35076. if (isStringLiteral$1(n.value)) {
  35077. const raw = rawText$1(n.value); // Unescape all quotes so we get an accurate preferred quote
  35078. let final = raw.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
  35079. const quote = getPreferredQuote$1(final, options.jsxSingleQuote ? "'" : '"');
  35080. const escape = quote === "'" ? "&apos;" : "&quot;";
  35081. final = final.slice(1, -1).replace(new RegExp(quote, "g"), escape);
  35082. res = concat$c([quote, final, quote]);
  35083. } else {
  35084. res = path.call(print, "value");
  35085. }
  35086. parts.push("=", res);
  35087. }
  35088. return concat$c(parts);
  35089. case "JSXIdentifier":
  35090. return "" + n.name;
  35091. case "JSXNamespacedName":
  35092. return join$6(":", [path.call(print, "namespace"), path.call(print, "name")]);
  35093. case "JSXMemberExpression":
  35094. return join$6(".", [path.call(print, "object"), path.call(print, "property")]);
  35095. case "TSQualifiedName":
  35096. return join$6(".", [path.call(print, "left"), path.call(print, "right")]);
  35097. case "JSXSpreadAttribute":
  35098. case "JSXSpreadChild":
  35099. {
  35100. return concat$c(["{", path.call(p => {
  35101. const printed = concat$c(["...", print(p)]);
  35102. const n = p.getValue();
  35103. if (!n.comments || !n.comments.length || !willPrintOwnComments(p)) {
  35104. return printed;
  35105. }
  35106. return concat$c([indent$8(concat$c([softline$6, comments.printComments(p, () => printed, options)])), softline$6]);
  35107. }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"), "}"]);
  35108. }
  35109. case "JSXExpressionContainer":
  35110. {
  35111. const parent = path.getParentNode(0);
  35112. const hasComments = n.expression.comments && n.expression.comments.length > 0;
  35113. const shouldInline = n.expression.type === "JSXEmptyExpression" || !hasComments && (n.expression.type === "ArrayExpression" || n.expression.type === "ObjectExpression" || n.expression.type === "ArrowFunctionExpression" || n.expression.type === "CallExpression" || n.expression.type === "OptionalCallExpression" || n.expression.type === "FunctionExpression" || n.expression.type === "TemplateLiteral" || n.expression.type === "TaggedTemplateExpression" || n.expression.type === "DoExpression" || isJSXNode$3(parent) && (n.expression.type === "ConditionalExpression" || isBinaryish$1(n.expression)));
  35114. if (shouldInline) {
  35115. return group$7(concat$c(["{", path.call(print, "expression"), lineSuffixBoundary$1, "}"]));
  35116. }
  35117. return group$7(concat$c(["{", indent$8(concat$c([softline$6, path.call(print, "expression")])), softline$6, lineSuffixBoundary$1, "}"]));
  35118. }
  35119. case "JSXFragment":
  35120. case "JSXElement":
  35121. {
  35122. const elem = comments.printComments(path, () => printJSXElement(path, options, print), options);
  35123. return maybeWrapJSXElementInParens(path, elem, options);
  35124. }
  35125. case "JSXOpeningElement":
  35126. {
  35127. const n = path.getValue();
  35128. const nameHasComments = n.name && n.name.comments && n.name.comments.length > 0 || n.typeParameters && n.typeParameters.comments && n.typeParameters.comments.length > 0; // Don't break self-closing elements with no attributes and no comments
  35129. if (n.selfClosing && !n.attributes.length && !nameHasComments) {
  35130. return concat$c(["<", path.call(print, "name"), path.call(print, "typeParameters"), " />"]);
  35131. } // don't break up opening elements with a single long text attribute
  35132. if (n.attributes && n.attributes.length === 1 && n.attributes[0].value && isStringLiteral$1(n.attributes[0].value) && !n.attributes[0].value.value.includes("\n") && // We should break for the following cases:
  35133. // <div
  35134. // // comment
  35135. // attr="value"
  35136. // >
  35137. // <div
  35138. // attr="value"
  35139. // // comment
  35140. // >
  35141. !nameHasComments && (!n.attributes[0].comments || !n.attributes[0].comments.length)) {
  35142. return group$7(concat$c(["<", path.call(print, "name"), path.call(print, "typeParameters"), " ", concat$c(path.map(print, "attributes")), n.selfClosing ? " />" : ">"]));
  35143. }
  35144. const lastAttrHasTrailingComments = n.attributes.length && hasTrailingComment$3(getLast$5(n.attributes));
  35145. const bracketSameLine = // Simple tags (no attributes and no comment in tag name) should be
  35146. // kept unbroken regardless of `jsxBracketSameLine`
  35147. !n.attributes.length && !nameHasComments || options.jsxBracketSameLine && ( // We should print the bracket in a new line for the following cases:
  35148. // <div
  35149. // // comment
  35150. // >
  35151. // <div
  35152. // attr // comment
  35153. // >
  35154. !nameHasComments || n.attributes.length) && !lastAttrHasTrailingComments; // We should print the opening element expanded if any prop value is a
  35155. // string literal with newlines
  35156. const shouldBreak = n.attributes && n.attributes.some(attr => attr.value && isStringLiteral$1(attr.value) && attr.value.value.includes("\n"));
  35157. return group$7(concat$c(["<", path.call(print, "name"), path.call(print, "typeParameters"), concat$c([indent$8(concat$c(path.map(attr => concat$c([line$8, print(attr)]), "attributes"))), n.selfClosing ? line$8 : bracketSameLine ? ">" : softline$6]), n.selfClosing ? "/>" : bracketSameLine ? "" : ">"]), {
  35158. shouldBreak
  35159. });
  35160. }
  35161. case "JSXClosingElement":
  35162. return concat$c(["</", path.call(print, "name"), ">"]);
  35163. case "JSXOpeningFragment":
  35164. case "JSXClosingFragment":
  35165. {
  35166. const hasComment = n.comments && n.comments.length;
  35167. const hasOwnLineComment = hasComment && !n.comments.every(comments$1.isBlockComment);
  35168. const isOpeningFragment = n.type === "JSXOpeningFragment";
  35169. return concat$c([isOpeningFragment ? "<" : "</", indent$8(concat$c([hasOwnLineComment ? hardline$6 : hasComment && !isOpeningFragment ? " " : "", comments.printDanglingComments(path, options, true)])), hasOwnLineComment ? hardline$6 : "", ">"]);
  35170. }
  35171. case "JSXText":
  35172. /* istanbul ignore next */
  35173. throw new Error("JSXTest should be handled by JSXElement");
  35174. case "JSXEmptyExpression":
  35175. {
  35176. const requiresHardline = n.comments && !n.comments.every(comments$1.isBlockComment);
  35177. return concat$c([comments.printDanglingComments(path, options,
  35178. /* sameIndent */
  35179. !requiresHardline), requiresHardline ? hardline$6 : ""]);
  35180. }
  35181. case "ClassBody":
  35182. if (!n.comments && n.body.length === 0) {
  35183. return "{}";
  35184. }
  35185. return concat$c(["{", n.body.length > 0 ? indent$8(concat$c([hardline$6, path.call(bodyPath => {
  35186. return printStatementSequence(bodyPath, options, print);
  35187. }, "body")])) : comments.printDanglingComments(path, options), hardline$6, "}"]);
  35188. case "ClassProperty":
  35189. case "TSAbstractClassProperty":
  35190. case "ClassPrivateProperty":
  35191. {
  35192. if (n.decorators && n.decorators.length !== 0) {
  35193. parts.push(printDecorators(path, options, print));
  35194. }
  35195. if (n.accessibility) {
  35196. parts.push(n.accessibility + " ");
  35197. }
  35198. if (n.declare) {
  35199. parts.push("declare ");
  35200. }
  35201. if (n.static) {
  35202. parts.push("static ");
  35203. }
  35204. if (n.type === "TSAbstractClassProperty" || n.abstract) {
  35205. parts.push("abstract ");
  35206. }
  35207. if (n.readonly) {
  35208. parts.push("readonly ");
  35209. }
  35210. const variance = getFlowVariance$1(n);
  35211. if (variance) {
  35212. parts.push(variance);
  35213. }
  35214. parts.push(printPropertyKey(path, options, print), printOptionalToken$2(path), printTypeAnnotation(path, options, print));
  35215. if (n.value) {
  35216. parts.push(" =", printAssignmentRight(n.key, n.value, path.call(print, "value"), options));
  35217. }
  35218. parts.push(semi);
  35219. return group$7(concat$c(parts));
  35220. }
  35221. case "ClassDeclaration":
  35222. case "ClassExpression":
  35223. if (n.declare) {
  35224. parts.push("declare ");
  35225. }
  35226. parts.push(concat$c(printClass(path, options, print)));
  35227. return concat$c(parts);
  35228. case "TSInterfaceHeritage":
  35229. case "TSExpressionWithTypeArguments":
  35230. // Babel AST
  35231. parts.push(path.call(print, "expression"));
  35232. if (n.typeParameters) {
  35233. parts.push(path.call(print, "typeParameters"));
  35234. }
  35235. return concat$c(parts);
  35236. case "TemplateElement":
  35237. return join$6(literalline$3, n.value.raw.split(/\r?\n/g));
  35238. case "TemplateLiteral":
  35239. {
  35240. const parentNode = path.getParentNode();
  35241. if (isJestEachTemplateLiteral$1(n, parentNode)) {
  35242. const printed = printJestEachTemplateLiteral(path, options, print);
  35243. if (printed) {
  35244. return printed;
  35245. }
  35246. }
  35247. let expressions = path.map(print, "expressions");
  35248. const isSimple = isSimpleTemplateLiteral$1(n);
  35249. if (isSimple) {
  35250. expressions = expressions.map(doc => printDocToString$2(doc, Object.assign({}, options, {
  35251. printWidth: Infinity
  35252. })).formatted);
  35253. }
  35254. parts.push(lineSuffixBoundary$1, "`");
  35255. path.each(childPath => {
  35256. const i = childPath.getName();
  35257. parts.push(print(childPath));
  35258. if (i < expressions.length) {
  35259. // For a template literal of the following form:
  35260. // `someQuery {
  35261. // ${call({
  35262. // a,
  35263. // b,
  35264. // })}
  35265. // }`
  35266. // the expression is on its own line (there is a \n in the previous
  35267. // quasi literal), therefore we want to indent the JavaScript
  35268. // expression inside at the beginning of ${ instead of the beginning
  35269. // of the `.
  35270. const {
  35271. tabWidth
  35272. } = options;
  35273. const quasi = childPath.getValue();
  35274. const indentSize = getIndentSize$2(quasi.value.raw, tabWidth);
  35275. let printed = expressions[i];
  35276. if (!isSimple) {
  35277. // Breaks at the template element boundaries (${ and }) are preferred to breaking
  35278. // in the middle of a MemberExpression
  35279. if (n.expressions[i].comments && n.expressions[i].comments.length || n.expressions[i].type === "MemberExpression" || n.expressions[i].type === "OptionalMemberExpression" || n.expressions[i].type === "ConditionalExpression" || n.expressions[i].type === "SequenceExpression" || n.expressions[i].type === "TSAsExpression" || isBinaryish$1(n.expressions[i])) {
  35280. printed = concat$c([indent$8(concat$c([softline$6, printed])), softline$6]);
  35281. }
  35282. }
  35283. const aligned = indentSize === 0 && quasi.value.raw.endsWith("\n") ? align$2(-Infinity, printed) : addAlignmentToDoc$2(printed, indentSize, tabWidth);
  35284. parts.push(group$7(concat$c(["${", aligned, lineSuffixBoundary$1, "}"])));
  35285. }
  35286. }, "quasis");
  35287. parts.push("`");
  35288. return concat$c(parts);
  35289. }
  35290. case "TaggedTemplateExpression":
  35291. return concat$c([path.call(print, "tag"), path.call(print, "typeParameters"), path.call(print, "quasi")]);
  35292. // These types are unprintable because they serve as abstract
  35293. // supertypes for other (printable) types.
  35294. case "Node":
  35295. case "Printable":
  35296. case "SourceLocation":
  35297. case "Position":
  35298. case "Statement":
  35299. case "Function":
  35300. case "Pattern":
  35301. case "Expression":
  35302. case "Declaration":
  35303. case "Specifier":
  35304. case "NamedSpecifier":
  35305. case "Comment":
  35306. case "MemberTypeAnnotation": // Flow
  35307. case "Type":
  35308. /* istanbul ignore next */
  35309. throw new Error("unprintable type: " + JSON.stringify(n.type));
  35310. // Type Annotations for Facebook Flow, typically stripped out or
  35311. // transformed away before printing.
  35312. case "TypeAnnotation":
  35313. case "TSTypeAnnotation":
  35314. if (n.typeAnnotation) {
  35315. return path.call(print, "typeAnnotation");
  35316. }
  35317. /* istanbul ignore next */
  35318. return "";
  35319. case "TSNamedTupleMember":
  35320. return concat$c([path.call(print, "label"), n.optional ? "?" : "", ": ", path.call(print, "elementType")]);
  35321. case "TSTupleType":
  35322. case "TupleTypeAnnotation":
  35323. {
  35324. const typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
  35325. const hasRest = n[typesField].length > 0 && getLast$5(n[typesField]).type === "TSRestType";
  35326. return group$7(concat$c(["[", indent$8(concat$c([softline$6, printArrayItems(path, options, typesField, print)])), ifBreak$4(shouldPrintComma$3(options, "all") && !hasRest ? "," : ""), comments.printDanglingComments(path, options,
  35327. /* sameIndent */
  35328. true), softline$6, "]"]));
  35329. }
  35330. case "ExistsTypeAnnotation":
  35331. return "*";
  35332. case "EmptyTypeAnnotation":
  35333. return "empty";
  35334. case "AnyTypeAnnotation":
  35335. return "any";
  35336. case "MixedTypeAnnotation":
  35337. return "mixed";
  35338. case "ArrayTypeAnnotation":
  35339. return concat$c([path.call(print, "elementType"), "[]"]);
  35340. case "BooleanTypeAnnotation":
  35341. return "boolean";
  35342. case "BooleanLiteralTypeAnnotation":
  35343. return "" + n.value;
  35344. case "DeclareClass":
  35345. return printFlowDeclaration(path, printClass(path, options, print));
  35346. case "TSDeclareFunction":
  35347. // For TypeScript the TSDeclareFunction node shares the AST
  35348. // structure with FunctionDeclaration
  35349. return concat$c([n.declare ? "declare " : "", printFunctionDeclaration(path, print, options), semi]);
  35350. case "DeclareFunction":
  35351. return printFlowDeclaration(path, ["function ", path.call(print, "id"), n.predicate ? " " : "", path.call(print, "predicate"), semi]);
  35352. case "DeclareModule":
  35353. return printFlowDeclaration(path, ["module ", path.call(print, "id"), " ", path.call(print, "body")]);
  35354. case "DeclareModuleExports":
  35355. return printFlowDeclaration(path, ["module.exports", ": ", path.call(print, "typeAnnotation"), semi]);
  35356. case "DeclareVariable":
  35357. return printFlowDeclaration(path, ["var ", path.call(print, "id"), semi]);
  35358. case "DeclareExportAllDeclaration":
  35359. return concat$c(["declare export *", printModuleSource$1(path, options, print)]);
  35360. case "DeclareOpaqueType":
  35361. case "OpaqueType":
  35362. {
  35363. parts.push("opaque type ", path.call(print, "id"), path.call(print, "typeParameters"));
  35364. if (n.supertype) {
  35365. parts.push(": ", path.call(print, "supertype"));
  35366. }
  35367. if (n.impltype) {
  35368. parts.push(" = ", path.call(print, "impltype"));
  35369. }
  35370. parts.push(semi);
  35371. if (n.type === "DeclareOpaqueType") {
  35372. return printFlowDeclaration(path, parts);
  35373. }
  35374. return concat$c(parts);
  35375. }
  35376. case "EnumDeclaration":
  35377. return concat$c(["enum ", path.call(print, "id"), " ", path.call(print, "body")]);
  35378. case "EnumBooleanBody":
  35379. case "EnumNumberBody":
  35380. case "EnumStringBody":
  35381. case "EnumSymbolBody":
  35382. {
  35383. if (n.type === "EnumSymbolBody" || n.explicitType) {
  35384. let type = null;
  35385. switch (n.type) {
  35386. case "EnumBooleanBody":
  35387. type = "boolean";
  35388. break;
  35389. case "EnumNumberBody":
  35390. type = "number";
  35391. break;
  35392. case "EnumStringBody":
  35393. type = "string";
  35394. break;
  35395. case "EnumSymbolBody":
  35396. type = "symbol";
  35397. break;
  35398. }
  35399. parts.push("of ", type, " ");
  35400. }
  35401. if (n.members.length === 0) {
  35402. parts.push(group$7(concat$c(["{", comments.printDanglingComments(path, options), softline$6, "}"])));
  35403. } else {
  35404. parts.push(group$7(concat$c(["{", indent$8(concat$c([hardline$6, printArrayItems(path, options, "members", print), shouldPrintComma$3(options) ? "," : ""])), comments.printDanglingComments(path, options,
  35405. /* sameIndent */
  35406. true), hardline$6, "}"])));
  35407. }
  35408. return concat$c(parts);
  35409. }
  35410. case "EnumBooleanMember":
  35411. case "EnumNumberMember":
  35412. case "EnumStringMember":
  35413. return concat$c([path.call(print, "id"), " = ", typeof n.init === "object" ? path.call(print, "init") : String(n.init)]);
  35414. case "EnumDefaultedMember":
  35415. return path.call(print, "id");
  35416. case "FunctionTypeAnnotation":
  35417. case "TSFunctionType":
  35418. {
  35419. // FunctionTypeAnnotation is ambiguous:
  35420. // declare function foo(a: B): void; OR
  35421. // var A: (a: B) => void;
  35422. const parent = path.getParentNode(0);
  35423. const parentParent = path.getParentNode(1);
  35424. const parentParentParent = path.getParentNode(2);
  35425. let isArrowFunctionTypeAnnotation = n.type === "TSFunctionType" || !((parent.type === "ObjectTypeProperty" || parent.type === "ObjectTypeInternalSlot") && !getFlowVariance$1(parent) && !parent.optional && options.locStart(parent) === options.locStart(n) || parent.type === "ObjectTypeCallProperty" || parentParentParent && parentParentParent.type === "DeclareFunction");
  35426. let needsColon = isArrowFunctionTypeAnnotation && (parent.type === "TypeAnnotation" || parent.type === "TSTypeAnnotation"); // Sadly we can't put it inside of FastPath::needsColon because we are
  35427. // printing ":" as part of the expression and it would put parenthesis
  35428. // around :(
  35429. const needsParens = needsColon && isArrowFunctionTypeAnnotation && (parent.type === "TypeAnnotation" || parent.type === "TSTypeAnnotation") && parentParent.type === "ArrowFunctionExpression";
  35430. if (isObjectTypePropertyAFunction$1(parent, options)) {
  35431. isArrowFunctionTypeAnnotation = true;
  35432. needsColon = true;
  35433. }
  35434. if (needsParens) {
  35435. parts.push("(");
  35436. }
  35437. parts.push(printFunctionParams(path, print, options,
  35438. /* expandArg */
  35439. false,
  35440. /* printTypeParams */
  35441. true)); // The returnType is not wrapped in a TypeAnnotation, so the colon
  35442. // needs to be added separately.
  35443. if (n.returnType || n.predicate || n.typeAnnotation) {
  35444. parts.push(isArrowFunctionTypeAnnotation ? " => " : ": ", path.call(print, "returnType"), path.call(print, "predicate"), path.call(print, "typeAnnotation"));
  35445. }
  35446. if (needsParens) {
  35447. parts.push(")");
  35448. }
  35449. return group$7(concat$c(parts));
  35450. }
  35451. case "TSRestType":
  35452. return concat$c(["...", path.call(print, "typeAnnotation")]);
  35453. case "TSOptionalType":
  35454. return concat$c([path.call(print, "typeAnnotation"), "?"]);
  35455. case "FunctionTypeParam":
  35456. return concat$c([path.call(print, "name"), printOptionalToken$2(path), n.name ? ": " : "", path.call(print, "typeAnnotation")]);
  35457. case "GenericTypeAnnotation":
  35458. return concat$c([path.call(print, "id"), path.call(print, "typeParameters")]);
  35459. case "DeclareInterface":
  35460. case "InterfaceDeclaration":
  35461. case "InterfaceTypeAnnotation":
  35462. case "TSInterfaceDeclaration":
  35463. {
  35464. if (n.type === "DeclareInterface" || n.declare) {
  35465. parts.push("declare ");
  35466. }
  35467. if (n.type === "TSInterfaceDeclaration") {
  35468. parts.push(n.abstract ? "abstract " : "", printTypeScriptModifiers(path, options, print));
  35469. }
  35470. parts.push("interface");
  35471. const partsGroup = [];
  35472. const extendsParts = [];
  35473. if (n.type !== "InterfaceTypeAnnotation") {
  35474. partsGroup.push(" ", path.call(print, "id"), path.call(print, "typeParameters"));
  35475. }
  35476. const shouldIndentOnlyHeritageClauses = n.typeParameters && !hasTrailingLineComment$1(n.typeParameters);
  35477. if (n.extends && n.extends.length !== 0) {
  35478. extendsParts.push(shouldIndentOnlyHeritageClauses ? ifBreak$4(" ", line$8, {
  35479. groupId: getTypeParametersGroupId(n.typeParameters)
  35480. }) : line$8, "extends ", (n.extends.length === 1 ? identity$2 : indent$8)(join$6(concat$c([",", line$8]), path.map(print, "extends"))));
  35481. }
  35482. if (n.id && hasTrailingComment$3(n.id) || n.extends && n.extends.length !== 0) {
  35483. const printedExtends = concat$c(extendsParts);
  35484. if (shouldIndentOnlyHeritageClauses) {
  35485. parts.push(group$7(concat$c(partsGroup.concat(ifBreak$4(indent$8(printedExtends), printedExtends)))));
  35486. } else {
  35487. parts.push(group$7(indent$8(concat$c(partsGroup.concat(printedExtends)))));
  35488. }
  35489. } else {
  35490. parts.push(...partsGroup, ...extendsParts);
  35491. }
  35492. parts.push(" ", path.call(print, "body"));
  35493. return group$7(concat$c(parts));
  35494. }
  35495. case "ClassImplements":
  35496. case "InterfaceExtends":
  35497. return concat$c([path.call(print, "id"), path.call(print, "typeParameters")]);
  35498. case "TSClassImplements":
  35499. return concat$c([path.call(print, "expression"), path.call(print, "typeParameters")]);
  35500. case "TSIntersectionType":
  35501. case "IntersectionTypeAnnotation":
  35502. {
  35503. const types = path.map(print, "types");
  35504. const result = [];
  35505. let wasIndented = false;
  35506. for (let i = 0; i < types.length; ++i) {
  35507. if (i === 0) {
  35508. result.push(types[i]);
  35509. } else if (isObjectType$1(n.types[i - 1]) && isObjectType$1(n.types[i])) {
  35510. // If both are objects, don't indent
  35511. result.push(concat$c([" & ", wasIndented ? indent$8(types[i]) : types[i]]));
  35512. } else if (!isObjectType$1(n.types[i - 1]) && !isObjectType$1(n.types[i])) {
  35513. // If no object is involved, go to the next line if it breaks
  35514. result.push(indent$8(concat$c([" &", line$8, types[i]])));
  35515. } else {
  35516. // If you go from object to non-object or vis-versa, then inline it
  35517. if (i > 1) {
  35518. wasIndented = true;
  35519. }
  35520. result.push(" & ", i > 1 ? indent$8(types[i]) : types[i]);
  35521. }
  35522. }
  35523. return group$7(concat$c(result));
  35524. }
  35525. case "TSUnionType":
  35526. case "UnionTypeAnnotation":
  35527. {
  35528. // single-line variation
  35529. // A | B | C
  35530. // multi-line variation
  35531. // | A
  35532. // | B
  35533. // | C
  35534. const parent = path.getParentNode(); // If there's a leading comment, the parent is doing the indentation
  35535. const shouldIndent = parent.type !== "TypeParameterInstantiation" && parent.type !== "TSTypeParameterInstantiation" && parent.type !== "GenericTypeAnnotation" && parent.type !== "TSTypeReference" && parent.type !== "TSTypeAssertion" && parent.type !== "TupleTypeAnnotation" && parent.type !== "TSTupleType" && !(parent.type === "FunctionTypeParam" && !parent.name) && !((parent.type === "TypeAlias" || parent.type === "VariableDeclarator" || parent.type === "TSTypeAliasDeclaration") && hasLeadingOwnLineComment$1(options.originalText, n, options)); // {
  35536. // a: string
  35537. // } | null | void
  35538. // should be inlined and not be printed in the multi-line variant
  35539. const shouldHug = shouldHugType(n); // We want to align the children but without its comment, so it looks like
  35540. // | child1
  35541. // // comment
  35542. // | child2
  35543. const printed = path.map(typePath => {
  35544. let printedType = typePath.call(print);
  35545. if (!shouldHug) {
  35546. printedType = align$2(2, printedType);
  35547. }
  35548. return comments.printComments(typePath, () => printedType, options);
  35549. }, "types");
  35550. if (shouldHug) {
  35551. return join$6(" | ", printed);
  35552. }
  35553. const shouldAddStartLine = shouldIndent && !hasLeadingOwnLineComment$1(options.originalText, n, options);
  35554. const code = concat$c([ifBreak$4(concat$c([shouldAddStartLine ? line$8 : "", "| "])), join$6(concat$c([line$8, "| "]), printed)]);
  35555. if (needsParens_1(path, options)) {
  35556. return group$7(concat$c([indent$8(code), softline$6]));
  35557. }
  35558. if (parent.type === "TupleTypeAnnotation" && parent.types.length > 1 || parent.type === "TSTupleType" && parent.elementTypes.length > 1) {
  35559. return group$7(concat$c([indent$8(concat$c([ifBreak$4(concat$c(["(", softline$6])), code])), softline$6, ifBreak$4(")")]));
  35560. }
  35561. return group$7(shouldIndent ? indent$8(code) : code);
  35562. }
  35563. case "NullableTypeAnnotation":
  35564. return concat$c(["?", path.call(print, "typeAnnotation")]);
  35565. case "TSNullKeyword":
  35566. case "NullLiteralTypeAnnotation":
  35567. return "null";
  35568. case "ThisTypeAnnotation":
  35569. return "this";
  35570. case "NumberTypeAnnotation":
  35571. return "number";
  35572. case "SymbolTypeAnnotation":
  35573. return "symbol";
  35574. case "ObjectTypeCallProperty":
  35575. if (n.static) {
  35576. parts.push("static ");
  35577. }
  35578. parts.push(path.call(print, "value"));
  35579. return concat$c(parts);
  35580. case "ObjectTypeIndexer":
  35581. {
  35582. const variance = getFlowVariance$1(n);
  35583. return concat$c([variance || "", "[", path.call(print, "id"), n.id ? ": " : "", path.call(print, "key"), "]: ", path.call(print, "value")]);
  35584. }
  35585. case "ObjectTypeProperty":
  35586. {
  35587. const variance = getFlowVariance$1(n);
  35588. let modifier = "";
  35589. if (n.proto) {
  35590. modifier = "proto ";
  35591. } else if (n.static) {
  35592. modifier = "static ";
  35593. }
  35594. return concat$c([modifier, isGetterOrSetter$1(n) ? n.kind + " " : "", variance || "", printPropertyKey(path, options, print), printOptionalToken$2(path), isFunctionNotation$1(n, options) ? "" : ": ", path.call(print, "value")]);
  35595. }
  35596. case "QualifiedTypeIdentifier":
  35597. return concat$c([path.call(print, "qualification"), ".", path.call(print, "id")]);
  35598. case "StringLiteralTypeAnnotation":
  35599. return nodeStr(n, options);
  35600. case "NumberLiteralTypeAnnotation":
  35601. assert__default['default'].strictEqual(typeof n.value, "number");
  35602. if (n.extra != null) {
  35603. return printNumber$1(n.extra.raw);
  35604. }
  35605. return printNumber$1(n.raw);
  35606. case "StringTypeAnnotation":
  35607. return "string";
  35608. case "DeclareTypeAlias":
  35609. case "TypeAlias":
  35610. {
  35611. if (n.type === "DeclareTypeAlias" || n.declare) {
  35612. parts.push("declare ");
  35613. }
  35614. const printed = printAssignmentRight(n.id, n.right, path.call(print, "right"), options);
  35615. parts.push("type ", path.call(print, "id"), path.call(print, "typeParameters"), " =", printed, semi);
  35616. return group$7(concat$c(parts));
  35617. }
  35618. case "TypeCastExpression":
  35619. {
  35620. return concat$c(["(", path.call(print, "expression"), printTypeAnnotation(path, options, print), ")"]);
  35621. }
  35622. case "TypeParameterDeclaration":
  35623. case "TypeParameterInstantiation":
  35624. {
  35625. const value = path.getValue();
  35626. const commentStart = options.originalText.slice(0, options.locStart(value)).lastIndexOf("/*"); // As noted in the TypeCastExpression comments above, we're able to use a normal whitespace regex here
  35627. // because we know for sure that this is a type definition.
  35628. const commentSyntax = commentStart >= 0 && options.originalText.slice(commentStart).match(/^\/\*\s*::/);
  35629. if (commentSyntax) {
  35630. return concat$c(["/*:: ", printTypeParameters(path, options, print, "params"), " */"]);
  35631. }
  35632. return printTypeParameters(path, options, print, "params");
  35633. }
  35634. case "TSTypeParameterDeclaration":
  35635. case "TSTypeParameterInstantiation":
  35636. return printTypeParameters(path, options, print, "params");
  35637. case "TSTypeParameter":
  35638. case "TypeParameter":
  35639. {
  35640. const parent = path.getParentNode();
  35641. if (parent.type === "TSMappedType") {
  35642. parts.push("[", path.call(print, "name"));
  35643. if (n.constraint) {
  35644. parts.push(" in ", path.call(print, "constraint"));
  35645. }
  35646. parts.push("]");
  35647. return concat$c(parts);
  35648. }
  35649. const variance = getFlowVariance$1(n);
  35650. if (variance) {
  35651. parts.push(variance);
  35652. }
  35653. parts.push(path.call(print, "name"));
  35654. if (n.bound) {
  35655. parts.push(": ");
  35656. parts.push(path.call(print, "bound"));
  35657. }
  35658. if (n.constraint) {
  35659. parts.push(" extends ", path.call(print, "constraint"));
  35660. }
  35661. if (n.default) {
  35662. parts.push(" = ", path.call(print, "default"));
  35663. } // Keep comma if the file extension is .tsx and
  35664. // has one type parameter that isn't extend with any types.
  35665. // Because, otherwise formatted result will be invalid as tsx.
  35666. const grandParent = path.getNode(2);
  35667. if (parent.params && parent.params.length === 1 && isTSXFile$1(options) && !n.constraint && grandParent.type === "ArrowFunctionExpression") {
  35668. parts.push(",");
  35669. }
  35670. return concat$c(parts);
  35671. }
  35672. case "TypeofTypeAnnotation":
  35673. return concat$c(["typeof ", path.call(print, "argument")]);
  35674. case "VoidTypeAnnotation":
  35675. return "void";
  35676. case "InferredPredicate":
  35677. return "%checks";
  35678. // Unhandled types below. If encountered, nodes of these types should
  35679. // be either left alone or desugared into AST types that are fully
  35680. // supported by the pretty-printer.
  35681. case "DeclaredPredicate":
  35682. return concat$c(["%checks(", path.call(print, "value"), ")"]);
  35683. case "TSAbstractKeyword":
  35684. return "abstract";
  35685. case "TSAnyKeyword":
  35686. return "any";
  35687. case "TSAsyncKeyword":
  35688. return "async";
  35689. case "TSBooleanKeyword":
  35690. return "boolean";
  35691. case "TSBigIntKeyword":
  35692. return "bigint";
  35693. case "TSConstKeyword":
  35694. return "const";
  35695. case "TSDeclareKeyword":
  35696. return "declare";
  35697. case "TSExportKeyword":
  35698. return "export";
  35699. case "TSNeverKeyword":
  35700. return "never";
  35701. case "TSNumberKeyword":
  35702. return "number";
  35703. case "TSObjectKeyword":
  35704. return "object";
  35705. case "TSProtectedKeyword":
  35706. return "protected";
  35707. case "TSPrivateKeyword":
  35708. return "private";
  35709. case "TSPublicKeyword":
  35710. return "public";
  35711. case "TSReadonlyKeyword":
  35712. return "readonly";
  35713. case "TSSymbolKeyword":
  35714. return "symbol";
  35715. case "TSStaticKeyword":
  35716. return "static";
  35717. case "TSStringKeyword":
  35718. return "string";
  35719. case "TSUndefinedKeyword":
  35720. return "undefined";
  35721. case "TSUnknownKeyword":
  35722. return "unknown";
  35723. case "TSVoidKeyword":
  35724. return "void";
  35725. case "TSAsExpression":
  35726. return concat$c([path.call(print, "expression"), " as ", path.call(print, "typeAnnotation")]);
  35727. case "TSArrayType":
  35728. return concat$c([path.call(print, "elementType"), "[]"]);
  35729. case "TSPropertySignature":
  35730. {
  35731. if (n.export) {
  35732. parts.push("export ");
  35733. }
  35734. if (n.accessibility) {
  35735. parts.push(n.accessibility + " ");
  35736. }
  35737. if (n.static) {
  35738. parts.push("static ");
  35739. }
  35740. if (n.readonly) {
  35741. parts.push("readonly ");
  35742. }
  35743. parts.push(printPropertyKey(path, options, print), printOptionalToken$2(path));
  35744. if (n.typeAnnotation) {
  35745. parts.push(": ");
  35746. parts.push(path.call(print, "typeAnnotation"));
  35747. } // This isn't valid semantically, but it's in the AST so we can print it.
  35748. if (n.initializer) {
  35749. parts.push(" = ", path.call(print, "initializer"));
  35750. }
  35751. return concat$c(parts);
  35752. }
  35753. case "TSParameterProperty":
  35754. if (n.accessibility) {
  35755. parts.push(n.accessibility + " ");
  35756. }
  35757. if (n.export) {
  35758. parts.push("export ");
  35759. }
  35760. if (n.static) {
  35761. parts.push("static ");
  35762. }
  35763. if (n.readonly) {
  35764. parts.push("readonly ");
  35765. }
  35766. parts.push(path.call(print, "parameter"));
  35767. return concat$c(parts);
  35768. case "TSTypeReference":
  35769. return concat$c([path.call(print, "typeName"), printTypeParameters(path, options, print, "typeParameters")]);
  35770. case "TSTypeQuery":
  35771. return concat$c(["typeof ", path.call(print, "exprName")]);
  35772. case "TSIndexSignature":
  35773. {
  35774. const parent = path.getParentNode(); // The typescript parser accepts multiple parameters here. If you're
  35775. // using them, it makes sense to have a trailing comma. But if you
  35776. // aren't, this is more like a computed property name than an array.
  35777. // So we leave off the trailing comma when there's just one parameter.
  35778. const trailingComma = n.parameters.length > 1 ? ifBreak$4(shouldPrintComma$3(options) ? "," : "") : "";
  35779. const parametersGroup = group$7(concat$c([indent$8(concat$c([softline$6, join$6(concat$c([", ", softline$6]), path.map(print, "parameters"))])), trailingComma, softline$6]));
  35780. return concat$c([n.export ? "export " : "", n.accessibility ? concat$c([n.accessibility, " "]) : "", n.static ? "static " : "", n.readonly ? "readonly " : "", "[", n.parameters ? parametersGroup : "", n.typeAnnotation ? "]: " : "]", n.typeAnnotation ? path.call(print, "typeAnnotation") : "", parent.type === "ClassBody" ? semi : ""]);
  35781. }
  35782. case "TSTypePredicate":
  35783. return concat$c([n.asserts ? "asserts " : "", path.call(print, "parameterName"), n.typeAnnotation ? concat$c([" is ", path.call(print, "typeAnnotation")]) : ""]);
  35784. case "TSNonNullExpression":
  35785. return concat$c([path.call(print, "expression"), "!"]);
  35786. case "TSThisType":
  35787. return "this";
  35788. case "TSImportType":
  35789. return concat$c([!n.isTypeOf ? "" : "typeof ", "import(", path.call(print, n.parameter ? "parameter" : "argument"), ")", !n.qualifier ? "" : concat$c([".", path.call(print, "qualifier")]), printTypeParameters(path, options, print, "typeParameters")]);
  35790. case "TSLiteralType":
  35791. return path.call(print, "literal");
  35792. case "TSIndexedAccessType":
  35793. return concat$c([path.call(print, "objectType"), "[", path.call(print, "indexType"), "]"]);
  35794. case "TSConstructSignatureDeclaration":
  35795. case "TSCallSignatureDeclaration":
  35796. case "TSConstructorType":
  35797. {
  35798. if (n.type !== "TSCallSignatureDeclaration") {
  35799. parts.push("new ");
  35800. }
  35801. parts.push(group$7(printFunctionParams(path, print, options,
  35802. /* expandArg */
  35803. false,
  35804. /* printTypeParams */
  35805. true)));
  35806. if (n.returnType || n.typeAnnotation) {
  35807. const isType = n.type === "TSConstructorType";
  35808. parts.push(isType ? " => " : ": ", path.call(print, "returnType"), path.call(print, "typeAnnotation"));
  35809. }
  35810. return concat$c(parts);
  35811. }
  35812. case "TSTypeOperator":
  35813. return concat$c([n.operator, " ", path.call(print, "typeAnnotation")]);
  35814. case "TSMappedType":
  35815. {
  35816. const shouldBreak = hasNewlineInRange$5(options.originalText, options.locStart(n), options.locEnd(n));
  35817. return group$7(concat$c(["{", indent$8(concat$c([options.bracketSpacing ? line$8 : softline$6, n.readonly ? concat$c([getTypeScriptMappedTypeModifier$1(n.readonly, "readonly"), " "]) : "", printTypeScriptModifiers(path, options, print), path.call(print, "typeParameter"), n.optional ? getTypeScriptMappedTypeModifier$1(n.optional, "?") : "", n.typeAnnotation ? ": " : "", path.call(print, "typeAnnotation"), ifBreak$4(semi, "")])), comments.printDanglingComments(path, options,
  35818. /* sameIndent */
  35819. true), options.bracketSpacing ? line$8 : softline$6, "}"]), {
  35820. shouldBreak
  35821. });
  35822. }
  35823. case "TSMethodSignature":
  35824. parts.push(n.accessibility ? concat$c([n.accessibility, " "]) : "", n.export ? "export " : "", n.static ? "static " : "", n.readonly ? "readonly " : "", n.computed ? "[" : "", path.call(print, "key"), n.computed ? "]" : "", printOptionalToken$2(path), printFunctionParams(path, print, options,
  35825. /* expandArg */
  35826. false,
  35827. /* printTypeParams */
  35828. true));
  35829. if (n.returnType || n.typeAnnotation) {
  35830. parts.push(": ", path.call(print, "returnType"), path.call(print, "typeAnnotation"));
  35831. }
  35832. return group$7(concat$c(parts));
  35833. case "TSNamespaceExportDeclaration":
  35834. parts.push("export as namespace ", path.call(print, "id"));
  35835. if (options.semi) {
  35836. parts.push(";");
  35837. }
  35838. return group$7(concat$c(parts));
  35839. case "TSEnumDeclaration":
  35840. if (n.declare) {
  35841. parts.push("declare ");
  35842. }
  35843. if (n.modifiers) {
  35844. parts.push(printTypeScriptModifiers(path, options, print));
  35845. }
  35846. if (n.const) {
  35847. parts.push("const ");
  35848. }
  35849. parts.push("enum ", path.call(print, "id"), " ");
  35850. if (n.members.length === 0) {
  35851. parts.push(group$7(concat$c(["{", comments.printDanglingComments(path, options), softline$6, "}"])));
  35852. } else {
  35853. parts.push(group$7(concat$c(["{", indent$8(concat$c([hardline$6, printArrayItems(path, options, "members", print), shouldPrintComma$3(options, "es5") ? "," : ""])), comments.printDanglingComments(path, options,
  35854. /* sameIndent */
  35855. true), hardline$6, "}"])));
  35856. }
  35857. return concat$c(parts);
  35858. case "TSEnumMember":
  35859. parts.push(path.call(print, "id"));
  35860. if (n.initializer) {
  35861. parts.push(" = ", path.call(print, "initializer"));
  35862. }
  35863. return concat$c(parts);
  35864. case "TSImportEqualsDeclaration":
  35865. if (n.isExport) {
  35866. parts.push("export ");
  35867. }
  35868. parts.push("import ", path.call(print, "id"), " = ", path.call(print, "moduleReference"));
  35869. if (options.semi) {
  35870. parts.push(";");
  35871. }
  35872. return group$7(concat$c(parts));
  35873. case "TSExternalModuleReference":
  35874. return concat$c(["require(", path.call(print, "expression"), ")"]);
  35875. case "TSModuleDeclaration":
  35876. {
  35877. const parent = path.getParentNode();
  35878. const isExternalModule = isLiteral$1(n.id);
  35879. const parentIsDeclaration = parent.type === "TSModuleDeclaration";
  35880. const bodyIsDeclaration = n.body && n.body.type === "TSModuleDeclaration";
  35881. if (parentIsDeclaration) {
  35882. parts.push(".");
  35883. } else {
  35884. if (n.declare) {
  35885. parts.push("declare ");
  35886. }
  35887. parts.push(printTypeScriptModifiers(path, options, print));
  35888. const textBetweenNodeAndItsId = options.originalText.slice(options.locStart(n), options.locStart(n.id)); // Global declaration looks like this:
  35889. // (declare)? global { ... }
  35890. const isGlobalDeclaration = n.id.type === "Identifier" && n.id.name === "global" && !/namespace|module/.test(textBetweenNodeAndItsId);
  35891. if (!isGlobalDeclaration) {
  35892. parts.push(isExternalModule || /(^|\s)module(\s|$)/.test(textBetweenNodeAndItsId) ? "module " : "namespace ");
  35893. }
  35894. }
  35895. parts.push(path.call(print, "id"));
  35896. if (bodyIsDeclaration) {
  35897. parts.push(path.call(print, "body"));
  35898. } else if (n.body) {
  35899. parts.push(" ", group$7(path.call(print, "body")));
  35900. } else {
  35901. parts.push(semi);
  35902. }
  35903. return concat$c(parts);
  35904. }
  35905. case "PrivateName":
  35906. return concat$c(["#", path.call(print, "id")]);
  35907. // TODO: Temporary auto-generated node type. To remove when typescript-estree has proper support for private fields.
  35908. case "TSPrivateIdentifier":
  35909. return n.escapedText;
  35910. case "TSConditionalType":
  35911. return ternary(path, options, print, {
  35912. beforeParts: () => [path.call(print, "checkType"), " ", "extends", " ", path.call(print, "extendsType")],
  35913. afterParts: () => [],
  35914. shouldCheckJsx: false,
  35915. conditionalNodeType: "TSConditionalType",
  35916. consequentNodePropertyName: "trueType",
  35917. alternateNodePropertyName: "falseType",
  35918. testNodePropertyNames: ["checkType", "extendsType"]
  35919. });
  35920. case "TSInferType":
  35921. return concat$c(["infer", " ", path.call(print, "typeParameter")]);
  35922. case "InterpreterDirective":
  35923. parts.push("#!", n.value, hardline$6);
  35924. if (isNextLineEmpty$4(options.originalText, n, options.locEnd)) {
  35925. parts.push(hardline$6);
  35926. }
  35927. return concat$c(parts);
  35928. case "NGRoot":
  35929. return concat$c([].concat(path.call(print, "node"), !n.node.comments || n.node.comments.length === 0 ? [] : concat$c([" //", n.node.comments[0].value.trimEnd()])));
  35930. case "NGChainedExpression":
  35931. return group$7(join$6(concat$c([";", line$8]), path.map(childPath => hasNgSideEffect$1(childPath) ? print(childPath) : concat$c(["(", print(childPath), ")"]), "expressions")));
  35932. case "NGEmptyExpression":
  35933. return "";
  35934. case "NGQuotedExpression":
  35935. return concat$c([n.prefix, ": ", n.value.trim()]);
  35936. case "NGMicrosyntax":
  35937. return concat$c(path.map((childPath, index) => concat$c([index === 0 ? "" : isNgForOf$1(childPath.getValue(), index, n) ? " " : concat$c([";", line$8]), print(childPath)]), "body"));
  35938. case "NGMicrosyntaxKey":
  35939. return /^[$_a-z][\w$]*(-[$_a-z][\w$])*$/i.test(n.name) ? n.name : JSON.stringify(n.name);
  35940. case "NGMicrosyntaxExpression":
  35941. return concat$c([path.call(print, "expression"), n.alias === null ? "" : concat$c([" as ", path.call(print, "alias")])]);
  35942. case "NGMicrosyntaxKeyedExpression":
  35943. {
  35944. const index = path.getName();
  35945. const parentNode = path.getParentNode();
  35946. const shouldNotPrintColon = isNgForOf$1(n, index, parentNode) || (index === 1 && (n.key.name === "then" || n.key.name === "else") || index === 2 && n.key.name === "else" && parentNode.body[index - 1].type === "NGMicrosyntaxKeyedExpression" && parentNode.body[index - 1].key.name === "then") && parentNode.body[0].type === "NGMicrosyntaxExpression";
  35947. return concat$c([path.call(print, "key"), shouldNotPrintColon ? " " : ": ", path.call(print, "expression")]);
  35948. }
  35949. case "NGMicrosyntaxLet":
  35950. return concat$c(["let ", path.call(print, "key"), n.value === null ? "" : concat$c([" = ", path.call(print, "value")])]);
  35951. case "NGMicrosyntaxAs":
  35952. return concat$c([path.call(print, "key"), " as ", path.call(print, "alias")]);
  35953. case "PipelineBareFunction":
  35954. return path.call(print, "callee");
  35955. case "PipelineTopicExpression":
  35956. return path.call(print, "expression");
  35957. case "PipelinePrimaryTopicReference":
  35958. {
  35959. parts.push("#");
  35960. return concat$c(parts);
  35961. }
  35962. case "ArgumentPlaceholder":
  35963. return "?";
  35964. // These are not valid TypeScript. Printing them just for the sake of error recovery.
  35965. case "TSJSDocAllType":
  35966. return "*";
  35967. case "TSJSDocUnknownType":
  35968. return "?";
  35969. case "TSJSDocNullableType":
  35970. return concat$c(["?", path.call(print, "typeAnnotation")]);
  35971. case "TSJSDocNonNullableType":
  35972. return concat$c(["!", path.call(print, "typeAnnotation")]);
  35973. case "TSJSDocFunctionType":
  35974. return concat$c(["function(", // The parameters could be here, but typescript-estree doesn't convert them anyway (throws an error).
  35975. "): ", path.call(print, "typeAnnotation")]);
  35976. default:
  35977. /* istanbul ignore next */
  35978. throw new Error("unknown type: " + JSON.stringify(n.type));
  35979. }
  35980. }
  35981. function printStatementSequence(path, options, print) {
  35982. const printed = [];
  35983. const bodyNode = path.getNode();
  35984. const isClass = bodyNode.type === "ClassBody";
  35985. path.map((stmtPath, i) => {
  35986. const stmt = stmtPath.getValue(); // Just in case the AST has been modified to contain falsy
  35987. // "statements," it's safer simply to skip them.
  35988. /* istanbul ignore if */
  35989. if (!stmt) {
  35990. return;
  35991. } // Skip printing EmptyStatement nodes to avoid leaving stray
  35992. // semicolons lying around.
  35993. if (stmt.type === "EmptyStatement") {
  35994. return;
  35995. }
  35996. const stmtPrinted = print(stmtPath);
  35997. const text = options.originalText;
  35998. const parts = []; // in no-semi mode, prepend statement with semicolon if it might break ASI
  35999. // don't prepend the only JSX element in a program with semicolon
  36000. if (!options.semi && !isClass && !isTheOnlyJSXElementInMarkdown$1(options, stmtPath) && stmtNeedsASIProtection(stmtPath, options)) {
  36001. if (stmt.comments && stmt.comments.some(comment => comment.leading)) {
  36002. parts.push(print(stmtPath, {
  36003. needsSemi: true
  36004. }));
  36005. } else {
  36006. parts.push(";", stmtPrinted);
  36007. }
  36008. } else {
  36009. parts.push(stmtPrinted);
  36010. }
  36011. if (!options.semi && isClass) {
  36012. if (classPropMayCauseASIProblems$1(stmtPath)) {
  36013. parts.push(";");
  36014. } else if (stmt.type === "ClassProperty") {
  36015. const nextChild = bodyNode.body[i + 1];
  36016. if (classChildNeedsASIProtection$1(nextChild)) {
  36017. parts.push(";");
  36018. }
  36019. }
  36020. }
  36021. if (isNextLineEmpty$4(text, stmt, options.locEnd) && !isLastStatement$1(stmtPath)) {
  36022. parts.push(hardline$6);
  36023. }
  36024. printed.push(concat$c(parts));
  36025. });
  36026. return join$6(hardline$6, printed);
  36027. }
  36028. function printPropertyKey(path, options, print) {
  36029. const node = path.getNode();
  36030. if (node.computed) {
  36031. return concat$c(["[", path.call(print, "key"), "]"]);
  36032. }
  36033. const parent = path.getParentNode();
  36034. const {
  36035. key
  36036. } = node;
  36037. if (node.type === "ClassPrivateProperty" && // flow has `Identifier` key, and babel has `PrivateName` key
  36038. key.type === "Identifier") {
  36039. return concat$c(["#", path.call(print, "key")]);
  36040. }
  36041. if (options.quoteProps === "consistent" && !needsQuoteProps.has(parent)) {
  36042. const objectHasStringProp = (parent.properties || parent.body || parent.members).some(prop => !prop.computed && prop.key && isStringLiteral$1(prop.key) && !isStringPropSafeToUnquote$1(prop, options));
  36043. needsQuoteProps.set(parent, objectHasStringProp);
  36044. }
  36045. if ((key.type === "Identifier" || isNumericLiteral$3(key) && isSimpleNumber$1(printNumber$1(rawText$1(key))) && // Avoid converting 999999999999999999999 to 1e+21, 0.99999999999999999 to 1 and 1.0 to 1.
  36046. String(key.value) === printNumber$1(rawText$1(key)) && // Quoting number keys is safe in JS and Flow, but not in TypeScript (as
  36047. // mentioned in `isStringPropSafeToUnquote`).
  36048. !(options.parser === "typescript" || options.parser === "babel-ts")) && (options.parser === "json" || options.quoteProps === "consistent" && needsQuoteProps.get(parent))) {
  36049. // a -> "a"
  36050. // 1 -> "1"
  36051. // 1.5 -> "1.5"
  36052. const prop = printString$1(JSON.stringify(key.type === "Identifier" ? key.name : key.value.toString()), options);
  36053. return path.call(keyPath => comments.printComments(keyPath, () => prop, options), "key");
  36054. }
  36055. if (isStringPropSafeToUnquote$1(node, options) && (options.quoteProps === "as-needed" || options.quoteProps === "consistent" && !needsQuoteProps.get(parent))) {
  36056. // 'a' -> a
  36057. // '1' -> 1
  36058. // '1.5' -> 1.5
  36059. return path.call(keyPath => comments.printComments(keyPath, () => /^\d/.test(key.value) ? printNumber$1(key.value) : key.value, options), "key");
  36060. }
  36061. return path.call(print, "key");
  36062. }
  36063. function printMethod(path, options, print) {
  36064. const node = path.getNode();
  36065. const {
  36066. kind
  36067. } = node;
  36068. const value = node.value || node;
  36069. const parts = [];
  36070. if (!kind || kind === "init" || kind === "method" || kind === "constructor") {
  36071. if (value.async) {
  36072. parts.push("async ");
  36073. }
  36074. if (value.generator) {
  36075. parts.push("*");
  36076. }
  36077. } else {
  36078. assert__default['default'].ok(kind === "get" || kind === "set");
  36079. parts.push(kind, " ");
  36080. }
  36081. parts.push(printPropertyKey(path, options, print), node.optional || node.key.optional ? "?" : "", node === value ? printMethodInternal(path, options, print) : path.call(path => printMethodInternal(path, options, print), "value"));
  36082. return concat$c(parts);
  36083. }
  36084. function printMethodInternal(path, options, print) {
  36085. const parts = [printFunctionTypeParameters$2(path, options, print), group$7(concat$c([printFunctionParams(path, print, options), printReturnType(path, print, options)]))];
  36086. if (path.getNode().body) {
  36087. parts.push(" ", path.call(print, "body"));
  36088. } else {
  36089. parts.push(options.semi ? ";" : "");
  36090. }
  36091. return concat$c(parts);
  36092. }
  36093. function printJestEachTemplateLiteral(path, options, print) {
  36094. /**
  36095. * a | b | expected
  36096. * ${1} | ${1} | ${2}
  36097. * ${1} | ${2} | ${3}
  36098. * ${2} | ${1} | ${3}
  36099. */
  36100. const node = path.getNode();
  36101. const headerNames = node.quasis[0].value.raw.trim().split(/\s*\|\s*/);
  36102. if (headerNames.length > 1 || headerNames.some(headerName => headerName.length !== 0)) {
  36103. options.__inJestEach = true;
  36104. const expressions = path.map(print, "expressions");
  36105. options.__inJestEach = false;
  36106. const parts = [];
  36107. const stringifiedExpressions = expressions.map(doc => "${" + printDocToString$2(doc, Object.assign({}, options, {
  36108. printWidth: Infinity,
  36109. endOfLine: "lf"
  36110. })).formatted + "}");
  36111. const tableBody = [{
  36112. hasLineBreak: false,
  36113. cells: []
  36114. }];
  36115. for (let i = 1; i < node.quasis.length; i++) {
  36116. const row = tableBody[tableBody.length - 1];
  36117. const correspondingExpression = stringifiedExpressions[i - 1];
  36118. row.cells.push(correspondingExpression);
  36119. if (correspondingExpression.includes("\n")) {
  36120. row.hasLineBreak = true;
  36121. }
  36122. if (node.quasis[i].value.raw.includes("\n")) {
  36123. tableBody.push({
  36124. hasLineBreak: false,
  36125. cells: []
  36126. });
  36127. }
  36128. }
  36129. const maxColumnCount = Math.max(headerNames.length, ...tableBody.map(row => row.cells.length));
  36130. const maxColumnWidths = Array.from({
  36131. length: maxColumnCount
  36132. }).fill(0);
  36133. const table = [{
  36134. cells: headerNames
  36135. }, ...tableBody.filter(row => row.cells.length !== 0)];
  36136. for (const {
  36137. cells
  36138. } of table.filter(row => !row.hasLineBreak)) {
  36139. cells.forEach((cell, index) => {
  36140. maxColumnWidths[index] = Math.max(maxColumnWidths[index], getStringWidth$3(cell));
  36141. });
  36142. }
  36143. parts.push(lineSuffixBoundary$1, "`", indent$8(concat$c([hardline$6, join$6(hardline$6, table.map(row => join$6(" | ", row.cells.map((cell, index) => row.hasLineBreak ? cell : cell + " ".repeat(maxColumnWidths[index] - getStringWidth$3(cell))))))])), hardline$6, "`");
  36144. return concat$c(parts);
  36145. }
  36146. }
  36147. function printTypeAnnotation(path, options, print) {
  36148. const node = path.getValue();
  36149. if (!node.typeAnnotation) {
  36150. return "";
  36151. }
  36152. const parentNode = path.getParentNode();
  36153. const isDefinite = node.definite || parentNode && parentNode.type === "VariableDeclarator" && parentNode.definite;
  36154. const isFunctionDeclarationIdentifier = parentNode.type === "DeclareFunction" && parentNode.id === node;
  36155. if (isFlowAnnotationComment$1(options.originalText, node.typeAnnotation, options)) {
  36156. return concat$c([" /*: ", path.call(print, "typeAnnotation"), " */"]);
  36157. }
  36158. return concat$c([isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ", path.call(print, "typeAnnotation")]);
  36159. }
  36160. function printFunctionParams(path, print, options, expandArg, printTypeParams) {
  36161. const fun = path.getValue();
  36162. const parent = path.getParentNode();
  36163. const paramsField = fun.parameters ? "parameters" : "params";
  36164. const isParametersInTestCall = isTestCall$1(parent);
  36165. const shouldHugParameters = shouldHugArguments(fun);
  36166. const shouldExpandParameters = expandArg && !(fun[paramsField] && fun[paramsField].some(n => n.comments));
  36167. const typeParams = printTypeParams ? printFunctionTypeParameters$2(path, options, print) : "";
  36168. let printed = [];
  36169. if (fun[paramsField]) {
  36170. const lastArgIndex = fun[paramsField].length - 1;
  36171. printed = path.map((childPath, index) => {
  36172. const parts = [];
  36173. const param = childPath.getValue();
  36174. parts.push(print(childPath));
  36175. if (index === lastArgIndex) {
  36176. if (fun.rest) {
  36177. parts.push(",", line$8);
  36178. }
  36179. } else if (isParametersInTestCall || shouldHugParameters || shouldExpandParameters) {
  36180. parts.push(", ");
  36181. } else if (isNextLineEmpty$4(options.originalText, param, options.locEnd)) {
  36182. parts.push(",", hardline$6, hardline$6);
  36183. } else {
  36184. parts.push(",", line$8);
  36185. }
  36186. return concat$c(parts);
  36187. }, paramsField);
  36188. }
  36189. if (fun.rest) {
  36190. printed.push(concat$c(["...", path.call(print, "rest")]));
  36191. }
  36192. if (printed.length === 0) {
  36193. return concat$c([typeParams, "(", comments.printDanglingComments(path, options,
  36194. /* sameIndent */
  36195. true, comment => getNextNonSpaceNonCommentCharacter$2(options.originalText, comment, options.locEnd) === ")"), ")"]);
  36196. }
  36197. const lastParam = getLast$5(fun[paramsField]); // If the parent is a call with the first/last argument expansion and this is the
  36198. // params of the first/last argument, we don't want the arguments to break and instead
  36199. // want the whole expression to be on a new line.
  36200. //
  36201. // Good: Bad:
  36202. // verylongcall( verylongcall((
  36203. // (a, b) => { a,
  36204. // } b,
  36205. // }) ) => {
  36206. // })
  36207. if (shouldExpandParameters) {
  36208. return group$7(concat$c([removeLines$1(typeParams), "(", concat$c(printed.map(removeLines$1)), ")"]));
  36209. } // Single object destructuring should hug
  36210. //
  36211. // function({
  36212. // a,
  36213. // b,
  36214. // c
  36215. // }) {}
  36216. const hasNotParameterDecorator = fun[paramsField].every(param => !param.decorators);
  36217. if (shouldHugParameters && hasNotParameterDecorator) {
  36218. return concat$c([typeParams, "(", concat$c(printed), ")"]);
  36219. } // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
  36220. if (isParametersInTestCall) {
  36221. return concat$c([typeParams, "(", concat$c(printed), ")"]);
  36222. }
  36223. const isFlowShorthandWithOneArg = (isObjectTypePropertyAFunction$1(parent, options) || isTypeAnnotationAFunction$1(parent, options) || parent.type === "TypeAlias" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || parent.type === "IntersectionTypeAnnotation" || parent.type === "FunctionTypeAnnotation" && parent.returnType === fun) && fun[paramsField].length === 1 && fun[paramsField][0].name === null && fun[paramsField][0].typeAnnotation && fun.typeParameters === null && isSimpleFlowType$1(fun[paramsField][0].typeAnnotation) && !fun.rest;
  36224. if (isFlowShorthandWithOneArg) {
  36225. if (options.arrowParens === "always") {
  36226. return concat$c(["(", concat$c(printed), ")"]);
  36227. }
  36228. return concat$c(printed);
  36229. }
  36230. const canHaveTrailingComma = !(lastParam && lastParam.type === "RestElement") && !fun.rest;
  36231. return concat$c([typeParams, "(", indent$8(concat$c([softline$6, concat$c(printed)])), ifBreak$4(canHaveTrailingComma && shouldPrintComma$3(options, "all") ? "," : ""), softline$6, ")"]);
  36232. }
  36233. function shouldPrintParamsWithoutParens(path, options) {
  36234. if (options.arrowParens === "always") {
  36235. return false;
  36236. }
  36237. if (options.arrowParens === "avoid") {
  36238. const node = path.getValue();
  36239. return canPrintParamsWithoutParens(node);
  36240. } // Fallback default; should be unreachable
  36241. /* istanbul ignore next */
  36242. return false;
  36243. }
  36244. function canPrintParamsWithoutParens(node) {
  36245. return node.params.length === 1 && !node.rest && !node.typeParameters && !hasDanglingComments$1(node) && node.params[0].type === "Identifier" && !node.params[0].typeAnnotation && !node.params[0].comments && !node.params[0].optional && !node.predicate && !node.returnType;
  36246. }
  36247. function printFunctionDeclaration(path, print, options) {
  36248. const n = path.getValue();
  36249. const parts = [];
  36250. if (n.async) {
  36251. parts.push("async ");
  36252. }
  36253. if (n.generator) {
  36254. parts.push("function* ");
  36255. } else {
  36256. parts.push("function ");
  36257. }
  36258. if (n.id) {
  36259. parts.push(path.call(print, "id"));
  36260. }
  36261. parts.push(printFunctionTypeParameters$2(path, options, print), group$7(concat$c([printFunctionParams(path, print, options), printReturnType(path, print, options)])), n.body ? " " : "", path.call(print, "body"));
  36262. return concat$c(parts);
  36263. }
  36264. function printReturnType(path, print, options) {
  36265. const n = path.getValue();
  36266. const returnType = path.call(print, "returnType");
  36267. if (n.returnType && isFlowAnnotationComment$1(options.originalText, n.returnType, options)) {
  36268. return concat$c([" /*: ", returnType, " */"]);
  36269. }
  36270. const parts = [returnType]; // prepend colon to TypeScript type annotation
  36271. if (n.returnType && n.returnType.typeAnnotation) {
  36272. parts.unshift(": ");
  36273. }
  36274. if (n.predicate) {
  36275. // The return type will already add the colon, but otherwise we
  36276. // need to do it ourselves
  36277. parts.push(n.returnType ? " " : ": ", path.call(print, "predicate"));
  36278. }
  36279. return concat$c(parts);
  36280. }
  36281. function printExportDeclaration(path, options, print) {
  36282. const decl = path.getValue();
  36283. const semi = options.semi ? ";" : "";
  36284. /** @type{Doc[]} */
  36285. const parts = ["export "];
  36286. const isDefault = decl.default || decl.type === "ExportDefaultDeclaration";
  36287. if (isDefault) {
  36288. parts.push("default ");
  36289. }
  36290. parts.push(comments.printDanglingComments(path, options,
  36291. /* sameIndent */
  36292. true));
  36293. if (needsHardlineAfterDanglingComment$1(decl)) {
  36294. parts.push(hardline$6);
  36295. }
  36296. if (decl.declaration) {
  36297. parts.push(path.call(print, "declaration"));
  36298. if (isDefault && decl.declaration.type !== "ClassDeclaration" && decl.declaration.type !== "FunctionDeclaration" && decl.declaration.type !== "TSInterfaceDeclaration" && decl.declaration.type !== "DeclareClass" && decl.declaration.type !== "DeclareFunction" && decl.declaration.type !== "TSDeclareFunction" && decl.declaration.type !== "EnumDeclaration") {
  36299. parts.push(semi);
  36300. }
  36301. } else {
  36302. parts.push(decl.exportKind === "type" ? "type " : "");
  36303. parts.push(printModuleSpecifiers$1(path, options, print));
  36304. parts.push(printModuleSource$1(path, options, print));
  36305. parts.push(semi);
  36306. }
  36307. return concat$c(parts);
  36308. }
  36309. function printFlowDeclaration(path, parts) {
  36310. const parentExportDecl = getParentExportDeclaration$1(path);
  36311. if (parentExportDecl) {
  36312. assert__default['default'].strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
  36313. } else {
  36314. // If the parent node has type DeclareExportDeclaration, then it
  36315. // will be responsible for printing the "declare" token. Otherwise
  36316. // it needs to be printed with this non-exported declaration node.
  36317. parts.unshift("declare ");
  36318. }
  36319. return concat$c(parts);
  36320. }
  36321. function printTypeScriptModifiers(path, options, print) {
  36322. const n = path.getValue();
  36323. if (!n.modifiers || !n.modifiers.length) {
  36324. return "";
  36325. }
  36326. return concat$c([join$6(" ", path.map(print, "modifiers")), " "]);
  36327. }
  36328. const typeParametersGroupIds = new WeakMap();
  36329. function getTypeParametersGroupId(node) {
  36330. if (!typeParametersGroupIds.has(node)) {
  36331. typeParametersGroupIds.set(node, Symbol("typeParameters"));
  36332. }
  36333. return typeParametersGroupIds.get(node);
  36334. }
  36335. function printTypeParameters(path, options, print, paramsKey) {
  36336. const n = path.getValue();
  36337. if (!n[paramsKey]) {
  36338. return "";
  36339. } // for TypeParameterDeclaration typeParameters is a single node
  36340. if (!Array.isArray(n[paramsKey])) {
  36341. return path.call(print, paramsKey);
  36342. }
  36343. const grandparent = path.getNode(2);
  36344. const greatGrandParent = path.getNode(3);
  36345. const greatGreatGrandParent = path.getNode(4);
  36346. const isParameterInTestCall = grandparent != null && isTestCall$1(grandparent);
  36347. const shouldInline = isParameterInTestCall || n[paramsKey].length === 0 || n[paramsKey].length === 1 && (shouldHugType(n[paramsKey][0]) || n[paramsKey][0].type === "GenericTypeAnnotation" && shouldHugType(n[paramsKey][0].id) || n[paramsKey][0].type === "TSTypeReference" && shouldHugType(n[paramsKey][0].typeName) || n[paramsKey][0].type === "NullableTypeAnnotation" || // See https://github.com/prettier/prettier/pull/6467 for the context.
  36348. greatGreatGrandParent && greatGreatGrandParent.type === "VariableDeclarator" && grandparent.type === "TSTypeAnnotation" && greatGrandParent.type !== "ArrowFunctionExpression" && n[paramsKey][0].type !== "TSUnionType" && n[paramsKey][0].type !== "UnionTypeAnnotation" && n[paramsKey][0].type !== "TSIntersectionType" && n[paramsKey][0].type !== "IntersectionTypeAnnotation" && n[paramsKey][0].type !== "TSConditionalType" && n[paramsKey][0].type !== "TSMappedType" && n[paramsKey][0].type !== "TSTypeOperator" && n[paramsKey][0].type !== "TSIndexedAccessType" && n[paramsKey][0].type !== "TSArrayType");
  36349. function printDanglingCommentsForInline(n) {
  36350. if (!hasDanglingComments$1(n)) {
  36351. return "";
  36352. }
  36353. const hasOnlyBlockComments = n.comments.every(comments$1.isBlockComment);
  36354. const printed = comments.printDanglingComments(path, options,
  36355. /* sameIndent */
  36356. hasOnlyBlockComments);
  36357. if (hasOnlyBlockComments) {
  36358. return printed;
  36359. }
  36360. return concat$c([printed, hardline$6]);
  36361. }
  36362. if (shouldInline) {
  36363. return concat$c(["<", join$6(", ", path.map(print, paramsKey)), printDanglingCommentsForInline(n), ">"]);
  36364. }
  36365. return group$7(concat$c(["<", indent$8(concat$c([softline$6, join$6(concat$c([",", line$8]), path.map(print, paramsKey))])), ifBreak$4(options.parser !== "typescript" && options.parser !== "babel-ts" && shouldPrintComma$3(options, "all") ? "," : ""), softline$6, ">"]), {
  36366. id: getTypeParametersGroupId(n)
  36367. });
  36368. }
  36369. function printClass(path, options, print) {
  36370. const n = path.getValue();
  36371. const parts = [];
  36372. if (n.abstract) {
  36373. parts.push("abstract ");
  36374. }
  36375. parts.push("class"); // Keep old behaviour of extends in same line
  36376. // If there is only on extends and there are not comments
  36377. const groupMode = n.id && hasTrailingComment$3(n.id) || n.superClass && n.superClass.comments && n.superClass.comments.length !== 0 || n.extends && n.extends.length !== 0 || // DeclareClass
  36378. n.mixins && n.mixins.length !== 0 || n.implements && n.implements.length !== 0;
  36379. const partsGroup = [];
  36380. const extendsParts = [];
  36381. if (n.id) {
  36382. partsGroup.push(" ", path.call(print, "id"));
  36383. }
  36384. partsGroup.push(path.call(print, "typeParameters"));
  36385. const hasMultipleHeritage = ["superClass", "extends", "mixins", "implements"].filter(key => !!n[key]).length > 1;
  36386. const shouldIndentOnlyHeritageClauses = n.typeParameters && !hasTrailingLineComment$1(n.typeParameters) && !hasMultipleHeritage;
  36387. function printList(listName) {
  36388. if (n[listName] && n[listName].length !== 0) {
  36389. const printedLeadingComments = comments.printDanglingComments(path, options,
  36390. /* sameIndent */
  36391. true, ({
  36392. marker
  36393. }) => marker === listName);
  36394. extendsParts.push(shouldIndentOnlyHeritageClauses ? ifBreak$4(" ", line$8, {
  36395. groupId: getTypeParametersGroupId(n.typeParameters)
  36396. }) : line$8, printedLeadingComments, printedLeadingComments && hardline$6, listName, group$7(indent$8(concat$c([line$8, join$6(concat$c([",", line$8]), path.map(print, listName))]))));
  36397. }
  36398. }
  36399. if (n.superClass) {
  36400. const printed = concat$c(["extends ", path.call(print, "superClass"), path.call(print, "superTypeParameters")]);
  36401. const printedWithComments = path.call(superClass => comments.printComments(superClass, () => printed, options), "superClass");
  36402. if (groupMode) {
  36403. extendsParts.push(line$8, group$7(printedWithComments));
  36404. } else {
  36405. extendsParts.push(" ", printedWithComments);
  36406. }
  36407. } else {
  36408. printList("extends");
  36409. }
  36410. printList("mixins");
  36411. printList("implements");
  36412. if (groupMode) {
  36413. const printedExtends = concat$c(extendsParts);
  36414. if (shouldIndentOnlyHeritageClauses) {
  36415. parts.push(group$7(concat$c(partsGroup.concat(ifBreak$4(indent$8(printedExtends), printedExtends)))));
  36416. } else {
  36417. parts.push(group$7(indent$8(concat$c(partsGroup.concat(printedExtends)))));
  36418. }
  36419. } else {
  36420. parts.push(...partsGroup, ...extendsParts);
  36421. }
  36422. parts.push(" ", path.call(print, "body"));
  36423. return parts;
  36424. }
  36425. function separatorNoWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
  36426. if (isFacebookTranslationTag) {
  36427. return "";
  36428. }
  36429. if (childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement) {
  36430. return child.length === 1 ? softline$6 : hardline$6;
  36431. }
  36432. return softline$6;
  36433. }
  36434. function separatorWithWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
  36435. if (isFacebookTranslationTag) {
  36436. return hardline$6;
  36437. }
  36438. if (child.length === 1) {
  36439. return childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement ? hardline$6 : softline$6;
  36440. }
  36441. return hardline$6;
  36442. } // JSX Children are strange, mostly for two reasons:
  36443. // 1. JSX reads newlines into string values, instead of skipping them like JS
  36444. // 2. up to one whitespace between elements within a line is significant,
  36445. // but not between lines.
  36446. //
  36447. // Leading, trailing, and lone whitespace all need to
  36448. // turn themselves into the rather ugly `{' '}` when breaking.
  36449. //
  36450. // We print JSX using the `fill` doc primitive.
  36451. // This requires that we give it an array of alternating
  36452. // content and whitespace elements.
  36453. // To ensure this we add dummy `""` content elements as needed.
  36454. function printJSXChildren(path, options, print, jsxWhitespace, isFacebookTranslationTag) {
  36455. const n = path.getValue();
  36456. const children = []; // using `map` instead of `each` because it provides `i`
  36457. path.map((childPath, i) => {
  36458. const child = childPath.getValue();
  36459. if (isLiteral$1(child)) {
  36460. const text = rawText$1(child); // Contains a non-whitespace character
  36461. if (isMeaningfulJSXText$1(child)) {
  36462. const words = text.split(matchJsxWhitespaceRegex$1); // Starts with whitespace
  36463. if (words[0] === "") {
  36464. children.push("");
  36465. words.shift();
  36466. if (/\n/.test(words[0])) {
  36467. const next = n.children[i + 1];
  36468. children.push(separatorWithWhitespace(isFacebookTranslationTag, words[1], child, next));
  36469. } else {
  36470. children.push(jsxWhitespace);
  36471. }
  36472. words.shift();
  36473. }
  36474. let endWhitespace; // Ends with whitespace
  36475. if (getLast$5(words) === "") {
  36476. words.pop();
  36477. endWhitespace = words.pop();
  36478. } // This was whitespace only without a new line.
  36479. if (words.length === 0) {
  36480. return;
  36481. }
  36482. words.forEach((word, i) => {
  36483. if (i % 2 === 1) {
  36484. children.push(line$8);
  36485. } else {
  36486. children.push(word);
  36487. }
  36488. });
  36489. if (endWhitespace !== undefined) {
  36490. if (/\n/.test(endWhitespace)) {
  36491. const next = n.children[i + 1];
  36492. children.push(separatorWithWhitespace(isFacebookTranslationTag, getLast$5(children), child, next));
  36493. } else {
  36494. children.push(jsxWhitespace);
  36495. }
  36496. } else {
  36497. const next = n.children[i + 1];
  36498. children.push(separatorNoWhitespace(isFacebookTranslationTag, getLast$5(children), child, next));
  36499. }
  36500. } else if (/\n/.test(text)) {
  36501. // Keep (up to one) blank line between tags/expressions/text.
  36502. // Note: We don't keep blank lines between text elements.
  36503. if (text.match(/\n/g).length > 1) {
  36504. children.push("");
  36505. children.push(hardline$6);
  36506. }
  36507. } else {
  36508. children.push("");
  36509. children.push(jsxWhitespace);
  36510. }
  36511. } else {
  36512. const printedChild = print(childPath);
  36513. children.push(printedChild);
  36514. const next = n.children[i + 1];
  36515. const directlyFollowedByMeaningfulText = next && isMeaningfulJSXText$1(next);
  36516. if (directlyFollowedByMeaningfulText) {
  36517. const firstWord = rawText$1(next).trim().split(matchJsxWhitespaceRegex$1)[0];
  36518. children.push(separatorNoWhitespace(isFacebookTranslationTag, firstWord, child, next));
  36519. } else {
  36520. children.push(hardline$6);
  36521. }
  36522. }
  36523. }, "children");
  36524. return children;
  36525. } // JSX expands children from the inside-out, instead of the outside-in.
  36526. // This is both to break children before attributes,
  36527. // and to ensure that when children break, their parents do as well.
  36528. //
  36529. // Any element that is written without any newlines and fits on a single line
  36530. // is left that way.
  36531. // Not only that, any user-written-line containing multiple JSX siblings
  36532. // should also be kept on one line if possible,
  36533. // so each user-written-line is wrapped in its own group.
  36534. //
  36535. // Elements that contain newlines or don't fit on a single line (recursively)
  36536. // are fully-split, using hardline and shouldBreak: true.
  36537. //
  36538. // To support that case properly, all leading and trailing spaces
  36539. // are stripped from the list of children, and replaced with a single hardline.
  36540. function printJSXElement(path, options, print) {
  36541. const n = path.getValue();
  36542. if (n.type === "JSXElement" && isEmptyJSXElement$1(n)) {
  36543. return concat$c([path.call(print, "openingElement"), path.call(print, "closingElement")]);
  36544. }
  36545. const openingLines = n.type === "JSXElement" ? path.call(print, "openingElement") : path.call(print, "openingFragment");
  36546. const closingLines = n.type === "JSXElement" ? path.call(print, "closingElement") : path.call(print, "closingFragment");
  36547. if (n.children.length === 1 && n.children[0].type === "JSXExpressionContainer" && (n.children[0].expression.type === "TemplateLiteral" || n.children[0].expression.type === "TaggedTemplateExpression")) {
  36548. return concat$c([openingLines, concat$c(path.map(print, "children")), closingLines]);
  36549. } // Convert `{" "}` to text nodes containing a space.
  36550. // This makes it easy to turn them into `jsxWhitespace` which
  36551. // can then print as either a space or `{" "}` when breaking.
  36552. n.children = n.children.map(child => {
  36553. if (isJSXWhitespaceExpression$1(child)) {
  36554. return {
  36555. type: "JSXText",
  36556. value: " ",
  36557. raw: " "
  36558. };
  36559. }
  36560. return child;
  36561. });
  36562. const containsTag = n.children.filter(isJSXNode$3).length > 0;
  36563. const containsMultipleExpressions = n.children.filter(child => child.type === "JSXExpressionContainer").length > 1;
  36564. const containsMultipleAttributes = n.type === "JSXElement" && n.openingElement.attributes.length > 1; // Record any breaks. Should never go from true to false, only false to true.
  36565. let forcedBreak = willBreak$3(openingLines) || containsTag || containsMultipleAttributes || containsMultipleExpressions;
  36566. const isMdxBlock = path.getParentNode().rootMarker === "mdx";
  36567. const rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
  36568. const jsxWhitespace = isMdxBlock ? concat$c([" "]) : ifBreak$4(concat$c([rawJsxWhitespace, softline$6]), " ");
  36569. const isFacebookTranslationTag = n.openingElement && n.openingElement.name && n.openingElement.name.name === "fbt";
  36570. const children = printJSXChildren(path, options, print, jsxWhitespace, isFacebookTranslationTag);
  36571. const containsText = n.children.some(child => isMeaningfulJSXText$1(child)); // We can end up we multiple whitespace elements with empty string
  36572. // content between them.
  36573. // We need to remove empty whitespace and softlines before JSX whitespace
  36574. // to get the correct output.
  36575. for (let i = children.length - 2; i >= 0; i--) {
  36576. const isPairOfEmptyStrings = children[i] === "" && children[i + 1] === "";
  36577. const isPairOfHardlines = children[i] === hardline$6 && children[i + 1] === "" && children[i + 2] === hardline$6;
  36578. const isLineFollowedByJSXWhitespace = (children[i] === softline$6 || children[i] === hardline$6) && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  36579. const isJSXWhitespaceFollowedByLine = children[i] === jsxWhitespace && children[i + 1] === "" && (children[i + 2] === softline$6 || children[i + 2] === hardline$6);
  36580. const isDoubleJSXWhitespace = children[i] === jsxWhitespace && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  36581. const isPairOfHardOrSoftLines = children[i] === softline$6 && children[i + 1] === "" && children[i + 2] === hardline$6 || children[i] === hardline$6 && children[i + 1] === "" && children[i + 2] === softline$6;
  36582. if (isPairOfHardlines && containsText || isPairOfEmptyStrings || isLineFollowedByJSXWhitespace || isDoubleJSXWhitespace || isPairOfHardOrSoftLines) {
  36583. children.splice(i, 2);
  36584. } else if (isJSXWhitespaceFollowedByLine) {
  36585. children.splice(i + 1, 2);
  36586. }
  36587. } // Trim trailing lines (or empty strings)
  36588. while (children.length && (isLineNext$1(getLast$5(children)) || isEmpty$1(getLast$5(children)))) {
  36589. children.pop();
  36590. } // Trim leading lines (or empty strings)
  36591. while (children.length && (isLineNext$1(children[0]) || isEmpty$1(children[0])) && (isLineNext$1(children[1]) || isEmpty$1(children[1]))) {
  36592. children.shift();
  36593. children.shift();
  36594. } // Tweak how we format children if outputting this element over multiple lines.
  36595. // Also detect whether we will force this element to output over multiple lines.
  36596. const multilineChildren = [];
  36597. children.forEach((child, i) => {
  36598. // There are a number of situations where we need to ensure we display
  36599. // whitespace as `{" "}` when outputting this element over multiple lines.
  36600. if (child === jsxWhitespace) {
  36601. if (i === 1 && children[i - 1] === "") {
  36602. if (children.length === 2) {
  36603. // Solitary whitespace
  36604. multilineChildren.push(rawJsxWhitespace);
  36605. return;
  36606. } // Leading whitespace
  36607. multilineChildren.push(concat$c([rawJsxWhitespace, hardline$6]));
  36608. return;
  36609. } else if (i === children.length - 1) {
  36610. // Trailing whitespace
  36611. multilineChildren.push(rawJsxWhitespace);
  36612. return;
  36613. } else if (children[i - 1] === "" && children[i - 2] === hardline$6) {
  36614. // Whitespace after line break
  36615. multilineChildren.push(rawJsxWhitespace);
  36616. return;
  36617. }
  36618. }
  36619. multilineChildren.push(child);
  36620. if (willBreak$3(child)) {
  36621. forcedBreak = true;
  36622. }
  36623. }); // If there is text we use `fill` to fit as much onto each line as possible.
  36624. // When there is no text (just tags and expressions) we use `group`
  36625. // to output each on a separate line.
  36626. const content = containsText ? fill$3(multilineChildren) : group$7(concat$c(multilineChildren), {
  36627. shouldBreak: true
  36628. });
  36629. if (isMdxBlock) {
  36630. return content;
  36631. }
  36632. const multiLineElem = group$7(concat$c([openingLines, indent$8(concat$c([hardline$6, content])), hardline$6, closingLines]));
  36633. if (forcedBreak) {
  36634. return multiLineElem;
  36635. }
  36636. return conditionalGroup$3([group$7(concat$c([openingLines, concat$c(children), closingLines])), multiLineElem]);
  36637. }
  36638. function maybeWrapJSXElementInParens(path, elem, options) {
  36639. const parent = path.getParentNode();
  36640. /* istanbul ignore next */
  36641. if (!parent) {
  36642. return elem;
  36643. }
  36644. const NO_WRAP_PARENTS = {
  36645. ArrayExpression: true,
  36646. JSXAttribute: true,
  36647. JSXElement: true,
  36648. JSXExpressionContainer: true,
  36649. JSXFragment: true,
  36650. ExpressionStatement: true,
  36651. CallExpression: true,
  36652. OptionalCallExpression: true,
  36653. ConditionalExpression: true,
  36654. JsExpressionRoot: true
  36655. };
  36656. if (NO_WRAP_PARENTS[parent.type]) {
  36657. return elem;
  36658. }
  36659. const shouldBreak = path.match(undefined, node => node.type === "ArrowFunctionExpression", isCallOrOptionalCallExpression$2, node => node.type === "JSXExpressionContainer");
  36660. const needsParens = needsParens_1(path, options);
  36661. return group$7(concat$c([needsParens ? "" : ifBreak$4("("), indent$8(concat$c([softline$6, elem])), softline$6, needsParens ? "" : ifBreak$4(")")]), {
  36662. shouldBreak
  36663. });
  36664. }
  36665. function shouldInlineLogicalExpression(node) {
  36666. if (node.type !== "LogicalExpression") {
  36667. return false;
  36668. }
  36669. if (node.right.type === "ObjectExpression" && node.right.properties.length !== 0) {
  36670. return true;
  36671. }
  36672. if (node.right.type === "ArrayExpression" && node.right.elements.length !== 0) {
  36673. return true;
  36674. }
  36675. if (isJSXNode$3(node.right)) {
  36676. return true;
  36677. }
  36678. return false;
  36679. } // For binary expressions to be consistent, we need to group
  36680. // subsequent operators with the same precedence level under a single
  36681. // group. Otherwise they will be nested such that some of them break
  36682. // onto new lines but not all. Operators with the same precedence
  36683. // level should either all break or not. Because we group them by
  36684. // precedence level and the AST is structured based on precedence
  36685. // level, things are naturally broken up correctly, i.e. `&&` is
  36686. // broken before `+`.
  36687. function printBinaryishExpressions(path, print, options, isNested, isInsideParenthesis) {
  36688. /** @type{Doc[]} */
  36689. let parts = [];
  36690. const node = path.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
  36691. if (isBinaryish$1(node)) {
  36692. // Put all operators with the same precedence level in the same
  36693. // group. The reason we only need to do this with the `left`
  36694. // expression is because given an expression like `1 + 2 - 3`, it
  36695. // is always parsed like `((1 + 2) - 3)`, meaning the `left` side
  36696. // is where the rest of the expression will exist. Binary
  36697. // expressions on the right side mean they have a difference
  36698. // precedence level and should be treated as a separate group, so
  36699. // print them normally. (This doesn't hold for the `**` operator,
  36700. // which is unique in that it is right-associative.)
  36701. if (shouldFlatten$2(node.operator, node.left.operator)) {
  36702. // Flatten them out by recursively calling this function.
  36703. parts = parts.concat(path.call(left => printBinaryishExpressions(left, print, options,
  36704. /* isNested */
  36705. true, isInsideParenthesis), "left"));
  36706. } else {
  36707. parts.push(group$7(path.call(print, "left")));
  36708. }
  36709. const shouldInline = shouldInlineLogicalExpression(node);
  36710. const lineBeforeOperator = (node.operator === "|>" || node.type === "NGPipeExpression" || node.operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment$1(options.originalText, node.right, options);
  36711. const operator = node.type === "NGPipeExpression" ? "|" : node.operator;
  36712. const rightSuffix = node.type === "NGPipeExpression" && node.arguments.length !== 0 ? group$7(indent$8(concat$c([softline$6, ": ", join$6(concat$c([softline$6, ":", ifBreak$4(" ")]), path.map(print, "arguments").map(arg => align$2(2, group$7(arg))))]))) : "";
  36713. const right = shouldInline ? concat$c([operator, " ", path.call(print, "right"), rightSuffix]) : concat$c([lineBeforeOperator ? line$8 : "", operator, lineBeforeOperator ? " " : line$8, path.call(print, "right"), rightSuffix]); // If there's only a single binary expression, we want to create a group
  36714. // in order to avoid having a small right part like -1 be on its own line.
  36715. const parent = path.getParentNode();
  36716. const shouldBreak = hasTrailingLineComment$1(node.left);
  36717. const shouldGroup = shouldBreak || !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
  36718. parts.push(lineBeforeOperator ? "" : " ", shouldGroup ? group$7(right, {
  36719. shouldBreak
  36720. }) : right); // The root comments are already printed, but we need to manually print
  36721. // the other ones since we don't call the normal print on BinaryExpression,
  36722. // only for the left and right parts
  36723. if (isNested && node.comments) {
  36724. parts = normalizeParts$1(comments.printComments(path, () => concat$c(parts), options).parts);
  36725. }
  36726. } else {
  36727. // Our stopping case. Simply print the node normally.
  36728. parts.push(group$7(path.call(print)));
  36729. }
  36730. return parts;
  36731. }
  36732. function printAssignmentRight(leftNode, rightNode, printedRight, options) {
  36733. if (hasLeadingOwnLineComment$1(options.originalText, rightNode, options)) {
  36734. return indent$8(concat$c([line$8, printedRight]));
  36735. }
  36736. const canBreak = isBinaryish$1(rightNode) && !shouldInlineLogicalExpression(rightNode) || rightNode.type === "ConditionalExpression" && isBinaryish$1(rightNode.test) && !shouldInlineLogicalExpression(rightNode.test) || rightNode.type === "StringLiteralTypeAnnotation" || rightNode.type === "ClassExpression" && rightNode.decorators && rightNode.decorators.length || (leftNode.type === "Identifier" || isStringLiteral$1(leftNode) || leftNode.type === "MemberExpression") && (isStringLiteral$1(rightNode) || isMemberExpressionChain$1(rightNode)) && // do not put values on a separate line from the key in json
  36737. options.parser !== "json" && options.parser !== "json5" || rightNode.type === "SequenceExpression";
  36738. if (canBreak) {
  36739. return group$7(indent$8(concat$c([line$8, printedRight])));
  36740. }
  36741. return concat$c([" ", printedRight]);
  36742. }
  36743. function printAssignment(leftNode, printedLeft, operator, rightNode, printedRight, options) {
  36744. if (!rightNode) {
  36745. return printedLeft;
  36746. }
  36747. const printed = printAssignmentRight(leftNode, rightNode, printedRight, options);
  36748. return group$7(concat$c([printedLeft, operator, printed]));
  36749. }
  36750. function adjustClause(node, clause, forceSpace) {
  36751. if (node.type === "EmptyStatement") {
  36752. return ";";
  36753. }
  36754. if (node.type === "BlockStatement" || forceSpace) {
  36755. return concat$c([" ", clause]);
  36756. }
  36757. return indent$8(concat$c([line$8, clause]));
  36758. }
  36759. function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
  36760. const raw = rawText$1(node);
  36761. const isDirectiveLiteral = isFlowOrTypeScriptDirectiveLiteral || node.type === "DirectiveLiteral";
  36762. return printString$1(raw, options, isDirectiveLiteral);
  36763. }
  36764. function printRegex(node) {
  36765. const flags = node.flags.split("").sort().join("");
  36766. return `/${node.pattern}/${flags}`;
  36767. }
  36768. function exprNeedsASIProtection(path, options) {
  36769. const node = path.getValue();
  36770. const maybeASIProblem = needsParens_1(path, options) || node.type === "ParenthesizedExpression" || node.type === "TypeCastExpression" || node.type === "ArrowFunctionExpression" && !shouldPrintParamsWithoutParens(path, options) || node.type === "ArrayExpression" || node.type === "ArrayPattern" || node.type === "UnaryExpression" && node.prefix && (node.operator === "+" || node.operator === "-") || node.type === "TemplateLiteral" || node.type === "TemplateElement" || isJSXNode$3(node) || node.type === "BindExpression" && !node.object || node.type === "RegExpLiteral" || node.type === "Literal" && node.pattern || node.type === "Literal" && node.regex;
  36771. if (maybeASIProblem) {
  36772. return true;
  36773. }
  36774. if (!hasNakedLeftSide$2(node)) {
  36775. return false;
  36776. }
  36777. return path.call(childPath => exprNeedsASIProtection(childPath, options), ...getLeftSidePathName$2(path, node));
  36778. }
  36779. function stmtNeedsASIProtection(path, options) {
  36780. const node = path.getNode();
  36781. if (node.type !== "ExpressionStatement") {
  36782. return false;
  36783. }
  36784. return path.call(childPath => exprNeedsASIProtection(childPath, options), "expression");
  36785. }
  36786. function shouldHugType(node) {
  36787. if (isSimpleFlowType$1(node) || isObjectType$1(node)) {
  36788. return true;
  36789. }
  36790. if (node.type === "UnionTypeAnnotation" || node.type === "TSUnionType") {
  36791. const voidCount = node.types.filter(n => n.type === "VoidTypeAnnotation" || n.type === "TSVoidKeyword" || n.type === "NullLiteralTypeAnnotation" || n.type === "TSNullKeyword").length;
  36792. const hasObject = node.types.some(n => n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral" || // This is a bit aggressive but captures Array<{x}>
  36793. n.type === "GenericTypeAnnotation" || n.type === "TSTypeReference");
  36794. if (node.types.length - 1 === voidCount && hasObject) {
  36795. return true;
  36796. }
  36797. }
  36798. return false;
  36799. }
  36800. function shouldHugArguments(fun) {
  36801. if (!fun || fun.rest) {
  36802. return false;
  36803. }
  36804. const params = fun.params || fun.parameters;
  36805. if (!params || params.length !== 1) {
  36806. return false;
  36807. }
  36808. const param = params[0];
  36809. return !param.comments && (param.type === "ObjectPattern" || param.type === "ArrayPattern" || param.type === "Identifier" && param.typeAnnotation && (param.typeAnnotation.type === "TypeAnnotation" || param.typeAnnotation.type === "TSTypeAnnotation") && isObjectType$1(param.typeAnnotation.typeAnnotation) || param.type === "FunctionTypeParam" && isObjectType$1(param.typeAnnotation) || param.type === "AssignmentPattern" && (param.left.type === "ObjectPattern" || param.left.type === "ArrayPattern") && (param.right.type === "Identifier" || param.right.type === "ObjectExpression" && param.right.properties.length === 0 || param.right.type === "ArrayExpression" && param.right.elements.length === 0));
  36810. }
  36811. function printArrayItems(path, options, printPath, print) {
  36812. const printedElements = [];
  36813. let separatorParts = [];
  36814. path.each(childPath => {
  36815. printedElements.push(concat$c(separatorParts));
  36816. printedElements.push(group$7(print(childPath)));
  36817. separatorParts = [",", line$8];
  36818. if (childPath.getValue() && isNextLineEmpty$4(options.originalText, childPath.getValue(), options.locEnd)) {
  36819. separatorParts.push(softline$6);
  36820. }
  36821. }, printPath);
  36822. return concat$c(printedElements);
  36823. }
  36824. function printReturnAndThrowArgument(path, options, print) {
  36825. const node = path.getValue();
  36826. const semi = options.semi ? ";" : "";
  36827. const parts = [];
  36828. if (node.argument) {
  36829. if (returnArgumentHasLeadingComment$1(options, node.argument)) {
  36830. parts.push(concat$c([" (", indent$8(concat$c([hardline$6, path.call(print, "argument")])), hardline$6, ")"]));
  36831. } else if (isBinaryish$1(node.argument) || node.argument.type === "SequenceExpression") {
  36832. parts.push(group$7(concat$c([ifBreak$4(" (", " "), indent$8(concat$c([softline$6, path.call(print, "argument")])), softline$6, ifBreak$4(")")])));
  36833. } else {
  36834. parts.push(" ", path.call(print, "argument"));
  36835. }
  36836. }
  36837. const lastComment = Array.isArray(node.comments) && node.comments[node.comments.length - 1];
  36838. const isLastCommentLine = lastComment && (lastComment.type === "CommentLine" || lastComment.type === "Line");
  36839. if (isLastCommentLine) {
  36840. parts.push(semi);
  36841. }
  36842. if (hasDanglingComments$1(node)) {
  36843. parts.push(" ", comments.printDanglingComments(path, options,
  36844. /* sameIndent */
  36845. true));
  36846. }
  36847. if (!isLastCommentLine) {
  36848. parts.push(semi);
  36849. }
  36850. return concat$c(parts);
  36851. }
  36852. function willPrintOwnComments(path
  36853. /*, options */
  36854. ) {
  36855. const node = path.getValue();
  36856. const parent = path.getParentNode();
  36857. return (node && (isJSXNode$3(node) || hasFlowShorthandAnnotationComment$2(node) || parent && (parent.type === "CallExpression" || parent.type === "OptionalCallExpression") && (hasFlowAnnotationComment$1(node.leadingComments) || hasFlowAnnotationComment$1(node.trailingComments))) || parent && (parent.type === "JSXSpreadAttribute" || parent.type === "JSXSpreadChild" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node)) && (!hasIgnoreComment$2(path) || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType");
  36858. }
  36859. function canAttachComment(node) {
  36860. return node.type && node.type !== "CommentBlock" && node.type !== "CommentLine" && node.type !== "Line" && node.type !== "Block" && node.type !== "EmptyStatement" && node.type !== "TemplateElement" && node.type !== "Import";
  36861. }
  36862. function printComment$1(commentPath, options) {
  36863. const comment = commentPath.getValue();
  36864. switch (comment.type) {
  36865. case "CommentBlock":
  36866. case "Block":
  36867. {
  36868. if (isIndentableBlockComment(comment)) {
  36869. const printed = printIndentableBlockComment(comment); // We need to prevent an edge case of a previous trailing comment
  36870. // printed as a `lineSuffix` which causes the comments to be
  36871. // interleaved. See https://github.com/prettier/prettier/issues/4412
  36872. if (comment.trailing && !hasNewline$5(options.originalText, options.locStart(comment), {
  36873. backwards: true
  36874. })) {
  36875. return concat$c([hardline$6, printed]);
  36876. }
  36877. return printed;
  36878. }
  36879. const commentEnd = options.locEnd(comment);
  36880. const isInsideFlowComment = options.originalText.slice(commentEnd - 3, commentEnd) === "*-/";
  36881. return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
  36882. }
  36883. case "CommentLine":
  36884. case "Line":
  36885. // Supports `//`, `#!`, `<!--`, and `-->`
  36886. return options.originalText.slice(options.locStart(comment), options.locEnd(comment)).trimEnd();
  36887. default:
  36888. /* istanbul ignore next */
  36889. throw new Error("Not a comment: " + JSON.stringify(comment));
  36890. }
  36891. }
  36892. function isIndentableBlockComment(comment) {
  36893. // If the comment has multiple lines and every line starts with a star
  36894. // we can fix the indentation of each line. The stars in the `/*` and
  36895. // `*/` delimiters are not included in the comment value, so add them
  36896. // back first.
  36897. const lines = `*${comment.value}*`.split("\n");
  36898. return lines.length > 1 && lines.every(line => line.trim()[0] === "*");
  36899. }
  36900. function printIndentableBlockComment(comment) {
  36901. const lines = comment.value.split("\n");
  36902. return concat$c(["/*", join$6(hardline$6, lines.map((line, index) => index === 0 ? line.trimEnd() : " " + (index < lines.length - 1 ? line.trim() : line.trimStart()))), "*/"]);
  36903. }
  36904. var printerEstree = {
  36905. preprocess: preprocess_1,
  36906. print: genericPrint,
  36907. embed: embed_1,
  36908. insertPragma: insertPragma$1,
  36909. massageAstNode: clean_1,
  36910. hasPrettierIgnore: hasPrettierIgnore$1,
  36911. willPrintOwnComments,
  36912. canAttachComment,
  36913. printComment: printComment$1,
  36914. isBlockComment: comments$1.isBlockComment,
  36915. handleComments: {
  36916. ownLine: comments$1.handleOwnLineComment,
  36917. endOfLine: comments$1.handleEndOfLineComment,
  36918. remaining: comments$1.handleRemainingComment
  36919. },
  36920. getGapRegex: comments$1.getGapRegex,
  36921. getCommentChildNodes: comments$1.getCommentChildNodes
  36922. };
  36923. const {
  36924. concat: concat$d,
  36925. hardline: hardline$7,
  36926. indent: indent$9,
  36927. join: join$7
  36928. } = document.builders;
  36929. function genericPrint$1(path, options, print) {
  36930. const node = path.getValue();
  36931. switch (node.type) {
  36932. case "JsonRoot":
  36933. return concat$d([path.call(print, "node"), hardline$7]);
  36934. case "ArrayExpression":
  36935. return node.elements.length === 0 ? "[]" : concat$d(["[", indent$9(concat$d([hardline$7, join$7(concat$d([",", hardline$7]), path.map(print, "elements"))])), hardline$7, "]"]);
  36936. case "ObjectExpression":
  36937. return node.properties.length === 0 ? "{}" : concat$d(["{", indent$9(concat$d([hardline$7, join$7(concat$d([",", hardline$7]), path.map(print, "properties"))])), hardline$7, "}"]);
  36938. case "ObjectProperty":
  36939. return concat$d([path.call(print, "key"), ": ", path.call(print, "value")]);
  36940. case "UnaryExpression":
  36941. return concat$d([node.operator === "+" ? "" : node.operator, path.call(print, "argument")]);
  36942. case "NullLiteral":
  36943. return "null";
  36944. case "BooleanLiteral":
  36945. return node.value ? "true" : "false";
  36946. case "StringLiteral":
  36947. case "NumericLiteral":
  36948. return JSON.stringify(node.value);
  36949. case "Identifier":
  36950. return JSON.stringify(node.name);
  36951. default:
  36952. /* istanbul ignore next */
  36953. throw new Error("unknown type: " + JSON.stringify(node.type));
  36954. }
  36955. }
  36956. function clean$1(node, newNode
  36957. /*, parent*/
  36958. ) {
  36959. delete newNode.start;
  36960. delete newNode.end;
  36961. delete newNode.extra;
  36962. delete newNode.loc;
  36963. delete newNode.comments;
  36964. delete newNode.errors;
  36965. delete newNode.range;
  36966. if (node.type === "Identifier") {
  36967. return {
  36968. type: "StringLiteral",
  36969. value: node.name
  36970. };
  36971. }
  36972. if (node.type === "UnaryExpression" && node.operator === "+") {
  36973. return newNode.argument;
  36974. }
  36975. }
  36976. var printerEstreeJson = {
  36977. preprocess: preprocess_1,
  36978. print: genericPrint$1,
  36979. massageAstNode: clean$1
  36980. };
  36981. const CATEGORY_COMMON = "Common"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  36982. var commonOptions = {
  36983. bracketSpacing: {
  36984. since: "0.0.0",
  36985. category: CATEGORY_COMMON,
  36986. type: "boolean",
  36987. default: true,
  36988. description: "Print spaces between brackets.",
  36989. oppositeDescription: "Do not print spaces between brackets."
  36990. },
  36991. singleQuote: {
  36992. since: "0.0.0",
  36993. category: CATEGORY_COMMON,
  36994. type: "boolean",
  36995. default: false,
  36996. description: "Use single quotes instead of double quotes."
  36997. },
  36998. proseWrap: {
  36999. since: "1.8.2",
  37000. category: CATEGORY_COMMON,
  37001. type: "choice",
  37002. default: [{
  37003. since: "1.8.2",
  37004. value: true
  37005. }, {
  37006. since: "1.9.0",
  37007. value: "preserve"
  37008. }],
  37009. description: "How to wrap prose.",
  37010. choices: [{
  37011. since: "1.9.0",
  37012. value: "always",
  37013. description: "Wrap prose if it exceeds the print width."
  37014. }, {
  37015. since: "1.9.0",
  37016. value: "never",
  37017. description: "Do not wrap prose."
  37018. }, {
  37019. since: "1.9.0",
  37020. value: "preserve",
  37021. description: "Wrap prose as-is."
  37022. }]
  37023. }
  37024. };
  37025. const CATEGORY_JAVASCRIPT = "JavaScript"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  37026. var options$2 = {
  37027. arrowParens: {
  37028. since: "1.9.0",
  37029. category: CATEGORY_JAVASCRIPT,
  37030. type: "choice",
  37031. default: [{
  37032. since: "1.9.0",
  37033. value: "avoid"
  37034. }, {
  37035. since: "2.0.0",
  37036. value: "always"
  37037. }],
  37038. description: "Include parentheses around a sole arrow function parameter.",
  37039. choices: [{
  37040. value: "always",
  37041. description: "Always include parens. Example: `(x) => x`"
  37042. }, {
  37043. value: "avoid",
  37044. description: "Omit parens when possible. Example: `x => x`"
  37045. }]
  37046. },
  37047. bracketSpacing: commonOptions.bracketSpacing,
  37048. jsxBracketSameLine: {
  37049. since: "0.17.0",
  37050. category: CATEGORY_JAVASCRIPT,
  37051. type: "boolean",
  37052. default: false,
  37053. description: "Put > on the last line instead of at a new line."
  37054. },
  37055. semi: {
  37056. since: "1.0.0",
  37057. category: CATEGORY_JAVASCRIPT,
  37058. type: "boolean",
  37059. default: true,
  37060. description: "Print semicolons.",
  37061. oppositeDescription: "Do not print semicolons, except at the beginning of lines which may need them."
  37062. },
  37063. singleQuote: commonOptions.singleQuote,
  37064. jsxSingleQuote: {
  37065. since: "1.15.0",
  37066. category: CATEGORY_JAVASCRIPT,
  37067. type: "boolean",
  37068. default: false,
  37069. description: "Use single quotes in JSX."
  37070. },
  37071. quoteProps: {
  37072. since: "1.17.0",
  37073. category: CATEGORY_JAVASCRIPT,
  37074. type: "choice",
  37075. default: "as-needed",
  37076. description: "Change when properties in objects are quoted.",
  37077. choices: [{
  37078. value: "as-needed",
  37079. description: "Only add quotes around object properties where required."
  37080. }, {
  37081. value: "consistent",
  37082. description: "If at least one property in an object requires quotes, quote all properties."
  37083. }, {
  37084. value: "preserve",
  37085. description: "Respect the input use of quotes in object properties."
  37086. }]
  37087. },
  37088. trailingComma: {
  37089. since: "0.0.0",
  37090. category: CATEGORY_JAVASCRIPT,
  37091. type: "choice",
  37092. default: [{
  37093. since: "0.0.0",
  37094. value: false
  37095. }, {
  37096. since: "0.19.0",
  37097. value: "none"
  37098. }, {
  37099. since: "2.0.0",
  37100. value: "es5"
  37101. }],
  37102. description: "Print trailing commas wherever possible when multi-line.",
  37103. choices: [{
  37104. value: "es5",
  37105. description: "Trailing commas where valid in ES5 (objects, arrays, etc.)"
  37106. }, {
  37107. value: "none",
  37108. description: "No trailing commas."
  37109. }, {
  37110. value: "all",
  37111. description: "Trailing commas wherever possible (including function arguments)."
  37112. }]
  37113. }
  37114. };
  37115. var name$2 = "JavaScript";
  37116. var type = "programming";
  37117. var tmScope = "source.js";
  37118. var aceMode = "javascript";
  37119. var codemirrorMode = "javascript";
  37120. var codemirrorMimeType = "text/javascript";
  37121. var color = "#f1e05a";
  37122. var aliases = [
  37123. "js",
  37124. "node"
  37125. ];
  37126. var extensions = [
  37127. ".js",
  37128. "._js",
  37129. ".bones",
  37130. ".cjs",
  37131. ".es",
  37132. ".es6",
  37133. ".frag",
  37134. ".gs",
  37135. ".jake",
  37136. ".jsb",
  37137. ".jscad",
  37138. ".jsfl",
  37139. ".jsm",
  37140. ".jss",
  37141. ".mjs",
  37142. ".njs",
  37143. ".pac",
  37144. ".sjs",
  37145. ".ssjs",
  37146. ".xsjs",
  37147. ".xsjslib"
  37148. ];
  37149. var filenames = [
  37150. "Jakefile"
  37151. ];
  37152. var interpreters = [
  37153. "chakra",
  37154. "d8",
  37155. "gjs",
  37156. "js",
  37157. "node",
  37158. "qjs",
  37159. "rhino",
  37160. "v8",
  37161. "v8-shell"
  37162. ];
  37163. var languageId = 183;
  37164. var JavaScript = {
  37165. name: name$2,
  37166. type: type,
  37167. tmScope: tmScope,
  37168. aceMode: aceMode,
  37169. codemirrorMode: codemirrorMode,
  37170. codemirrorMimeType: codemirrorMimeType,
  37171. color: color,
  37172. aliases: aliases,
  37173. extensions: extensions,
  37174. filenames: filenames,
  37175. interpreters: interpreters,
  37176. languageId: languageId
  37177. };
  37178. var JavaScript$1 = /*#__PURE__*/Object.freeze({
  37179. __proto__: null,
  37180. name: name$2,
  37181. type: type,
  37182. tmScope: tmScope,
  37183. aceMode: aceMode,
  37184. codemirrorMode: codemirrorMode,
  37185. codemirrorMimeType: codemirrorMimeType,
  37186. color: color,
  37187. aliases: aliases,
  37188. extensions: extensions,
  37189. filenames: filenames,
  37190. interpreters: interpreters,
  37191. languageId: languageId,
  37192. 'default': JavaScript
  37193. });
  37194. var name$3 = "JSX";
  37195. var type$1 = "programming";
  37196. var group$8 = "JavaScript";
  37197. var extensions$1 = [
  37198. ".jsx"
  37199. ];
  37200. var tmScope$1 = "source.js.jsx";
  37201. var aceMode$1 = "javascript";
  37202. var codemirrorMode$1 = "jsx";
  37203. var codemirrorMimeType$1 = "text/jsx";
  37204. var languageId$1 = 178;
  37205. var JSX = {
  37206. name: name$3,
  37207. type: type$1,
  37208. group: group$8,
  37209. extensions: extensions$1,
  37210. tmScope: tmScope$1,
  37211. aceMode: aceMode$1,
  37212. codemirrorMode: codemirrorMode$1,
  37213. codemirrorMimeType: codemirrorMimeType$1,
  37214. languageId: languageId$1
  37215. };
  37216. var JSX$1 = /*#__PURE__*/Object.freeze({
  37217. __proto__: null,
  37218. name: name$3,
  37219. type: type$1,
  37220. group: group$8,
  37221. extensions: extensions$1,
  37222. tmScope: tmScope$1,
  37223. aceMode: aceMode$1,
  37224. codemirrorMode: codemirrorMode$1,
  37225. codemirrorMimeType: codemirrorMimeType$1,
  37226. languageId: languageId$1,
  37227. 'default': JSX
  37228. });
  37229. var name$4 = "TypeScript";
  37230. var type$2 = "programming";
  37231. var color$1 = "#2b7489";
  37232. var aliases$1 = [
  37233. "ts"
  37234. ];
  37235. var interpreters$1 = [
  37236. "deno",
  37237. "ts-node"
  37238. ];
  37239. var extensions$2 = [
  37240. ".ts"
  37241. ];
  37242. var tmScope$2 = "source.ts";
  37243. var aceMode$2 = "typescript";
  37244. var codemirrorMode$2 = "javascript";
  37245. var codemirrorMimeType$2 = "application/typescript";
  37246. var languageId$2 = 378;
  37247. var TypeScript = {
  37248. name: name$4,
  37249. type: type$2,
  37250. color: color$1,
  37251. aliases: aliases$1,
  37252. interpreters: interpreters$1,
  37253. extensions: extensions$2,
  37254. tmScope: tmScope$2,
  37255. aceMode: aceMode$2,
  37256. codemirrorMode: codemirrorMode$2,
  37257. codemirrorMimeType: codemirrorMimeType$2,
  37258. languageId: languageId$2
  37259. };
  37260. var TypeScript$1 = /*#__PURE__*/Object.freeze({
  37261. __proto__: null,
  37262. name: name$4,
  37263. type: type$2,
  37264. color: color$1,
  37265. aliases: aliases$1,
  37266. interpreters: interpreters$1,
  37267. extensions: extensions$2,
  37268. tmScope: tmScope$2,
  37269. aceMode: aceMode$2,
  37270. codemirrorMode: codemirrorMode$2,
  37271. codemirrorMimeType: codemirrorMimeType$2,
  37272. languageId: languageId$2,
  37273. 'default': TypeScript
  37274. });
  37275. var name$5 = "TSX";
  37276. var type$3 = "programming";
  37277. var group$9 = "TypeScript";
  37278. var extensions$3 = [
  37279. ".tsx"
  37280. ];
  37281. var tmScope$3 = "source.tsx";
  37282. var aceMode$3 = "javascript";
  37283. var codemirrorMode$3 = "jsx";
  37284. var codemirrorMimeType$3 = "text/jsx";
  37285. var languageId$3 = 94901924;
  37286. var TSX = {
  37287. name: name$5,
  37288. type: type$3,
  37289. group: group$9,
  37290. extensions: extensions$3,
  37291. tmScope: tmScope$3,
  37292. aceMode: aceMode$3,
  37293. codemirrorMode: codemirrorMode$3,
  37294. codemirrorMimeType: codemirrorMimeType$3,
  37295. languageId: languageId$3
  37296. };
  37297. var TSX$1 = /*#__PURE__*/Object.freeze({
  37298. __proto__: null,
  37299. name: name$5,
  37300. type: type$3,
  37301. group: group$9,
  37302. extensions: extensions$3,
  37303. tmScope: tmScope$3,
  37304. aceMode: aceMode$3,
  37305. codemirrorMode: codemirrorMode$3,
  37306. codemirrorMimeType: codemirrorMimeType$3,
  37307. languageId: languageId$3,
  37308. 'default': TSX
  37309. });
  37310. var name$6 = "JSON";
  37311. var type$4 = "data";
  37312. var tmScope$4 = "source.json";
  37313. var aceMode$4 = "json";
  37314. var codemirrorMode$4 = "javascript";
  37315. var codemirrorMimeType$4 = "application/json";
  37316. var searchable = false;
  37317. var extensions$4 = [
  37318. ".json",
  37319. ".avsc",
  37320. ".geojson",
  37321. ".gltf",
  37322. ".har",
  37323. ".ice",
  37324. ".JSON-tmLanguage",
  37325. ".jsonl",
  37326. ".mcmeta",
  37327. ".tfstate",
  37328. ".tfstate.backup",
  37329. ".topojson",
  37330. ".webapp",
  37331. ".webmanifest",
  37332. ".yy",
  37333. ".yyp"
  37334. ];
  37335. var filenames$1 = [
  37336. ".arcconfig",
  37337. ".htmlhintrc",
  37338. ".tern-config",
  37339. ".tern-project",
  37340. ".watchmanconfig",
  37341. "composer.lock",
  37342. "mcmod.info"
  37343. ];
  37344. var languageId$4 = 174;
  37345. var _JSON = {
  37346. name: name$6,
  37347. type: type$4,
  37348. tmScope: tmScope$4,
  37349. aceMode: aceMode$4,
  37350. codemirrorMode: codemirrorMode$4,
  37351. codemirrorMimeType: codemirrorMimeType$4,
  37352. searchable: searchable,
  37353. extensions: extensions$4,
  37354. filenames: filenames$1,
  37355. languageId: languageId$4
  37356. };
  37357. var _JSON$1 = /*#__PURE__*/Object.freeze({
  37358. __proto__: null,
  37359. name: name$6,
  37360. type: type$4,
  37361. tmScope: tmScope$4,
  37362. aceMode: aceMode$4,
  37363. codemirrorMode: codemirrorMode$4,
  37364. codemirrorMimeType: codemirrorMimeType$4,
  37365. searchable: searchable,
  37366. extensions: extensions$4,
  37367. filenames: filenames$1,
  37368. languageId: languageId$4,
  37369. 'default': _JSON
  37370. });
  37371. var name$7 = "JSON with Comments";
  37372. var type$5 = "data";
  37373. var group$a = "JSON";
  37374. var tmScope$5 = "source.js";
  37375. var aceMode$5 = "javascript";
  37376. var codemirrorMode$5 = "javascript";
  37377. var codemirrorMimeType$5 = "text/javascript";
  37378. var aliases$2 = [
  37379. "jsonc"
  37380. ];
  37381. var extensions$5 = [
  37382. ".jsonc",
  37383. ".sublime-build",
  37384. ".sublime-commands",
  37385. ".sublime-completions",
  37386. ".sublime-keymap",
  37387. ".sublime-macro",
  37388. ".sublime-menu",
  37389. ".sublime-mousemap",
  37390. ".sublime-project",
  37391. ".sublime-settings",
  37392. ".sublime-theme",
  37393. ".sublime-workspace",
  37394. ".sublime_metrics",
  37395. ".sublime_session"
  37396. ];
  37397. var filenames$2 = [
  37398. ".babelrc",
  37399. ".eslintrc.json",
  37400. ".jscsrc",
  37401. ".jshintrc",
  37402. ".jslintrc",
  37403. "jsconfig.json",
  37404. "language-configuration.json",
  37405. "tsconfig.json"
  37406. ];
  37407. var languageId$5 = 423;
  37408. var JSON_with_Comments = {
  37409. name: name$7,
  37410. type: type$5,
  37411. group: group$a,
  37412. tmScope: tmScope$5,
  37413. aceMode: aceMode$5,
  37414. codemirrorMode: codemirrorMode$5,
  37415. codemirrorMimeType: codemirrorMimeType$5,
  37416. aliases: aliases$2,
  37417. extensions: extensions$5,
  37418. filenames: filenames$2,
  37419. languageId: languageId$5
  37420. };
  37421. var JSON_with_Comments$1 = /*#__PURE__*/Object.freeze({
  37422. __proto__: null,
  37423. name: name$7,
  37424. type: type$5,
  37425. group: group$a,
  37426. tmScope: tmScope$5,
  37427. aceMode: aceMode$5,
  37428. codemirrorMode: codemirrorMode$5,
  37429. codemirrorMimeType: codemirrorMimeType$5,
  37430. aliases: aliases$2,
  37431. extensions: extensions$5,
  37432. filenames: filenames$2,
  37433. languageId: languageId$5,
  37434. 'default': JSON_with_Comments
  37435. });
  37436. var name$8 = "JSON5";
  37437. var type$6 = "data";
  37438. var extensions$6 = [
  37439. ".json5"
  37440. ];
  37441. var tmScope$6 = "source.js";
  37442. var aceMode$6 = "javascript";
  37443. var codemirrorMode$6 = "javascript";
  37444. var codemirrorMimeType$6 = "application/json";
  37445. var languageId$6 = 175;
  37446. var JSON5$1 = {
  37447. name: name$8,
  37448. type: type$6,
  37449. extensions: extensions$6,
  37450. tmScope: tmScope$6,
  37451. aceMode: aceMode$6,
  37452. codemirrorMode: codemirrorMode$6,
  37453. codemirrorMimeType: codemirrorMimeType$6,
  37454. languageId: languageId$6
  37455. };
  37456. var JSON5$2 = /*#__PURE__*/Object.freeze({
  37457. __proto__: null,
  37458. name: name$8,
  37459. type: type$6,
  37460. extensions: extensions$6,
  37461. tmScope: tmScope$6,
  37462. aceMode: aceMode$6,
  37463. codemirrorMode: codemirrorMode$6,
  37464. codemirrorMimeType: codemirrorMimeType$6,
  37465. languageId: languageId$6,
  37466. 'default': JSON5$1
  37467. });
  37468. var require$$0$2 = getCjsExportFromNamespace(JavaScript$1);
  37469. var require$$1 = getCjsExportFromNamespace(JSX$1);
  37470. var require$$2 = getCjsExportFromNamespace(TypeScript$1);
  37471. var require$$3 = getCjsExportFromNamespace(TSX$1);
  37472. var require$$4$1 = getCjsExportFromNamespace(_JSON$1);
  37473. var require$$5 = getCjsExportFromNamespace(JSON_with_Comments$1);
  37474. var require$$6 = getCjsExportFromNamespace(JSON5$2);
  37475. const languages = [createLanguage(require$$0$2, data => ({
  37476. since: "0.0.0",
  37477. parsers: ["babel", "flow"],
  37478. vscodeLanguageIds: ["javascript", "mongo"],
  37479. interpreters: data.interpreters.concat(["nodejs"])
  37480. })), createLanguage(require$$0$2, () => ({
  37481. name: "Flow",
  37482. since: "0.0.0",
  37483. parsers: ["babel", "flow"],
  37484. vscodeLanguageIds: ["javascript"],
  37485. aliases: [],
  37486. filenames: [],
  37487. extensions: [".js.flow"]
  37488. })), createLanguage(require$$1, () => ({
  37489. since: "0.0.0",
  37490. parsers: ["babel", "flow"],
  37491. vscodeLanguageIds: ["javascriptreact"]
  37492. })), createLanguage(require$$2, () => ({
  37493. since: "1.4.0",
  37494. parsers: ["typescript", "babel-ts"],
  37495. vscodeLanguageIds: ["typescript"]
  37496. })), createLanguage(require$$3, () => ({
  37497. since: "1.4.0",
  37498. parsers: ["typescript", "babel-ts"],
  37499. vscodeLanguageIds: ["typescriptreact"]
  37500. })), createLanguage(require$$4$1, () => ({
  37501. name: "JSON.stringify",
  37502. since: "1.13.0",
  37503. parsers: ["json-stringify"],
  37504. vscodeLanguageIds: ["json"],
  37505. extensions: [],
  37506. // .json file defaults to json instead of json-stringify
  37507. filenames: ["package.json", "package-lock.json", "composer.json"]
  37508. })), createLanguage(require$$4$1, data => ({
  37509. since: "1.5.0",
  37510. parsers: ["json"],
  37511. vscodeLanguageIds: ["json"],
  37512. filenames: data.filenames.concat([".prettierrc"])
  37513. })), createLanguage(require$$5, data => ({
  37514. since: "1.5.0",
  37515. parsers: ["json"],
  37516. vscodeLanguageIds: ["jsonc"],
  37517. filenames: data.filenames.concat([".eslintrc"])
  37518. })), createLanguage(require$$6, () => ({
  37519. since: "1.13.0",
  37520. parsers: ["json5"],
  37521. vscodeLanguageIds: ["json5"]
  37522. }))];
  37523. const printers = {
  37524. estree: printerEstree,
  37525. "estree-json": printerEstreeJson
  37526. };
  37527. const parsers = {
  37528. // JS - Babel
  37529. get babel() {
  37530. return require("./parser-babel").parsers.babel;
  37531. },
  37532. get "babel-flow"() {
  37533. return require("./parser-babel").parsers["babel-flow"];
  37534. },
  37535. get "babel-ts"() {
  37536. return require("./parser-babel").parsers["babel-ts"];
  37537. },
  37538. get json() {
  37539. return require("./parser-babel").parsers.json;
  37540. },
  37541. get json5() {
  37542. return require("./parser-babel").parsers.json5;
  37543. },
  37544. get "json-stringify"() {
  37545. return require("./parser-babel").parsers["json-stringify"];
  37546. },
  37547. get __js_expression() {
  37548. return require("./parser-babel").parsers.__js_expression;
  37549. },
  37550. get __vue_expression() {
  37551. return require("./parser-babel").parsers.__vue_expression;
  37552. },
  37553. get __vue_event_binding() {
  37554. return require("./parser-babel").parsers.__vue_event_binding;
  37555. },
  37556. // JS - Flow
  37557. get flow() {
  37558. return require("./parser-flow").parsers.flow;
  37559. },
  37560. // JS - TypeScript
  37561. get typescript() {
  37562. return require("./parser-typescript").parsers.typescript;
  37563. },
  37564. // JS - Angular Action
  37565. get __ng_action() {
  37566. return require("./parser-angular").parsers.__ng_action;
  37567. },
  37568. // JS - Angular Binding
  37569. get __ng_binding() {
  37570. return require("./parser-angular").parsers.__ng_binding;
  37571. },
  37572. // JS - Angular Interpolation
  37573. get __ng_interpolation() {
  37574. return require("./parser-angular").parsers.__ng_interpolation;
  37575. },
  37576. // JS - Angular Directive
  37577. get __ng_directive() {
  37578. return require("./parser-angular").parsers.__ng_directive;
  37579. }
  37580. };
  37581. var languageJs = {
  37582. languages,
  37583. options: options$2,
  37584. printers,
  37585. parsers
  37586. };
  37587. const {
  37588. isFrontMatterNode: isFrontMatterNode$1
  37589. } = util;
  37590. function clean$2(ast, newObj, parent) {
  37591. ["raw", // front-matter
  37592. "raws", "sourceIndex", "source", "before", "after", "trailingComma"].forEach(name => {
  37593. delete newObj[name];
  37594. });
  37595. if (isFrontMatterNode$1(ast) && ast.lang === "yaml") {
  37596. delete newObj.value;
  37597. }
  37598. if (ast.type === "css-comment" && parent.type === "css-root" && parent.nodes.length !== 0) {
  37599. // --insert-pragma
  37600. // first non-front-matter comment
  37601. if (parent.nodes[0] === ast || isFrontMatterNode$1(parent.nodes[0]) && parent.nodes[1] === ast) {
  37602. /**
  37603. * something
  37604. *
  37605. * @format
  37606. */
  37607. delete newObj.text; // standalone pragma
  37608. if (/^\*\s*@(format|prettier)\s*$/.test(ast.text)) {
  37609. return null;
  37610. }
  37611. } // Last comment is not parsed, when omitting semicolon, #8675
  37612. if (parent.type === "css-root" && getLast(parent.nodes) === ast) {
  37613. return null;
  37614. }
  37615. }
  37616. if (ast.type === "value-root") {
  37617. delete newObj.text;
  37618. }
  37619. if (ast.type === "media-query" || ast.type === "media-query-list" || ast.type === "media-feature-expression") {
  37620. delete newObj.value;
  37621. }
  37622. if (ast.type === "css-rule") {
  37623. delete newObj.params;
  37624. }
  37625. if (ast.type === "selector-combinator") {
  37626. newObj.value = newObj.value.replace(/\s+/g, " ");
  37627. }
  37628. if (ast.type === "media-feature") {
  37629. newObj.value = newObj.value.replace(/ /g, "");
  37630. }
  37631. if (ast.type === "value-word" && (ast.isColor && ast.isHex || ["initial", "inherit", "unset", "revert"].includes(newObj.value.replace().toLowerCase())) || ast.type === "media-feature" || ast.type === "selector-root-invalid" || ast.type === "selector-pseudo") {
  37632. newObj.value = newObj.value.toLowerCase();
  37633. }
  37634. if (ast.type === "css-decl") {
  37635. newObj.prop = newObj.prop.toLowerCase();
  37636. }
  37637. if (ast.type === "css-atrule" || ast.type === "css-import") {
  37638. newObj.name = newObj.name.toLowerCase();
  37639. }
  37640. if (ast.type === "value-number") {
  37641. newObj.unit = newObj.unit.toLowerCase();
  37642. }
  37643. if ((ast.type === "media-feature" || ast.type === "media-keyword" || ast.type === "media-type" || ast.type === "media-unknown" || ast.type === "media-url" || ast.type === "media-value" || ast.type === "selector-attribute" || ast.type === "selector-string" || ast.type === "selector-class" || ast.type === "selector-combinator" || ast.type === "value-string") && newObj.value) {
  37644. newObj.value = cleanCSSStrings(newObj.value);
  37645. }
  37646. if (ast.type === "selector-attribute") {
  37647. newObj.attribute = newObj.attribute.trim();
  37648. if (newObj.namespace) {
  37649. if (typeof newObj.namespace === "string") {
  37650. newObj.namespace = newObj.namespace.trim();
  37651. if (newObj.namespace.length === 0) {
  37652. newObj.namespace = true;
  37653. }
  37654. }
  37655. }
  37656. if (newObj.value) {
  37657. newObj.value = newObj.value.trim().replace(/^["']|["']$/g, "");
  37658. delete newObj.quoted;
  37659. }
  37660. }
  37661. if ((ast.type === "media-value" || ast.type === "media-type" || ast.type === "value-number" || ast.type === "selector-root-invalid" || ast.type === "selector-class" || ast.type === "selector-combinator" || ast.type === "selector-tag") && newObj.value) {
  37662. newObj.value = newObj.value.replace(/([\d+.Ee-]+)([A-Za-z]*)/g, (match, numStr, unit) => {
  37663. const num = Number(numStr);
  37664. return isNaN(num) ? match : num + unit.toLowerCase();
  37665. });
  37666. }
  37667. if (ast.type === "selector-tag") {
  37668. const lowercasedValue = ast.value.toLowerCase();
  37669. if (["from", "to"].includes(lowercasedValue)) {
  37670. newObj.value = lowercasedValue;
  37671. }
  37672. } // Workaround when `postcss-values-parser` parse `not`, `and` or `or` keywords as `value-func`
  37673. if (ast.type === "css-atrule" && ast.name.toLowerCase() === "supports") {
  37674. delete newObj.value;
  37675. } // Workaround for SCSS nested properties
  37676. if (ast.type === "selector-unknown") {
  37677. delete newObj.value;
  37678. }
  37679. }
  37680. function cleanCSSStrings(value) {
  37681. return value.replace(/'/g, '"').replace(/\\([^\dA-Fa-f])/g, "$1");
  37682. }
  37683. var clean_1$1 = clean$2;
  37684. const {
  37685. builders: {
  37686. hardline: hardline$8,
  37687. concat: concat$e,
  37688. markAsRoot: markAsRoot$1
  37689. }
  37690. } = document;
  37691. const DELIMITER_MAP = {
  37692. "---": "yaml",
  37693. "+++": "toml"
  37694. };
  37695. function parse$7(text) {
  37696. const delimiterRegex = Object.keys(DELIMITER_MAP).map(escapeStringRegexp).join("|");
  37697. const match = text.match( // trailing spaces after delimiters are allowed
  37698. new RegExp(`^(${delimiterRegex})([^\\n]*)\\n(?:([\\s\\S]*?)\\n)?\\1[^\\n\\S]*(\\n|$)`));
  37699. if (match === null) {
  37700. return {
  37701. frontMatter: null,
  37702. content: text
  37703. };
  37704. }
  37705. const [raw, delimiter, language, value] = match;
  37706. let lang = DELIMITER_MAP[delimiter];
  37707. if (lang !== "toml" && language && language.trim()) {
  37708. lang = language.trim();
  37709. }
  37710. return {
  37711. frontMatter: {
  37712. type: "front-matter",
  37713. lang,
  37714. value,
  37715. raw: raw.replace(/\n$/, "")
  37716. },
  37717. content: raw.replace(/[^\n]/g, " ") + text.slice(raw.length)
  37718. };
  37719. }
  37720. function print$1(node, textToDoc) {
  37721. if (node.lang === "yaml") {
  37722. const value = node.value.trim();
  37723. const doc = value ? textToDoc(value, {
  37724. parser: "yaml"
  37725. }, {
  37726. stripTrailingHardline: true
  37727. }) : "";
  37728. return markAsRoot$1(concat$e(["---", hardline$8, doc, doc ? hardline$8 : "", "---"]));
  37729. }
  37730. }
  37731. var frontMatter = {
  37732. parse: parse$7,
  37733. print: print$1
  37734. };
  37735. const {
  37736. builders: {
  37737. hardline: hardline$9,
  37738. concat: concat$f
  37739. }
  37740. } = document;
  37741. const {
  37742. print: printFrontMatter
  37743. } = frontMatter;
  37744. function embed$1(path, print, textToDoc
  37745. /*, options */
  37746. ) {
  37747. const node = path.getValue();
  37748. if (node.type === "front-matter") {
  37749. const doc = printFrontMatter(node, textToDoc);
  37750. return doc ? concat$f([doc, hardline$9]) : "";
  37751. }
  37752. }
  37753. var embed_1$1 = embed$1;
  37754. const {
  37755. parse: parseFrontMatter
  37756. } = frontMatter;
  37757. function hasPragma$1(text) {
  37758. return pragma.hasPragma(parseFrontMatter(text).content);
  37759. }
  37760. function insertPragma$2(text) {
  37761. const {
  37762. frontMatter,
  37763. content
  37764. } = parseFrontMatter(text);
  37765. return (frontMatter ? frontMatter.raw + "\n\n" : "") + pragma.insertPragma(content);
  37766. }
  37767. var pragma$1 = {
  37768. hasPragma: hasPragma$1,
  37769. insertPragma: insertPragma$2
  37770. };
  37771. const colorAdjusterFunctions = new Set(["red", "green", "blue", "alpha", "a", "rgb", "hue", "h", "saturation", "s", "lightness", "l", "whiteness", "w", "blackness", "b", "tint", "shade", "blend", "blenda", "contrast", "hsl", "hsla", "hwb", "hwba"]);
  37772. function getAncestorCounter(path, typeOrTypes) {
  37773. const types = [].concat(typeOrTypes);
  37774. let counter = -1;
  37775. let ancestorNode;
  37776. while (ancestorNode = path.getParentNode(++counter)) {
  37777. if (types.includes(ancestorNode.type)) {
  37778. return counter;
  37779. }
  37780. }
  37781. return -1;
  37782. }
  37783. function getAncestorNode(path, typeOrTypes) {
  37784. const counter = getAncestorCounter(path, typeOrTypes);
  37785. return counter === -1 ? null : path.getParentNode(counter);
  37786. }
  37787. function getPropOfDeclNode(path) {
  37788. const declAncestorNode = getAncestorNode(path, "css-decl");
  37789. return declAncestorNode && declAncestorNode.prop && declAncestorNode.prop.toLowerCase();
  37790. }
  37791. function hasSCSSInterpolation(groupList) {
  37792. if (groupList && groupList.length) {
  37793. for (let i = groupList.length - 1; i > 0; i--) {
  37794. // If we find `#{`, return true.
  37795. if (groupList[i].type === "word" && groupList[i].value === "{" && groupList[i - 1].type === "word" && groupList[i - 1].value.endsWith("#")) {
  37796. return true;
  37797. }
  37798. }
  37799. }
  37800. return false;
  37801. }
  37802. function hasStringOrFunction(groupList) {
  37803. if (groupList && groupList.length) {
  37804. for (let i = 0; i < groupList.length; i++) {
  37805. if (groupList[i].type === "string" || groupList[i].type === "func") {
  37806. return true;
  37807. }
  37808. }
  37809. }
  37810. return false;
  37811. }
  37812. function isSCSS(parser, text) {
  37813. const hasExplicitParserChoice = parser === "less" || parser === "scss";
  37814. const IS_POSSIBLY_SCSS = /(\w\s*:\s*[^:}]+|#){|@import[^\n]+(?:url|,)/;
  37815. return hasExplicitParserChoice ? parser === "scss" : IS_POSSIBLY_SCSS.test(text);
  37816. }
  37817. function isSCSSVariable(node) {
  37818. return !!(node && node.type === "word" && node.value.startsWith("$"));
  37819. }
  37820. function isWideKeywords(value) {
  37821. return ["initial", "inherit", "unset", "revert"].includes(value.toLowerCase());
  37822. }
  37823. function isKeyframeAtRuleKeywords(path, value) {
  37824. const atRuleAncestorNode = getAncestorNode(path, "css-atrule");
  37825. return atRuleAncestorNode && atRuleAncestorNode.name && atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") && ["from", "to"].includes(value.toLowerCase());
  37826. }
  37827. function maybeToLowerCase(value) {
  37828. return value.includes("$") || value.includes("@") || value.includes("#") || value.startsWith("%") || value.startsWith("--") || value.startsWith(":--") || value.includes("(") && value.includes(")") ? value : value.toLowerCase();
  37829. }
  37830. function insideValueFunctionNode(path, functionName) {
  37831. const funcAncestorNode = getAncestorNode(path, "value-func");
  37832. return funcAncestorNode && funcAncestorNode.value && funcAncestorNode.value.toLowerCase() === functionName;
  37833. }
  37834. function insideICSSRuleNode(path) {
  37835. const ruleAncestorNode = getAncestorNode(path, "css-rule");
  37836. return ruleAncestorNode && ruleAncestorNode.raws && ruleAncestorNode.raws.selector && (ruleAncestorNode.raws.selector.startsWith(":import") || ruleAncestorNode.raws.selector.startsWith(":export"));
  37837. }
  37838. function insideAtRuleNode(path, atRuleNameOrAtRuleNames) {
  37839. const atRuleNames = [].concat(atRuleNameOrAtRuleNames);
  37840. const atRuleAncestorNode = getAncestorNode(path, "css-atrule");
  37841. return atRuleAncestorNode && atRuleNames.includes(atRuleAncestorNode.name.toLowerCase());
  37842. }
  37843. function insideURLFunctionInImportAtRuleNode(path) {
  37844. const node = path.getValue();
  37845. const atRuleAncestorNode = getAncestorNode(path, "css-atrule");
  37846. return atRuleAncestorNode && atRuleAncestorNode.name === "import" && node.groups[0].value === "url" && node.groups.length === 2;
  37847. }
  37848. function isURLFunctionNode(node) {
  37849. return node.type === "value-func" && node.value.toLowerCase() === "url";
  37850. }
  37851. function isLastNode(path, node) {
  37852. const parentNode = path.getParentNode();
  37853. /* istanbul ignore next */
  37854. if (!parentNode) {
  37855. return false;
  37856. }
  37857. const {
  37858. nodes
  37859. } = parentNode;
  37860. return nodes && nodes.indexOf(node) === nodes.length - 1;
  37861. }
  37862. function isDetachedRulesetDeclarationNode(node) {
  37863. // If a Less file ends up being parsed with the SCSS parser, Less
  37864. // variable declarations will be parsed as atrules with names ending
  37865. // with a colon, so keep the original case then.
  37866. /* istanbul ignore next */
  37867. if (!node.selector) {
  37868. return false;
  37869. }
  37870. return typeof node.selector === "string" && /^@.+:.*$/.test(node.selector) || node.selector.value && /^@.+:.*$/.test(node.selector.value);
  37871. }
  37872. function isForKeywordNode(node) {
  37873. return node.type === "value-word" && ["from", "through", "end"].includes(node.value);
  37874. }
  37875. function isIfElseKeywordNode(node) {
  37876. return node.type === "value-word" && ["and", "or", "not"].includes(node.value);
  37877. }
  37878. function isEachKeywordNode(node) {
  37879. return node.type === "value-word" && node.value === "in";
  37880. }
  37881. function isMultiplicationNode(node) {
  37882. return node.type === "value-operator" && node.value === "*";
  37883. }
  37884. function isDivisionNode(node) {
  37885. return node.type === "value-operator" && node.value === "/";
  37886. }
  37887. function isAdditionNode(node) {
  37888. return node.type === "value-operator" && node.value === "+";
  37889. }
  37890. function isSubtractionNode(node) {
  37891. return node.type === "value-operator" && node.value === "-";
  37892. }
  37893. function isModuloNode(node) {
  37894. return node.type === "value-operator" && node.value === "%";
  37895. }
  37896. function isMathOperatorNode(node) {
  37897. return isMultiplicationNode(node) || isDivisionNode(node) || isAdditionNode(node) || isSubtractionNode(node) || isModuloNode(node);
  37898. }
  37899. function isEqualityOperatorNode(node) {
  37900. return node.type === "value-word" && ["==", "!="].includes(node.value);
  37901. }
  37902. function isRelationalOperatorNode(node) {
  37903. return node.type === "value-word" && ["<", ">", "<=", ">="].includes(node.value);
  37904. }
  37905. function isSCSSControlDirectiveNode(node) {
  37906. return node.type === "css-atrule" && ["if", "else", "for", "each", "while"].includes(node.name);
  37907. }
  37908. function isSCSSNestedPropertyNode(node) {
  37909. /* istanbul ignore next */
  37910. if (!node.selector) {
  37911. return false;
  37912. }
  37913. return node.selector.replace(/\/\*.*?\*\//, "").replace(/\/\/.*?\n/, "").trim().endsWith(":");
  37914. }
  37915. function isDetachedRulesetCallNode(node) {
  37916. return node.raws && node.raws.params && /^\(\s*\)$/.test(node.raws.params);
  37917. }
  37918. function isTemplatePlaceholderNode(node) {
  37919. return node.name.startsWith("prettier-placeholder");
  37920. }
  37921. function isTemplatePropNode(node) {
  37922. return node.prop.startsWith("@prettier-placeholder");
  37923. }
  37924. function isPostcssSimpleVarNode(currentNode, nextNode) {
  37925. return currentNode.value === "$$" && currentNode.type === "value-func" && nextNode && nextNode.type === "value-word" && !nextNode.raws.before;
  37926. }
  37927. function hasComposesNode(node) {
  37928. return node.value && node.value.type === "value-root" && node.value.group && node.value.group.type === "value-value" && node.prop.toLowerCase() === "composes";
  37929. }
  37930. function hasParensAroundNode(node) {
  37931. return node.value && node.value.group && node.value.group.group && node.value.group.group.type === "value-paren_group" && node.value.group.group.open !== null && node.value.group.group.close !== null;
  37932. }
  37933. function hasEmptyRawBefore(node) {
  37934. return node.raws && node.raws.before === "";
  37935. }
  37936. function isKeyValuePairNode(node) {
  37937. return node.type === "value-comma_group" && node.groups && node.groups[1] && node.groups[1].type === "value-colon";
  37938. }
  37939. function isKeyValuePairInParenGroupNode(node) {
  37940. return node.type === "value-paren_group" && node.groups && node.groups[0] && isKeyValuePairNode(node.groups[0]);
  37941. }
  37942. function isSCSSMapItemNode(path) {
  37943. const node = path.getValue(); // Ignore empty item (i.e. `$key: ()`)
  37944. if (node.groups.length === 0) {
  37945. return false;
  37946. }
  37947. const parentParentNode = path.getParentNode(1); // Check open parens contain key/value pair (i.e. `(key: value)` and `(key: (value, other-value)`)
  37948. if (!isKeyValuePairInParenGroupNode(node) && !(parentParentNode && isKeyValuePairInParenGroupNode(parentParentNode))) {
  37949. return false;
  37950. }
  37951. const declNode = getAncestorNode(path, "css-decl"); // SCSS map declaration (i.e. `$map: (key: value, other-key: other-value)`)
  37952. if (declNode && declNode.prop && declNode.prop.startsWith("$")) {
  37953. return true;
  37954. } // List as value of key inside SCSS map (i.e. `$map: (key: (value other-value other-other-value))`)
  37955. if (isKeyValuePairInParenGroupNode(parentParentNode)) {
  37956. return true;
  37957. } // SCSS Map is argument of function (i.e. `func((key: value, other-key: other-value))`)
  37958. if (parentParentNode.type === "value-func") {
  37959. return true;
  37960. }
  37961. return false;
  37962. }
  37963. function isInlineValueCommentNode(node) {
  37964. return node.type === "value-comment" && node.inline;
  37965. }
  37966. function isHashNode(node) {
  37967. return node.type === "value-word" && node.value === "#";
  37968. }
  37969. function isLeftCurlyBraceNode(node) {
  37970. return node.type === "value-word" && node.value === "{";
  37971. }
  37972. function isRightCurlyBraceNode(node) {
  37973. return node.type === "value-word" && node.value === "}";
  37974. }
  37975. function isWordNode(node) {
  37976. return ["value-word", "value-atword"].includes(node.type);
  37977. }
  37978. function isColonNode(node) {
  37979. return node.type === "value-colon";
  37980. }
  37981. function isMediaAndSupportsKeywords(node) {
  37982. return node.value && ["not", "and", "or"].includes(node.value.toLowerCase());
  37983. }
  37984. function isColorAdjusterFuncNode(node) {
  37985. if (node.type !== "value-func") {
  37986. return false;
  37987. }
  37988. return colorAdjusterFunctions.has(node.value.toLowerCase());
  37989. } // TODO: only check `less` when we don't use `less` to parse `css`
  37990. function isLessParser(options) {
  37991. return options.parser === "css" || options.parser === "less";
  37992. }
  37993. function lastLineHasInlineComment(text) {
  37994. return /\/\//.test(text.split(/[\n\r]/).pop());
  37995. }
  37996. function stringifyNode(node) {
  37997. if (node.groups) {
  37998. const open = node.open && node.open.value ? node.open.value : "";
  37999. const groups = node.groups.reduce((previousValue, currentValue, index) => {
  38000. return previousValue + stringifyNode(currentValue) + (node.groups[0].type === "comma_group" && index !== node.groups.length - 1 ? "," : "");
  38001. }, "");
  38002. const close = node.close && node.close.value ? node.close.value : "";
  38003. return open + groups + close;
  38004. }
  38005. const before = node.raws && node.raws.before ? node.raws.before : "";
  38006. const quote = node.raws && node.raws.quote ? node.raws.quote : "";
  38007. const atword = node.type === "atword" ? "@" : "";
  38008. const value = node.value ? node.value : "";
  38009. const unit = node.unit ? node.unit : "";
  38010. const group = node.group ? stringifyNode(node.group) : "";
  38011. const after = node.raws && node.raws.after ? node.raws.after : "";
  38012. return before + quote + atword + value + quote + unit + group + after;
  38013. }
  38014. var utils$7 = {
  38015. getAncestorCounter,
  38016. getAncestorNode,
  38017. getPropOfDeclNode,
  38018. hasSCSSInterpolation,
  38019. hasStringOrFunction,
  38020. maybeToLowerCase,
  38021. insideValueFunctionNode,
  38022. insideICSSRuleNode,
  38023. insideAtRuleNode,
  38024. insideURLFunctionInImportAtRuleNode,
  38025. isKeyframeAtRuleKeywords,
  38026. isWideKeywords,
  38027. isSCSS,
  38028. isSCSSVariable,
  38029. isLastNode,
  38030. isLessParser,
  38031. isSCSSControlDirectiveNode,
  38032. isDetachedRulesetDeclarationNode,
  38033. isRelationalOperatorNode,
  38034. isEqualityOperatorNode,
  38035. isMultiplicationNode,
  38036. isDivisionNode,
  38037. isAdditionNode,
  38038. isSubtractionNode,
  38039. isModuloNode,
  38040. isMathOperatorNode,
  38041. isEachKeywordNode,
  38042. isForKeywordNode,
  38043. isURLFunctionNode,
  38044. isIfElseKeywordNode,
  38045. hasComposesNode,
  38046. hasParensAroundNode,
  38047. hasEmptyRawBefore,
  38048. isSCSSNestedPropertyNode,
  38049. isDetachedRulesetCallNode,
  38050. isTemplatePlaceholderNode,
  38051. isTemplatePropNode,
  38052. isPostcssSimpleVarNode,
  38053. isKeyValuePairNode,
  38054. isKeyValuePairInParenGroupNode,
  38055. isSCSSMapItemNode,
  38056. isInlineValueCommentNode,
  38057. isHashNode,
  38058. isLeftCurlyBraceNode,
  38059. isRightCurlyBraceNode,
  38060. isWordNode,
  38061. isColonNode,
  38062. isMediaAndSupportsKeywords,
  38063. isColorAdjusterFuncNode,
  38064. lastLineHasInlineComment,
  38065. stringifyNode
  38066. };
  38067. const {
  38068. printNumber: printNumber$2,
  38069. printString: printString$2,
  38070. hasIgnoreComment: hasIgnoreComment$3,
  38071. hasNewline: hasNewline$6,
  38072. isFrontMatterNode: isFrontMatterNode$2,
  38073. isNextLineEmpty: isNextLineEmpty$5
  38074. } = util;
  38075. const {
  38076. builders: {
  38077. concat: concat$g,
  38078. join: join$8,
  38079. line: line$9,
  38080. hardline: hardline$a,
  38081. softline: softline$7,
  38082. group: group$b,
  38083. fill: fill$4,
  38084. indent: indent$a,
  38085. dedent: dedent$2,
  38086. ifBreak: ifBreak$5,
  38087. breakParent: breakParent$5
  38088. },
  38089. utils: {
  38090. removeLines: removeLines$2
  38091. }
  38092. } = document;
  38093. const {
  38094. insertPragma: insertPragma$3
  38095. } = pragma$1;
  38096. const {
  38097. getAncestorNode: getAncestorNode$1,
  38098. getPropOfDeclNode: getPropOfDeclNode$1,
  38099. maybeToLowerCase: maybeToLowerCase$1,
  38100. insideValueFunctionNode: insideValueFunctionNode$1,
  38101. insideICSSRuleNode: insideICSSRuleNode$1,
  38102. insideAtRuleNode: insideAtRuleNode$1,
  38103. insideURLFunctionInImportAtRuleNode: insideURLFunctionInImportAtRuleNode$1,
  38104. isKeyframeAtRuleKeywords: isKeyframeAtRuleKeywords$1,
  38105. isWideKeywords: isWideKeywords$1,
  38106. isSCSS: isSCSS$1,
  38107. isLastNode: isLastNode$1,
  38108. isLessParser: isLessParser$1,
  38109. isSCSSControlDirectiveNode: isSCSSControlDirectiveNode$1,
  38110. isDetachedRulesetDeclarationNode: isDetachedRulesetDeclarationNode$1,
  38111. isRelationalOperatorNode: isRelationalOperatorNode$1,
  38112. isEqualityOperatorNode: isEqualityOperatorNode$1,
  38113. isMultiplicationNode: isMultiplicationNode$1,
  38114. isDivisionNode: isDivisionNode$1,
  38115. isAdditionNode: isAdditionNode$1,
  38116. isSubtractionNode: isSubtractionNode$1,
  38117. isMathOperatorNode: isMathOperatorNode$1,
  38118. isEachKeywordNode: isEachKeywordNode$1,
  38119. isForKeywordNode: isForKeywordNode$1,
  38120. isURLFunctionNode: isURLFunctionNode$1,
  38121. isIfElseKeywordNode: isIfElseKeywordNode$1,
  38122. hasComposesNode: hasComposesNode$1,
  38123. hasParensAroundNode: hasParensAroundNode$1,
  38124. hasEmptyRawBefore: hasEmptyRawBefore$1,
  38125. isKeyValuePairNode: isKeyValuePairNode$1,
  38126. isDetachedRulesetCallNode: isDetachedRulesetCallNode$1,
  38127. isTemplatePlaceholderNode: isTemplatePlaceholderNode$1,
  38128. isTemplatePropNode: isTemplatePropNode$1,
  38129. isPostcssSimpleVarNode: isPostcssSimpleVarNode$1,
  38130. isSCSSMapItemNode: isSCSSMapItemNode$1,
  38131. isInlineValueCommentNode: isInlineValueCommentNode$1,
  38132. isHashNode: isHashNode$1,
  38133. isLeftCurlyBraceNode: isLeftCurlyBraceNode$1,
  38134. isRightCurlyBraceNode: isRightCurlyBraceNode$1,
  38135. isWordNode: isWordNode$1,
  38136. isColonNode: isColonNode$1,
  38137. isMediaAndSupportsKeywords: isMediaAndSupportsKeywords$1,
  38138. isColorAdjusterFuncNode: isColorAdjusterFuncNode$1,
  38139. lastLineHasInlineComment: lastLineHasInlineComment$1
  38140. } = utils$7;
  38141. function shouldPrintComma$4(options) {
  38142. return options.trailingComma === "es5" || options.trailingComma === "all";
  38143. }
  38144. function genericPrint$2(path, options, print) {
  38145. const node = path.getValue();
  38146. /* istanbul ignore if */
  38147. if (!node) {
  38148. return "";
  38149. }
  38150. if (typeof node === "string") {
  38151. return node;
  38152. }
  38153. switch (node.type) {
  38154. case "front-matter":
  38155. return concat$g([node.raw, hardline$a]);
  38156. case "css-root":
  38157. {
  38158. const nodes = printNodeSequence(path, options, print);
  38159. const after = node.raws.after.trim();
  38160. return concat$g([nodes, after ? ` ${after}` : "", nodes.parts.length && !options.__isHTMLStyleAttribute ? hardline$a : ""]);
  38161. }
  38162. case "css-comment":
  38163. {
  38164. const isInlineComment = node.inline || node.raws.inline;
  38165. const text = options.originalText.slice(options.locStart(node), options.locEnd(node));
  38166. return isInlineComment ? text.trimEnd() : text;
  38167. }
  38168. case "css-rule":
  38169. {
  38170. return concat$g([path.call(print, "selector"), node.important ? " !important" : "", node.nodes ? concat$g([node.selector && node.selector.type === "selector-unknown" && lastLineHasInlineComment$1(node.selector.value) ? line$9 : " ", "{", node.nodes.length > 0 ? indent$a(concat$g([hardline$a, printNodeSequence(path, options, print)])) : "", hardline$a, "}", isDetachedRulesetDeclarationNode$1(node) ? ";" : ""]) : ";"]);
  38171. }
  38172. case "css-decl":
  38173. {
  38174. const parentNode = path.getParentNode();
  38175. const {
  38176. between: rawBetween
  38177. } = node.raws;
  38178. const trimmedBetween = rawBetween.trim();
  38179. const isColon = trimmedBetween === ":";
  38180. let value = hasComposesNode$1(node) ? removeLines$2(path.call(print, "value")) : path.call(print, "value");
  38181. if (!isColon && lastLineHasInlineComment$1(trimmedBetween)) {
  38182. value = indent$a(concat$g([hardline$a, dedent$2(value)]));
  38183. }
  38184. return concat$g([node.raws.before.replace(/[\s;]/g, ""), insideICSSRuleNode$1(path) ? node.prop : maybeToLowerCase$1(node.prop), trimmedBetween.startsWith("//") ? " " : "", trimmedBetween, node.extend ? "" : " ", isLessParser$1(options) && node.extend && node.selector ? concat$g(["extend(", path.call(print, "selector"), ")"]) : "", value, node.raws.important ? node.raws.important.replace(/\s*!\s*important/i, " !important") : node.important ? " !important" : "", node.raws.scssDefault ? node.raws.scssDefault.replace(/\s*!default/i, " !default") : node.scssDefault ? " !default" : "", node.raws.scssGlobal ? node.raws.scssGlobal.replace(/\s*!global/i, " !global") : node.scssGlobal ? " !global" : "", node.nodes ? concat$g([" {", indent$a(concat$g([softline$7, printNodeSequence(path, options, print)])), softline$7, "}"]) : isTemplatePropNode$1(node) && !parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" ? "" : options.__isHTMLStyleAttribute && isLastNode$1(path, node) ? ifBreak$5(";", "") : ";"]);
  38185. }
  38186. case "css-atrule":
  38187. {
  38188. const parentNode = path.getParentNode();
  38189. const isTemplatePlaceholderNodeWithoutSemiColon = isTemplatePlaceholderNode$1(node) && !parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";";
  38190. if (isLessParser$1(options)) {
  38191. if (node.mixin) {
  38192. return concat$g([path.call(print, "selector"), node.important ? " !important" : "", isTemplatePlaceholderNodeWithoutSemiColon ? "" : ";"]);
  38193. }
  38194. if (node.function) {
  38195. return concat$g([node.name, concat$g([path.call(print, "params")]), isTemplatePlaceholderNodeWithoutSemiColon ? "" : ";"]);
  38196. }
  38197. if (node.variable) {
  38198. return concat$g(["@", node.name, ": ", node.value ? concat$g([path.call(print, "value")]) : "", node.raws.between.trim() ? node.raws.between.trim() + " " : "", node.nodes ? concat$g(["{", indent$a(concat$g([node.nodes.length > 0 ? softline$7 : "", printNodeSequence(path, options, print)])), softline$7, "}"]) : "", isTemplatePlaceholderNodeWithoutSemiColon ? "" : ";"]);
  38199. }
  38200. }
  38201. return concat$g(["@", // If a Less file ends up being parsed with the SCSS parser, Less
  38202. // variable declarations will be parsed as at-rules with names ending
  38203. // with a colon, so keep the original case then.
  38204. isDetachedRulesetCallNode$1(node) || node.name.endsWith(":") ? node.name : maybeToLowerCase$1(node.name), node.params ? concat$g([isDetachedRulesetCallNode$1(node) ? "" : isTemplatePlaceholderNode$1(node) ? node.raws.afterName === "" ? "" : node.name.endsWith(":") ? " " : /^\s*\n\s*\n/.test(node.raws.afterName) ? concat$g([hardline$a, hardline$a]) : /^\s*\n/.test(node.raws.afterName) ? hardline$a : " " : " ", path.call(print, "params")]) : "", node.selector ? indent$a(concat$g([" ", path.call(print, "selector")])) : "", node.value ? group$b(concat$g([" ", path.call(print, "value"), isSCSSControlDirectiveNode$1(node) ? hasParensAroundNode$1(node) ? " " : line$9 : ""])) : node.name === "else" ? " " : "", node.nodes ? concat$g([isSCSSControlDirectiveNode$1(node) ? "" : node.selector && !node.selector.nodes && typeof node.selector.value === "string" && lastLineHasInlineComment$1(node.selector.value) || !node.selector && typeof node.params === "string" && lastLineHasInlineComment$1(node.params) ? line$9 : " ", "{", indent$a(concat$g([node.nodes.length > 0 ? softline$7 : "", printNodeSequence(path, options, print)])), softline$7, "}"]) : isTemplatePlaceholderNodeWithoutSemiColon ? "" : ";"]);
  38205. }
  38206. // postcss-media-query-parser
  38207. case "media-query-list":
  38208. {
  38209. const parts = [];
  38210. path.each(childPath => {
  38211. const node = childPath.getValue();
  38212. if (node.type === "media-query" && node.value === "") {
  38213. return;
  38214. }
  38215. parts.push(childPath.call(print));
  38216. }, "nodes");
  38217. return group$b(indent$a(join$8(line$9, parts)));
  38218. }
  38219. case "media-query":
  38220. {
  38221. return concat$g([join$8(" ", path.map(print, "nodes")), isLastNode$1(path, node) ? "" : ","]);
  38222. }
  38223. case "media-type":
  38224. {
  38225. return adjustNumbers(adjustStrings(node.value, options));
  38226. }
  38227. case "media-feature-expression":
  38228. {
  38229. if (!node.nodes) {
  38230. return node.value;
  38231. }
  38232. return concat$g(["(", concat$g(path.map(print, "nodes")), ")"]);
  38233. }
  38234. case "media-feature":
  38235. {
  38236. return maybeToLowerCase$1(adjustStrings(node.value.replace(/ +/g, " "), options));
  38237. }
  38238. case "media-colon":
  38239. {
  38240. return concat$g([node.value, " "]);
  38241. }
  38242. case "media-value":
  38243. {
  38244. return adjustNumbers(adjustStrings(node.value, options));
  38245. }
  38246. case "media-keyword":
  38247. {
  38248. return adjustStrings(node.value, options);
  38249. }
  38250. case "media-url":
  38251. {
  38252. return adjustStrings(node.value.replace(/^url\(\s+/gi, "url(").replace(/\s+\)$/gi, ")"), options);
  38253. }
  38254. case "media-unknown":
  38255. {
  38256. return node.value;
  38257. }
  38258. // postcss-selector-parser
  38259. case "selector-root":
  38260. {
  38261. return group$b(concat$g([insideAtRuleNode$1(path, "custom-selector") ? concat$g([getAncestorNode$1(path, "css-atrule").customSelector, line$9]) : "", join$8(concat$g([",", insideAtRuleNode$1(path, ["extend", "custom-selector", "nest"]) ? line$9 : hardline$a]), path.map(print, "nodes"))]));
  38262. }
  38263. case "selector-selector":
  38264. {
  38265. return group$b(indent$a(concat$g(path.map(print, "nodes"))));
  38266. }
  38267. case "selector-comment":
  38268. {
  38269. return node.value;
  38270. }
  38271. case "selector-string":
  38272. {
  38273. return adjustStrings(node.value, options);
  38274. }
  38275. case "selector-tag":
  38276. {
  38277. const parentNode = path.getParentNode();
  38278. const index = parentNode && parentNode.nodes.indexOf(node);
  38279. const prevNode = index && parentNode.nodes[index - 1];
  38280. return concat$g([node.namespace ? concat$g([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", prevNode.type === "selector-nesting" ? node.value : adjustNumbers(isKeyframeAtRuleKeywords$1(path, node.value) ? node.value.toLowerCase() : node.value)]);
  38281. }
  38282. case "selector-id":
  38283. {
  38284. return concat$g(["#", node.value]);
  38285. }
  38286. case "selector-class":
  38287. {
  38288. return concat$g([".", adjustNumbers(adjustStrings(node.value, options))]);
  38289. }
  38290. case "selector-attribute":
  38291. {
  38292. return concat$g(["[", node.namespace ? concat$g([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", node.attribute.trim(), node.operator ? node.operator : "", node.value ? quoteAttributeValue(adjustStrings(node.value.trim(), options), options) : "", node.insensitive ? " i" : "", "]"]);
  38293. }
  38294. case "selector-combinator":
  38295. {
  38296. if (node.value === "+" || node.value === ">" || node.value === "~" || node.value === ">>>") {
  38297. const parentNode = path.getParentNode();
  38298. const leading = parentNode.type === "selector-selector" && parentNode.nodes[0] === node ? "" : line$9;
  38299. return concat$g([leading, node.value, isLastNode$1(path, node) ? "" : " "]);
  38300. }
  38301. const leading = node.value.trim().startsWith("(") ? line$9 : "";
  38302. const value = adjustNumbers(adjustStrings(node.value.trim(), options)) || line$9;
  38303. return concat$g([leading, value]);
  38304. }
  38305. case "selector-universal":
  38306. {
  38307. return concat$g([node.namespace ? concat$g([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", node.value]);
  38308. }
  38309. case "selector-pseudo":
  38310. {
  38311. return concat$g([maybeToLowerCase$1(node.value), node.nodes && node.nodes.length > 0 ? concat$g(["(", join$8(", ", path.map(print, "nodes")), ")"]) : ""]);
  38312. }
  38313. case "selector-nesting":
  38314. {
  38315. return node.value;
  38316. }
  38317. case "selector-unknown":
  38318. {
  38319. const ruleAncestorNode = getAncestorNode$1(path, "css-rule"); // Nested SCSS property
  38320. if (ruleAncestorNode && ruleAncestorNode.isSCSSNesterProperty) {
  38321. return adjustNumbers(adjustStrings(maybeToLowerCase$1(node.value), options));
  38322. } // originalText has to be used for Less, see replaceQuotesInInlineComments in loc.js
  38323. const parentNode = path.getParentNode();
  38324. if (parentNode.raws && parentNode.raws.selector) {
  38325. const start = options.locStart(parentNode);
  38326. const end = start + parentNode.raws.selector.length;
  38327. return options.originalText.slice(start, end).trim();
  38328. } // Same reason above
  38329. const grandParent = path.getParentNode(1);
  38330. if (parentNode.type === "value-paren_group" && grandParent && grandParent.type === "value-func" && grandParent.value === "selector") {
  38331. const start = options.locStart(parentNode.open) + 1;
  38332. const end = options.locEnd(parentNode.close) - 1;
  38333. const selector = options.originalText.slice(start, end).trim();
  38334. return lastLineHasInlineComment$1(selector) ? concat$g([breakParent$5, selector]) : selector;
  38335. }
  38336. return node.value;
  38337. }
  38338. // postcss-values-parser
  38339. case "value-value":
  38340. case "value-root":
  38341. {
  38342. return path.call(print, "group");
  38343. }
  38344. case "value-comment":
  38345. {
  38346. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  38347. }
  38348. case "value-comma_group":
  38349. {
  38350. const parentNode = path.getParentNode();
  38351. const parentParentNode = path.getParentNode(1);
  38352. const declAncestorProp = getPropOfDeclNode$1(path);
  38353. const isGridValue = declAncestorProp && parentNode.type === "value-value" && (declAncestorProp === "grid" || declAncestorProp.startsWith("grid-template"));
  38354. const atRuleAncestorNode = getAncestorNode$1(path, "css-atrule");
  38355. const isControlDirective = atRuleAncestorNode && isSCSSControlDirectiveNode$1(atRuleAncestorNode);
  38356. const printed = path.map(print, "groups");
  38357. const parts = [];
  38358. const insideURLFunction = insideValueFunctionNode$1(path, "url");
  38359. let insideSCSSInterpolationInString = false;
  38360. let didBreak = false;
  38361. for (let i = 0; i < node.groups.length; ++i) {
  38362. parts.push(printed[i]);
  38363. const iPrevNode = node.groups[i - 1];
  38364. const iNode = node.groups[i];
  38365. const iNextNode = node.groups[i + 1];
  38366. const iNextNextNode = node.groups[i + 2];
  38367. if (insideURLFunction) {
  38368. if (iNextNode && isAdditionNode$1(iNextNode) || isAdditionNode$1(iNode)) {
  38369. parts.push(" ");
  38370. }
  38371. continue;
  38372. } // Ignore after latest node (i.e. before semicolon)
  38373. if (!iNextNode) {
  38374. continue;
  38375. } // styled.div` background: var(--${one}); `
  38376. if (iNode.type === "value-word" && iNode.value.endsWith("-") && iNextNode.type === "value-atword" && iNextNode.value.startsWith("prettier-placeholder-")) {
  38377. continue;
  38378. } // Ignore spaces before/after string interpolation (i.e. `"#{my-fn("_")}"`)
  38379. const isStartSCSSInterpolationInString = iNode.type === "value-string" && iNode.value.startsWith("#{");
  38380. const isEndingSCSSInterpolationInString = insideSCSSInterpolationInString && iNextNode.type === "value-string" && iNextNode.value.endsWith("}");
  38381. if (isStartSCSSInterpolationInString || isEndingSCSSInterpolationInString) {
  38382. insideSCSSInterpolationInString = !insideSCSSInterpolationInString;
  38383. continue;
  38384. }
  38385. if (insideSCSSInterpolationInString) {
  38386. continue;
  38387. } // Ignore colon (i.e. `:`)
  38388. if (isColonNode$1(iNode) || isColonNode$1(iNextNode)) {
  38389. continue;
  38390. } // Ignore `@` in Less (i.e. `@@var;`)
  38391. if (iNode.type === "value-atword" && iNode.value === "") {
  38392. continue;
  38393. } // Ignore `~` in Less (i.e. `content: ~"^//* some horrible but needed css hack";`)
  38394. if (iNode.value === "~") {
  38395. continue;
  38396. } // Ignore escape `\`
  38397. if (iNode.value && iNode.value.includes("\\") && iNextNode && iNextNode.type !== "value-comment") {
  38398. continue;
  38399. } // Ignore escaped `/`
  38400. if (iPrevNode && iPrevNode.value && iPrevNode.value.indexOf("\\") === iPrevNode.value.length - 1 && iNode.type === "value-operator" && iNode.value === "/") {
  38401. continue;
  38402. } // Ignore `\` (i.e. `$variable: \@small;`)
  38403. if (iNode.value === "\\") {
  38404. continue;
  38405. } // Ignore `$$` (i.e. `background-color: $$(style)Color;`)
  38406. if (isPostcssSimpleVarNode$1(iNode, iNextNode)) {
  38407. continue;
  38408. } // Ignore spaces after `#` and after `{` and before `}` in SCSS interpolation (i.e. `#{variable}`)
  38409. if (isHashNode$1(iNode) || isLeftCurlyBraceNode$1(iNode) || isRightCurlyBraceNode$1(iNextNode) || isLeftCurlyBraceNode$1(iNextNode) && hasEmptyRawBefore$1(iNextNode) || isRightCurlyBraceNode$1(iNode) && hasEmptyRawBefore$1(iNextNode)) {
  38410. continue;
  38411. } // Ignore css variables and interpolation in SCSS (i.e. `--#{$var}`)
  38412. if (iNode.value === "--" && isHashNode$1(iNextNode)) {
  38413. continue;
  38414. } // Formatting math operations
  38415. const isMathOperator = isMathOperatorNode$1(iNode);
  38416. const isNextMathOperator = isMathOperatorNode$1(iNextNode); // Print spaces before and after math operators beside SCSS interpolation as is
  38417. // (i.e. `#{$var}+5`, `#{$var} +5`, `#{$var}+ 5`, `#{$var} + 5`)
  38418. // (i.e. `5+#{$var}`, `5 +#{$var}`, `5+ #{$var}`, `5 + #{$var}`)
  38419. if ((isMathOperator && isHashNode$1(iNextNode) || isNextMathOperator && isRightCurlyBraceNode$1(iNode)) && hasEmptyRawBefore$1(iNextNode)) {
  38420. continue;
  38421. } // Print spaces before and after addition and subtraction math operators as is in `calc` function
  38422. // due to the fact that it is not valid syntax
  38423. // (i.e. `calc(1px+1px)`, `calc(1px+ 1px)`, `calc(1px +1px)`, `calc(1px + 1px)`)
  38424. if (insideValueFunctionNode$1(path, "calc") && (isAdditionNode$1(iNode) || isAdditionNode$1(iNextNode) || isSubtractionNode$1(iNode) || isSubtractionNode$1(iNextNode)) && hasEmptyRawBefore$1(iNextNode)) {
  38425. continue;
  38426. } // Print spaces after `+` and `-` in color adjuster functions as is (e.g. `color(red l(+ 20%))`)
  38427. // Adjusters with signed numbers (e.g. `color(red l(+20%))`) output as-is.
  38428. const isColorAdjusterNode = (isAdditionNode$1(iNode) || isSubtractionNode$1(iNode)) && i === 0 && (iNextNode.type === "value-number" || iNextNode.isHex) && parentParentNode && isColorAdjusterFuncNode$1(parentParentNode) && !hasEmptyRawBefore$1(iNextNode);
  38429. const requireSpaceBeforeOperator = iNextNextNode && iNextNextNode.type === "value-func" || iNextNextNode && isWordNode$1(iNextNextNode) || iNode.type === "value-func" || isWordNode$1(iNode);
  38430. const requireSpaceAfterOperator = iNextNode.type === "value-func" || isWordNode$1(iNextNode) || iPrevNode && iPrevNode.type === "value-func" || iPrevNode && isWordNode$1(iPrevNode); // Formatting `/`, `+`, `-` sign
  38431. if (!(isMultiplicationNode$1(iNextNode) || isMultiplicationNode$1(iNode)) && !insideValueFunctionNode$1(path, "calc") && !isColorAdjusterNode && (isDivisionNode$1(iNextNode) && !requireSpaceBeforeOperator || isDivisionNode$1(iNode) && !requireSpaceAfterOperator || isAdditionNode$1(iNextNode) && !requireSpaceBeforeOperator || isAdditionNode$1(iNode) && !requireSpaceAfterOperator || isSubtractionNode$1(iNextNode) || isSubtractionNode$1(iNode)) && (hasEmptyRawBefore$1(iNextNode) || isMathOperator && (!iPrevNode || iPrevNode && isMathOperatorNode$1(iPrevNode)))) {
  38432. continue;
  38433. } // Add `hardline` after inline comment (i.e. `// comment\n foo: bar;`)
  38434. if (isInlineValueCommentNode$1(iNode)) {
  38435. if (parentNode.type === "value-paren_group") {
  38436. parts.push(dedent$2(hardline$a));
  38437. continue;
  38438. }
  38439. parts.push(hardline$a);
  38440. continue;
  38441. } // Handle keywords in SCSS control directive
  38442. if (isControlDirective && (isEqualityOperatorNode$1(iNextNode) || isRelationalOperatorNode$1(iNextNode) || isIfElseKeywordNode$1(iNextNode) || isEachKeywordNode$1(iNode) || isForKeywordNode$1(iNode))) {
  38443. parts.push(" ");
  38444. continue;
  38445. } // At-rule `namespace` should be in one line
  38446. if (atRuleAncestorNode && atRuleAncestorNode.name.toLowerCase() === "namespace") {
  38447. parts.push(" ");
  38448. continue;
  38449. } // Formatting `grid` property
  38450. if (isGridValue) {
  38451. if (iNode.source && iNextNode.source && iNode.source.start.line !== iNextNode.source.start.line) {
  38452. parts.push(hardline$a);
  38453. didBreak = true;
  38454. } else {
  38455. parts.push(" ");
  38456. }
  38457. continue;
  38458. } // Add `space` before next math operation
  38459. // Note: `grip` property have `/` delimiter and it is not math operation, so
  38460. // `grid` property handles above
  38461. if (isNextMathOperator) {
  38462. parts.push(" ");
  38463. continue;
  38464. } // allow function(returns-list($list)...)
  38465. if (iNextNode && iNextNode.value === "...") {
  38466. continue;
  38467. } // Be default all values go through `line`
  38468. parts.push(line$9);
  38469. }
  38470. if (didBreak) {
  38471. parts.unshift(hardline$a);
  38472. }
  38473. if (isControlDirective) {
  38474. return group$b(indent$a(concat$g(parts)));
  38475. } // Indent is not needed for import url when url is very long
  38476. // and node has two groups
  38477. // when type is value-comma_group
  38478. // example @import url("verylongurl") projection,tv
  38479. if (insideURLFunctionInImportAtRuleNode$1(path)) {
  38480. return group$b(fill$4(parts));
  38481. }
  38482. return group$b(indent$a(fill$4(parts)));
  38483. }
  38484. case "value-paren_group":
  38485. {
  38486. const parentNode = path.getParentNode();
  38487. if (parentNode && isURLFunctionNode$1(parentNode) && (node.groups.length === 1 || node.groups.length > 0 && node.groups[0].type === "value-comma_group" && node.groups[0].groups.length > 0 && node.groups[0].groups[0].type === "value-word" && node.groups[0].groups[0].value.startsWith("data:"))) {
  38488. return concat$g([node.open ? path.call(print, "open") : "", join$8(",", path.map(print, "groups")), node.close ? path.call(print, "close") : ""]);
  38489. }
  38490. if (!node.open) {
  38491. const printed = path.map(print, "groups");
  38492. const res = [];
  38493. for (let i = 0; i < printed.length; i++) {
  38494. if (i !== 0) {
  38495. res.push(concat$g([",", line$9]));
  38496. }
  38497. res.push(printed[i]);
  38498. }
  38499. return group$b(indent$a(fill$4(res)));
  38500. }
  38501. const isSCSSMapItem = isSCSSMapItemNode$1(path);
  38502. const lastItem = node.groups[node.groups.length - 1];
  38503. const isLastItemComment = lastItem && lastItem.type === "value-comment";
  38504. return group$b(concat$g([node.open ? path.call(print, "open") : "", indent$a(concat$g([softline$7, join$8(concat$g([",", line$9]), path.map(childPath => {
  38505. const node = childPath.getValue();
  38506. const printed = print(childPath); // Key/Value pair in open paren already indented
  38507. if (isKeyValuePairNode$1(node) && node.type === "value-comma_group" && node.groups && node.groups[2] && node.groups[2].type === "value-paren_group") {
  38508. printed.contents.contents.parts[1] = group$b(printed.contents.contents.parts[1]);
  38509. return group$b(dedent$2(printed));
  38510. }
  38511. return printed;
  38512. }, "groups"))])), ifBreak$5(!isLastItemComment && isSCSS$1(options.parser, options.originalText) && isSCSSMapItem && shouldPrintComma$4(options) ? "," : ""), softline$7, node.close ? path.call(print, "close") : ""]), {
  38513. shouldBreak: isSCSSMapItem
  38514. });
  38515. }
  38516. case "value-func":
  38517. {
  38518. return concat$g([node.value, insideAtRuleNode$1(path, "supports") && isMediaAndSupportsKeywords$1(node) ? " " : "", path.call(print, "group")]);
  38519. }
  38520. case "value-paren":
  38521. {
  38522. return node.value;
  38523. }
  38524. case "value-number":
  38525. {
  38526. return concat$g([printCssNumber(node.value), maybeToLowerCase$1(node.unit)]);
  38527. }
  38528. case "value-operator":
  38529. {
  38530. return node.value;
  38531. }
  38532. case "value-word":
  38533. {
  38534. if (node.isColor && node.isHex || isWideKeywords$1(node.value)) {
  38535. return node.value.toLowerCase();
  38536. }
  38537. return node.value;
  38538. }
  38539. case "value-colon":
  38540. {
  38541. const parentNode = path.getParentNode();
  38542. const index = parentNode && parentNode.groups.indexOf(node);
  38543. const prevNode = index && parentNode.groups[index - 1];
  38544. return concat$g([node.value, // Don't add spaces on escaped colon `:`, e.g: grid-template-rows: [row-1-00\:00] auto;
  38545. prevNode && prevNode.value[prevNode.value.length - 1] === "\\" || // Don't add spaces on `:` in `url` function (i.e. `url(fbglyph: cross-outline, fig-white)`)
  38546. insideValueFunctionNode$1(path, "url") ? "" : line$9]);
  38547. }
  38548. // TODO: confirm this code is dead
  38549. /* istanbul ignore next */
  38550. case "value-comma":
  38551. {
  38552. return concat$g([node.value, " "]);
  38553. }
  38554. case "value-string":
  38555. {
  38556. return printString$2(node.raws.quote + node.value + node.raws.quote, options);
  38557. }
  38558. case "value-atword":
  38559. {
  38560. return concat$g(["@", node.value]);
  38561. }
  38562. case "value-unicode-range":
  38563. {
  38564. return node.value;
  38565. }
  38566. case "value-unknown":
  38567. {
  38568. return node.value;
  38569. }
  38570. default:
  38571. /* istanbul ignore next */
  38572. throw new Error(`Unknown postcss type ${JSON.stringify(node.type)}`);
  38573. }
  38574. }
  38575. function printNodeSequence(path, options, print) {
  38576. const node = path.getValue();
  38577. const parts = [];
  38578. let i = 0;
  38579. path.map(pathChild => {
  38580. const prevNode = node.nodes[i - 1];
  38581. if (prevNode && prevNode.type === "css-comment" && prevNode.text.trim() === "prettier-ignore") {
  38582. const childNode = pathChild.getValue();
  38583. parts.push(options.originalText.slice(options.locStart(childNode), options.locEnd(childNode)));
  38584. } else {
  38585. parts.push(pathChild.call(print));
  38586. }
  38587. if (i !== node.nodes.length - 1) {
  38588. if (node.nodes[i + 1].type === "css-comment" && !hasNewline$6(options.originalText, options.locStart(node.nodes[i + 1]), {
  38589. backwards: true
  38590. }) && !isFrontMatterNode$2(node.nodes[i]) || node.nodes[i + 1].type === "css-atrule" && node.nodes[i + 1].name === "else" && node.nodes[i].type !== "css-comment") {
  38591. parts.push(" ");
  38592. } else {
  38593. parts.push(options.__isHTMLStyleAttribute ? line$9 : hardline$a);
  38594. if (isNextLineEmpty$5(options.originalText, pathChild.getValue(), options.locEnd) && !isFrontMatterNode$2(node.nodes[i])) {
  38595. parts.push(hardline$a);
  38596. }
  38597. }
  38598. }
  38599. i++;
  38600. }, "nodes");
  38601. return concat$g(parts);
  38602. }
  38603. const STRING_REGEX$3 = /(["'])(?:(?!\1)[^\\]|\\[\S\s])*\1/g;
  38604. const NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[Ee][+-]?\d+)?/g;
  38605. const STANDARD_UNIT_REGEX = /[A-Za-z]+/g;
  38606. const WORD_PART_REGEX = /[$@]?[A-Z_a-z\u0080-\uFFFF][\w\u0080-\uFFFF-]*/g;
  38607. const ADJUST_NUMBERS_REGEX = new RegExp(STRING_REGEX$3.source + "|" + `(${WORD_PART_REGEX.source})?` + `(${NUMBER_REGEX.source})` + `(${STANDARD_UNIT_REGEX.source})?`, "g");
  38608. function adjustStrings(value, options) {
  38609. return value.replace(STRING_REGEX$3, match => printString$2(match, options));
  38610. }
  38611. function quoteAttributeValue(value, options) {
  38612. const quote = options.singleQuote ? "'" : '"';
  38613. return value.includes('"') || value.includes("'") ? value : quote + value + quote;
  38614. }
  38615. function adjustNumbers(value) {
  38616. return value.replace(ADJUST_NUMBERS_REGEX, (match, quote, wordPart, number, unit) => !wordPart && number ? printCssNumber(number) + maybeToLowerCase$1(unit || "") : match);
  38617. }
  38618. function printCssNumber(rawNumber) {
  38619. return printNumber$2(rawNumber) // Remove trailing `.0`.
  38620. .replace(/\.0(?=$|e)/, "");
  38621. }
  38622. var printerPostcss = {
  38623. print: genericPrint$2,
  38624. embed: embed_1$1,
  38625. insertPragma: insertPragma$3,
  38626. hasPrettierIgnore: hasIgnoreComment$3,
  38627. massageAstNode: clean_1$1
  38628. };
  38629. var options$3 = {
  38630. singleQuote: commonOptions.singleQuote
  38631. };
  38632. var name$9 = "CSS";
  38633. var type$7 = "markup";
  38634. var tmScope$7 = "source.css";
  38635. var aceMode$7 = "css";
  38636. var codemirrorMode$7 = "css";
  38637. var codemirrorMimeType$7 = "text/css";
  38638. var color$2 = "#563d7c";
  38639. var extensions$7 = [
  38640. ".css"
  38641. ];
  38642. var languageId$7 = 50;
  38643. var CSS = {
  38644. name: name$9,
  38645. type: type$7,
  38646. tmScope: tmScope$7,
  38647. aceMode: aceMode$7,
  38648. codemirrorMode: codemirrorMode$7,
  38649. codemirrorMimeType: codemirrorMimeType$7,
  38650. color: color$2,
  38651. extensions: extensions$7,
  38652. languageId: languageId$7
  38653. };
  38654. var CSS$1 = /*#__PURE__*/Object.freeze({
  38655. __proto__: null,
  38656. name: name$9,
  38657. type: type$7,
  38658. tmScope: tmScope$7,
  38659. aceMode: aceMode$7,
  38660. codemirrorMode: codemirrorMode$7,
  38661. codemirrorMimeType: codemirrorMimeType$7,
  38662. color: color$2,
  38663. extensions: extensions$7,
  38664. languageId: languageId$7,
  38665. 'default': CSS
  38666. });
  38667. var name$a = "PostCSS";
  38668. var type$8 = "markup";
  38669. var tmScope$8 = "source.postcss";
  38670. var group$c = "CSS";
  38671. var extensions$8 = [
  38672. ".pcss",
  38673. ".postcss"
  38674. ];
  38675. var aceMode$8 = "text";
  38676. var languageId$8 = 262764437;
  38677. var PostCSS = {
  38678. name: name$a,
  38679. type: type$8,
  38680. tmScope: tmScope$8,
  38681. group: group$c,
  38682. extensions: extensions$8,
  38683. aceMode: aceMode$8,
  38684. languageId: languageId$8
  38685. };
  38686. var PostCSS$1 = /*#__PURE__*/Object.freeze({
  38687. __proto__: null,
  38688. name: name$a,
  38689. type: type$8,
  38690. tmScope: tmScope$8,
  38691. group: group$c,
  38692. extensions: extensions$8,
  38693. aceMode: aceMode$8,
  38694. languageId: languageId$8,
  38695. 'default': PostCSS
  38696. });
  38697. var name$b = "Less";
  38698. var type$9 = "markup";
  38699. var group$d = "CSS";
  38700. var extensions$9 = [
  38701. ".less"
  38702. ];
  38703. var tmScope$9 = "source.css.less";
  38704. var aceMode$9 = "less";
  38705. var codemirrorMode$8 = "css";
  38706. var codemirrorMimeType$8 = "text/css";
  38707. var languageId$9 = 198;
  38708. var Less = {
  38709. name: name$b,
  38710. type: type$9,
  38711. group: group$d,
  38712. extensions: extensions$9,
  38713. tmScope: tmScope$9,
  38714. aceMode: aceMode$9,
  38715. codemirrorMode: codemirrorMode$8,
  38716. codemirrorMimeType: codemirrorMimeType$8,
  38717. languageId: languageId$9
  38718. };
  38719. var Less$1 = /*#__PURE__*/Object.freeze({
  38720. __proto__: null,
  38721. name: name$b,
  38722. type: type$9,
  38723. group: group$d,
  38724. extensions: extensions$9,
  38725. tmScope: tmScope$9,
  38726. aceMode: aceMode$9,
  38727. codemirrorMode: codemirrorMode$8,
  38728. codemirrorMimeType: codemirrorMimeType$8,
  38729. languageId: languageId$9,
  38730. 'default': Less
  38731. });
  38732. var name$c = "SCSS";
  38733. var type$a = "markup";
  38734. var tmScope$a = "source.css.scss";
  38735. var group$e = "CSS";
  38736. var aceMode$a = "scss";
  38737. var codemirrorMode$9 = "css";
  38738. var codemirrorMimeType$9 = "text/x-scss";
  38739. var extensions$a = [
  38740. ".scss"
  38741. ];
  38742. var languageId$a = 329;
  38743. var SCSS = {
  38744. name: name$c,
  38745. type: type$a,
  38746. tmScope: tmScope$a,
  38747. group: group$e,
  38748. aceMode: aceMode$a,
  38749. codemirrorMode: codemirrorMode$9,
  38750. codemirrorMimeType: codemirrorMimeType$9,
  38751. extensions: extensions$a,
  38752. languageId: languageId$a
  38753. };
  38754. var SCSS$1 = /*#__PURE__*/Object.freeze({
  38755. __proto__: null,
  38756. name: name$c,
  38757. type: type$a,
  38758. tmScope: tmScope$a,
  38759. group: group$e,
  38760. aceMode: aceMode$a,
  38761. codemirrorMode: codemirrorMode$9,
  38762. codemirrorMimeType: codemirrorMimeType$9,
  38763. extensions: extensions$a,
  38764. languageId: languageId$a,
  38765. 'default': SCSS
  38766. });
  38767. var require$$0$3 = getCjsExportFromNamespace(CSS$1);
  38768. var require$$1$1 = getCjsExportFromNamespace(PostCSS$1);
  38769. var require$$2$1 = getCjsExportFromNamespace(Less$1);
  38770. var require$$3$1 = getCjsExportFromNamespace(SCSS$1);
  38771. const languages$1 = [createLanguage(require$$0$3, () => ({
  38772. since: "1.4.0",
  38773. parsers: ["css"],
  38774. vscodeLanguageIds: ["css"]
  38775. })), createLanguage(require$$1$1, () => ({
  38776. since: "1.4.0",
  38777. parsers: ["css"],
  38778. vscodeLanguageIds: ["postcss"]
  38779. })), createLanguage(require$$2$1, () => ({
  38780. since: "1.4.0",
  38781. parsers: ["less"],
  38782. vscodeLanguageIds: ["less"]
  38783. })), createLanguage(require$$3$1, () => ({
  38784. since: "1.4.0",
  38785. parsers: ["scss"],
  38786. vscodeLanguageIds: ["scss"]
  38787. }))];
  38788. const printers$1 = {
  38789. postcss: printerPostcss
  38790. };
  38791. const parsers$1 = {
  38792. // TODO: switch these to just `postcss` and use `language` instead.
  38793. get css() {
  38794. return require("./parser-postcss").parsers.css;
  38795. },
  38796. get less() {
  38797. return require("./parser-postcss").parsers.less;
  38798. },
  38799. get scss() {
  38800. return require("./parser-postcss").parsers.scss;
  38801. }
  38802. };
  38803. var languageCss = {
  38804. languages: languages$1,
  38805. options: options$3,
  38806. printers: printers$1,
  38807. parsers: parsers$1
  38808. };
  38809. var clean$3 = function (ast, newNode) {
  38810. delete newNode.loc;
  38811. delete newNode.selfClosing; // (Glimmer/HTML) ignore TextNode whitespace
  38812. if (ast.type === "TextNode") {
  38813. const trimmed = ast.chars.trim();
  38814. if (!trimmed) {
  38815. return null;
  38816. }
  38817. newNode.chars = trimmed;
  38818. }
  38819. };
  38820. var index = [
  38821. "area",
  38822. "base",
  38823. "basefont",
  38824. "bgsound",
  38825. "br",
  38826. "col",
  38827. "command",
  38828. "embed",
  38829. "frame",
  38830. "hr",
  38831. "image",
  38832. "img",
  38833. "input",
  38834. "isindex",
  38835. "keygen",
  38836. "link",
  38837. "menuitem",
  38838. "meta",
  38839. "nextid",
  38840. "param",
  38841. "source",
  38842. "track",
  38843. "wbr"
  38844. ];
  38845. var htmlVoidElements = /*#__PURE__*/Object.freeze({
  38846. __proto__: null,
  38847. 'default': index
  38848. });
  38849. var htmlVoidElements$1 = getCjsExportFromNamespace(htmlVoidElements);
  38850. function isUppercase(string) {
  38851. return string.toUpperCase() === string;
  38852. }
  38853. function isGlimmerComponent(node) {
  38854. return isNodeOfSomeType(node, ["ElementNode"]) && typeof node.tag === "string" && (isUppercase(node.tag[0]) || node.tag.includes("."));
  38855. }
  38856. const voidTags = new Set(htmlVoidElements$1);
  38857. function isVoid(node) {
  38858. return isGlimmerComponent(node) && (node.children === 0 || node.children.every(n => isWhitespaceNode(n))) || voidTags.has(node.tag);
  38859. }
  38860. function isWhitespaceNode(node) {
  38861. return isNodeOfSomeType(node, ["TextNode"]) && !/\S/.test(node.chars);
  38862. }
  38863. function isNodeOfSomeType(node, types) {
  38864. return node && types.some(type => node.type === type);
  38865. }
  38866. function isParentOfSomeType(path, types) {
  38867. const parentNode = path.getParentNode(0);
  38868. return isNodeOfSomeType(parentNode, types);
  38869. }
  38870. function isPreviousNodeOfSomeType(path, types) {
  38871. const previousNode = getPreviousNode(path);
  38872. return isNodeOfSomeType(previousNode, types);
  38873. }
  38874. function isNextNodeOfSomeType(path, types) {
  38875. const nextNode = getNextNode(path);
  38876. return isNodeOfSomeType(nextNode, types);
  38877. }
  38878. function getSiblingNode(path, offset) {
  38879. const node = path.getValue();
  38880. const parentNode = path.getParentNode(0) || {};
  38881. const children = parentNode.children || parentNode.body || parentNode.parts || [];
  38882. const index = children.indexOf(node);
  38883. return index !== -1 && children[index + offset];
  38884. }
  38885. function getPreviousNode(path, lookBack = 1) {
  38886. return getSiblingNode(path, -lookBack);
  38887. }
  38888. function getNextNode(path) {
  38889. return getSiblingNode(path, 1);
  38890. }
  38891. function isPrettierIgnoreNode(node) {
  38892. return isNodeOfSomeType(node, ["MustacheCommentStatement"]) && typeof node.value === "string" && node.value.trim() === "prettier-ignore";
  38893. }
  38894. function hasPrettierIgnore$2(path) {
  38895. const node = path.getValue();
  38896. const previousPreviousNode = getPreviousNode(path, 2);
  38897. return isPrettierIgnoreNode(node) || isPrettierIgnoreNode(previousPreviousNode);
  38898. }
  38899. var utils$8 = {
  38900. getNextNode,
  38901. getPreviousNode,
  38902. hasPrettierIgnore: hasPrettierIgnore$2,
  38903. isNextNodeOfSomeType,
  38904. isNodeOfSomeType,
  38905. isParentOfSomeType,
  38906. isPreviousNodeOfSomeType,
  38907. isVoid,
  38908. isWhitespaceNode
  38909. };
  38910. const {
  38911. concat: concat$h,
  38912. group: group$f,
  38913. hardline: hardline$b,
  38914. ifBreak: ifBreak$6,
  38915. indent: indent$b,
  38916. join: join$9,
  38917. line: line$a,
  38918. softline: softline$8
  38919. } = document.builders;
  38920. const {
  38921. getNextNode: getNextNode$1,
  38922. getPreviousNode: getPreviousNode$1,
  38923. hasPrettierIgnore: hasPrettierIgnore$3,
  38924. isNextNodeOfSomeType: isNextNodeOfSomeType$1,
  38925. isNodeOfSomeType: isNodeOfSomeType$1,
  38926. isParentOfSomeType: isParentOfSomeType$1,
  38927. isPreviousNodeOfSomeType: isPreviousNodeOfSomeType$1,
  38928. isVoid: isVoid$1,
  38929. isWhitespaceNode: isWhitespaceNode$1
  38930. } = utils$8; // Formatter based on @glimmerjs/syntax's built-in test formatter:
  38931. // https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
  38932. function print$2(path, options, print) {
  38933. const n = path.getValue();
  38934. /* istanbul ignore if*/
  38935. if (!n) {
  38936. return "";
  38937. }
  38938. if (hasPrettierIgnore$3(path)) {
  38939. const startOffset = locationToOffset(options.originalText, n.loc.start.line - 1, n.loc.start.column);
  38940. const endOffset = locationToOffset(options.originalText, n.loc.end.line - 1, n.loc.end.column);
  38941. const ignoredText = options.originalText.slice(startOffset, endOffset);
  38942. return ignoredText;
  38943. }
  38944. switch (n.type) {
  38945. case "Block":
  38946. case "Program":
  38947. case "Template":
  38948. {
  38949. return group$f(concat$h(path.map(print, "body")));
  38950. }
  38951. case "ElementNode":
  38952. {
  38953. // TODO: make it whitespace sensitive
  38954. const bim = isNextNodeOfSomeType$1(path, ["ElementNode"]) ? hardline$b : "";
  38955. if (isVoid$1(n)) {
  38956. return concat$h([group$f(printStartingTag(path, print)), bim]);
  38957. }
  38958. const isWhitespaceOnly = n.children.every(n => isWhitespaceNode$1(n));
  38959. return concat$h([group$f(printStartingTag(path, print)), group$f(concat$h([isWhitespaceOnly ? "" : indent$b(printChildren(path, options, print)), n.children.length ? hardline$b : "", concat$h(["</", n.tag, ">"])])), bim]);
  38960. }
  38961. case "BlockStatement":
  38962. {
  38963. const pp = path.getParentNode(1);
  38964. const isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
  38965. if (isElseIf) {
  38966. return concat$h([printElseIfBlock(path, print), printProgram(path, print), printInverse(path, print)]);
  38967. }
  38968. return concat$h([printOpenBlock(path, print), group$f(concat$h([printProgram(path, print), printInverse(path, print), printCloseBlock(path, print)]))]);
  38969. }
  38970. case "ElementModifierStatement":
  38971. {
  38972. return group$f(concat$h(["{{", printPathAndParams(path, print), softline$8, "}}"]));
  38973. }
  38974. case "MustacheStatement":
  38975. {
  38976. const isParentOfSpecifiedTypes = isParentOfSomeType$1(path, ["AttrNode", "ConcatStatement"]);
  38977. const isChildOfElementNodeAndDoesNotHaveParams = isParentOfSomeType$1(path, ["ElementNode"]) && doesNotHaveHashParams(n) && doesNotHavePositionalParams(n);
  38978. const shouldBreakOpeningMustache = isParentOfSpecifiedTypes || isChildOfElementNodeAndDoesNotHaveParams;
  38979. return group$f(concat$h([printOpeningMustache(n), shouldBreakOpeningMustache ? indent$b(softline$8) : "", printPathAndParams(path, print), softline$8, printClosingMustache(n)]));
  38980. }
  38981. case "SubExpression":
  38982. {
  38983. return group$f(concat$h(["(", printSubExpressionPathAndParams(path, print), softline$8, ")"]));
  38984. }
  38985. case "AttrNode":
  38986. {
  38987. const isText = n.value.type === "TextNode";
  38988. const isEmptyText = isText && n.value.chars === ""; // If the text is empty and the value's loc start and end columns are the
  38989. // same, there is no value for this AttrNode and it should be printed
  38990. // without the `=""`. Example: `<img data-test>` -> `<img data-test>`
  38991. const isEmptyValue = isEmptyText && n.value.loc.start.column === n.value.loc.end.column;
  38992. if (isEmptyValue) {
  38993. return concat$h([n.name]);
  38994. }
  38995. const value = path.call(print, "value");
  38996. const quotedValue = isText ? printStringLiteral(value.parts.join(), options) : value;
  38997. return concat$h([n.name, "=", quotedValue]);
  38998. }
  38999. case "ConcatStatement":
  39000. {
  39001. const quote = options.singleQuote ? "'" : '"';
  39002. return concat$h([quote, ...path.map(partPath => print(partPath), "parts"), quote]);
  39003. }
  39004. case "Hash":
  39005. {
  39006. return concat$h([join$9(line$a, path.map(print, "pairs"))]);
  39007. }
  39008. case "HashPair":
  39009. {
  39010. return concat$h([n.key, "=", path.call(print, "value")]);
  39011. }
  39012. case "TextNode":
  39013. {
  39014. const maxLineBreaksToPreserve = 2;
  39015. const isFirstElement = !getPreviousNode$1(path);
  39016. const isLastElement = !getNextNode$1(path);
  39017. const isWhitespaceOnly = !/\S/.test(n.chars);
  39018. const lineBreaksCount = countNewLines(n.chars);
  39019. let leadingLineBreaksCount = countLeadingNewLines(n.chars);
  39020. let trailingLineBreaksCount = countTrailingNewLines(n.chars);
  39021. if ((isFirstElement || isLastElement) && isWhitespaceOnly && isParentOfSomeType$1(path, ["Block", "ElementNode", "Template"])) {
  39022. return "";
  39023. }
  39024. if (isWhitespaceOnly && lineBreaksCount) {
  39025. leadingLineBreaksCount = Math.min(lineBreaksCount, maxLineBreaksToPreserve);
  39026. trailingLineBreaksCount = 0;
  39027. } else {
  39028. if (isNextNodeOfSomeType$1(path, ["BlockStatement", "ElementNode"])) {
  39029. trailingLineBreaksCount = Math.max(trailingLineBreaksCount, 1);
  39030. }
  39031. if (isPreviousNodeOfSomeType$1(path, ["BlockStatement", "ElementNode"])) {
  39032. leadingLineBreaksCount = Math.max(leadingLineBreaksCount, 1);
  39033. }
  39034. }
  39035. const inAttrNode = path.stack.includes("attributes");
  39036. if (inAttrNode) {
  39037. // TODO: format style and srcset attributes
  39038. // and cleanup concat that is not necessary
  39039. if (!isInAttributeOfName(path, "class")) {
  39040. return concat$h([n.chars]);
  39041. }
  39042. let leadingSpace = "";
  39043. let trailingSpace = "";
  39044. if (isParentOfSomeType$1(path, ["ConcatStatement"])) {
  39045. if (isPreviousNodeOfSomeType$1(path, ["MustacheStatement"])) {
  39046. leadingSpace = " ";
  39047. }
  39048. if (isNextNodeOfSomeType$1(path, ["MustacheStatement"])) {
  39049. trailingSpace = " ";
  39050. }
  39051. }
  39052. return concat$h([...generateHardlines(leadingLineBreaksCount, maxLineBreaksToPreserve), n.chars.replace(/^\s+/g, leadingSpace).replace(/\s+$/, trailingSpace), ...generateHardlines(trailingLineBreaksCount, maxLineBreaksToPreserve)]);
  39053. }
  39054. let leadingSpace = "";
  39055. let trailingSpace = "";
  39056. if (trailingLineBreaksCount === 0 && isNextNodeOfSomeType$1(path, ["MustacheStatement"])) {
  39057. trailingSpace = " ";
  39058. }
  39059. if (leadingLineBreaksCount === 0 && isPreviousNodeOfSomeType$1(path, ["MustacheStatement"])) {
  39060. leadingSpace = " ";
  39061. }
  39062. if (isFirstElement) {
  39063. leadingLineBreaksCount = 0;
  39064. leadingSpace = "";
  39065. }
  39066. if (isLastElement) {
  39067. trailingLineBreaksCount = 0;
  39068. trailingSpace = "";
  39069. }
  39070. let text = n.chars;
  39071. /* if `{{my-component}}` (or any text starting with a mustache)
  39072. * makes it to the TextNode,
  39073. * it means it was escaped,
  39074. * so let's print it escaped, ie.; `\{{my-component}}` */
  39075. if (text.startsWith("{{") && text.includes("}}")) {
  39076. text = "\\" + text;
  39077. }
  39078. return concat$h([...generateHardlines(leadingLineBreaksCount, maxLineBreaksToPreserve), text.replace(/^\s+/g, leadingSpace).replace(/\s+$/, trailingSpace), ...generateHardlines(trailingLineBreaksCount, maxLineBreaksToPreserve)]);
  39079. }
  39080. case "MustacheCommentStatement":
  39081. {
  39082. const dashes = n.value.includes("}}") ? "--" : "";
  39083. return concat$h(["{{!", dashes, n.value, dashes, "}}"]);
  39084. }
  39085. case "PathExpression":
  39086. {
  39087. return n.original;
  39088. }
  39089. case "BooleanLiteral":
  39090. {
  39091. return String(n.value);
  39092. }
  39093. case "CommentStatement":
  39094. {
  39095. return concat$h(["<!--", n.value, "-->"]);
  39096. }
  39097. case "StringLiteral":
  39098. {
  39099. return printStringLiteral(n.value, options);
  39100. }
  39101. case "NumberLiteral":
  39102. {
  39103. return String(n.value);
  39104. }
  39105. case "UndefinedLiteral":
  39106. {
  39107. return "undefined";
  39108. }
  39109. case "NullLiteral":
  39110. {
  39111. return "null";
  39112. }
  39113. /* istanbul ignore next */
  39114. default:
  39115. throw new Error("unknown glimmer type: " + JSON.stringify(n.type));
  39116. }
  39117. }
  39118. /* ElementNode print helpers */
  39119. function printStartingTag(path, print) {
  39120. const node = path.getValue();
  39121. return concat$h(["<", node.tag, printAttributesLike(path, print), printBlockParams(node), printStartingTagEndMarker(node)]);
  39122. }
  39123. function printAttributesLike(path, print) {
  39124. const node = path.getValue();
  39125. return indent$b(concat$h([node.attributes.length ? line$a : "", join$9(line$a, path.map(print, "attributes")), node.modifiers.length ? line$a : "", join$9(line$a, path.map(print, "modifiers")), node.comments.length ? line$a : "", join$9(line$a, path.map(print, "comments"))]));
  39126. }
  39127. function printChildren(path, options, print) {
  39128. return concat$h(path.map((childPath, childIndex) => {
  39129. if (childIndex === 0) {
  39130. return concat$h([softline$8, print(childPath, options, print)]);
  39131. }
  39132. return print(childPath, options, print);
  39133. }, "children"));
  39134. }
  39135. function printStartingTagEndMarker(node) {
  39136. if (isVoid$1(node)) {
  39137. return ifBreak$6(concat$h([softline$8, "/>"]), concat$h([" />", softline$8]));
  39138. }
  39139. return ifBreak$6(concat$h([softline$8, ">"]), ">");
  39140. }
  39141. /* MustacheStatement print helpers */
  39142. function printOpeningMustache(node) {
  39143. const mustache = node.escaped === false ? "{{{" : "{{";
  39144. const strip = node.strip && node.strip.open ? "~" : "";
  39145. return concat$h([mustache, strip]);
  39146. }
  39147. function printClosingMustache(node) {
  39148. const mustache = node.escaped === false ? "}}}" : "}}";
  39149. const strip = node.strip && node.strip.close ? "~" : "";
  39150. return concat$h([strip, mustache]);
  39151. }
  39152. /* BlockStatement print helpers */
  39153. function printOpeningBlockOpeningMustache(node) {
  39154. const opening = printOpeningMustache(node);
  39155. const strip = node.openStrip.open ? "~" : "";
  39156. return concat$h([opening, strip, "#"]);
  39157. }
  39158. function printOpeningBlockClosingMustache(node) {
  39159. const closing = printClosingMustache(node);
  39160. const strip = node.openStrip.close ? "~" : "";
  39161. return concat$h([strip, closing]);
  39162. }
  39163. function printClosingBlockOpeningMustache(node) {
  39164. const opening = printOpeningMustache(node);
  39165. const strip = node.closeStrip.open ? "~" : "";
  39166. return concat$h([opening, strip, "/"]);
  39167. }
  39168. function printClosingBlockClosingMustache(node) {
  39169. const closing = printClosingMustache(node);
  39170. const strip = node.closeStrip.close ? "~" : "";
  39171. return concat$h([strip, closing]);
  39172. }
  39173. function printInverseBlockOpeningMustache(node) {
  39174. const opening = printOpeningMustache(node);
  39175. const strip = node.inverseStrip.open ? "~" : "";
  39176. return concat$h([opening, strip]);
  39177. }
  39178. function printInverseBlockClosingMustache(node) {
  39179. const closing = printClosingMustache(node);
  39180. const strip = node.inverseStrip.close ? "~" : "";
  39181. return concat$h([strip, closing]);
  39182. }
  39183. function printOpenBlock(path, print) {
  39184. const node = path.getValue();
  39185. return group$f(concat$h([printOpeningBlockOpeningMustache(node), printPathAndParams(path, print), printBlockParams(node.program), softline$8, printOpeningBlockClosingMustache(node)]));
  39186. }
  39187. function printElseBlock(node) {
  39188. return concat$h([hardline$b, printInverseBlockOpeningMustache(node), "else", printInverseBlockClosingMustache(node)]);
  39189. }
  39190. function printElseIfBlock(path, print) {
  39191. const parentNode = path.getParentNode(1);
  39192. return concat$h([printInverseBlockOpeningMustache(parentNode), "else ", printPathAndParams(path, print), printInverseBlockClosingMustache(parentNode)]);
  39193. }
  39194. function printCloseBlock(path, print) {
  39195. const node = path.getValue();
  39196. return concat$h([blockStatementHasOnlyWhitespaceInProgram(node) ? softline$8 : hardline$b, printClosingBlockOpeningMustache(node), path.call(print, "path"), printClosingBlockClosingMustache(node)]);
  39197. }
  39198. function blockStatementHasOnlyWhitespaceInProgram(node) {
  39199. return isNodeOfSomeType$1(node, ["BlockStatement"]) && node.program.body.every(n => isWhitespaceNode$1(n));
  39200. }
  39201. function blockStatementHasElseIf(node) {
  39202. return blockStatementHasElse(node) && node.inverse.body.length === 1 && isNodeOfSomeType$1(node.inverse.body[0], ["BlockStatement"]) && node.inverse.body[0].path.parts[0] === "if";
  39203. }
  39204. function blockStatementHasElse(node) {
  39205. return isNodeOfSomeType$1(node, ["BlockStatement"]) && node.inverse;
  39206. }
  39207. function printProgram(path, print) {
  39208. const node = path.getValue();
  39209. if (blockStatementHasOnlyWhitespaceInProgram(node)) {
  39210. return "";
  39211. }
  39212. const program = path.call(print, "program");
  39213. return indent$b(concat$h([hardline$b, program]));
  39214. }
  39215. function printInverse(path, print) {
  39216. const node = path.getValue();
  39217. const inverse = path.call(print, "inverse");
  39218. const parts = concat$h([hardline$b, inverse]);
  39219. if (blockStatementHasElseIf(node)) {
  39220. return parts;
  39221. }
  39222. if (blockStatementHasElse(node)) {
  39223. return concat$h([printElseBlock(node), indent$b(parts)]);
  39224. }
  39225. return "";
  39226. }
  39227. /* TextNode print helpers */
  39228. function isInAttributeOfName(path, type) {
  39229. return isParentOfSomeType$1(path, ["AttrNode"]) && path.getParentNode().name.toLowerCase() === type || isParentOfSomeType$1(path, ["ConcatStatement"]) && path.getParentNode(1).name.toLowerCase() === type;
  39230. }
  39231. function countNewLines(string) {
  39232. /* istanbul ignore next */
  39233. string = typeof string === "string" ? string : "";
  39234. return string.split("\n").length - 1;
  39235. }
  39236. function countLeadingNewLines(string) {
  39237. /* istanbul ignore next */
  39238. string = typeof string === "string" ? string : "";
  39239. const newLines = (string.match(/^([^\S\n\r]*[\n\r])+/g) || [])[0] || "";
  39240. return countNewLines(newLines);
  39241. }
  39242. function countTrailingNewLines(string) {
  39243. /* istanbul ignore next */
  39244. string = typeof string === "string" ? string : "";
  39245. const newLines = (string.match(/([\n\r][^\S\n\r]*)+$/g) || [])[0] || "";
  39246. return countNewLines(newLines);
  39247. }
  39248. function generateHardlines(number = 0, max = 0) {
  39249. return new Array(Math.min(number, max)).fill(hardline$b);
  39250. }
  39251. /* StringLiteral print helpers */
  39252. /**
  39253. * Prints a string literal with the correct surrounding quotes based on
  39254. * `options.singleQuote` and the number of escaped quotes contained in
  39255. * the string literal. This function is the glimmer equivalent of `printString`
  39256. * in `common/util`, but has differences because of the way escaped characters
  39257. * are treated in hbs string literals.
  39258. * @param {string} stringLiteral - the string literal value
  39259. * @param {object} options - the prettier options object
  39260. */
  39261. function printStringLiteral(stringLiteral, options) {
  39262. const double = {
  39263. quote: '"',
  39264. regex: /"/g
  39265. };
  39266. const single = {
  39267. quote: "'",
  39268. regex: /'/g
  39269. };
  39270. const preferred = options.singleQuote ? single : double;
  39271. const alternate = preferred === single ? double : single;
  39272. let shouldUseAlternateQuote = false; // If `stringLiteral` contains at least one of the quote preferred for
  39273. // enclosing the string, we might want to enclose with the alternate quote
  39274. // instead, to minimize the number of escaped quotes.
  39275. if (stringLiteral.includes(preferred.quote) || stringLiteral.includes(alternate.quote)) {
  39276. const numPreferredQuotes = (stringLiteral.match(preferred.regex) || []).length;
  39277. const numAlternateQuotes = (stringLiteral.match(alternate.regex) || []).length;
  39278. shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
  39279. }
  39280. const enclosingQuote = shouldUseAlternateQuote ? alternate : preferred;
  39281. const escapedStringLiteral = stringLiteral.replace(enclosingQuote.regex, `\\${enclosingQuote.quote}`);
  39282. return concat$h([enclosingQuote.quote, escapedStringLiteral, enclosingQuote.quote]);
  39283. }
  39284. /* SubExpression print helpers */
  39285. function printSubExpressionPathAndParams(path, print) {
  39286. const p = printPath(path, print);
  39287. const params = printParams(path, print);
  39288. if (!params) {
  39289. return p;
  39290. }
  39291. return indent$b(concat$h([p, line$a, group$f(params)]));
  39292. }
  39293. /* misc. print helpers */
  39294. function printPathAndParams(path, print) {
  39295. const p = printPath(path, print);
  39296. const params = printParams(path, print);
  39297. if (!params) {
  39298. return p;
  39299. }
  39300. return indent$b(group$f(concat$h([p, line$a, params])));
  39301. }
  39302. function printPath(path, print) {
  39303. return path.call(print, "path");
  39304. }
  39305. function printParams(path, print) {
  39306. const node = path.getValue();
  39307. const parts = [];
  39308. if (node.params.length) {
  39309. const params = path.map(print, "params");
  39310. parts.push(...params);
  39311. }
  39312. if (node.hash && node.hash.pairs.length > 0) {
  39313. const hash = path.call(print, "hash");
  39314. parts.push(hash);
  39315. }
  39316. if (!parts.length) {
  39317. return "";
  39318. }
  39319. return join$9(line$a, parts);
  39320. }
  39321. function printBlockParams(node) {
  39322. if (!node || !node.blockParams.length) {
  39323. return "";
  39324. }
  39325. return concat$h([" as |", node.blockParams.join(" "), "|"]);
  39326. }
  39327. /* istanbul ignore next
  39328. https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/compiler/lib/location.ts#L5-L29
  39329. */
  39330. function locationToOffset(source, line, column) {
  39331. let seenLines = 0;
  39332. let seenChars = 0; // eslint-disable-next-line no-constant-condition
  39333. while (true) {
  39334. if (seenChars === source.length) {
  39335. return null;
  39336. }
  39337. let nextLine = source.indexOf("\n", seenChars);
  39338. if (nextLine === -1) {
  39339. nextLine = source.length;
  39340. }
  39341. if (seenLines === line) {
  39342. if (seenChars + column > nextLine) {
  39343. return null;
  39344. }
  39345. return seenChars + column;
  39346. } else if (nextLine === -1) {
  39347. return null;
  39348. }
  39349. seenLines += 1;
  39350. seenChars = nextLine + 1;
  39351. }
  39352. }
  39353. function doesNotHaveHashParams(node) {
  39354. return node.hash.pairs.length === 0;
  39355. }
  39356. function doesNotHavePositionalParams(node) {
  39357. return node.params.length === 0;
  39358. }
  39359. var printerGlimmer = {
  39360. print: print$2,
  39361. massageAstNode: clean$3
  39362. };
  39363. var name$d = "Handlebars";
  39364. var type$b = "markup";
  39365. var group$g = "HTML";
  39366. var aliases$3 = [
  39367. "hbs",
  39368. "htmlbars"
  39369. ];
  39370. var extensions$b = [
  39371. ".handlebars",
  39372. ".hbs"
  39373. ];
  39374. var tmScope$b = "text.html.handlebars";
  39375. var aceMode$b = "handlebars";
  39376. var languageId$b = 155;
  39377. var Handlebars = {
  39378. name: name$d,
  39379. type: type$b,
  39380. group: group$g,
  39381. aliases: aliases$3,
  39382. extensions: extensions$b,
  39383. tmScope: tmScope$b,
  39384. aceMode: aceMode$b,
  39385. languageId: languageId$b
  39386. };
  39387. var Handlebars$1 = /*#__PURE__*/Object.freeze({
  39388. __proto__: null,
  39389. name: name$d,
  39390. type: type$b,
  39391. group: group$g,
  39392. aliases: aliases$3,
  39393. extensions: extensions$b,
  39394. tmScope: tmScope$b,
  39395. aceMode: aceMode$b,
  39396. languageId: languageId$b,
  39397. 'default': Handlebars
  39398. });
  39399. var require$$0$4 = getCjsExportFromNamespace(Handlebars$1);
  39400. const languages$2 = [createLanguage(require$$0$4, () => ({
  39401. since: null,
  39402. // unreleased
  39403. parsers: ["glimmer"],
  39404. vscodeLanguageIds: ["handlebars"]
  39405. }))];
  39406. const printers$2 = {
  39407. glimmer: printerGlimmer
  39408. };
  39409. const parsers$2 = {
  39410. get glimmer() {
  39411. return require("./parser-glimmer").parsers.glimmer;
  39412. }
  39413. };
  39414. var languageHandlebars = {
  39415. languages: languages$2,
  39416. printers: printers$2,
  39417. parsers: parsers$2
  39418. };
  39419. function hasPragma$2(text) {
  39420. return /^\s*#[^\S\n]*@(format|prettier)\s*(\n|$)/.test(text);
  39421. }
  39422. function insertPragma$4(text) {
  39423. return "# @format\n\n" + text;
  39424. }
  39425. var pragma$2 = {
  39426. hasPragma: hasPragma$2,
  39427. insertPragma: insertPragma$4
  39428. };
  39429. const {
  39430. concat: concat$i,
  39431. join: join$a,
  39432. hardline: hardline$c,
  39433. line: line$b,
  39434. softline: softline$9,
  39435. group: group$h,
  39436. indent: indent$c,
  39437. ifBreak: ifBreak$7
  39438. } = document.builders;
  39439. const {
  39440. hasIgnoreComment: hasIgnoreComment$4,
  39441. isNextLineEmpty: isNextLineEmpty$6
  39442. } = util;
  39443. const {
  39444. insertPragma: insertPragma$5
  39445. } = pragma$2;
  39446. function genericPrint$3(path, options, print) {
  39447. const n = path.getValue();
  39448. if (!n) {
  39449. return "";
  39450. }
  39451. if (typeof n === "string") {
  39452. return n;
  39453. }
  39454. switch (n.kind) {
  39455. case "Document":
  39456. {
  39457. const parts = [];
  39458. path.map((pathChild, index) => {
  39459. parts.push(concat$i([pathChild.call(print)]));
  39460. if (index !== n.definitions.length - 1) {
  39461. parts.push(hardline$c);
  39462. if (isNextLineEmpty$6(options.originalText, pathChild.getValue(), options.locEnd)) {
  39463. parts.push(hardline$c);
  39464. }
  39465. }
  39466. }, "definitions");
  39467. return concat$i([concat$i(parts), hardline$c]);
  39468. }
  39469. case "OperationDefinition":
  39470. {
  39471. const hasOperation = options.originalText[options.locStart(n)] !== "{";
  39472. const hasName = !!n.name;
  39473. return concat$i([hasOperation ? n.operation : "", hasOperation && hasName ? concat$i([" ", path.call(print, "name")]) : "", n.variableDefinitions && n.variableDefinitions.length ? group$h(concat$i(["(", indent$c(concat$i([softline$9, join$a(concat$i([ifBreak$7("", ", "), softline$9]), path.map(print, "variableDefinitions"))])), softline$9, ")"])) : "", printDirectives(path, print, n), n.selectionSet ? !hasOperation && !hasName ? "" : " " : "", path.call(print, "selectionSet")]);
  39474. }
  39475. case "FragmentDefinition":
  39476. {
  39477. return concat$i(["fragment ", path.call(print, "name"), n.variableDefinitions && n.variableDefinitions.length ? group$h(concat$i(["(", indent$c(concat$i([softline$9, join$a(concat$i([ifBreak$7("", ", "), softline$9]), path.map(print, "variableDefinitions"))])), softline$9, ")"])) : "", " on ", path.call(print, "typeCondition"), printDirectives(path, print, n), " ", path.call(print, "selectionSet")]);
  39478. }
  39479. case "SelectionSet":
  39480. {
  39481. return concat$i(["{", indent$c(concat$i([hardline$c, join$a(hardline$c, path.call(selectionsPath => printSequence(selectionsPath, options, print), "selections"))])), hardline$c, "}"]);
  39482. }
  39483. case "Field":
  39484. {
  39485. return group$h(concat$i([n.alias ? concat$i([path.call(print, "alias"), ": "]) : "", path.call(print, "name"), n.arguments.length > 0 ? group$h(concat$i(["(", indent$c(concat$i([softline$9, join$a(concat$i([ifBreak$7("", ", "), softline$9]), path.call(argsPath => printSequence(argsPath, options, print), "arguments"))])), softline$9, ")"])) : "", printDirectives(path, print, n), n.selectionSet ? " " : "", path.call(print, "selectionSet")]));
  39486. }
  39487. case "Name":
  39488. {
  39489. return n.value;
  39490. }
  39491. case "StringValue":
  39492. {
  39493. if (n.block) {
  39494. return concat$i(['"""', hardline$c, join$a(hardline$c, n.value.replace(/"""/g, "\\$&").split("\n")), hardline$c, '"""']);
  39495. }
  39496. return concat$i(['"', n.value.replace(/["\\]/g, "\\$&").replace(/\n/g, "\\n"), '"']);
  39497. }
  39498. case "IntValue":
  39499. case "FloatValue":
  39500. case "EnumValue":
  39501. {
  39502. return n.value;
  39503. }
  39504. case "BooleanValue":
  39505. {
  39506. return n.value ? "true" : "false";
  39507. }
  39508. case "NullValue":
  39509. {
  39510. return "null";
  39511. }
  39512. case "Variable":
  39513. {
  39514. return concat$i(["$", path.call(print, "name")]);
  39515. }
  39516. case "ListValue":
  39517. {
  39518. return group$h(concat$i(["[", indent$c(concat$i([softline$9, join$a(concat$i([ifBreak$7("", ", "), softline$9]), path.map(print, "values"))])), softline$9, "]"]));
  39519. }
  39520. case "ObjectValue":
  39521. {
  39522. return group$h(concat$i(["{", options.bracketSpacing && n.fields.length > 0 ? " " : "", indent$c(concat$i([softline$9, join$a(concat$i([ifBreak$7("", ", "), softline$9]), path.map(print, "fields"))])), softline$9, ifBreak$7("", options.bracketSpacing && n.fields.length > 0 ? " " : ""), "}"]));
  39523. }
  39524. case "ObjectField":
  39525. case "Argument":
  39526. {
  39527. return concat$i([path.call(print, "name"), ": ", path.call(print, "value")]);
  39528. }
  39529. case "Directive":
  39530. {
  39531. return concat$i(["@", path.call(print, "name"), n.arguments.length > 0 ? group$h(concat$i(["(", indent$c(concat$i([softline$9, join$a(concat$i([ifBreak$7("", ", "), softline$9]), path.call(argsPath => printSequence(argsPath, options, print), "arguments"))])), softline$9, ")"])) : ""]);
  39532. }
  39533. case "NamedType":
  39534. {
  39535. return path.call(print, "name");
  39536. }
  39537. case "VariableDefinition":
  39538. {
  39539. return concat$i([path.call(print, "variable"), ": ", path.call(print, "type"), n.defaultValue ? concat$i([" = ", path.call(print, "defaultValue")]) : "", printDirectives(path, print, n)]);
  39540. }
  39541. case "ObjectTypeExtension":
  39542. case "ObjectTypeDefinition":
  39543. {
  39544. return concat$i([path.call(print, "description"), n.description ? hardline$c : "", n.kind === "ObjectTypeExtension" ? "extend " : "", "type ", path.call(print, "name"), n.interfaces.length > 0 ? concat$i([" implements ", concat$i(printInterfaces(path, options, print))]) : "", printDirectives(path, print, n), n.fields.length > 0 ? concat$i([" {", indent$c(concat$i([hardline$c, join$a(hardline$c, path.call(fieldsPath => printSequence(fieldsPath, options, print), "fields"))])), hardline$c, "}"]) : ""]);
  39545. }
  39546. case "FieldDefinition":
  39547. {
  39548. return concat$i([path.call(print, "description"), n.description ? hardline$c : "", path.call(print, "name"), n.arguments.length > 0 ? group$h(concat$i(["(", indent$c(concat$i([softline$9, join$a(concat$i([ifBreak$7("", ", "), softline$9]), path.call(argsPath => printSequence(argsPath, options, print), "arguments"))])), softline$9, ")"])) : "", ": ", path.call(print, "type"), printDirectives(path, print, n)]);
  39549. }
  39550. case "DirectiveDefinition":
  39551. {
  39552. return concat$i([path.call(print, "description"), n.description ? hardline$c : "", "directive ", "@", path.call(print, "name"), n.arguments.length > 0 ? group$h(concat$i(["(", indent$c(concat$i([softline$9, join$a(concat$i([ifBreak$7("", ", "), softline$9]), path.call(argsPath => printSequence(argsPath, options, print), "arguments"))])), softline$9, ")"])) : "", n.repeatable ? " repeatable" : "", concat$i([" on ", join$a(" | ", path.map(print, "locations"))])]);
  39553. }
  39554. case "EnumTypeExtension":
  39555. case "EnumTypeDefinition":
  39556. {
  39557. return concat$i([path.call(print, "description"), n.description ? hardline$c : "", n.kind === "EnumTypeExtension" ? "extend " : "", "enum ", path.call(print, "name"), printDirectives(path, print, n), n.values.length > 0 ? concat$i([" {", indent$c(concat$i([hardline$c, join$a(hardline$c, path.call(valuesPath => printSequence(valuesPath, options, print), "values"))])), hardline$c, "}"]) : ""]);
  39558. }
  39559. case "EnumValueDefinition":
  39560. {
  39561. return concat$i([path.call(print, "description"), n.description ? hardline$c : "", path.call(print, "name"), printDirectives(path, print, n)]);
  39562. }
  39563. case "InputValueDefinition":
  39564. {
  39565. return concat$i([path.call(print, "description"), n.description ? n.description.block ? hardline$c : line$b : "", path.call(print, "name"), ": ", path.call(print, "type"), n.defaultValue ? concat$i([" = ", path.call(print, "defaultValue")]) : "", printDirectives(path, print, n)]);
  39566. }
  39567. case "InputObjectTypeExtension":
  39568. case "InputObjectTypeDefinition":
  39569. {
  39570. return concat$i([path.call(print, "description"), n.description ? hardline$c : "", n.kind === "InputObjectTypeExtension" ? "extend " : "", "input ", path.call(print, "name"), printDirectives(path, print, n), n.fields.length > 0 ? concat$i([" {", indent$c(concat$i([hardline$c, join$a(hardline$c, path.call(fieldsPath => printSequence(fieldsPath, options, print), "fields"))])), hardline$c, "}"]) : ""]);
  39571. }
  39572. case "SchemaDefinition":
  39573. {
  39574. return concat$i(["schema", printDirectives(path, print, n), " {", n.operationTypes.length > 0 ? indent$c(concat$i([hardline$c, join$a(hardline$c, path.call(opsPath => printSequence(opsPath, options, print), "operationTypes"))])) : "", hardline$c, "}"]);
  39575. }
  39576. case "OperationTypeDefinition":
  39577. {
  39578. return concat$i([path.call(print, "operation"), ": ", path.call(print, "type")]);
  39579. }
  39580. case "InterfaceTypeExtension":
  39581. case "InterfaceTypeDefinition":
  39582. {
  39583. return concat$i([path.call(print, "description"), n.description ? hardline$c : "", n.kind === "InterfaceTypeExtension" ? "extend " : "", "interface ", path.call(print, "name"), n.interfaces.length > 0 ? concat$i([" implements ", concat$i(printInterfaces(path, options, print))]) : "", printDirectives(path, print, n), n.fields.length > 0 ? concat$i([" {", indent$c(concat$i([hardline$c, join$a(hardline$c, path.call(fieldsPath => printSequence(fieldsPath, options, print), "fields"))])), hardline$c, "}"]) : ""]);
  39584. }
  39585. case "FragmentSpread":
  39586. {
  39587. return concat$i(["...", path.call(print, "name"), printDirectives(path, print, n)]);
  39588. }
  39589. case "InlineFragment":
  39590. {
  39591. return concat$i(["...", n.typeCondition ? concat$i([" on ", path.call(print, "typeCondition")]) : "", printDirectives(path, print, n), " ", path.call(print, "selectionSet")]);
  39592. }
  39593. case "UnionTypeExtension":
  39594. case "UnionTypeDefinition":
  39595. {
  39596. return group$h(concat$i([path.call(print, "description"), n.description ? hardline$c : "", group$h(concat$i([n.kind === "UnionTypeExtension" ? "extend " : "", "union ", path.call(print, "name"), printDirectives(path, print, n), n.types.length > 0 ? concat$i([" =", ifBreak$7("", " "), indent$c(concat$i([ifBreak$7(concat$i([line$b, " "])), join$a(concat$i([line$b, "| "]), path.map(print, "types"))]))]) : ""]))]));
  39597. }
  39598. case "ScalarTypeExtension":
  39599. case "ScalarTypeDefinition":
  39600. {
  39601. return concat$i([path.call(print, "description"), n.description ? hardline$c : "", n.kind === "ScalarTypeExtension" ? "extend " : "", "scalar ", path.call(print, "name"), printDirectives(path, print, n)]);
  39602. }
  39603. case "NonNullType":
  39604. {
  39605. return concat$i([path.call(print, "type"), "!"]);
  39606. }
  39607. case "ListType":
  39608. {
  39609. return concat$i(["[", path.call(print, "type"), "]"]);
  39610. }
  39611. default:
  39612. /* istanbul ignore next */
  39613. throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
  39614. }
  39615. }
  39616. function printDirectives(path, print, n) {
  39617. if (n.directives.length === 0) {
  39618. return "";
  39619. }
  39620. const printed = join$a(line$b, path.map(print, "directives"));
  39621. if (n.kind === "FragmentDefinition" || n.kind === "OperationDefinition") {
  39622. return group$h(concat$i([line$b, printed]));
  39623. }
  39624. return concat$i([" ", group$h(indent$c(concat$i([softline$9, printed])))]);
  39625. }
  39626. function printSequence(sequencePath, options, print) {
  39627. const count = sequencePath.getValue().length;
  39628. return sequencePath.map((path, i) => {
  39629. const printed = print(path);
  39630. if (isNextLineEmpty$6(options.originalText, path.getValue(), options.locEnd) && i < count - 1) {
  39631. return concat$i([printed, hardline$c]);
  39632. }
  39633. return printed;
  39634. });
  39635. }
  39636. function canAttachComment$1(node) {
  39637. return node.kind && node.kind !== "Comment";
  39638. }
  39639. function printComment$2(commentPath) {
  39640. const comment = commentPath.getValue();
  39641. if (comment.kind === "Comment") {
  39642. return "#" + comment.value.trimEnd();
  39643. }
  39644. /* istanbul ignore next */
  39645. throw new Error("Not a comment: " + JSON.stringify(comment));
  39646. }
  39647. function printInterfaces(path, options, print) {
  39648. const node = path.getNode();
  39649. const parts = [];
  39650. const {
  39651. interfaces
  39652. } = node;
  39653. const printed = path.map(node => print(node), "interfaces");
  39654. for (let index = 0; index < interfaces.length; index++) {
  39655. const interfaceNode = interfaces[index];
  39656. parts.push(printed[index]);
  39657. const nextInterfaceNode = interfaces[index + 1];
  39658. if (nextInterfaceNode) {
  39659. const textBetween = options.originalText.slice(interfaceNode.loc.end, nextInterfaceNode.loc.start);
  39660. const hasComment = textBetween.includes("#");
  39661. const separator = textBetween.replace(/#.*/g, "").trim();
  39662. parts.push(separator === "," ? "," : " &");
  39663. parts.push(hasComment ? line$b : " ");
  39664. }
  39665. }
  39666. return parts;
  39667. }
  39668. function clean$4(node, newNode
  39669. /*, parent*/
  39670. ) {
  39671. delete newNode.loc;
  39672. delete newNode.comments;
  39673. }
  39674. var printerGraphql = {
  39675. print: genericPrint$3,
  39676. massageAstNode: clean$4,
  39677. hasPrettierIgnore: hasIgnoreComment$4,
  39678. insertPragma: insertPragma$5,
  39679. printComment: printComment$2,
  39680. canAttachComment: canAttachComment$1
  39681. };
  39682. var options$4 = {
  39683. bracketSpacing: commonOptions.bracketSpacing
  39684. };
  39685. var name$e = "GraphQL";
  39686. var type$c = "data";
  39687. var extensions$c = [
  39688. ".graphql",
  39689. ".gql",
  39690. ".graphqls"
  39691. ];
  39692. var tmScope$c = "source.graphql";
  39693. var aceMode$c = "text";
  39694. var languageId$c = 139;
  39695. var GraphQL = {
  39696. name: name$e,
  39697. type: type$c,
  39698. extensions: extensions$c,
  39699. tmScope: tmScope$c,
  39700. aceMode: aceMode$c,
  39701. languageId: languageId$c
  39702. };
  39703. var GraphQL$1 = /*#__PURE__*/Object.freeze({
  39704. __proto__: null,
  39705. name: name$e,
  39706. type: type$c,
  39707. extensions: extensions$c,
  39708. tmScope: tmScope$c,
  39709. aceMode: aceMode$c,
  39710. languageId: languageId$c,
  39711. 'default': GraphQL
  39712. });
  39713. var require$$0$5 = getCjsExportFromNamespace(GraphQL$1);
  39714. const languages$3 = [createLanguage(require$$0$5, () => ({
  39715. since: "1.5.0",
  39716. parsers: ["graphql"],
  39717. vscodeLanguageIds: ["graphql"]
  39718. }))];
  39719. const printers$3 = {
  39720. graphql: printerGraphql
  39721. };
  39722. const parsers$3 = {
  39723. get graphql() {
  39724. return require("./parser-graphql").parsers.graphql;
  39725. }
  39726. };
  39727. var languageGraphql = {
  39728. languages: languages$3,
  39729. options: options$4,
  39730. printers: printers$3,
  39731. parsers: parsers$3
  39732. };
  39733. var json = {
  39734. "cjkPattern": "(?:[\\u02ea-\\u02eb\\u1100-\\u11ff\\u2e80-\\u2e99\\u2e9b-\\u2ef3\\u2f00-\\u2fd5\\u3000-\\u303f\\u3041-\\u3096\\u3099-\\u309f\\u30a1-\\u30fa\\u30fc-\\u30ff\\u3105-\\u312f\\u3131-\\u318e\\u3190-\\u3191\\u3196-\\u31ba\\u31c0-\\u31e3\\u31f0-\\u321e\\u322a-\\u3247\\u3260-\\u327e\\u328a-\\u32b0\\u32c0-\\u32cb\\u32d0-\\u3370\\u337b-\\u337f\\u33e0-\\u33fe\\u3400-\\u4db5\\u4e00-\\u9fef\\ua960-\\ua97c\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\uf900-\\ufa6d\\ufa70-\\ufad9\\ufe10-\\ufe1f\\ufe30-\\ufe6f\\uff00-\\uffef]|[\\ud840-\\ud868\\ud86a-\\ud86c\\ud86f-\\ud872\\ud874-\\ud879][\\udc00-\\udfff]|\\ud82c[\\udc00-\\udd1e\\udd50-\\udd52\\udd64-\\udd67]|\\ud83c[\\ude00\\ude50-\\ude51]|\\ud869[\\udc00-\\uded6\\udf00-\\udfff]|\\ud86d[\\udc00-\\udf34\\udf40-\\udfff]|\\ud86e[\\udc00-\\udc1d\\udc20-\\udfff]|\\ud873[\\udc00-\\udea1\\udeb0-\\udfff]|\\ud87a[\\udc00-\\udfe0]|\\ud87e[\\udc00-\\ude1d])(?:[\\ufe00-\\ufe0f]|\\udb40[\\udd00-\\uddef])?",
  39735. "kPattern": "[\\u1100-\\u11ff\\u3001-\\u3003\\u3008-\\u3011\\u3013-\\u301f\\u302e-\\u3030\\u3037\\u30fb\\u3131-\\u318e\\u3200-\\u321e\\u3260-\\u327e\\ua960-\\ua97c\\uac00-\\ud7a3\\ud7b0-\\ud7c6\\ud7cb-\\ud7fb\\ufe45-\\ufe46\\uff61-\\uff65\\uffa0-\\uffbe\\uffc2-\\uffc7\\uffca-\\uffcf\\uffd2-\\uffd7\\uffda-\\uffdc]",
  39736. "punctuationPattern": "[\\u0021-\\u002f\\u003a-\\u0040\\u005b-\\u0060\\u007b-\\u007e\\u00a1\\u00a7\\u00ab\\u00b6-\\u00b7\\u00bb\\u00bf\\u037e\\u0387\\u055a-\\u055f\\u0589-\\u058a\\u05be\\u05c0\\u05c3\\u05c6\\u05f3-\\u05f4\\u0609-\\u060a\\u060c-\\u060d\\u061b\\u061e-\\u061f\\u066a-\\u066d\\u06d4\\u0700-\\u070d\\u07f7-\\u07f9\\u0830-\\u083e\\u085e\\u0964-\\u0965\\u0970\\u09fd\\u0a76\\u0af0\\u0c77\\u0c84\\u0df4\\u0e4f\\u0e5a-\\u0e5b\\u0f04-\\u0f12\\u0f14\\u0f3a-\\u0f3d\\u0f85\\u0fd0-\\u0fd4\\u0fd9-\\u0fda\\u104a-\\u104f\\u10fb\\u1360-\\u1368\\u1400\\u166e\\u169b-\\u169c\\u16eb-\\u16ed\\u1735-\\u1736\\u17d4-\\u17d6\\u17d8-\\u17da\\u1800-\\u180a\\u1944-\\u1945\\u1a1e-\\u1a1f\\u1aa0-\\u1aa6\\u1aa8-\\u1aad\\u1b5a-\\u1b60\\u1bfc-\\u1bff\\u1c3b-\\u1c3f\\u1c7e-\\u1c7f\\u1cc0-\\u1cc7\\u1cd3\\u2010-\\u2027\\u2030-\\u2043\\u2045-\\u2051\\u2053-\\u205e\\u207d-\\u207e\\u208d-\\u208e\\u2308-\\u230b\\u2329-\\u232a\\u2768-\\u2775\\u27c5-\\u27c6\\u27e6-\\u27ef\\u2983-\\u2998\\u29d8-\\u29db\\u29fc-\\u29fd\\u2cf9-\\u2cfc\\u2cfe-\\u2cff\\u2d70\\u2e00-\\u2e2e\\u2e30-\\u2e4f\\u3001-\\u3003\\u3008-\\u3011\\u3014-\\u301f\\u3030\\u303d\\u30a0\\u30fb\\ua4fe-\\ua4ff\\ua60d-\\ua60f\\ua673\\ua67e\\ua6f2-\\ua6f7\\ua874-\\ua877\\ua8ce-\\ua8cf\\ua8f8-\\ua8fa\\ua8fc\\ua92e-\\ua92f\\ua95f\\ua9c1-\\ua9cd\\ua9de-\\ua9df\\uaa5c-\\uaa5f\\uaade-\\uaadf\\uaaf0-\\uaaf1\\uabeb\\ufd3e-\\ufd3f\\ufe10-\\ufe19\\ufe30-\\ufe52\\ufe54-\\ufe61\\ufe63\\ufe68\\ufe6a-\\ufe6b\\uff01-\\uff03\\uff05-\\uff0a\\uff0c-\\uff0f\\uff1a-\\uff1b\\uff1f-\\uff20\\uff3b-\\uff3d\\uff3f\\uff5b\\uff5d\\uff5f-\\uff65]|\\ud800[\\udd00-\\udd02\\udf9f\\udfd0]|\\ud801[\\udd6f]|\\ud802[\\udc57\\udd1f\\udd3f\\ude50-\\ude58\\ude7f\\udef0-\\udef6\\udf39-\\udf3f\\udf99-\\udf9c]|\\ud803[\\udf55-\\udf59]|\\ud804[\\udc47-\\udc4d\\udcbb-\\udcbc\\udcbe-\\udcc1\\udd40-\\udd43\\udd74-\\udd75\\uddc5-\\uddc8\\uddcd\\udddb\\udddd-\\udddf\\ude38-\\ude3d\\udea9]|\\ud805[\\udc4b-\\udc4f\\udc5b\\udc5d\\udcc6\\uddc1-\\uddd7\\ude41-\\ude43\\ude60-\\ude6c\\udf3c-\\udf3e]|\\ud806[\\udc3b\\udde2\\ude3f-\\ude46\\ude9a-\\ude9c\\ude9e-\\udea2]|\\ud807[\\udc41-\\udc45\\udc70-\\udc71\\udef7-\\udef8\\udfff]|\\ud809[\\udc70-\\udc74]|\\ud81a[\\ude6e-\\ude6f\\udef5\\udf37-\\udf3b\\udf44]|\\ud81b[\\ude97-\\ude9a\\udfe2]|\\ud82f[\\udc9f]|\\ud836[\\ude87-\\ude8b]|\\ud83a[\\udd5e-\\udd5f]"
  39737. };
  39738. const {
  39739. getLast: getLast$6
  39740. } = util;
  39741. const {
  39742. cjkPattern,
  39743. kPattern,
  39744. punctuationPattern
  39745. } = json;
  39746. const INLINE_NODE_TYPES = ["liquidNode", "inlineCode", "emphasis", "strong", "delete", "link", "linkReference", "image", "imageReference", "footnote", "footnoteReference", "sentence", "whitespace", "word", "break", "inlineMath"];
  39747. const INLINE_NODE_WRAPPER_TYPES = INLINE_NODE_TYPES.concat(["tableCell", "paragraph", "heading"]);
  39748. const kRegex = new RegExp(kPattern);
  39749. const punctuationRegex = new RegExp(punctuationPattern);
  39750. /**
  39751. * split text into whitespaces and words
  39752. * @param {string} text
  39753. * @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
  39754. */
  39755. function splitText(text, options) {
  39756. const KIND_NON_CJK = "non-cjk";
  39757. const KIND_CJ_LETTER = "cj-letter";
  39758. const KIND_K_LETTER = "k-letter";
  39759. const KIND_CJK_PUNCTUATION = "cjk-punctuation";
  39760. const nodes = [];
  39761. (options.proseWrap === "preserve" ? text : text.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")).split(/([\t\n ]+)/).forEach((token, index, tokens) => {
  39762. // whitespace
  39763. if (index % 2 === 1) {
  39764. nodes.push({
  39765. type: "whitespace",
  39766. value: /\n/.test(token) ? "\n" : " "
  39767. });
  39768. return;
  39769. } // word separated by whitespace
  39770. if ((index === 0 || index === tokens.length - 1) && token === "") {
  39771. return;
  39772. }
  39773. token.split(new RegExp(`(${cjkPattern})`)).forEach((innerToken, innerIndex, innerTokens) => {
  39774. if ((innerIndex === 0 || innerIndex === innerTokens.length - 1) && innerToken === "") {
  39775. return;
  39776. } // non-CJK word
  39777. if (innerIndex % 2 === 0) {
  39778. if (innerToken !== "") {
  39779. appendNode({
  39780. type: "word",
  39781. value: innerToken,
  39782. kind: KIND_NON_CJK,
  39783. hasLeadingPunctuation: punctuationRegex.test(innerToken[0]),
  39784. hasTrailingPunctuation: punctuationRegex.test(getLast$6(innerToken))
  39785. });
  39786. }
  39787. return;
  39788. } // CJK character
  39789. appendNode(punctuationRegex.test(innerToken) ? {
  39790. type: "word",
  39791. value: innerToken,
  39792. kind: KIND_CJK_PUNCTUATION,
  39793. hasLeadingPunctuation: true,
  39794. hasTrailingPunctuation: true
  39795. } : {
  39796. type: "word",
  39797. value: innerToken,
  39798. kind: kRegex.test(innerToken) ? KIND_K_LETTER : KIND_CJ_LETTER,
  39799. hasLeadingPunctuation: false,
  39800. hasTrailingPunctuation: false
  39801. });
  39802. });
  39803. });
  39804. return nodes;
  39805. function appendNode(node) {
  39806. const lastNode = getLast$6(nodes);
  39807. if (lastNode && lastNode.type === "word") {
  39808. if (lastNode.kind === KIND_NON_CJK && node.kind === KIND_CJ_LETTER && !lastNode.hasTrailingPunctuation || lastNode.kind === KIND_CJ_LETTER && node.kind === KIND_NON_CJK && !node.hasLeadingPunctuation) {
  39809. nodes.push({
  39810. type: "whitespace",
  39811. value: " "
  39812. });
  39813. } else if (!isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) && // disallow leading/trailing full-width whitespace
  39814. ![lastNode.value, node.value].some(value => /\u3000/.test(value))) {
  39815. nodes.push({
  39816. type: "whitespace",
  39817. value: ""
  39818. });
  39819. }
  39820. }
  39821. nodes.push(node);
  39822. function isBetween(kind1, kind2) {
  39823. return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1;
  39824. }
  39825. }
  39826. }
  39827. function getOrderedListItemInfo(orderListItem, originalText) {
  39828. const [, numberText, marker, leadingSpaces] = originalText.slice(orderListItem.position.start.offset, orderListItem.position.end.offset).match(/^\s*(\d+)(\.|\))(\s*)/);
  39829. return {
  39830. numberText,
  39831. marker,
  39832. leadingSpaces
  39833. };
  39834. }
  39835. function hasGitDiffFriendlyOrderedList(node, options) {
  39836. if (!node.ordered) {
  39837. return false;
  39838. }
  39839. if (node.children.length < 2) {
  39840. return false;
  39841. }
  39842. const firstNumber = Number(getOrderedListItemInfo(node.children[0], options.originalText).numberText);
  39843. const secondNumber = Number(getOrderedListItemInfo(node.children[1], options.originalText).numberText);
  39844. if (firstNumber === 0 && node.children.length > 2) {
  39845. const thirdNumber = Number(getOrderedListItemInfo(node.children[2], options.originalText).numberText);
  39846. return secondNumber === 1 && thirdNumber === 1;
  39847. }
  39848. return secondNumber === 1;
  39849. } // workaround for https://github.com/remarkjs/remark/issues/351
  39850. // leading and trailing newlines are stripped by remark
  39851. function getFencedCodeBlockValue(node, originalText) {
  39852. const text = originalText.trimEnd().slice(node.position.start.offset, node.position.end.offset);
  39853. const leadingSpaceCount = text.match(/^\s*/)[0].length;
  39854. const replaceRegex = new RegExp(`^\\s{0,${leadingSpaceCount}}`);
  39855. const lineContents = text.split("\n");
  39856. const markerStyle = text[leadingSpaceCount]; // ` or ~
  39857. const marker = text.slice(leadingSpaceCount).match(new RegExp(`^[${markerStyle}]+`))[0]; // https://spec.commonmark.org/0.28/#example-104: Closing fences may be indented by 0-3 spaces
  39858. // https://spec.commonmark.org/0.28/#example-93: The closing code fence must be at least as long as the opening fence
  39859. const hasEndMarker = new RegExp(`^\\s{0,3}${marker}`).test(lineContents[lineContents.length - 1].slice(getIndent(lineContents.length - 1)));
  39860. return lineContents.slice(1, hasEndMarker ? -1 : undefined).map((x, i) => x.slice(getIndent(i + 1)).replace(replaceRegex, "")).join("\n");
  39861. function getIndent(lineIndex) {
  39862. return node.position.indent[lineIndex - 1] - 1;
  39863. }
  39864. }
  39865. function mapAst(ast, handler) {
  39866. return function preorder(node, index, parentStack) {
  39867. parentStack = parentStack || [];
  39868. const newNode = Object.assign({}, handler(node, index, parentStack));
  39869. if (newNode.children) {
  39870. newNode.children = newNode.children.map((child, index) => {
  39871. return preorder(child, index, [newNode].concat(parentStack));
  39872. });
  39873. }
  39874. return newNode;
  39875. }(ast, null, null);
  39876. }
  39877. function isAutolink(node, options) {
  39878. if (!node || node.type !== "link" || node.children.length !== 1) {
  39879. return false;
  39880. }
  39881. const child = node.children[0];
  39882. return child && options.locStart(node) === options.locStart(child) && options.locEnd(node) === options.locEnd(child);
  39883. }
  39884. var utils$9 = {
  39885. mapAst,
  39886. splitText,
  39887. punctuationPattern,
  39888. getFencedCodeBlockValue,
  39889. getOrderedListItemInfo,
  39890. hasGitDiffFriendlyOrderedList,
  39891. INLINE_NODE_TYPES,
  39892. INLINE_NODE_WRAPPER_TYPES,
  39893. isAutolink
  39894. };
  39895. const {
  39896. getParserName: getParserName$1,
  39897. getMaxContinuousCount: getMaxContinuousCount$2
  39898. } = util;
  39899. const {
  39900. builders: {
  39901. hardline: hardline$d,
  39902. concat: concat$j,
  39903. markAsRoot: markAsRoot$2
  39904. },
  39905. utils: {
  39906. replaceNewlinesWithLiterallines: replaceNewlinesWithLiterallines$2
  39907. }
  39908. } = document;
  39909. const {
  39910. print: printFrontMatter$1
  39911. } = frontMatter;
  39912. const {
  39913. getFencedCodeBlockValue: getFencedCodeBlockValue$1
  39914. } = utils$9;
  39915. function embed$2(path, print, textToDoc, options) {
  39916. const node = path.getValue();
  39917. if (node.type === "code" && node.lang !== null) {
  39918. // only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk)
  39919. const langMatch = node.lang.match(/^[\w-]+/);
  39920. const lang = langMatch ? langMatch[0] : "";
  39921. const parser = getParserName$1(lang, options);
  39922. if (parser) {
  39923. const styleUnit = options.__inJsTemplate ? "~" : "`";
  39924. const style = styleUnit.repeat(Math.max(3, getMaxContinuousCount$2(node.value, styleUnit) + 1));
  39925. const doc = textToDoc(getFencedCodeBlockValue$1(node, options.originalText), {
  39926. parser
  39927. }, {
  39928. stripTrailingHardline: true
  39929. });
  39930. return markAsRoot$2(concat$j([style, node.lang, node.meta ? " " + node.meta : "", hardline$d, replaceNewlinesWithLiterallines$2(doc), hardline$d, style]));
  39931. }
  39932. }
  39933. switch (node.type) {
  39934. case "front-matter":
  39935. return printFrontMatter$1(node, textToDoc);
  39936. // MDX
  39937. case "importExport":
  39938. return concat$j([textToDoc(node.value, {
  39939. parser: "babel"
  39940. }, {
  39941. stripTrailingHardline: true
  39942. }), hardline$d]);
  39943. case "jsx":
  39944. return textToDoc(`<$>${node.value}</$>`, {
  39945. parser: "__js_expression",
  39946. rootMarker: "mdx"
  39947. }, {
  39948. stripTrailingHardline: true
  39949. });
  39950. }
  39951. return null;
  39952. }
  39953. var embed_1$2 = embed$2;
  39954. const {
  39955. parse: parseFrontMatter$1
  39956. } = frontMatter;
  39957. const pragmas = ["format", "prettier"];
  39958. function startWithPragma(text) {
  39959. const pragma = `@(${pragmas.join("|")})`;
  39960. const regex = new RegExp([`<!--\\s*${pragma}\\s*-->`, `<!--.*\r?\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->`].join("|"), "m");
  39961. const matched = text.match(regex);
  39962. return matched && matched.index === 0;
  39963. }
  39964. var pragma$3 = {
  39965. startWithPragma,
  39966. hasPragma: text => startWithPragma(parseFrontMatter$1(text).content.trimStart()),
  39967. insertPragma: text => {
  39968. const extracted = parseFrontMatter$1(text);
  39969. const pragma = `<!-- @${pragmas[0]} -->`;
  39970. return extracted.frontMatter ? `${extracted.frontMatter.raw}\n\n${pragma}\n\n${extracted.content}` : `${pragma}\n\n${extracted.content}`;
  39971. }
  39972. };
  39973. const {
  39974. getOrderedListItemInfo: getOrderedListItemInfo$1,
  39975. mapAst: mapAst$1,
  39976. splitText: splitText$1
  39977. } = utils$9; // 0x0 ~ 0x10ffff
  39978. // eslint-disable-next-line no-control-regex
  39979. const isSingleCharRegex = /^([\u0000-\uffff]|[\ud800-\udbff][\udc00-\udfff])$/;
  39980. function preprocess$1(ast, options) {
  39981. ast = restoreUnescapedCharacter(ast, options);
  39982. ast = mergeContinuousTexts(ast);
  39983. ast = transformInlineCode(ast);
  39984. ast = transformIndentedCodeblockAndMarkItsParentList(ast, options);
  39985. ast = markAlignedList(ast, options);
  39986. ast = splitTextIntoSentences(ast, options);
  39987. ast = transformImportExport(ast);
  39988. ast = mergeContinuousImportExport(ast);
  39989. return ast;
  39990. }
  39991. function transformImportExport(ast) {
  39992. return mapAst$1(ast, node => {
  39993. if (node.type !== "import" && node.type !== "export") {
  39994. return node;
  39995. }
  39996. return Object.assign({}, node, {
  39997. type: "importExport"
  39998. });
  39999. });
  40000. }
  40001. function transformInlineCode(ast) {
  40002. return mapAst$1(ast, node => {
  40003. if (node.type !== "inlineCode") {
  40004. return node;
  40005. }
  40006. return Object.assign({}, node, {
  40007. value: node.value.replace(/\s+/g, " ")
  40008. });
  40009. });
  40010. }
  40011. function restoreUnescapedCharacter(ast, options) {
  40012. return mapAst$1(ast, node => {
  40013. return node.type !== "text" ? node : Object.assign({}, node, {
  40014. value: node.value !== "*" && node.value !== "_" && node.value !== "$" && // handle these cases in printer
  40015. isSingleCharRegex.test(node.value) && node.position.end.offset - node.position.start.offset !== node.value.length ? options.originalText.slice(node.position.start.offset, node.position.end.offset) : node.value
  40016. });
  40017. });
  40018. }
  40019. function mergeContinuousImportExport(ast) {
  40020. return mergeChildren(ast, (prevNode, node) => prevNode.type === "importExport" && node.type === "importExport", (prevNode, node) => ({
  40021. type: "importExport",
  40022. value: prevNode.value + "\n\n" + node.value,
  40023. position: {
  40024. start: prevNode.position.start,
  40025. end: node.position.end
  40026. }
  40027. }));
  40028. }
  40029. function mergeChildren(ast, shouldMerge, mergeNode) {
  40030. return mapAst$1(ast, node => {
  40031. if (!node.children) {
  40032. return node;
  40033. }
  40034. const children = node.children.reduce((current, child) => {
  40035. const lastChild = current[current.length - 1];
  40036. if (lastChild && shouldMerge(lastChild, child)) {
  40037. current.splice(-1, 1, mergeNode(lastChild, child));
  40038. } else {
  40039. current.push(child);
  40040. }
  40041. return current;
  40042. }, []);
  40043. return Object.assign({}, node, {
  40044. children
  40045. });
  40046. });
  40047. }
  40048. function mergeContinuousTexts(ast) {
  40049. return mergeChildren(ast, (prevNode, node) => prevNode.type === "text" && node.type === "text", (prevNode, node) => ({
  40050. type: "text",
  40051. value: prevNode.value + node.value,
  40052. position: {
  40053. start: prevNode.position.start,
  40054. end: node.position.end
  40055. }
  40056. }));
  40057. }
  40058. function splitTextIntoSentences(ast, options) {
  40059. return mapAst$1(ast, (node, index, [parentNode]) => {
  40060. if (node.type !== "text") {
  40061. return node;
  40062. }
  40063. let {
  40064. value
  40065. } = node;
  40066. if (parentNode.type === "paragraph") {
  40067. if (index === 0) {
  40068. value = value.trimStart();
  40069. }
  40070. if (index === parentNode.children.length - 1) {
  40071. value = value.trimEnd();
  40072. }
  40073. }
  40074. return {
  40075. type: "sentence",
  40076. position: node.position,
  40077. children: splitText$1(value, options)
  40078. };
  40079. });
  40080. }
  40081. function transformIndentedCodeblockAndMarkItsParentList(ast, options) {
  40082. return mapAst$1(ast, (node, index, parentStack) => {
  40083. if (node.type === "code") {
  40084. // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
  40085. const isIndented = /^\n?( {4,}|\t)/.test(options.originalText.slice(node.position.start.offset, node.position.end.offset));
  40086. node.isIndented = isIndented;
  40087. if (isIndented) {
  40088. for (let i = 0; i < parentStack.length; i++) {
  40089. const parent = parentStack[i]; // no need to check checked items
  40090. if (parent.hasIndentedCodeblock) {
  40091. break;
  40092. }
  40093. if (parent.type === "list") {
  40094. parent.hasIndentedCodeblock = true;
  40095. }
  40096. }
  40097. }
  40098. }
  40099. return node;
  40100. });
  40101. }
  40102. function markAlignedList(ast, options) {
  40103. return mapAst$1(ast, (node, index, parentStack) => {
  40104. if (node.type === "list" && node.children.length !== 0) {
  40105. // if one of its parents is not aligned, it's not possible to be aligned in sub-lists
  40106. for (let i = 0; i < parentStack.length; i++) {
  40107. const parent = parentStack[i];
  40108. if (parent.type === "list" && !parent.isAligned) {
  40109. node.isAligned = false;
  40110. return node;
  40111. }
  40112. }
  40113. node.isAligned = isAligned(node);
  40114. }
  40115. return node;
  40116. });
  40117. function getListItemStart(listItem) {
  40118. return listItem.children.length === 0 ? -1 : listItem.children[0].position.start.column - 1;
  40119. }
  40120. function isAligned(list) {
  40121. if (!list.ordered) {
  40122. /**
  40123. * - 123
  40124. * - 123
  40125. */
  40126. return true;
  40127. }
  40128. const [firstItem, secondItem] = list.children;
  40129. const firstInfo = getOrderedListItemInfo$1(firstItem, options.originalText);
  40130. if (firstInfo.leadingSpaces.length > 1) {
  40131. /**
  40132. * 1. 123
  40133. *
  40134. * 1. 123
  40135. * 1. 123
  40136. */
  40137. return true;
  40138. }
  40139. const firstStart = getListItemStart(firstItem);
  40140. if (firstStart === -1) {
  40141. /**
  40142. * 1.
  40143. *
  40144. * 1.
  40145. * 1.
  40146. */
  40147. return false;
  40148. }
  40149. if (list.children.length === 1) {
  40150. /**
  40151. * aligned:
  40152. *
  40153. * 11. 123
  40154. *
  40155. * not aligned:
  40156. *
  40157. * 1. 123
  40158. */
  40159. return firstStart % options.tabWidth === 0;
  40160. }
  40161. const secondStart = getListItemStart(secondItem);
  40162. if (firstStart !== secondStart) {
  40163. /**
  40164. * 11. 123
  40165. * 1. 123
  40166. *
  40167. * 1. 123
  40168. * 11. 123
  40169. */
  40170. return false;
  40171. }
  40172. if (firstStart % options.tabWidth === 0) {
  40173. /**
  40174. * 11. 123
  40175. * 12. 123
  40176. */
  40177. return true;
  40178. }
  40179. /**
  40180. * aligned:
  40181. *
  40182. * 11. 123
  40183. * 1. 123
  40184. *
  40185. * not aligned:
  40186. *
  40187. * 1. 123
  40188. * 2. 123
  40189. */
  40190. const secondInfo = getOrderedListItemInfo$1(secondItem, options.originalText);
  40191. return secondInfo.leadingSpaces.length > 1;
  40192. }
  40193. }
  40194. var preprocess_1$1 = preprocess$1;
  40195. const {
  40196. getLast: getLast$7,
  40197. getMinNotPresentContinuousCount: getMinNotPresentContinuousCount$1,
  40198. getMaxContinuousCount: getMaxContinuousCount$3,
  40199. getStringWidth: getStringWidth$4
  40200. } = util;
  40201. const {
  40202. builders: {
  40203. breakParent: breakParent$6,
  40204. concat: concat$k,
  40205. join: join$b,
  40206. line: line$c,
  40207. literalline: literalline$4,
  40208. markAsRoot: markAsRoot$3,
  40209. hardline: hardline$e,
  40210. softline: softline$a,
  40211. ifBreak: ifBreak$8,
  40212. fill: fill$5,
  40213. align: align$3,
  40214. indent: indent$d,
  40215. group: group$i
  40216. },
  40217. utils: {
  40218. normalizeDoc: normalizeDoc$1
  40219. },
  40220. printer: {
  40221. printDocToString: printDocToString$3
  40222. }
  40223. } = document;
  40224. const {
  40225. replaceEndOfLineWith: replaceEndOfLineWith$1,
  40226. isFrontMatterNode: isFrontMatterNode$3
  40227. } = util;
  40228. const {
  40229. getFencedCodeBlockValue: getFencedCodeBlockValue$2,
  40230. hasGitDiffFriendlyOrderedList: hasGitDiffFriendlyOrderedList$1,
  40231. splitText: splitText$2,
  40232. punctuationPattern: punctuationPattern$1,
  40233. INLINE_NODE_TYPES: INLINE_NODE_TYPES$1,
  40234. INLINE_NODE_WRAPPER_TYPES: INLINE_NODE_WRAPPER_TYPES$1,
  40235. isAutolink: isAutolink$1
  40236. } = utils$9;
  40237. const TRAILING_HARDLINE_NODES = new Set(["importExport"]);
  40238. const SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
  40239. const SIBLING_NODE_TYPES = new Set(["listItem", "definition", "footnoteDefinition"]);
  40240. function genericPrint$4(path, options, print) {
  40241. const node = path.getValue();
  40242. if (shouldRemainTheSameContent(path)) {
  40243. return concat$k(splitText$2(options.originalText.slice(node.position.start.offset, node.position.end.offset), options).map(node => node.type === "word" ? node.value : node.value === "" ? "" : printLine(path, node.value, options)));
  40244. }
  40245. switch (node.type) {
  40246. case "front-matter":
  40247. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  40248. case "root":
  40249. if (node.children.length === 0) {
  40250. return "";
  40251. }
  40252. return concat$k([normalizeDoc$1(printRoot(path, options, print)), !TRAILING_HARDLINE_NODES.has(getLastDescendantNode(node).type) ? hardline$e : ""]);
  40253. case "paragraph":
  40254. return printChildren$1(path, options, print, {
  40255. postprocessor: fill$5
  40256. });
  40257. case "sentence":
  40258. return printChildren$1(path, options, print);
  40259. case "word":
  40260. {
  40261. let escapedValue = node.value.replace(/[$*]/g, "\\$&") // escape all `*` and `$` (math)
  40262. .replace(new RegExp([`(^|${punctuationPattern$1})(_+)`, `(_+)(${punctuationPattern$1}|$)`].join("|"), "g"), (_, text1, underscore1, underscore2, text2) => (underscore1 ? `${text1}${underscore1}` : `${underscore2}${text2}`).replace(/_/g, "\\_")); // escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
  40263. const isFirstSentence = (node, name, index) => node.type === "sentence" && index === 0;
  40264. const isLastChildAutolink = (node, name, index) => isAutolink$1(node.children[index - 1], options);
  40265. if (escapedValue !== node.value && (path.match(undefined, isFirstSentence, isLastChildAutolink) || path.match(undefined, isFirstSentence, (node, name, index) => node.type === "emphasis" && index === 0, isLastChildAutolink))) {
  40266. // backslash is parsed as part of autolinks, so we need to remove it
  40267. escapedValue = escapedValue.replace(/^(\\?[*_])+/, prefix => prefix.replace(/\\/g, ""));
  40268. }
  40269. return escapedValue;
  40270. }
  40271. case "whitespace":
  40272. {
  40273. const parentNode = path.getParentNode();
  40274. const index = parentNode.children.indexOf(node);
  40275. const nextNode = parentNode.children[index + 1];
  40276. const proseWrap = // leading char that may cause different syntax
  40277. nextNode && /^>|^([*+-]|#{1,6}|\d+[).])$/.test(nextNode.value) ? "never" : options.proseWrap;
  40278. return printLine(path, node.value, {
  40279. proseWrap
  40280. });
  40281. }
  40282. case "emphasis":
  40283. {
  40284. let style;
  40285. if (isAutolink$1(node.children[0], options)) {
  40286. style = options.originalText[node.position.start.offset];
  40287. } else {
  40288. const parentNode = path.getParentNode();
  40289. const index = parentNode.children.indexOf(node);
  40290. const prevNode = parentNode.children[index - 1];
  40291. const nextNode = parentNode.children[index + 1];
  40292. const hasPrevOrNextWord = // `1*2*3` is considered emphasis but `1_2_3` is not
  40293. prevNode && prevNode.type === "sentence" && prevNode.children.length > 0 && getLast$7(prevNode.children).type === "word" && !getLast$7(prevNode.children).hasTrailingPunctuation || nextNode && nextNode.type === "sentence" && nextNode.children.length > 0 && nextNode.children[0].type === "word" && !nextNode.children[0].hasLeadingPunctuation;
  40294. style = hasPrevOrNextWord || getAncestorNode$2(path, "emphasis") ? "*" : "_";
  40295. }
  40296. return concat$k([style, printChildren$1(path, options, print), style]);
  40297. }
  40298. case "strong":
  40299. return concat$k(["**", printChildren$1(path, options, print), "**"]);
  40300. case "delete":
  40301. return concat$k(["~~", printChildren$1(path, options, print), "~~"]);
  40302. case "inlineCode":
  40303. {
  40304. const backtickCount = getMinNotPresentContinuousCount$1(node.value, "`");
  40305. const style = "`".repeat(backtickCount || 1);
  40306. const gap = backtickCount && !/^\s/.test(node.value) ? " " : "";
  40307. return concat$k([style, gap, node.value, gap, style]);
  40308. }
  40309. case "link":
  40310. switch (options.originalText[node.position.start.offset]) {
  40311. case "<":
  40312. {
  40313. const mailto = "mailto:";
  40314. const url = // <hello@example.com> is parsed as { url: "mailto:hello@example.com" }
  40315. node.url.startsWith(mailto) && options.originalText.slice(node.position.start.offset + 1, node.position.start.offset + 1 + mailto.length) !== mailto ? node.url.slice(mailto.length) : node.url;
  40316. return concat$k(["<", url, ">"]);
  40317. }
  40318. case "[":
  40319. return concat$k(["[", printChildren$1(path, options, print), "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  40320. default:
  40321. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  40322. }
  40323. case "image":
  40324. return concat$k(["![", node.alt || "", "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  40325. case "blockquote":
  40326. return concat$k(["> ", align$3("> ", printChildren$1(path, options, print))]);
  40327. case "heading":
  40328. return concat$k(["#".repeat(node.depth) + " ", printChildren$1(path, options, print)]);
  40329. case "code":
  40330. {
  40331. if (node.isIndented) {
  40332. // indented code block
  40333. const alignment = " ".repeat(4);
  40334. return align$3(alignment, concat$k([alignment, concat$k(replaceEndOfLineWith$1(node.value, hardline$e))]));
  40335. } // fenced code block
  40336. const styleUnit = options.__inJsTemplate ? "~" : "`";
  40337. const style = styleUnit.repeat(Math.max(3, getMaxContinuousCount$3(node.value, styleUnit) + 1));
  40338. return concat$k([style, node.lang || "", node.meta ? " " + node.meta : "", hardline$e, concat$k(replaceEndOfLineWith$1(getFencedCodeBlockValue$2(node, options.originalText), hardline$e)), hardline$e, style]);
  40339. }
  40340. case "html":
  40341. {
  40342. const parentNode = path.getParentNode();
  40343. const value = parentNode.type === "root" && getLast$7(parentNode.children) === node ? node.value.trimEnd() : node.value;
  40344. const isHtmlComment = /^<!--[\S\s]*-->$/.test(value);
  40345. return concat$k(replaceEndOfLineWith$1(value, isHtmlComment ? hardline$e : markAsRoot$3(literalline$4)));
  40346. }
  40347. case "list":
  40348. {
  40349. const nthSiblingIndex = getNthListSiblingIndex(node, path.getParentNode());
  40350. const isGitDiffFriendlyOrderedList = hasGitDiffFriendlyOrderedList$1(node, options);
  40351. return printChildren$1(path, options, print, {
  40352. processor: (childPath, index) => {
  40353. const prefix = getPrefix();
  40354. const childNode = childPath.getValue();
  40355. if (childNode.children.length === 2 && childNode.children[1].type === "html" && childNode.children[0].position.start.column !== childNode.children[1].position.start.column) {
  40356. return concat$k([prefix, printListItem(childPath, options, print, prefix)]);
  40357. }
  40358. return concat$k([prefix, align$3(" ".repeat(prefix.length), printListItem(childPath, options, print, prefix))]);
  40359. function getPrefix() {
  40360. const rawPrefix = node.ordered ? (index === 0 ? node.start : isGitDiffFriendlyOrderedList ? 1 : node.start + index) + (nthSiblingIndex % 2 === 0 ? ". " : ") ") : nthSiblingIndex % 2 === 0 ? "- " : "* ";
  40361. return node.isAligned ||
  40362. /* workaround for https://github.com/remarkjs/remark/issues/315 */
  40363. node.hasIndentedCodeblock ? alignListPrefix(rawPrefix, options) : rawPrefix;
  40364. }
  40365. }
  40366. });
  40367. }
  40368. case "thematicBreak":
  40369. {
  40370. const counter = getAncestorCounter$1(path, "list");
  40371. if (counter === -1) {
  40372. return "---";
  40373. }
  40374. const nthSiblingIndex = getNthListSiblingIndex(path.getParentNode(counter), path.getParentNode(counter + 1));
  40375. return nthSiblingIndex % 2 === 0 ? "***" : "---";
  40376. }
  40377. case "linkReference":
  40378. return concat$k(["[", printChildren$1(path, options, print), "]", node.referenceType === "full" ? concat$k(["[", node.identifier, "]"]) : node.referenceType === "collapsed" ? "[]" : ""]);
  40379. case "imageReference":
  40380. switch (node.referenceType) {
  40381. case "full":
  40382. return concat$k(["![", node.alt || "", "][", node.identifier, "]"]);
  40383. default:
  40384. return concat$k(["![", node.alt, "]", node.referenceType === "collapsed" ? "[]" : ""]);
  40385. }
  40386. case "definition":
  40387. {
  40388. const lineOrSpace = options.proseWrap === "always" ? line$c : " ";
  40389. return group$i(concat$k([concat$k(["[", node.identifier, "]:"]), indent$d(concat$k([lineOrSpace, printUrl(node.url), node.title === null ? "" : concat$k([lineOrSpace, printTitle(node.title, options, false)])]))]));
  40390. }
  40391. // `footnote` requires `.use(footnotes, {inlineNotes: true})`, we are not using this option
  40392. // https://github.com/remarkjs/remark-footnotes#optionsinlinenotes
  40393. /* istanbul ignore next */
  40394. case "footnote":
  40395. return concat$k(["[^", printChildren$1(path, options, print), "]"]);
  40396. case "footnoteReference":
  40397. return concat$k(["[^", node.identifier, "]"]);
  40398. case "footnoteDefinition":
  40399. {
  40400. const nextNode = path.getParentNode().children[path.getName() + 1];
  40401. const shouldInlineFootnote = node.children.length === 1 && node.children[0].type === "paragraph" && (options.proseWrap === "never" || options.proseWrap === "preserve" && node.children[0].position.start.line === node.children[0].position.end.line);
  40402. return concat$k(["[^", node.identifier, "]: ", shouldInlineFootnote ? printChildren$1(path, options, print) : group$i(concat$k([align$3(" ".repeat(4), printChildren$1(path, options, print, {
  40403. processor: (childPath, index) => {
  40404. return index === 0 ? group$i(concat$k([softline$a, childPath.call(print)])) : childPath.call(print);
  40405. }
  40406. })), nextNode && nextNode.type === "footnoteDefinition" ? softline$a : ""]))]);
  40407. }
  40408. case "table":
  40409. return printTable(path, options, print);
  40410. case "tableCell":
  40411. return printChildren$1(path, options, print);
  40412. case "break":
  40413. return /\s/.test(options.originalText[node.position.start.offset]) ? concat$k([" ", markAsRoot$3(literalline$4)]) : concat$k(["\\", hardline$e]);
  40414. case "liquidNode":
  40415. return concat$k(replaceEndOfLineWith$1(node.value, hardline$e));
  40416. // MDX
  40417. case "importExport":
  40418. case "jsx":
  40419. // fallback to the original text if multiparser failed
  40420. // or `embeddedLanguageFormatting: "off"`
  40421. return concat$k([node.value, hardline$e]);
  40422. case "math":
  40423. return concat$k(["$$", hardline$e, node.value ? concat$k([concat$k(replaceEndOfLineWith$1(node.value, hardline$e)), hardline$e]) : "", "$$"]);
  40424. case "inlineMath":
  40425. {
  40426. // remark-math trims content but we don't want to remove whitespaces
  40427. // since it's very possible that it's recognized as math accidentally
  40428. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  40429. }
  40430. case "tableRow": // handled in "table"
  40431. case "listItem": // handled in "list"
  40432. default:
  40433. /* istanbul ignore next */
  40434. throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
  40435. }
  40436. }
  40437. function printListItem(path, options, print, listPrefix) {
  40438. const node = path.getValue();
  40439. const prefix = node.checked === null ? "" : node.checked ? "[x] " : "[ ] ";
  40440. return concat$k([prefix, printChildren$1(path, options, print, {
  40441. processor: (childPath, index) => {
  40442. if (index === 0 && childPath.getValue().type !== "list") {
  40443. return align$3(" ".repeat(prefix.length), childPath.call(print));
  40444. }
  40445. const alignment = " ".repeat(clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
  40446. );
  40447. return concat$k([alignment, align$3(alignment, childPath.call(print))]);
  40448. }
  40449. })]);
  40450. }
  40451. function alignListPrefix(prefix, options) {
  40452. const additionalSpaces = getAdditionalSpaces();
  40453. return prefix + " ".repeat(additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
  40454. );
  40455. function getAdditionalSpaces() {
  40456. const restSpaces = prefix.length % options.tabWidth;
  40457. return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
  40458. }
  40459. }
  40460. function getNthListSiblingIndex(node, parentNode) {
  40461. return getNthSiblingIndex(node, parentNode, siblingNode => siblingNode.ordered === node.ordered);
  40462. }
  40463. function getNthSiblingIndex(node, parentNode, condition) {
  40464. condition = condition || (() => true);
  40465. let index = -1;
  40466. for (const childNode of parentNode.children) {
  40467. if (childNode.type === node.type && condition(childNode)) {
  40468. index++;
  40469. } else {
  40470. index = -1;
  40471. }
  40472. if (childNode === node) {
  40473. return index;
  40474. }
  40475. }
  40476. }
  40477. function getAncestorCounter$1(path, typeOrTypes) {
  40478. const types = [].concat(typeOrTypes);
  40479. let counter = -1;
  40480. let ancestorNode;
  40481. while (ancestorNode = path.getParentNode(++counter)) {
  40482. if (types.includes(ancestorNode.type)) {
  40483. return counter;
  40484. }
  40485. }
  40486. return -1;
  40487. }
  40488. function getAncestorNode$2(path, typeOrTypes) {
  40489. const counter = getAncestorCounter$1(path, typeOrTypes);
  40490. return counter === -1 ? null : path.getParentNode(counter);
  40491. }
  40492. function printLine(path, value, options) {
  40493. if (options.proseWrap === "preserve" && value === "\n") {
  40494. return hardline$e;
  40495. }
  40496. const isBreakable = options.proseWrap === "always" && !getAncestorNode$2(path, SINGLE_LINE_NODE_TYPES);
  40497. return value !== "" ? isBreakable ? line$c : " " : isBreakable ? softline$a : "";
  40498. }
  40499. function printTable(path, options, print) {
  40500. const hardlineWithoutBreakParent = hardline$e.parts[0];
  40501. const node = path.getValue();
  40502. const contents = []; // { [rowIndex: number]: { [columnIndex: number]: string } }
  40503. path.map(rowPath => {
  40504. const rowContents = [];
  40505. rowPath.map(cellPath => {
  40506. rowContents.push(printDocToString$3(cellPath.call(print), options).formatted);
  40507. }, "children");
  40508. contents.push(rowContents);
  40509. }, "children"); // Get the width of each column
  40510. const columnMaxWidths = contents.reduce((currentWidths, rowContents) => currentWidths.map((width, columnIndex) => Math.max(width, getStringWidth$4(rowContents[columnIndex]))), contents[0].map(() => 3) // minimum width = 3 (---, :--, :-:, --:)
  40511. );
  40512. const alignedTable = join$b(hardlineWithoutBreakParent, [printRow(contents[0]), printSeparator(), join$b(hardlineWithoutBreakParent, contents.slice(1).map(rowContents => printRow(rowContents)))]);
  40513. if (options.proseWrap !== "never") {
  40514. return concat$k([breakParent$6, alignedTable]);
  40515. } // Only if the --prose-wrap never is set and it exceeds the print width.
  40516. const compactTable = join$b(hardlineWithoutBreakParent, [printRow(contents[0],
  40517. /* isCompact */
  40518. true), printSeparator(
  40519. /* isCompact */
  40520. true), join$b(hardlineWithoutBreakParent, contents.slice(1).map(rowContents => printRow(rowContents,
  40521. /* isCompact */
  40522. true)))]);
  40523. return concat$k([breakParent$6, group$i(ifBreak$8(compactTable, alignedTable))]);
  40524. function printSeparator(isCompact) {
  40525. return concat$k(["| ", join$b(" | ", columnMaxWidths.map((width, index) => {
  40526. const spaces = isCompact ? 3 : width;
  40527. switch (node.align[index]) {
  40528. case "left":
  40529. return ":" + "-".repeat(spaces - 1);
  40530. case "right":
  40531. return "-".repeat(spaces - 1) + ":";
  40532. case "center":
  40533. return ":" + "-".repeat(spaces - 2) + ":";
  40534. default:
  40535. return "-".repeat(spaces);
  40536. }
  40537. })), " |"]);
  40538. }
  40539. function printRow(rowContents, isCompact) {
  40540. return concat$k(["| ", join$b(" | ", isCompact ? rowContents : rowContents.map((rowContent, columnIndex) => {
  40541. switch (node.align[columnIndex]) {
  40542. case "right":
  40543. return alignRight(rowContent, columnMaxWidths[columnIndex]);
  40544. case "center":
  40545. return alignCenter(rowContent, columnMaxWidths[columnIndex]);
  40546. default:
  40547. return alignLeft(rowContent, columnMaxWidths[columnIndex]);
  40548. }
  40549. })), " |"]);
  40550. }
  40551. function alignLeft(text, width) {
  40552. const spaces = width - getStringWidth$4(text);
  40553. return concat$k([text, " ".repeat(spaces)]);
  40554. }
  40555. function alignRight(text, width) {
  40556. const spaces = width - getStringWidth$4(text);
  40557. return concat$k([" ".repeat(spaces), text]);
  40558. }
  40559. function alignCenter(text, width) {
  40560. const spaces = width - getStringWidth$4(text);
  40561. const left = Math.floor(spaces / 2);
  40562. const right = spaces - left;
  40563. return concat$k([" ".repeat(left), text, " ".repeat(right)]);
  40564. }
  40565. }
  40566. function printRoot(path, options, print) {
  40567. /** @typedef {{ index: number, offset: number }} IgnorePosition */
  40568. /** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */
  40569. const ignoreRanges = [];
  40570. /** @type {IgnorePosition | null} */
  40571. let ignoreStart = null;
  40572. const {
  40573. children
  40574. } = path.getValue();
  40575. children.forEach((childNode, index) => {
  40576. switch (isPrettierIgnore(childNode)) {
  40577. case "start":
  40578. if (ignoreStart === null) {
  40579. ignoreStart = {
  40580. index,
  40581. offset: childNode.position.end.offset
  40582. };
  40583. }
  40584. break;
  40585. case "end":
  40586. if (ignoreStart !== null) {
  40587. ignoreRanges.push({
  40588. start: ignoreStart,
  40589. end: {
  40590. index,
  40591. offset: childNode.position.start.offset
  40592. }
  40593. });
  40594. ignoreStart = null;
  40595. }
  40596. break;
  40597. }
  40598. });
  40599. return printChildren$1(path, options, print, {
  40600. processor: (childPath, index) => {
  40601. if (ignoreRanges.length !== 0) {
  40602. const ignoreRange = ignoreRanges[0];
  40603. if (index === ignoreRange.start.index) {
  40604. return concat$k([children[ignoreRange.start.index].value, options.originalText.slice(ignoreRange.start.offset, ignoreRange.end.offset), children[ignoreRange.end.index].value]);
  40605. }
  40606. if (ignoreRange.start.index < index && index < ignoreRange.end.index) {
  40607. return false;
  40608. }
  40609. if (index === ignoreRange.end.index) {
  40610. ignoreRanges.shift();
  40611. return false;
  40612. }
  40613. }
  40614. return childPath.call(print);
  40615. }
  40616. });
  40617. }
  40618. function printChildren$1(path, options, print, events) {
  40619. events = events || {};
  40620. const postprocessor = events.postprocessor || concat$k;
  40621. const processor = events.processor || (childPath => childPath.call(print));
  40622. const node = path.getValue();
  40623. const parts = [];
  40624. let lastChildNode;
  40625. path.map((childPath, index) => {
  40626. const childNode = childPath.getValue();
  40627. const result = processor(childPath, index);
  40628. if (result !== false) {
  40629. const data = {
  40630. parts,
  40631. prevNode: lastChildNode,
  40632. parentNode: node,
  40633. options
  40634. };
  40635. if (!shouldNotPrePrintHardline(childNode, data)) {
  40636. parts.push(hardline$e); // Can't find a case to pass `shouldPrePrintTripleHardline`
  40637. /* istanbul ignore next */
  40638. if (lastChildNode && TRAILING_HARDLINE_NODES.has(lastChildNode.type)) {
  40639. if (shouldPrePrintTripleHardline(childNode, data)) {
  40640. parts.push(hardline$e);
  40641. }
  40642. } else {
  40643. if (shouldPrePrintDoubleHardline(childNode, data) || shouldPrePrintTripleHardline(childNode, data)) {
  40644. parts.push(hardline$e);
  40645. }
  40646. if (shouldPrePrintTripleHardline(childNode, data)) {
  40647. parts.push(hardline$e);
  40648. }
  40649. }
  40650. }
  40651. parts.push(result);
  40652. lastChildNode = childNode;
  40653. }
  40654. }, "children");
  40655. return postprocessor(parts);
  40656. }
  40657. function getLastDescendantNode(node) {
  40658. let current = node;
  40659. while (current.children && current.children.length !== 0) {
  40660. current = current.children[current.children.length - 1];
  40661. }
  40662. return current;
  40663. }
  40664. /** @return {false | 'next' | 'start' | 'end'} */
  40665. function isPrettierIgnore(node) {
  40666. if (node.type !== "html") {
  40667. return false;
  40668. }
  40669. const match = node.value.match(/^<!--\s*prettier-ignore(?:-(start|end))?\s*-->$/);
  40670. return match === null ? false : match[1] ? match[1] : "next";
  40671. }
  40672. function shouldNotPrePrintHardline(node, data) {
  40673. const isFirstNode = data.parts.length === 0;
  40674. const isInlineNode = INLINE_NODE_TYPES$1.includes(node.type);
  40675. const isInlineHTML = node.type === "html" && INLINE_NODE_WRAPPER_TYPES$1.includes(data.parentNode.type);
  40676. return isFirstNode || isInlineNode || isInlineHTML;
  40677. }
  40678. function shouldPrePrintDoubleHardline(node, data) {
  40679. const isSequence = (data.prevNode && data.prevNode.type) === node.type;
  40680. const isSiblingNode = isSequence && SIBLING_NODE_TYPES.has(node.type);
  40681. const isInTightListItem = data.parentNode.type === "listItem" && !data.parentNode.loose;
  40682. const isPrevNodeLooseListItem = data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
  40683. const isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
  40684. const isBlockHtmlWithoutBlankLineBetweenPrevHtml = node.type === "html" && data.prevNode && data.prevNode.type === "html" && data.prevNode.position.end.line + 1 === node.position.start.line;
  40685. const isHtmlDirectAfterListItem = node.type === "html" && data.parentNode.type === "listItem" && data.prevNode && data.prevNode.type === "paragraph" && data.prevNode.position.end.line + 1 === node.position.start.line;
  40686. return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml || isHtmlDirectAfterListItem);
  40687. }
  40688. function shouldPrePrintTripleHardline(node, data) {
  40689. const isPrevNodeList = data.prevNode && data.prevNode.type === "list";
  40690. const isIndentedCode = node.type === "code" && node.isIndented;
  40691. return isPrevNodeList && isIndentedCode;
  40692. }
  40693. function shouldRemainTheSameContent(path) {
  40694. const ancestorNode = getAncestorNode$2(path, ["linkReference", "imageReference"]);
  40695. return ancestorNode && (ancestorNode.type !== "linkReference" || ancestorNode.referenceType !== "full");
  40696. }
  40697. function printUrl(url, dangerousCharOrChars) {
  40698. const dangerousChars = [" "].concat(dangerousCharOrChars || []);
  40699. return new RegExp(dangerousChars.map(x => `\\${x}`).join("|")).test(url) ? `<${url}>` : url;
  40700. }
  40701. function printTitle(title, options, printSpace) {
  40702. if (printSpace == null) {
  40703. printSpace = true;
  40704. }
  40705. if (!title) {
  40706. return "";
  40707. }
  40708. if (printSpace) {
  40709. return " " + printTitle(title, options, false);
  40710. } // title is escaped after `remark-parse` v7
  40711. title = title.replace(/\\(["')])/g, "$1");
  40712. if (title.includes('"') && title.includes("'") && !title.includes(")")) {
  40713. return `(${title})`; // avoid escaped quotes
  40714. } // faster than using RegExps: https://jsperf.com/performance-of-match-vs-split
  40715. const singleCount = title.split("'").length - 1;
  40716. const doubleCount = title.split('"').length - 1;
  40717. const quote = singleCount > doubleCount ? '"' : doubleCount > singleCount ? "'" : options.singleQuote ? "'" : '"';
  40718. title = title.replace(/\\/, "\\\\");
  40719. title = title.replace(new RegExp(`(${quote})`, "g"), "\\$1");
  40720. return `${quote}${title}${quote}`;
  40721. }
  40722. function clamp(value, min, max) {
  40723. return value < min ? min : value > max ? max : value;
  40724. }
  40725. function clean$5(ast, newObj, parent) {
  40726. delete newObj.position;
  40727. delete newObj.raw; // front-matter
  40728. // for codeblock
  40729. if (ast.type === "front-matter" || ast.type === "code" || ast.type === "yaml" || ast.type === "import" || ast.type === "export" || ast.type === "jsx") {
  40730. delete newObj.value;
  40731. }
  40732. if (ast.type === "list") {
  40733. delete newObj.isAligned;
  40734. }
  40735. if (ast.type === "list" || ast.type === "listItem") {
  40736. delete newObj.spread;
  40737. delete newObj.loose;
  40738. } // texts can be splitted or merged
  40739. if (ast.type === "text") {
  40740. return null;
  40741. }
  40742. if (ast.type === "inlineCode") {
  40743. newObj.value = ast.value.replace(/[\t\n ]+/g, " ");
  40744. }
  40745. if (ast.type === "definition" || ast.type === "linkReference") {
  40746. newObj.label = ast.label.trim().replace(/[\t\n ]+/g, " ").toLowerCase();
  40747. }
  40748. if ((ast.type === "definition" || ast.type === "link" || ast.type === "image") && ast.title) {
  40749. newObj.title = ast.title.replace(/\\(["')])/g, "$1");
  40750. } // for insert pragma
  40751. if (parent && parent.type === "root" && parent.children.length > 0 && (parent.children[0] === ast || isFrontMatterNode$3(parent.children[0]) && parent.children[1] === ast) && ast.type === "html" && pragma$3.startWithPragma(ast.value)) {
  40752. return null;
  40753. }
  40754. }
  40755. function hasPrettierIgnore$4(path) {
  40756. const index = +path.getName();
  40757. if (index === 0) {
  40758. return false;
  40759. }
  40760. const prevNode = path.getParentNode().children[index - 1];
  40761. return isPrettierIgnore(prevNode) === "next";
  40762. }
  40763. var printerMarkdown = {
  40764. preprocess: preprocess_1$1,
  40765. print: genericPrint$4,
  40766. embed: embed_1$2,
  40767. massageAstNode: clean$5,
  40768. hasPrettierIgnore: hasPrettierIgnore$4,
  40769. insertPragma: pragma$3.insertPragma
  40770. };
  40771. var options$5 = {
  40772. proseWrap: commonOptions.proseWrap,
  40773. singleQuote: commonOptions.singleQuote
  40774. };
  40775. var name$f = "Markdown";
  40776. var type$d = "prose";
  40777. var aliases$4 = [
  40778. "pandoc"
  40779. ];
  40780. var aceMode$d = "markdown";
  40781. var codemirrorMode$a = "gfm";
  40782. var codemirrorMimeType$a = "text/x-gfm";
  40783. var wrap = true;
  40784. var extensions$d = [
  40785. ".md",
  40786. ".markdown",
  40787. ".mdown",
  40788. ".mdwn",
  40789. ".mdx",
  40790. ".mkd",
  40791. ".mkdn",
  40792. ".mkdown",
  40793. ".ronn",
  40794. ".workbook"
  40795. ];
  40796. var filenames$3 = [
  40797. "contents.lr"
  40798. ];
  40799. var tmScope$d = "source.gfm";
  40800. var languageId$d = 222;
  40801. var Markdown = {
  40802. name: name$f,
  40803. type: type$d,
  40804. aliases: aliases$4,
  40805. aceMode: aceMode$d,
  40806. codemirrorMode: codemirrorMode$a,
  40807. codemirrorMimeType: codemirrorMimeType$a,
  40808. wrap: wrap,
  40809. extensions: extensions$d,
  40810. filenames: filenames$3,
  40811. tmScope: tmScope$d,
  40812. languageId: languageId$d
  40813. };
  40814. var Markdown$1 = /*#__PURE__*/Object.freeze({
  40815. __proto__: null,
  40816. name: name$f,
  40817. type: type$d,
  40818. aliases: aliases$4,
  40819. aceMode: aceMode$d,
  40820. codemirrorMode: codemirrorMode$a,
  40821. codemirrorMimeType: codemirrorMimeType$a,
  40822. wrap: wrap,
  40823. extensions: extensions$d,
  40824. filenames: filenames$3,
  40825. tmScope: tmScope$d,
  40826. languageId: languageId$d,
  40827. 'default': Markdown
  40828. });
  40829. var require$$0$6 = getCjsExportFromNamespace(Markdown$1);
  40830. const languages$4 = [createLanguage(require$$0$6, data => ({
  40831. since: "1.8.0",
  40832. parsers: ["markdown"],
  40833. vscodeLanguageIds: ["markdown"],
  40834. filenames: data.filenames.concat(["README"]),
  40835. extensions: data.extensions.filter(extension => extension !== ".mdx")
  40836. })), createLanguage(require$$0$6, () => ({
  40837. name: "MDX",
  40838. since: "1.15.0",
  40839. parsers: ["mdx"],
  40840. vscodeLanguageIds: ["mdx"],
  40841. filenames: [],
  40842. extensions: [".mdx"]
  40843. }))];
  40844. const printers$4 = {
  40845. mdast: printerMarkdown
  40846. };
  40847. const parsers$4 = {
  40848. /* istanbul ignore next */
  40849. get remark() {
  40850. return require("./parser-markdown").parsers.remark;
  40851. },
  40852. get markdown() {
  40853. return require("./parser-markdown").parsers.remark;
  40854. },
  40855. get mdx() {
  40856. return require("./parser-markdown").parsers.mdx;
  40857. }
  40858. };
  40859. var languageMarkdown = {
  40860. languages: languages$4,
  40861. options: options$5,
  40862. printers: printers$4,
  40863. parsers: parsers$4
  40864. };
  40865. const {
  40866. isFrontMatterNode: isFrontMatterNode$4
  40867. } = util;
  40868. var clean$6 = function (ast, newNode) {
  40869. delete newNode.sourceSpan;
  40870. delete newNode.startSourceSpan;
  40871. delete newNode.endSourceSpan;
  40872. delete newNode.nameSpan;
  40873. delete newNode.valueSpan;
  40874. if (ast.type === "text" || ast.type === "comment") {
  40875. return null;
  40876. } // may be formatted by multiparser
  40877. if (isFrontMatterNode$4(ast) || ast.type === "yaml" || ast.type === "toml") {
  40878. return null;
  40879. }
  40880. if (ast.type === "attribute") {
  40881. delete newNode.value;
  40882. }
  40883. if (ast.type === "docType") {
  40884. delete newNode.value;
  40885. }
  40886. };
  40887. var index$1 = [
  40888. "a",
  40889. "abbr",
  40890. "acronym",
  40891. "address",
  40892. "applet",
  40893. "area",
  40894. "article",
  40895. "aside",
  40896. "audio",
  40897. "b",
  40898. "base",
  40899. "basefont",
  40900. "bdi",
  40901. "bdo",
  40902. "bgsound",
  40903. "big",
  40904. "blink",
  40905. "blockquote",
  40906. "body",
  40907. "br",
  40908. "button",
  40909. "canvas",
  40910. "caption",
  40911. "center",
  40912. "cite",
  40913. "code",
  40914. "col",
  40915. "colgroup",
  40916. "command",
  40917. "content",
  40918. "data",
  40919. "datalist",
  40920. "dd",
  40921. "del",
  40922. "details",
  40923. "dfn",
  40924. "dialog",
  40925. "dir",
  40926. "div",
  40927. "dl",
  40928. "dt",
  40929. "element",
  40930. "em",
  40931. "embed",
  40932. "fieldset",
  40933. "figcaption",
  40934. "figure",
  40935. "font",
  40936. "footer",
  40937. "form",
  40938. "frame",
  40939. "frameset",
  40940. "h1",
  40941. "h2",
  40942. "h3",
  40943. "h4",
  40944. "h5",
  40945. "h6",
  40946. "head",
  40947. "header",
  40948. "hgroup",
  40949. "hr",
  40950. "html",
  40951. "i",
  40952. "iframe",
  40953. "image",
  40954. "img",
  40955. "input",
  40956. "ins",
  40957. "isindex",
  40958. "kbd",
  40959. "keygen",
  40960. "label",
  40961. "legend",
  40962. "li",
  40963. "link",
  40964. "listing",
  40965. "main",
  40966. "map",
  40967. "mark",
  40968. "marquee",
  40969. "math",
  40970. "menu",
  40971. "menuitem",
  40972. "meta",
  40973. "meter",
  40974. "multicol",
  40975. "nav",
  40976. "nextid",
  40977. "nobr",
  40978. "noembed",
  40979. "noframes",
  40980. "noscript",
  40981. "object",
  40982. "ol",
  40983. "optgroup",
  40984. "option",
  40985. "output",
  40986. "p",
  40987. "param",
  40988. "picture",
  40989. "plaintext",
  40990. "pre",
  40991. "progress",
  40992. "q",
  40993. "rb",
  40994. "rbc",
  40995. "rp",
  40996. "rt",
  40997. "rtc",
  40998. "ruby",
  40999. "s",
  41000. "samp",
  41001. "script",
  41002. "section",
  41003. "select",
  41004. "shadow",
  41005. "slot",
  41006. "small",
  41007. "source",
  41008. "spacer",
  41009. "span",
  41010. "strike",
  41011. "strong",
  41012. "style",
  41013. "sub",
  41014. "summary",
  41015. "sup",
  41016. "svg",
  41017. "table",
  41018. "tbody",
  41019. "td",
  41020. "template",
  41021. "textarea",
  41022. "tfoot",
  41023. "th",
  41024. "thead",
  41025. "time",
  41026. "title",
  41027. "tr",
  41028. "track",
  41029. "tt",
  41030. "u",
  41031. "ul",
  41032. "var",
  41033. "video",
  41034. "wbr",
  41035. "xmp"
  41036. ];
  41037. var htmlTagNames = /*#__PURE__*/Object.freeze({
  41038. __proto__: null,
  41039. 'default': index$1
  41040. });
  41041. var a = [
  41042. "accesskey",
  41043. "charset",
  41044. "coords",
  41045. "download",
  41046. "href",
  41047. "hreflang",
  41048. "name",
  41049. "ping",
  41050. "referrerpolicy",
  41051. "rel",
  41052. "rev",
  41053. "shape",
  41054. "tabindex",
  41055. "target",
  41056. "type"
  41057. ];
  41058. var abbr = [
  41059. "title"
  41060. ];
  41061. var applet = [
  41062. "align",
  41063. "alt",
  41064. "archive",
  41065. "code",
  41066. "codebase",
  41067. "height",
  41068. "hspace",
  41069. "name",
  41070. "object",
  41071. "vspace",
  41072. "width"
  41073. ];
  41074. var area = [
  41075. "accesskey",
  41076. "alt",
  41077. "coords",
  41078. "download",
  41079. "href",
  41080. "hreflang",
  41081. "nohref",
  41082. "ping",
  41083. "referrerpolicy",
  41084. "rel",
  41085. "shape",
  41086. "tabindex",
  41087. "target",
  41088. "type"
  41089. ];
  41090. var audio = [
  41091. "autoplay",
  41092. "controls",
  41093. "crossorigin",
  41094. "loop",
  41095. "muted",
  41096. "preload",
  41097. "src"
  41098. ];
  41099. var base = [
  41100. "href",
  41101. "target"
  41102. ];
  41103. var basefont = [
  41104. "color",
  41105. "face",
  41106. "size"
  41107. ];
  41108. var bdo = [
  41109. "dir"
  41110. ];
  41111. var blockquote = [
  41112. "cite"
  41113. ];
  41114. var body = [
  41115. "alink",
  41116. "background",
  41117. "bgcolor",
  41118. "link",
  41119. "text",
  41120. "vlink"
  41121. ];
  41122. var br = [
  41123. "clear"
  41124. ];
  41125. var button = [
  41126. "accesskey",
  41127. "autofocus",
  41128. "disabled",
  41129. "form",
  41130. "formaction",
  41131. "formenctype",
  41132. "formmethod",
  41133. "formnovalidate",
  41134. "formtarget",
  41135. "name",
  41136. "tabindex",
  41137. "type",
  41138. "value"
  41139. ];
  41140. var canvas = [
  41141. "height",
  41142. "width"
  41143. ];
  41144. var caption = [
  41145. "align"
  41146. ];
  41147. var col = [
  41148. "align",
  41149. "char",
  41150. "charoff",
  41151. "span",
  41152. "valign",
  41153. "width"
  41154. ];
  41155. var colgroup = [
  41156. "align",
  41157. "char",
  41158. "charoff",
  41159. "span",
  41160. "valign",
  41161. "width"
  41162. ];
  41163. var data$1 = [
  41164. "value"
  41165. ];
  41166. var del$1 = [
  41167. "cite",
  41168. "datetime"
  41169. ];
  41170. var details = [
  41171. "open"
  41172. ];
  41173. var dfn = [
  41174. "title"
  41175. ];
  41176. var dialog = [
  41177. "open"
  41178. ];
  41179. var dir = [
  41180. "compact"
  41181. ];
  41182. var div = [
  41183. "align"
  41184. ];
  41185. var dl = [
  41186. "compact"
  41187. ];
  41188. var embed$3 = [
  41189. "height",
  41190. "src",
  41191. "type",
  41192. "width"
  41193. ];
  41194. var fieldset = [
  41195. "disabled",
  41196. "form",
  41197. "name"
  41198. ];
  41199. var font = [
  41200. "color",
  41201. "face",
  41202. "size"
  41203. ];
  41204. var form = [
  41205. "accept",
  41206. "accept-charset",
  41207. "action",
  41208. "autocomplete",
  41209. "enctype",
  41210. "method",
  41211. "name",
  41212. "novalidate",
  41213. "target"
  41214. ];
  41215. var frame = [
  41216. "frameborder",
  41217. "longdesc",
  41218. "marginheight",
  41219. "marginwidth",
  41220. "name",
  41221. "noresize",
  41222. "scrolling",
  41223. "src"
  41224. ];
  41225. var frameset = [
  41226. "cols",
  41227. "rows"
  41228. ];
  41229. var h1 = [
  41230. "align"
  41231. ];
  41232. var h2 = [
  41233. "align"
  41234. ];
  41235. var h3 = [
  41236. "align"
  41237. ];
  41238. var h4 = [
  41239. "align"
  41240. ];
  41241. var h5 = [
  41242. "align"
  41243. ];
  41244. var h6 = [
  41245. "align"
  41246. ];
  41247. var head = [
  41248. "profile"
  41249. ];
  41250. var hr = [
  41251. "align",
  41252. "noshade",
  41253. "size",
  41254. "width"
  41255. ];
  41256. var html = [
  41257. "manifest",
  41258. "version"
  41259. ];
  41260. var iframe = [
  41261. "align",
  41262. "allow",
  41263. "allowfullscreen",
  41264. "allowpaymentrequest",
  41265. "allowusermedia",
  41266. "frameborder",
  41267. "height",
  41268. "longdesc",
  41269. "marginheight",
  41270. "marginwidth",
  41271. "name",
  41272. "referrerpolicy",
  41273. "sandbox",
  41274. "scrolling",
  41275. "src",
  41276. "srcdoc",
  41277. "width"
  41278. ];
  41279. var img = [
  41280. "align",
  41281. "alt",
  41282. "border",
  41283. "crossorigin",
  41284. "decoding",
  41285. "height",
  41286. "hspace",
  41287. "ismap",
  41288. "longdesc",
  41289. "name",
  41290. "referrerpolicy",
  41291. "sizes",
  41292. "src",
  41293. "srcset",
  41294. "usemap",
  41295. "vspace",
  41296. "width"
  41297. ];
  41298. var input = [
  41299. "accept",
  41300. "accesskey",
  41301. "align",
  41302. "alt",
  41303. "autocomplete",
  41304. "autofocus",
  41305. "checked",
  41306. "dirname",
  41307. "disabled",
  41308. "form",
  41309. "formaction",
  41310. "formenctype",
  41311. "formmethod",
  41312. "formnovalidate",
  41313. "formtarget",
  41314. "height",
  41315. "ismap",
  41316. "list",
  41317. "max",
  41318. "maxlength",
  41319. "min",
  41320. "minlength",
  41321. "multiple",
  41322. "name",
  41323. "pattern",
  41324. "placeholder",
  41325. "readonly",
  41326. "required",
  41327. "size",
  41328. "src",
  41329. "step",
  41330. "tabindex",
  41331. "title",
  41332. "type",
  41333. "usemap",
  41334. "value",
  41335. "width"
  41336. ];
  41337. var ins = [
  41338. "cite",
  41339. "datetime"
  41340. ];
  41341. var isindex = [
  41342. "prompt"
  41343. ];
  41344. var label = [
  41345. "accesskey",
  41346. "for",
  41347. "form"
  41348. ];
  41349. var legend = [
  41350. "accesskey",
  41351. "align"
  41352. ];
  41353. var li = [
  41354. "type",
  41355. "value"
  41356. ];
  41357. var link$3 = [
  41358. "as",
  41359. "charset",
  41360. "color",
  41361. "crossorigin",
  41362. "href",
  41363. "hreflang",
  41364. "imagesizes",
  41365. "imagesrcset",
  41366. "integrity",
  41367. "media",
  41368. "nonce",
  41369. "referrerpolicy",
  41370. "rel",
  41371. "rev",
  41372. "sizes",
  41373. "target",
  41374. "title",
  41375. "type"
  41376. ];
  41377. var map$1 = [
  41378. "name"
  41379. ];
  41380. var menu = [
  41381. "compact"
  41382. ];
  41383. var meta = [
  41384. "charset",
  41385. "content",
  41386. "http-equiv",
  41387. "name",
  41388. "scheme"
  41389. ];
  41390. var meter = [
  41391. "high",
  41392. "low",
  41393. "max",
  41394. "min",
  41395. "optimum",
  41396. "value"
  41397. ];
  41398. var object = [
  41399. "align",
  41400. "archive",
  41401. "border",
  41402. "classid",
  41403. "codebase",
  41404. "codetype",
  41405. "data",
  41406. "declare",
  41407. "form",
  41408. "height",
  41409. "hspace",
  41410. "name",
  41411. "standby",
  41412. "tabindex",
  41413. "type",
  41414. "typemustmatch",
  41415. "usemap",
  41416. "vspace",
  41417. "width"
  41418. ];
  41419. var ol = [
  41420. "compact",
  41421. "reversed",
  41422. "start",
  41423. "type"
  41424. ];
  41425. var optgroup = [
  41426. "disabled",
  41427. "label"
  41428. ];
  41429. var option = [
  41430. "disabled",
  41431. "label",
  41432. "selected",
  41433. "value"
  41434. ];
  41435. var output = [
  41436. "for",
  41437. "form",
  41438. "name"
  41439. ];
  41440. var p = [
  41441. "align"
  41442. ];
  41443. var param = [
  41444. "name",
  41445. "type",
  41446. "value",
  41447. "valuetype"
  41448. ];
  41449. var pre = [
  41450. "width"
  41451. ];
  41452. var progress = [
  41453. "max",
  41454. "value"
  41455. ];
  41456. var q = [
  41457. "cite"
  41458. ];
  41459. var script = [
  41460. "async",
  41461. "charset",
  41462. "crossorigin",
  41463. "defer",
  41464. "integrity",
  41465. "language",
  41466. "nomodule",
  41467. "nonce",
  41468. "referrerpolicy",
  41469. "src",
  41470. "type"
  41471. ];
  41472. var select = [
  41473. "autocomplete",
  41474. "autofocus",
  41475. "disabled",
  41476. "form",
  41477. "multiple",
  41478. "name",
  41479. "required",
  41480. "size",
  41481. "tabindex"
  41482. ];
  41483. var slot = [
  41484. "name"
  41485. ];
  41486. var source$2 = [
  41487. "media",
  41488. "sizes",
  41489. "src",
  41490. "srcset",
  41491. "type"
  41492. ];
  41493. var style = [
  41494. "media",
  41495. "nonce",
  41496. "title",
  41497. "type"
  41498. ];
  41499. var table = [
  41500. "align",
  41501. "bgcolor",
  41502. "border",
  41503. "cellpadding",
  41504. "cellspacing",
  41505. "frame",
  41506. "rules",
  41507. "summary",
  41508. "width"
  41509. ];
  41510. var tbody = [
  41511. "align",
  41512. "char",
  41513. "charoff",
  41514. "valign"
  41515. ];
  41516. var td = [
  41517. "abbr",
  41518. "align",
  41519. "axis",
  41520. "bgcolor",
  41521. "char",
  41522. "charoff",
  41523. "colspan",
  41524. "headers",
  41525. "height",
  41526. "nowrap",
  41527. "rowspan",
  41528. "scope",
  41529. "valign",
  41530. "width"
  41531. ];
  41532. var textarea = [
  41533. "accesskey",
  41534. "autocomplete",
  41535. "autofocus",
  41536. "cols",
  41537. "dirname",
  41538. "disabled",
  41539. "form",
  41540. "maxlength",
  41541. "minlength",
  41542. "name",
  41543. "placeholder",
  41544. "readonly",
  41545. "required",
  41546. "rows",
  41547. "tabindex",
  41548. "wrap"
  41549. ];
  41550. var tfoot = [
  41551. "align",
  41552. "char",
  41553. "charoff",
  41554. "valign"
  41555. ];
  41556. var th = [
  41557. "abbr",
  41558. "align",
  41559. "axis",
  41560. "bgcolor",
  41561. "char",
  41562. "charoff",
  41563. "colspan",
  41564. "headers",
  41565. "height",
  41566. "nowrap",
  41567. "rowspan",
  41568. "scope",
  41569. "valign",
  41570. "width"
  41571. ];
  41572. var thead = [
  41573. "align",
  41574. "char",
  41575. "charoff",
  41576. "valign"
  41577. ];
  41578. var time = [
  41579. "datetime"
  41580. ];
  41581. var tr = [
  41582. "align",
  41583. "bgcolor",
  41584. "char",
  41585. "charoff",
  41586. "valign"
  41587. ];
  41588. var track = [
  41589. "default",
  41590. "kind",
  41591. "label",
  41592. "src",
  41593. "srclang"
  41594. ];
  41595. var ul = [
  41596. "compact",
  41597. "type"
  41598. ];
  41599. var video = [
  41600. "autoplay",
  41601. "controls",
  41602. "crossorigin",
  41603. "height",
  41604. "loop",
  41605. "muted",
  41606. "playsinline",
  41607. "poster",
  41608. "preload",
  41609. "src",
  41610. "width"
  41611. ];
  41612. var index$2 = {
  41613. "*": [
  41614. "accesskey",
  41615. "autocapitalize",
  41616. "autofocus",
  41617. "class",
  41618. "contenteditable",
  41619. "dir",
  41620. "draggable",
  41621. "enterkeyhint",
  41622. "hidden",
  41623. "id",
  41624. "inputmode",
  41625. "is",
  41626. "itemid",
  41627. "itemprop",
  41628. "itemref",
  41629. "itemscope",
  41630. "itemtype",
  41631. "lang",
  41632. "nonce",
  41633. "slot",
  41634. "spellcheck",
  41635. "style",
  41636. "tabindex",
  41637. "title",
  41638. "translate"
  41639. ],
  41640. a: a,
  41641. abbr: abbr,
  41642. applet: applet,
  41643. area: area,
  41644. audio: audio,
  41645. base: base,
  41646. basefont: basefont,
  41647. bdo: bdo,
  41648. blockquote: blockquote,
  41649. body: body,
  41650. br: br,
  41651. button: button,
  41652. canvas: canvas,
  41653. caption: caption,
  41654. col: col,
  41655. colgroup: colgroup,
  41656. data: data$1,
  41657. del: del$1,
  41658. details: details,
  41659. dfn: dfn,
  41660. dialog: dialog,
  41661. dir: dir,
  41662. div: div,
  41663. dl: dl,
  41664. embed: embed$3,
  41665. fieldset: fieldset,
  41666. font: font,
  41667. form: form,
  41668. frame: frame,
  41669. frameset: frameset,
  41670. h1: h1,
  41671. h2: h2,
  41672. h3: h3,
  41673. h4: h4,
  41674. h5: h5,
  41675. h6: h6,
  41676. head: head,
  41677. hr: hr,
  41678. html: html,
  41679. iframe: iframe,
  41680. img: img,
  41681. input: input,
  41682. ins: ins,
  41683. isindex: isindex,
  41684. label: label,
  41685. legend: legend,
  41686. li: li,
  41687. link: link$3,
  41688. map: map$1,
  41689. menu: menu,
  41690. meta: meta,
  41691. meter: meter,
  41692. object: object,
  41693. ol: ol,
  41694. optgroup: optgroup,
  41695. option: option,
  41696. output: output,
  41697. p: p,
  41698. param: param,
  41699. pre: pre,
  41700. progress: progress,
  41701. q: q,
  41702. script: script,
  41703. select: select,
  41704. slot: slot,
  41705. source: source$2,
  41706. style: style,
  41707. table: table,
  41708. tbody: tbody,
  41709. td: td,
  41710. textarea: textarea,
  41711. tfoot: tfoot,
  41712. th: th,
  41713. thead: thead,
  41714. time: time,
  41715. tr: tr,
  41716. track: track,
  41717. ul: ul,
  41718. video: video
  41719. };
  41720. var htmlElementAttributes = /*#__PURE__*/Object.freeze({
  41721. __proto__: null,
  41722. a: a,
  41723. abbr: abbr,
  41724. applet: applet,
  41725. area: area,
  41726. audio: audio,
  41727. base: base,
  41728. basefont: basefont,
  41729. bdo: bdo,
  41730. blockquote: blockquote,
  41731. body: body,
  41732. br: br,
  41733. button: button,
  41734. canvas: canvas,
  41735. caption: caption,
  41736. col: col,
  41737. colgroup: colgroup,
  41738. data: data$1,
  41739. del: del$1,
  41740. details: details,
  41741. dfn: dfn,
  41742. dialog: dialog,
  41743. dir: dir,
  41744. div: div,
  41745. dl: dl,
  41746. embed: embed$3,
  41747. fieldset: fieldset,
  41748. font: font,
  41749. form: form,
  41750. frame: frame,
  41751. frameset: frameset,
  41752. h1: h1,
  41753. h2: h2,
  41754. h3: h3,
  41755. h4: h4,
  41756. h5: h5,
  41757. h6: h6,
  41758. head: head,
  41759. hr: hr,
  41760. html: html,
  41761. iframe: iframe,
  41762. img: img,
  41763. input: input,
  41764. ins: ins,
  41765. isindex: isindex,
  41766. label: label,
  41767. legend: legend,
  41768. li: li,
  41769. link: link$3,
  41770. map: map$1,
  41771. menu: menu,
  41772. meta: meta,
  41773. meter: meter,
  41774. object: object,
  41775. ol: ol,
  41776. optgroup: optgroup,
  41777. option: option,
  41778. output: output,
  41779. p: p,
  41780. param: param,
  41781. pre: pre,
  41782. progress: progress,
  41783. q: q,
  41784. script: script,
  41785. select: select,
  41786. slot: slot,
  41787. source: source$2,
  41788. style: style,
  41789. table: table,
  41790. tbody: tbody,
  41791. td: td,
  41792. textarea: textarea,
  41793. tfoot: tfoot,
  41794. th: th,
  41795. thead: thead,
  41796. time: time,
  41797. tr: tr,
  41798. track: track,
  41799. ul: ul,
  41800. video: video,
  41801. 'default': index$2
  41802. });
  41803. var json$1 = {
  41804. "CSS_DISPLAY_TAGS": {
  41805. "area": "none",
  41806. "base": "none",
  41807. "basefont": "none",
  41808. "datalist": "none",
  41809. "head": "none",
  41810. "link": "none",
  41811. "meta": "none",
  41812. "noembed": "none",
  41813. "noframes": "none",
  41814. "param": "block",
  41815. "rp": "none",
  41816. "script": "block",
  41817. "source": "block",
  41818. "style": "none",
  41819. "template": "inline",
  41820. "track": "block",
  41821. "title": "none",
  41822. "html": "block",
  41823. "body": "block",
  41824. "address": "block",
  41825. "blockquote": "block",
  41826. "center": "block",
  41827. "div": "block",
  41828. "figure": "block",
  41829. "figcaption": "block",
  41830. "footer": "block",
  41831. "form": "block",
  41832. "header": "block",
  41833. "hr": "block",
  41834. "legend": "block",
  41835. "listing": "block",
  41836. "main": "block",
  41837. "p": "block",
  41838. "plaintext": "block",
  41839. "pre": "block",
  41840. "xmp": "block",
  41841. "slot": "contents",
  41842. "ruby": "ruby",
  41843. "rt": "ruby-text",
  41844. "article": "block",
  41845. "aside": "block",
  41846. "h1": "block",
  41847. "h2": "block",
  41848. "h3": "block",
  41849. "h4": "block",
  41850. "h5": "block",
  41851. "h6": "block",
  41852. "hgroup": "block",
  41853. "nav": "block",
  41854. "section": "block",
  41855. "dir": "block",
  41856. "dd": "block",
  41857. "dl": "block",
  41858. "dt": "block",
  41859. "ol": "block",
  41860. "ul": "block",
  41861. "li": "list-item",
  41862. "table": "table",
  41863. "caption": "table-caption",
  41864. "colgroup": "table-column-group",
  41865. "col": "table-column",
  41866. "thead": "table-header-group",
  41867. "tbody": "table-row-group",
  41868. "tfoot": "table-footer-group",
  41869. "tr": "table-row",
  41870. "td": "table-cell",
  41871. "th": "table-cell",
  41872. "fieldset": "block",
  41873. "button": "inline-block",
  41874. "details": "block",
  41875. "summary": "block",
  41876. "dialog": "block",
  41877. "meter": "inline-block",
  41878. "progress": "inline-block",
  41879. "object": "inline-block",
  41880. "video": "inline-block",
  41881. "audio": "inline-block",
  41882. "select": "inline-block",
  41883. "option": "block",
  41884. "optgroup": "block"
  41885. },
  41886. "CSS_DISPLAY_DEFAULT": "inline",
  41887. "CSS_WHITE_SPACE_TAGS": {
  41888. "listing": "pre",
  41889. "plaintext": "pre",
  41890. "pre": "pre",
  41891. "xmp": "pre",
  41892. "nobr": "nowrap",
  41893. "table": "initial",
  41894. "textarea": "pre-wrap"
  41895. },
  41896. "CSS_WHITE_SPACE_DEFAULT": "normal"
  41897. };
  41898. var htmlTagNames$1 = getCjsExportFromNamespace(htmlTagNames);
  41899. var htmlElementAttributes$1 = getCjsExportFromNamespace(htmlElementAttributes);
  41900. const {
  41901. getParserName: getParserName$2,
  41902. isFrontMatterNode: isFrontMatterNode$5
  41903. } = util;
  41904. const {
  41905. CSS_DISPLAY_TAGS,
  41906. CSS_DISPLAY_DEFAULT,
  41907. CSS_WHITE_SPACE_TAGS,
  41908. CSS_WHITE_SPACE_DEFAULT
  41909. } = json$1;
  41910. const HTML_TAGS = arrayToMap(htmlTagNames$1);
  41911. const HTML_ELEMENT_ATTRIBUTES = mapObject(htmlElementAttributes$1, arrayToMap); // https://infra.spec.whatwg.org/#ascii-whitespace
  41912. const HTML_WHITESPACE = new Set(["\t", "\n", "\f", "\r", " "]);
  41913. const htmlTrimStart = string => string.replace(/^[\t\n\f\r ]+/, "");
  41914. const htmlTrimEnd = string => string.replace(/[\t\n\f\r ]+$/, "");
  41915. const htmlTrim = string => htmlTrimStart(htmlTrimEnd(string));
  41916. const htmlTrimLeadingBlankLines = string => string.replace(/^[\t\f\r ]*?\n/g, "");
  41917. const htmlTrimPreserveIndentation = string => htmlTrimLeadingBlankLines(htmlTrimEnd(string));
  41918. const splitByHtmlWhitespace = string => string.split(/[\t\n\f\r ]+/);
  41919. const getLeadingHtmlWhitespace = string => string.match(/^[\t\n\f\r ]*/)[0];
  41920. const getLeadingAndTrailingHtmlWhitespace = string => {
  41921. const [, leadingWhitespace, text, trailingWhitespace] = string.match(/^([\t\n\f\r ]*)([\S\s]*?)([\t\n\f\r ]*)$/);
  41922. return {
  41923. leadingWhitespace,
  41924. trailingWhitespace,
  41925. text
  41926. };
  41927. };
  41928. const hasHtmlWhitespace = string => /[\t\n\f\r ]/.test(string);
  41929. function arrayToMap(array) {
  41930. const map = Object.create(null);
  41931. for (const value of array) {
  41932. map[value] = true;
  41933. }
  41934. return map;
  41935. }
  41936. function mapObject(object, fn) {
  41937. const newObject = Object.create(null);
  41938. for (const key of Object.keys(object)) {
  41939. newObject[key] = fn(object[key], key);
  41940. }
  41941. return newObject;
  41942. }
  41943. function shouldPreserveContent(node, options) {
  41944. // unterminated node in ie conditional comment
  41945. // e.g. <!--[if lt IE 9]><html><![endif]-->
  41946. if (node.type === "ieConditionalComment" && node.lastChild && !node.lastChild.isSelfClosing && !node.lastChild.endSourceSpan) {
  41947. return true;
  41948. } // incomplete html in ie conditional comment
  41949. // e.g. <!--[if lt IE 9]></div><![endif]-->
  41950. if (node.type === "ieConditionalComment" && !node.complete) {
  41951. return true;
  41952. } // TODO: handle non-text children in <pre>
  41953. if (isPreLikeNode(node) && node.children.some(child => child.type !== "text" && child.type !== "interpolation")) {
  41954. return true;
  41955. }
  41956. if (isVueNonHtmlBlock(node, options) && !isScriptLikeTag(node) && node.type !== "interpolation") {
  41957. return true;
  41958. }
  41959. return false;
  41960. }
  41961. function hasPrettierIgnore$5(node) {
  41962. /* istanbul ignore next */
  41963. if (node.type === "attribute") {
  41964. return false;
  41965. }
  41966. /* istanbul ignore next */
  41967. if (!node.parent) {
  41968. return false;
  41969. }
  41970. if (typeof node.index !== "number" || node.index === 0) {
  41971. return false;
  41972. }
  41973. const prevNode = node.parent.children[node.index - 1];
  41974. return isPrettierIgnore$1(prevNode);
  41975. }
  41976. function isPrettierIgnore$1(node) {
  41977. return node.type === "comment" && node.value.trim() === "prettier-ignore";
  41978. }
  41979. function getPrettierIgnoreAttributeCommentData(value) {
  41980. const match = value.trim().match(/^prettier-ignore-attribute(?:\s+([^]+))?$/);
  41981. if (!match) {
  41982. return false;
  41983. }
  41984. if (!match[1]) {
  41985. return true;
  41986. }
  41987. return match[1].split(/\s+/);
  41988. }
  41989. /** there's no opening/closing tag or it's considered not breakable */
  41990. function isTextLikeNode(node) {
  41991. return node.type === "text" || node.type === "comment";
  41992. }
  41993. function isScriptLikeTag(node) {
  41994. return node.type === "element" && (node.fullName === "script" || node.fullName === "style" || node.fullName === "svg:style" || isUnknownNamespace(node) && (node.name === "script" || node.name === "style"));
  41995. }
  41996. function canHaveInterpolation(node) {
  41997. return node.children && !isScriptLikeTag(node);
  41998. }
  41999. function isWhitespaceSensitiveNode(node) {
  42000. return isScriptLikeTag(node) || node.type === "interpolation" || isIndentationSensitiveNode(node);
  42001. }
  42002. function isIndentationSensitiveNode(node) {
  42003. return getNodeCssStyleWhiteSpace(node).startsWith("pre");
  42004. }
  42005. function isLeadingSpaceSensitiveNode(node, options) {
  42006. const isLeadingSpaceSensitive = _isLeadingSpaceSensitiveNode();
  42007. if (isLeadingSpaceSensitive && !node.prev && node.parent && node.parent.tagDefinition && node.parent.tagDefinition.ignoreFirstLf) {
  42008. return node.type === "interpolation";
  42009. }
  42010. return isLeadingSpaceSensitive;
  42011. function _isLeadingSpaceSensitiveNode() {
  42012. if (isFrontMatterNode$5(node)) {
  42013. return false;
  42014. }
  42015. if ((node.type === "text" || node.type === "interpolation") && node.prev && (node.prev.type === "text" || node.prev.type === "interpolation")) {
  42016. return true;
  42017. }
  42018. if (!node.parent || node.parent.cssDisplay === "none") {
  42019. return false;
  42020. }
  42021. if (isPreLikeNode(node.parent)) {
  42022. return true;
  42023. }
  42024. if (!node.prev && (node.parent.type === "root" || isPreLikeNode(node) && node.parent || isScriptLikeTag(node.parent) || isVueCustomBlock(node.parent, options) || !isFirstChildLeadingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) {
  42025. return false;
  42026. }
  42027. if (node.prev && !isNextLeadingSpaceSensitiveCssDisplay(node.prev.cssDisplay)) {
  42028. return false;
  42029. }
  42030. return true;
  42031. }
  42032. }
  42033. function isTrailingSpaceSensitiveNode(node, options) {
  42034. if (isFrontMatterNode$5(node)) {
  42035. return false;
  42036. }
  42037. if ((node.type === "text" || node.type === "interpolation") && node.next && (node.next.type === "text" || node.next.type === "interpolation")) {
  42038. return true;
  42039. }
  42040. if (!node.parent || node.parent.cssDisplay === "none") {
  42041. return false;
  42042. }
  42043. if (isPreLikeNode(node.parent)) {
  42044. return true;
  42045. }
  42046. if (!node.next && (node.parent.type === "root" || isPreLikeNode(node) && node.parent || isScriptLikeTag(node.parent) || isVueCustomBlock(node.parent, options) || !isLastChildTrailingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) {
  42047. return false;
  42048. }
  42049. if (node.next && !isPrevTrailingSpaceSensitiveCssDisplay(node.next.cssDisplay)) {
  42050. return false;
  42051. }
  42052. return true;
  42053. }
  42054. function isDanglingSpaceSensitiveNode(node) {
  42055. return isDanglingSpaceSensitiveCssDisplay(node.cssDisplay) && !isScriptLikeTag(node);
  42056. }
  42057. function forceNextEmptyLine(node) {
  42058. return isFrontMatterNode$5(node) || node.next && node.sourceSpan.end && node.sourceSpan.end.line + 1 < node.next.sourceSpan.start.line;
  42059. }
  42060. /** firstChild leadingSpaces and lastChild trailingSpaces */
  42061. function forceBreakContent(node) {
  42062. return forceBreakChildren(node) || node.type === "element" && node.children.length !== 0 && (["body", "script", "style"].includes(node.name) || node.children.some(child => hasNonTextChild(child))) || node.firstChild && node.firstChild === node.lastChild && node.firstChild.type !== "text" && hasLeadingLineBreak(node.firstChild) && (!node.lastChild.isTrailingSpaceSensitive || hasTrailingLineBreak(node.lastChild));
  42063. }
  42064. /** spaces between children */
  42065. function forceBreakChildren(node) {
  42066. return node.type === "element" && node.children.length !== 0 && (["html", "head", "ul", "ol", "select"].includes(node.name) || node.cssDisplay.startsWith("table") && node.cssDisplay !== "table-cell");
  42067. }
  42068. function preferHardlineAsLeadingSpaces(node) {
  42069. return preferHardlineAsSurroundingSpaces(node) || node.prev && preferHardlineAsTrailingSpaces(node.prev) || hasSurroundingLineBreak(node);
  42070. }
  42071. function preferHardlineAsTrailingSpaces(node) {
  42072. return preferHardlineAsSurroundingSpaces(node) || node.type === "element" && node.fullName === "br" || hasSurroundingLineBreak(node);
  42073. }
  42074. function hasSurroundingLineBreak(node) {
  42075. return hasLeadingLineBreak(node) && hasTrailingLineBreak(node);
  42076. }
  42077. function hasLeadingLineBreak(node) {
  42078. return node.hasLeadingSpaces && (node.prev ? node.prev.sourceSpan.end.line < node.sourceSpan.start.line : node.parent.type === "root" || node.parent.startSourceSpan.end.line < node.sourceSpan.start.line);
  42079. }
  42080. function hasTrailingLineBreak(node) {
  42081. return node.hasTrailingSpaces && (node.next ? node.next.sourceSpan.start.line > node.sourceSpan.end.line : node.parent.type === "root" || node.parent.endSourceSpan && node.parent.endSourceSpan.start.line > node.sourceSpan.end.line);
  42082. }
  42083. function preferHardlineAsSurroundingSpaces(node) {
  42084. switch (node.type) {
  42085. case "ieConditionalComment":
  42086. case "comment":
  42087. case "directive":
  42088. return true;
  42089. case "element":
  42090. return ["script", "select"].includes(node.name);
  42091. }
  42092. return false;
  42093. }
  42094. function getLastDescendant(node) {
  42095. return node.lastChild ? getLastDescendant(node.lastChild) : node;
  42096. }
  42097. function hasNonTextChild(node) {
  42098. return node.children && node.children.some(child => child.type !== "text");
  42099. }
  42100. function _inferScriptParser(node) {
  42101. const {
  42102. type,
  42103. lang
  42104. } = node.attrMap;
  42105. if (type === "module" || type === "text/javascript" || type === "text/babel" || type === "application/javascript" || lang === "jsx") {
  42106. return "babel";
  42107. }
  42108. if (type === "application/x-typescript" || lang === "ts" || lang === "tsx") {
  42109. return "typescript";
  42110. }
  42111. if (type === "text/markdown") {
  42112. return "markdown";
  42113. }
  42114. if (type === "text/html") {
  42115. return "html";
  42116. }
  42117. if (type && (type.endsWith("json") || type.endsWith("importmap"))) {
  42118. return "json";
  42119. }
  42120. if (type === "text/x-handlebars-template") {
  42121. return "glimmer";
  42122. }
  42123. }
  42124. function inferStyleParser(node) {
  42125. const {
  42126. lang
  42127. } = node.attrMap;
  42128. if (!lang || lang === "postcss" || lang === "css") {
  42129. return "css";
  42130. }
  42131. if (lang === "scss") {
  42132. return "scss";
  42133. }
  42134. if (lang === "less") {
  42135. return "less";
  42136. }
  42137. }
  42138. function inferScriptParser(node, options) {
  42139. if (node.name === "script" && !node.attrMap.src) {
  42140. if (!node.attrMap.lang && !node.attrMap.type) {
  42141. return "babel";
  42142. }
  42143. return _inferScriptParser(node);
  42144. }
  42145. if (node.name === "style") {
  42146. return inferStyleParser(node);
  42147. }
  42148. if (options && isVueNonHtmlBlock(node, options)) {
  42149. return _inferScriptParser(node) || !("src" in node.attrMap) && getParserName$2(node.attrMap.lang, options);
  42150. }
  42151. }
  42152. function isBlockLikeCssDisplay(cssDisplay) {
  42153. return cssDisplay === "block" || cssDisplay === "list-item" || cssDisplay.startsWith("table");
  42154. }
  42155. function isFirstChildLeadingSpaceSensitiveCssDisplay(cssDisplay) {
  42156. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  42157. }
  42158. function isLastChildTrailingSpaceSensitiveCssDisplay(cssDisplay) {
  42159. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  42160. }
  42161. function isPrevTrailingSpaceSensitiveCssDisplay(cssDisplay) {
  42162. return !isBlockLikeCssDisplay(cssDisplay);
  42163. }
  42164. function isNextLeadingSpaceSensitiveCssDisplay(cssDisplay) {
  42165. return !isBlockLikeCssDisplay(cssDisplay);
  42166. }
  42167. function isDanglingSpaceSensitiveCssDisplay(cssDisplay) {
  42168. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  42169. }
  42170. function isPreLikeNode(node) {
  42171. return getNodeCssStyleWhiteSpace(node).startsWith("pre");
  42172. }
  42173. function countParents(path, predicate) {
  42174. let counter = 0;
  42175. for (let i = path.stack.length - 1; i >= 0; i--) {
  42176. const value = path.stack[i];
  42177. if (value && typeof value === "object" && !Array.isArray(value) && predicate(value)) {
  42178. counter++;
  42179. }
  42180. }
  42181. return counter;
  42182. }
  42183. function hasParent(node, fn) {
  42184. let current = node;
  42185. while (current) {
  42186. if (fn(current)) {
  42187. return true;
  42188. }
  42189. current = current.parent;
  42190. }
  42191. return false;
  42192. }
  42193. function getNodeCssStyleDisplay(node, options) {
  42194. if (node.prev && node.prev.type === "comment") {
  42195. // <!-- display: block -->
  42196. const match = node.prev.value.match(/^\s*display:\s*([a-z]+)\s*$/);
  42197. if (match) {
  42198. return match[1];
  42199. }
  42200. }
  42201. let isInSvgForeignObject = false;
  42202. if (node.type === "element" && node.namespace === "svg") {
  42203. if (hasParent(node, parent => parent.fullName === "svg:foreignObject")) {
  42204. isInSvgForeignObject = true;
  42205. } else {
  42206. return node.name === "svg" ? "inline-block" : "block";
  42207. }
  42208. }
  42209. switch (options.htmlWhitespaceSensitivity) {
  42210. case "strict":
  42211. return "inline";
  42212. case "ignore":
  42213. return "block";
  42214. default:
  42215. {
  42216. // See https://github.com/prettier/prettier/issues/8151
  42217. if (options.parser === "vue" && node.parent && node.parent.type === "root") {
  42218. return "block";
  42219. }
  42220. return node.type === "element" && (!node.namespace || isInSvgForeignObject || isUnknownNamespace(node)) && CSS_DISPLAY_TAGS[node.name] || CSS_DISPLAY_DEFAULT;
  42221. }
  42222. }
  42223. }
  42224. function isUnknownNamespace(node) {
  42225. return node.type === "element" && !node.hasExplicitNamespace && !["html", "svg"].includes(node.namespace);
  42226. }
  42227. function getNodeCssStyleWhiteSpace(node) {
  42228. return node.type === "element" && (!node.namespace || isUnknownNamespace(node)) && CSS_WHITE_SPACE_TAGS[node.name] || CSS_WHITE_SPACE_DEFAULT;
  42229. }
  42230. function getMinIndentation(text) {
  42231. let minIndentation = Infinity;
  42232. for (const lineText of text.split("\n")) {
  42233. if (lineText.length === 0) {
  42234. continue;
  42235. }
  42236. if (!HTML_WHITESPACE.has(lineText[0])) {
  42237. return 0;
  42238. }
  42239. const indentation = getLeadingHtmlWhitespace(lineText).length;
  42240. if (lineText.length === indentation) {
  42241. continue;
  42242. }
  42243. if (indentation < minIndentation) {
  42244. minIndentation = indentation;
  42245. }
  42246. }
  42247. return minIndentation === Infinity ? 0 : minIndentation;
  42248. }
  42249. function dedentString(text, minIndent = getMinIndentation(text)) {
  42250. return minIndent === 0 ? text : text.split("\n").map(lineText => lineText.slice(minIndent)).join("\n");
  42251. }
  42252. function shouldNotPrintClosingTag(node, options) {
  42253. return !node.isSelfClosing && !node.endSourceSpan && (hasPrettierIgnore$5(node) || shouldPreserveContent(node.parent, options));
  42254. }
  42255. function countChars(text, char) {
  42256. let counter = 0;
  42257. for (let i = 0; i < text.length; i++) {
  42258. if (text[i] === char) {
  42259. counter++;
  42260. }
  42261. }
  42262. return counter;
  42263. }
  42264. function unescapeQuoteEntities(text) {
  42265. return text.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
  42266. } // top-level elements (excluding <template>, <style> and <script>) in Vue SFC are considered custom block
  42267. // See https://vue-loader.vuejs.org/spec.html for detail
  42268. const vueRootElementsSet = new Set(["template", "style", "script"]);
  42269. function isVueCustomBlock(node, options) {
  42270. return isVueSfcBlock(node, options) && !vueRootElementsSet.has(node.fullName);
  42271. }
  42272. function isVueSfcBlock(node, options) {
  42273. return options.parser === "vue" && node.type === "element" && node.parent.type === "root" && node.fullName.toLowerCase() !== "html";
  42274. }
  42275. function isVueNonHtmlBlock(node, options) {
  42276. return isVueSfcBlock(node, options) && (isVueCustomBlock(node, options) || node.attrMap.lang && node.attrMap.lang !== "html");
  42277. }
  42278. var utils$a = {
  42279. HTML_ELEMENT_ATTRIBUTES,
  42280. HTML_TAGS,
  42281. htmlTrim,
  42282. htmlTrimPreserveIndentation,
  42283. splitByHtmlWhitespace,
  42284. hasHtmlWhitespace,
  42285. getLeadingAndTrailingHtmlWhitespace,
  42286. canHaveInterpolation,
  42287. countChars,
  42288. countParents,
  42289. dedentString,
  42290. forceBreakChildren,
  42291. forceBreakContent,
  42292. forceNextEmptyLine,
  42293. getLastDescendant,
  42294. getNodeCssStyleDisplay,
  42295. getNodeCssStyleWhiteSpace,
  42296. getPrettierIgnoreAttributeCommentData,
  42297. hasPrettierIgnore: hasPrettierIgnore$5,
  42298. inferScriptParser,
  42299. isVueCustomBlock,
  42300. isVueNonHtmlBlock,
  42301. isDanglingSpaceSensitiveNode,
  42302. isIndentationSensitiveNode,
  42303. isLeadingSpaceSensitiveNode,
  42304. isPreLikeNode,
  42305. isScriptLikeTag,
  42306. isTextLikeNode,
  42307. isTrailingSpaceSensitiveNode,
  42308. isWhitespaceSensitiveNode,
  42309. isUnknownNamespace,
  42310. preferHardlineAsLeadingSpaces,
  42311. preferHardlineAsTrailingSpaces,
  42312. shouldNotPrintClosingTag,
  42313. shouldPreserveContent,
  42314. unescapeQuoteEntities
  42315. };
  42316. const {
  42317. htmlTrim: htmlTrim$1,
  42318. getLeadingAndTrailingHtmlWhitespace: getLeadingAndTrailingHtmlWhitespace$1,
  42319. hasHtmlWhitespace: hasHtmlWhitespace$1,
  42320. canHaveInterpolation: canHaveInterpolation$1,
  42321. getNodeCssStyleDisplay: getNodeCssStyleDisplay$1,
  42322. isDanglingSpaceSensitiveNode: isDanglingSpaceSensitiveNode$1,
  42323. isIndentationSensitiveNode: isIndentationSensitiveNode$1,
  42324. isLeadingSpaceSensitiveNode: isLeadingSpaceSensitiveNode$1,
  42325. isTrailingSpaceSensitiveNode: isTrailingSpaceSensitiveNode$1,
  42326. isWhitespaceSensitiveNode: isWhitespaceSensitiveNode$1
  42327. } = utils$a;
  42328. const PREPROCESS_PIPELINE = [removeIgnorableFirstLf, mergeIeConditonalStartEndCommentIntoElementOpeningTag, mergeCdataIntoText, extractInterpolation, extractWhitespaces, addCssDisplay, addIsSelfClosing, addHasHtmComponentClosingTag, addIsSpaceSensitive, mergeSimpleElementIntoText];
  42329. function preprocess$2(ast, options) {
  42330. for (const fn of PREPROCESS_PIPELINE) {
  42331. ast = fn(ast, options);
  42332. }
  42333. return ast;
  42334. }
  42335. function removeIgnorableFirstLf(ast
  42336. /*, options */
  42337. ) {
  42338. return ast.map(node => {
  42339. if (node.type === "element" && node.tagDefinition.ignoreFirstLf && node.children.length !== 0 && node.children[0].type === "text" && node.children[0].value[0] === "\n") {
  42340. const [text, ...rest] = node.children;
  42341. return node.clone({
  42342. children: text.value.length === 1 ? rest : [text.clone({
  42343. value: text.value.slice(1)
  42344. }), ...rest]
  42345. });
  42346. }
  42347. return node;
  42348. });
  42349. }
  42350. function mergeIeConditonalStartEndCommentIntoElementOpeningTag(ast
  42351. /*, options */
  42352. ) {
  42353. /**
  42354. * <!--[if ...]><!--><target><!--<![endif]-->
  42355. */
  42356. const isTarget = node => node.type === "element" && node.prev && node.prev.type === "ieConditionalStartComment" && node.prev.sourceSpan.end.offset === node.startSourceSpan.start.offset && node.firstChild && node.firstChild.type === "ieConditionalEndComment" && node.firstChild.sourceSpan.start.offset === node.startSourceSpan.end.offset;
  42357. return ast.map(node => {
  42358. if (node.children) {
  42359. const isTargetResults = node.children.map(isTarget);
  42360. if (isTargetResults.some(Boolean)) {
  42361. const newChildren = [];
  42362. for (let i = 0; i < node.children.length; i++) {
  42363. const child = node.children[i];
  42364. if (isTargetResults[i + 1]) {
  42365. // ieConditionalStartComment
  42366. continue;
  42367. }
  42368. if (isTargetResults[i]) {
  42369. const ieConditionalStartComment = child.prev;
  42370. const ieConditionalEndComment = child.firstChild;
  42371. const ParseSourceSpan = child.sourceSpan.constructor;
  42372. const startSourceSpan = new ParseSourceSpan(ieConditionalStartComment.sourceSpan.start, ieConditionalEndComment.sourceSpan.end);
  42373. const sourceSpan = new ParseSourceSpan(startSourceSpan.start, child.sourceSpan.end);
  42374. newChildren.push(child.clone({
  42375. condition: ieConditionalStartComment.condition,
  42376. sourceSpan,
  42377. startSourceSpan,
  42378. children: child.children.slice(1)
  42379. }));
  42380. continue;
  42381. }
  42382. newChildren.push(child);
  42383. }
  42384. return node.clone({
  42385. children: newChildren
  42386. });
  42387. }
  42388. }
  42389. return node;
  42390. });
  42391. }
  42392. function mergeNodeIntoText(ast, shouldMerge, getValue) {
  42393. return ast.map(node => {
  42394. if (node.children) {
  42395. const shouldMergeResults = node.children.map(shouldMerge);
  42396. if (shouldMergeResults.some(Boolean)) {
  42397. const newChildren = [];
  42398. for (let i = 0; i < node.children.length; i++) {
  42399. const child = node.children[i];
  42400. if (child.type !== "text" && !shouldMergeResults[i]) {
  42401. newChildren.push(child);
  42402. continue;
  42403. }
  42404. const newChild = child.type === "text" ? child : child.clone({
  42405. type: "text",
  42406. value: getValue(child)
  42407. });
  42408. if (newChildren.length === 0 || newChildren[newChildren.length - 1].type !== "text") {
  42409. newChildren.push(newChild);
  42410. continue;
  42411. }
  42412. const lastChild = newChildren.pop();
  42413. const ParseSourceSpan = lastChild.sourceSpan.constructor;
  42414. newChildren.push(lastChild.clone({
  42415. value: lastChild.value + newChild.value,
  42416. sourceSpan: new ParseSourceSpan(lastChild.sourceSpan.start, newChild.sourceSpan.end)
  42417. }));
  42418. }
  42419. return node.clone({
  42420. children: newChildren
  42421. });
  42422. }
  42423. }
  42424. return node;
  42425. });
  42426. }
  42427. function mergeCdataIntoText(ast
  42428. /*, options */
  42429. ) {
  42430. return mergeNodeIntoText(ast, node => node.type === "cdata", node => `<![CDATA[${node.value}]]>`);
  42431. }
  42432. function mergeSimpleElementIntoText(ast
  42433. /*, options */
  42434. ) {
  42435. const isSimpleElement = node => node.type === "element" && node.attrs.length === 0 && node.children.length === 1 && node.firstChild.type === "text" && !hasHtmlWhitespace$1(node.children[0].value) && !node.firstChild.hasLeadingSpaces && !node.firstChild.hasTrailingSpaces && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces && node.isTrailingSpaceSensitive && !node.hasTrailingSpaces && node.prev && node.prev.type === "text" && node.next && node.next.type === "text";
  42436. return ast.map(node => {
  42437. if (node.children) {
  42438. const isSimpleElementResults = node.children.map(isSimpleElement);
  42439. if (isSimpleElementResults.some(Boolean)) {
  42440. const newChildren = [];
  42441. for (let i = 0; i < node.children.length; i++) {
  42442. const child = node.children[i];
  42443. if (isSimpleElementResults[i]) {
  42444. const lastChild = newChildren.pop();
  42445. const nextChild = node.children[++i];
  42446. const ParseSourceSpan = node.sourceSpan.constructor;
  42447. const {
  42448. isTrailingSpaceSensitive,
  42449. hasTrailingSpaces
  42450. } = nextChild;
  42451. newChildren.push(lastChild.clone({
  42452. value: lastChild.value + `<${child.rawName}>` + child.firstChild.value + `</${child.rawName}>` + nextChild.value,
  42453. sourceSpan: new ParseSourceSpan(lastChild.sourceSpan.start, nextChild.sourceSpan.end),
  42454. isTrailingSpaceSensitive,
  42455. hasTrailingSpaces
  42456. }));
  42457. } else {
  42458. newChildren.push(child);
  42459. }
  42460. }
  42461. return node.clone({
  42462. children: newChildren
  42463. });
  42464. }
  42465. }
  42466. return node;
  42467. });
  42468. }
  42469. function extractInterpolation(ast, options) {
  42470. if (options.parser === "html") {
  42471. return ast;
  42472. }
  42473. const interpolationRegex = /{{([\S\s]+?)}}/g;
  42474. return ast.map(node => {
  42475. if (!canHaveInterpolation$1(node)) {
  42476. return node;
  42477. }
  42478. const newChildren = [];
  42479. for (const child of node.children) {
  42480. if (child.type !== "text") {
  42481. newChildren.push(child);
  42482. continue;
  42483. }
  42484. const ParseSourceSpan = child.sourceSpan.constructor;
  42485. let startSourceSpan = child.sourceSpan.start;
  42486. let endSourceSpan = null;
  42487. const components = child.value.split(interpolationRegex);
  42488. for (let i = 0; i < components.length; i++, startSourceSpan = endSourceSpan) {
  42489. const value = components[i];
  42490. if (i % 2 === 0) {
  42491. endSourceSpan = startSourceSpan.moveBy(value.length);
  42492. if (value.length !== 0) {
  42493. newChildren.push({
  42494. type: "text",
  42495. value,
  42496. sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan)
  42497. });
  42498. }
  42499. continue;
  42500. }
  42501. endSourceSpan = startSourceSpan.moveBy(value.length + 4); // `{{` + `}}`
  42502. newChildren.push({
  42503. type: "interpolation",
  42504. sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan),
  42505. children: value.length === 0 ? [] : [{
  42506. type: "text",
  42507. value,
  42508. sourceSpan: new ParseSourceSpan(startSourceSpan.moveBy(2), endSourceSpan.moveBy(-2))
  42509. }]
  42510. });
  42511. }
  42512. }
  42513. return node.clone({
  42514. children: newChildren
  42515. });
  42516. });
  42517. }
  42518. /**
  42519. * - add `hasLeadingSpaces` field
  42520. * - add `hasTrailingSpaces` field
  42521. * - add `hasDanglingSpaces` field for parent nodes
  42522. * - add `isWhitespaceSensitive`, `isIndentationSensitive` field for text nodes
  42523. * - remove insensitive whitespaces
  42524. */
  42525. function extractWhitespaces(ast
  42526. /*, options*/
  42527. ) {
  42528. const TYPE_WHITESPACE = "whitespace";
  42529. return ast.map(node => {
  42530. if (!node.children) {
  42531. return node;
  42532. }
  42533. if (node.children.length === 0 || node.children.length === 1 && node.children[0].type === "text" && htmlTrim$1(node.children[0].value).length === 0) {
  42534. return node.clone({
  42535. children: [],
  42536. hasDanglingSpaces: node.children.length !== 0
  42537. });
  42538. }
  42539. const isWhitespaceSensitive = isWhitespaceSensitiveNode$1(node);
  42540. const isIndentationSensitive = isIndentationSensitiveNode$1(node);
  42541. return node.clone({
  42542. isWhitespaceSensitive,
  42543. isIndentationSensitive,
  42544. children: node.children // extract whitespace nodes
  42545. .reduce((newChildren, child) => {
  42546. if (child.type !== "text" || isWhitespaceSensitive) {
  42547. return newChildren.concat(child);
  42548. }
  42549. const localChildren = [];
  42550. const {
  42551. leadingWhitespace,
  42552. text,
  42553. trailingWhitespace
  42554. } = getLeadingAndTrailingHtmlWhitespace$1(child.value);
  42555. if (leadingWhitespace) {
  42556. localChildren.push({
  42557. type: TYPE_WHITESPACE
  42558. });
  42559. }
  42560. const ParseSourceSpan = child.sourceSpan.constructor;
  42561. if (text) {
  42562. localChildren.push({
  42563. type: "text",
  42564. value: text,
  42565. sourceSpan: new ParseSourceSpan(child.sourceSpan.start.moveBy(leadingWhitespace.length), child.sourceSpan.end.moveBy(-trailingWhitespace.length))
  42566. });
  42567. }
  42568. if (trailingWhitespace) {
  42569. localChildren.push({
  42570. type: TYPE_WHITESPACE
  42571. });
  42572. }
  42573. return newChildren.concat(localChildren);
  42574. }, []) // set hasLeadingSpaces/hasTrailingSpaces and filter whitespace nodes
  42575. .reduce((newChildren, child, i, children) => {
  42576. if (child.type === TYPE_WHITESPACE) {
  42577. return newChildren;
  42578. }
  42579. const hasLeadingSpaces = i !== 0 && children[i - 1].type === TYPE_WHITESPACE;
  42580. const hasTrailingSpaces = i !== children.length - 1 && children[i + 1].type === TYPE_WHITESPACE;
  42581. return newChildren.concat(Object.assign({}, child, {
  42582. hasLeadingSpaces,
  42583. hasTrailingSpaces
  42584. }));
  42585. }, [])
  42586. });
  42587. });
  42588. }
  42589. function addIsSelfClosing(ast
  42590. /*, options */
  42591. ) {
  42592. return ast.map(node => Object.assign(node, {
  42593. isSelfClosing: !node.children || node.type === "element" && (node.tagDefinition.isVoid || // self-closing
  42594. node.startSourceSpan === node.endSourceSpan)
  42595. }));
  42596. }
  42597. function addHasHtmComponentClosingTag(ast, options) {
  42598. return ast.map(node => node.type !== "element" ? node : Object.assign(node, {
  42599. hasHtmComponentClosingTag: node.endSourceSpan && /^<\s*\/\s*\/\s*>$/.test(options.originalText.slice(node.endSourceSpan.start.offset, node.endSourceSpan.end.offset))
  42600. }));
  42601. }
  42602. function addCssDisplay(ast, options) {
  42603. return ast.map(node => Object.assign(node, {
  42604. cssDisplay: getNodeCssStyleDisplay$1(node, options)
  42605. }));
  42606. }
  42607. /**
  42608. * - add `isLeadingSpaceSensitive` field
  42609. * - add `isTrailingSpaceSensitive` field
  42610. * - add `isDanglingSpaceSensitive` field for parent nodes
  42611. */
  42612. function addIsSpaceSensitive(ast, options) {
  42613. return ast.map(node => {
  42614. if (!node.children) {
  42615. return node;
  42616. }
  42617. if (node.children.length === 0) {
  42618. return node.clone({
  42619. isDanglingSpaceSensitive: isDanglingSpaceSensitiveNode$1(node)
  42620. });
  42621. }
  42622. return node.clone({
  42623. children: node.children.map(child => {
  42624. return Object.assign({}, child, {
  42625. isLeadingSpaceSensitive: isLeadingSpaceSensitiveNode$1(child, options),
  42626. isTrailingSpaceSensitive: isTrailingSpaceSensitiveNode$1(child, options)
  42627. });
  42628. }).map((child, index, children) => Object.assign({}, child, {
  42629. isLeadingSpaceSensitive: index === 0 ? child.isLeadingSpaceSensitive : children[index - 1].isTrailingSpaceSensitive && child.isLeadingSpaceSensitive,
  42630. isTrailingSpaceSensitive: index === children.length - 1 ? child.isTrailingSpaceSensitive : children[index + 1].isLeadingSpaceSensitive && child.isTrailingSpaceSensitive
  42631. }))
  42632. });
  42633. });
  42634. }
  42635. var preprocess_1$2 = preprocess$2;
  42636. function hasPragma$3(text) {
  42637. return /^\s*<!--\s*@(format|prettier)\s*-->/.test(text);
  42638. }
  42639. function insertPragma$6(text) {
  42640. return "<!-- @format -->\n\n" + text.replace(/^\s*\n/, "");
  42641. }
  42642. var pragma$4 = {
  42643. hasPragma: hasPragma$3,
  42644. insertPragma: insertPragma$6
  42645. };
  42646. const {
  42647. builders: {
  42648. concat: concat$l,
  42649. group: group$j
  42650. }
  42651. } = document;
  42652. /**
  42653. * v-for="... in ..."
  42654. * v-for="... of ..."
  42655. * v-for="(..., ...) in ..."
  42656. * v-for="(..., ...) of ..."
  42657. */
  42658. function printVueFor(value, textToDoc) {
  42659. const {
  42660. left,
  42661. operator,
  42662. right
  42663. } = parseVueFor(value);
  42664. return concat$l([group$j(textToDoc(`function _(${left}) {}`, {
  42665. parser: "babel",
  42666. __isVueForBindingLeft: true
  42667. })), " ", operator, " ", textToDoc(right, {
  42668. parser: "__js_expression"
  42669. }, {
  42670. stripTrailingHardline: true
  42671. })]);
  42672. } // modified from https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/parser/index.js#L370-L387
  42673. function parseVueFor(value) {
  42674. const forAliasRE = /([^]*?)\s+(in|of)\s+([^]*)/;
  42675. const forIteratorRE = /,([^,\]}]*)(?:,([^,\]}]*))?$/;
  42676. const stripParensRE = /^\(|\)$/g;
  42677. const inMatch = value.match(forAliasRE);
  42678. if (!inMatch) {
  42679. return;
  42680. }
  42681. const res = {};
  42682. res.for = inMatch[3].trim();
  42683. const alias = inMatch[1].trim().replace(stripParensRE, "");
  42684. const iteratorMatch = alias.match(forIteratorRE);
  42685. if (iteratorMatch) {
  42686. res.alias = alias.replace(forIteratorRE, "");
  42687. res.iterator1 = iteratorMatch[1].trim();
  42688. if (iteratorMatch[2]) {
  42689. res.iterator2 = iteratorMatch[2].trim();
  42690. }
  42691. } else {
  42692. res.alias = alias;
  42693. }
  42694. return {
  42695. left: `${[res.alias, res.iterator1, res.iterator2].filter(Boolean).join(",")}`,
  42696. operator: inMatch[2],
  42697. right: res.for
  42698. };
  42699. }
  42700. function printVueSlotScope(value, textToDoc) {
  42701. return textToDoc(`function _(${value}) {}`, {
  42702. parser: "babel",
  42703. __isVueSlotScope: true
  42704. }, {
  42705. stripTrailingHardline: true
  42706. });
  42707. }
  42708. function isVueEventBindingExpression$2(eventBindingValue) {
  42709. // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/codegen/events.js#L3-L4
  42710. // arrow function or anonymous function
  42711. const fnExpRE = /^([\w$]+|\([^)]*?\))\s*=>|^function\s*\(/; // simple member expression chain (a, a.b, a['b'], a["b"], a[0], a[b])
  42712. const simplePathRE = /^[$A-Z_a-z][\w$]*(?:\.[$A-Z_a-z][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[$A-Z_a-z][\w$]*])*$/; // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/helpers.js#L104
  42713. const value = eventBindingValue.trim();
  42714. return fnExpRE.test(value) || simplePathRE.test(value);
  42715. }
  42716. var syntaxVue = {
  42717. isVueEventBindingExpression: isVueEventBindingExpression$2,
  42718. printVueFor,
  42719. printVueSlotScope
  42720. };
  42721. var parseSrcset = createCommonjsModule(function (module) {
  42722. /**
  42723. * Srcset Parser
  42724. *
  42725. * By Alex Bell | MIT License
  42726. *
  42727. * JS Parser for the string value that appears in markup <img srcset="here">
  42728. *
  42729. * @returns Array [{url: _, d: _, w: _, h:_}, ...]
  42730. *
  42731. * Based super duper closely on the reference algorithm at:
  42732. * https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-srcset-attribute
  42733. *
  42734. * Most comments are copied in directly from the spec
  42735. * (except for comments in parens).
  42736. */
  42737. (function (root, factory) {
  42738. if ( module.exports) {
  42739. // Node. Does not work with strict CommonJS, but
  42740. // only CommonJS-like environments that support module.exports,
  42741. // like Node.
  42742. module.exports = factory();
  42743. } else {
  42744. // Browser globals (root is window)
  42745. root.parseSrcset = factory();
  42746. }
  42747. })(this, function () {
  42748. // 1. Let input be the value passed to this algorithm.
  42749. return function (input, options) {
  42750. var logger = options && options.logger || console; // UTILITY FUNCTIONS
  42751. // Manual is faster than RegEx
  42752. // http://bjorn.tipling.com/state-and-regular-expressions-in-javascript
  42753. // http://jsperf.com/whitespace-character/5
  42754. function isSpace(c) {
  42755. return c === "\u0020" || // space
  42756. c === "\u0009" || // horizontal tab
  42757. c === "\u000A" || // new line
  42758. c === "\u000C" || // form feed
  42759. c === "\u000D"; // carriage return
  42760. }
  42761. function collectCharacters(regEx) {
  42762. var chars,
  42763. match = regEx.exec(input.substring(pos));
  42764. if (match) {
  42765. chars = match[0];
  42766. pos += chars.length;
  42767. return chars;
  42768. }
  42769. }
  42770. var inputLength = input.length,
  42771. // (Don't use \s, to avoid matching non-breaking space)
  42772. regexLeadingSpaces = /^[ \t\n\r\u000c]+/,
  42773. regexLeadingCommasOrSpaces = /^[, \t\n\r\u000c]+/,
  42774. regexLeadingNotSpaces = /^[^ \t\n\r\u000c]+/,
  42775. regexTrailingCommas = /[,]+$/,
  42776. regexNonNegativeInteger = /^\d+$/,
  42777. // ( Positive or negative or unsigned integers or decimals, without or without exponents.
  42778. // Must include at least one digit.
  42779. // According to spec tests any decimal point must be followed by a digit.
  42780. // No leading plus sign is allowed.)
  42781. // https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floating-point-number
  42782. regexFloatingPoint = /^-?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/,
  42783. url,
  42784. descriptors,
  42785. currentDescriptor,
  42786. state,
  42787. c,
  42788. // 2. Let position be a pointer into input, initially pointing at the start
  42789. // of the string.
  42790. pos = 0,
  42791. // 3. Let candidates be an initially empty source set.
  42792. candidates = []; // 4. Splitting loop: Collect a sequence of characters that are space
  42793. // characters or U+002C COMMA characters. If any U+002C COMMA characters
  42794. // were collected, that is a parse error.
  42795. while (true) {
  42796. collectCharacters(regexLeadingCommasOrSpaces); // 5. If position is past the end of input, return candidates and abort these steps.
  42797. if (pos >= inputLength) {
  42798. return candidates; // (we're done, this is the sole return path)
  42799. } // 6. Collect a sequence of characters that are not space characters,
  42800. // and let that be url.
  42801. url = collectCharacters(regexLeadingNotSpaces); // 7. Let descriptors be a new empty list.
  42802. descriptors = []; // 8. If url ends with a U+002C COMMA character (,), follow these substeps:
  42803. // (1). Remove all trailing U+002C COMMA characters from url. If this removed
  42804. // more than one character, that is a parse error.
  42805. if (url.slice(-1) === ",") {
  42806. url = url.replace(regexTrailingCommas, ""); // (Jump ahead to step 9 to skip tokenization and just push the candidate).
  42807. parseDescriptors(); // Otherwise, follow these substeps:
  42808. } else {
  42809. tokenize();
  42810. } // (close else of step 8)
  42811. // 16. Return to the step labeled splitting loop.
  42812. } // (Close of big while loop.)
  42813. /**
  42814. * Tokenizes descriptor properties prior to parsing
  42815. * Returns undefined.
  42816. */
  42817. function tokenize() {
  42818. // 8.1. Descriptor tokeniser: Skip whitespace
  42819. collectCharacters(regexLeadingSpaces); // 8.2. Let current descriptor be the empty string.
  42820. currentDescriptor = ""; // 8.3. Let state be in descriptor.
  42821. state = "in descriptor";
  42822. while (true) {
  42823. // 8.4. Let c be the character at position.
  42824. c = input.charAt(pos); // Do the following depending on the value of state.
  42825. // For the purpose of this step, "EOF" is a special character representing
  42826. // that position is past the end of input.
  42827. // In descriptor
  42828. if (state === "in descriptor") {
  42829. // Do the following, depending on the value of c:
  42830. // Space character
  42831. // If current descriptor is not empty, append current descriptor to
  42832. // descriptors and let current descriptor be the empty string.
  42833. // Set state to after descriptor.
  42834. if (isSpace(c)) {
  42835. if (currentDescriptor) {
  42836. descriptors.push(currentDescriptor);
  42837. currentDescriptor = "";
  42838. state = "after descriptor";
  42839. } // U+002C COMMA (,)
  42840. // Advance position to the next character in input. If current descriptor
  42841. // is not empty, append current descriptor to descriptors. Jump to the step
  42842. // labeled descriptor parser.
  42843. } else if (c === ",") {
  42844. pos += 1;
  42845. if (currentDescriptor) {
  42846. descriptors.push(currentDescriptor);
  42847. }
  42848. parseDescriptors();
  42849. return; // U+0028 LEFT PARENTHESIS (()
  42850. // Append c to current descriptor. Set state to in parens.
  42851. } else if (c === "\u0028") {
  42852. currentDescriptor = currentDescriptor + c;
  42853. state = "in parens"; // EOF
  42854. // If current descriptor is not empty, append current descriptor to
  42855. // descriptors. Jump to the step labeled descriptor parser.
  42856. } else if (c === "") {
  42857. if (currentDescriptor) {
  42858. descriptors.push(currentDescriptor);
  42859. }
  42860. parseDescriptors();
  42861. return; // Anything else
  42862. // Append c to current descriptor.
  42863. } else {
  42864. currentDescriptor = currentDescriptor + c;
  42865. } // (end "in descriptor"
  42866. // In parens
  42867. } else if (state === "in parens") {
  42868. // U+0029 RIGHT PARENTHESIS ())
  42869. // Append c to current descriptor. Set state to in descriptor.
  42870. if (c === ")") {
  42871. currentDescriptor = currentDescriptor + c;
  42872. state = "in descriptor"; // EOF
  42873. // Append current descriptor to descriptors. Jump to the step labeled
  42874. // descriptor parser.
  42875. } else if (c === "") {
  42876. descriptors.push(currentDescriptor);
  42877. parseDescriptors();
  42878. return; // Anything else
  42879. // Append c to current descriptor.
  42880. } else {
  42881. currentDescriptor = currentDescriptor + c;
  42882. } // After descriptor
  42883. } else if (state === "after descriptor") {
  42884. // Do the following, depending on the value of c:
  42885. // Space character: Stay in this state.
  42886. if (isSpace(c)) ; else if (c === "") {
  42887. parseDescriptors();
  42888. return; // Anything else
  42889. // Set state to in descriptor. Set position to the previous character in input.
  42890. } else {
  42891. state = "in descriptor";
  42892. pos -= 1;
  42893. }
  42894. } // Advance position to the next character in input.
  42895. pos += 1; // Repeat this step.
  42896. } // (close while true loop)
  42897. }
  42898. /**
  42899. * Adds descriptor properties to a candidate, pushes to the candidates array
  42900. * @return undefined
  42901. */
  42902. // Declared outside of the while loop so that it's only created once.
  42903. function parseDescriptors() {
  42904. // 9. Descriptor parser: Let error be no.
  42905. var pError = false,
  42906. // 10. Let width be absent.
  42907. // 11. Let density be absent.
  42908. // 12. Let future-compat-h be absent. (We're implementing it now as h)
  42909. w,
  42910. d,
  42911. h,
  42912. i,
  42913. candidate = {},
  42914. desc,
  42915. lastChar,
  42916. value,
  42917. intVal,
  42918. floatVal; // 13. For each descriptor in descriptors, run the appropriate set of steps
  42919. // from the following list:
  42920. for (i = 0; i < descriptors.length; i++) {
  42921. desc = descriptors[i];
  42922. lastChar = desc[desc.length - 1];
  42923. value = desc.substring(0, desc.length - 1);
  42924. intVal = parseInt(value, 10);
  42925. floatVal = parseFloat(value); // If the descriptor consists of a valid non-negative integer followed by
  42926. // a U+0077 LATIN SMALL LETTER W character
  42927. if (regexNonNegativeInteger.test(value) && lastChar === "w") {
  42928. // If width and density are not both absent, then let error be yes.
  42929. if (w || d) {
  42930. pError = true;
  42931. } // Apply the rules for parsing non-negative integers to the descriptor.
  42932. // If the result is zero, let error be yes.
  42933. // Otherwise, let width be the result.
  42934. if (intVal === 0) {
  42935. pError = true;
  42936. } else {
  42937. w = intVal;
  42938. } // If the descriptor consists of a valid floating-point number followed by
  42939. // a U+0078 LATIN SMALL LETTER X character
  42940. } else if (regexFloatingPoint.test(value) && lastChar === "x") {
  42941. // If width, density and future-compat-h are not all absent, then let error
  42942. // be yes.
  42943. if (w || d || h) {
  42944. pError = true;
  42945. } // Apply the rules for parsing floating-point number values to the descriptor.
  42946. // If the result is less than zero, let error be yes. Otherwise, let density
  42947. // be the result.
  42948. if (floatVal < 0) {
  42949. pError = true;
  42950. } else {
  42951. d = floatVal;
  42952. } // If the descriptor consists of a valid non-negative integer followed by
  42953. // a U+0068 LATIN SMALL LETTER H character
  42954. } else if (regexNonNegativeInteger.test(value) && lastChar === "h") {
  42955. // If height and density are not both absent, then let error be yes.
  42956. if (h || d) {
  42957. pError = true;
  42958. } // Apply the rules for parsing non-negative integers to the descriptor.
  42959. // If the result is zero, let error be yes. Otherwise, let future-compat-h
  42960. // be the result.
  42961. if (intVal === 0) {
  42962. pError = true;
  42963. } else {
  42964. h = intVal;
  42965. } // Anything else, Let error be yes.
  42966. } else {
  42967. pError = true;
  42968. }
  42969. } // (close step 13 for loop)
  42970. // 15. If error is still no, then append a new image source to candidates whose
  42971. // URL is url, associated with a width width if not absent and a pixel
  42972. // density density if not absent. Otherwise, there is a parse error.
  42973. if (!pError) {
  42974. candidate.url = url;
  42975. if (w) {
  42976. candidate.w = w;
  42977. }
  42978. if (d) {
  42979. candidate.d = d;
  42980. }
  42981. if (h) {
  42982. candidate.h = h;
  42983. }
  42984. candidates.push(candidate);
  42985. } else if (logger && logger.error) {
  42986. logger.error("Invalid srcset descriptor found in '" + input + "' at '" + desc + "'.");
  42987. }
  42988. } // (close parseDescriptors fn)
  42989. };
  42990. });
  42991. });
  42992. const {
  42993. builders: {
  42994. concat: concat$m,
  42995. ifBreak: ifBreak$9,
  42996. join: join$c,
  42997. line: line$d
  42998. }
  42999. } = document;
  43000. function printImgSrcset(value) {
  43001. const srcset = parseSrcset(value, {
  43002. logger: {
  43003. error(message) {
  43004. throw new Error(message);
  43005. }
  43006. }
  43007. });
  43008. const hasW = srcset.some(({
  43009. w
  43010. }) => w);
  43011. const hasH = srcset.some(({
  43012. h
  43013. }) => h);
  43014. const hasX = srcset.some(({
  43015. d
  43016. }) => d);
  43017. if (hasW + hasH + hasX > 1) {
  43018. throw new Error("Mixed descriptor in srcset is not supported");
  43019. }
  43020. const key = hasW ? "w" : hasH ? "h" : "d";
  43021. const unit = hasW ? "w" : hasH ? "h" : "x";
  43022. const getMax = values => Math.max(...values);
  43023. const urls = srcset.map(src => src.url);
  43024. const maxUrlLength = getMax(urls.map(url => url.length));
  43025. const descriptors = srcset.map(src => src[key]).map(descriptor => descriptor ? descriptor.toString() : "");
  43026. const descriptorLeftLengths = descriptors.map(descriptor => {
  43027. const index = descriptor.indexOf(".");
  43028. return index === -1 ? descriptor.length : index;
  43029. });
  43030. const maxDescriptorLeftLength = getMax(descriptorLeftLengths);
  43031. return join$c(concat$m([",", line$d]), urls.map((url, index) => {
  43032. const parts = [url];
  43033. const descriptor = descriptors[index];
  43034. if (descriptor) {
  43035. const urlPadding = maxUrlLength - url.length + 1;
  43036. const descriptorPadding = maxDescriptorLeftLength - descriptorLeftLengths[index];
  43037. const alignment = " ".repeat(urlPadding + descriptorPadding);
  43038. parts.push(ifBreak$9(alignment, " "), descriptor + unit);
  43039. }
  43040. return concat$m(parts);
  43041. }));
  43042. }
  43043. function printClassNames(value) {
  43044. return value.trim().split(/\s+/).join(" ");
  43045. }
  43046. var syntaxAttribute = {
  43047. printImgSrcset,
  43048. printClassNames
  43049. };
  43050. const {
  43051. builders,
  43052. utils: {
  43053. mapDoc: mapDoc$2,
  43054. normalizeParts: normalizeParts$2
  43055. }
  43056. } = document;
  43057. const {
  43058. replaceEndOfLineWith: replaceEndOfLineWith$2
  43059. } = util;
  43060. const {
  43061. print: printFrontMatter$2
  43062. } = frontMatter;
  43063. const {
  43064. breakParent: breakParent$7,
  43065. dedentToRoot: dedentToRoot$2,
  43066. fill: fill$6,
  43067. group: group$k,
  43068. hardline: hardline$f,
  43069. ifBreak: ifBreak$a,
  43070. indent: indent$e,
  43071. join: join$d,
  43072. line: line$e,
  43073. literalline: literalline$5,
  43074. softline: softline$b
  43075. } = builders;
  43076. const {
  43077. htmlTrimPreserveIndentation: htmlTrimPreserveIndentation$1,
  43078. splitByHtmlWhitespace: splitByHtmlWhitespace$1,
  43079. countChars: countChars$1,
  43080. countParents: countParents$1,
  43081. dedentString: dedentString$1,
  43082. forceBreakChildren: forceBreakChildren$1,
  43083. forceBreakContent: forceBreakContent$1,
  43084. forceNextEmptyLine: forceNextEmptyLine$1,
  43085. getLastDescendant: getLastDescendant$1,
  43086. getPrettierIgnoreAttributeCommentData: getPrettierIgnoreAttributeCommentData$1,
  43087. hasPrettierIgnore: hasPrettierIgnore$6,
  43088. inferScriptParser: inferScriptParser$1,
  43089. isVueCustomBlock: isVueCustomBlock$1,
  43090. isVueNonHtmlBlock: isVueNonHtmlBlock$1,
  43091. isScriptLikeTag: isScriptLikeTag$1,
  43092. isTextLikeNode: isTextLikeNode$1,
  43093. preferHardlineAsLeadingSpaces: preferHardlineAsLeadingSpaces$1,
  43094. shouldNotPrintClosingTag: shouldNotPrintClosingTag$1,
  43095. shouldPreserveContent: shouldPreserveContent$1,
  43096. unescapeQuoteEntities: unescapeQuoteEntities$1,
  43097. isPreLikeNode: isPreLikeNode$1
  43098. } = utils$a;
  43099. const {
  43100. insertPragma: insertPragma$7
  43101. } = pragma$4;
  43102. const {
  43103. printVueFor: printVueFor$1,
  43104. printVueSlotScope: printVueSlotScope$1,
  43105. isVueEventBindingExpression: isVueEventBindingExpression$3
  43106. } = syntaxVue;
  43107. const {
  43108. printImgSrcset: printImgSrcset$1,
  43109. printClassNames: printClassNames$1
  43110. } = syntaxAttribute;
  43111. function concat$n(parts) {
  43112. const newParts = normalizeParts$2(parts);
  43113. return newParts.length === 0 ? "" : newParts.length === 1 ? newParts[0] : builders.concat(newParts);
  43114. }
  43115. function embed$4(path, print, textToDoc, options) {
  43116. const node = path.getValue();
  43117. switch (node.type) {
  43118. case "element":
  43119. {
  43120. if (isScriptLikeTag$1(node) || node.type === "interpolation") {
  43121. // Fall through to "text"
  43122. return;
  43123. }
  43124. if (!node.isSelfClosing && isVueNonHtmlBlock$1(node, options)) {
  43125. const parser = inferScriptParser$1(node, options);
  43126. if (!parser) {
  43127. return;
  43128. }
  43129. const content = getNodeContent(node, options);
  43130. let isEmpty = /^\s*$/.test(content);
  43131. let doc = "";
  43132. if (!isEmpty) {
  43133. doc = textToDoc(htmlTrimPreserveIndentation$1(content), {
  43134. parser
  43135. }, {
  43136. stripTrailingHardline: true
  43137. });
  43138. isEmpty = doc === "";
  43139. }
  43140. return concat$n([printOpeningTagPrefix(node, options), group$k(printOpeningTag(path, options, print)), isEmpty ? "" : hardline$f, doc, isEmpty ? "" : hardline$f, printClosingTag(node, options), printClosingTagSuffix(node, options)]);
  43141. }
  43142. break;
  43143. }
  43144. case "text":
  43145. {
  43146. if (isScriptLikeTag$1(node.parent)) {
  43147. const parser = inferScriptParser$1(node.parent);
  43148. if (parser) {
  43149. const value = parser === "markdown" ? dedentString$1(node.value.replace(/^[^\S\n]*?\n/, "")) : node.value;
  43150. const textToDocOptions = {
  43151. parser
  43152. };
  43153. if (options.parser === "html" && parser === "babel") {
  43154. let sourceType = "script";
  43155. const {
  43156. attrMap
  43157. } = node.parent;
  43158. if (attrMap && (attrMap.type === "module" || attrMap.type === "text/babel" && attrMap["data-type"] === "module")) {
  43159. sourceType = "module";
  43160. }
  43161. textToDocOptions.__babelSourceType = sourceType;
  43162. }
  43163. return builders.concat([concat$n([breakParent$7, printOpeningTagPrefix(node, options), textToDoc(value, textToDocOptions, {
  43164. stripTrailingHardline: true
  43165. }), printClosingTagSuffix(node, options)])]);
  43166. }
  43167. } else if (node.parent.type === "interpolation") {
  43168. return concat$n([indent$e(concat$n([line$e, textToDoc(node.value, Object.assign({
  43169. __isInHtmlInterpolation: true
  43170. }, options.parser === "angular" ? {
  43171. parser: "__ng_interpolation",
  43172. trailingComma: "none"
  43173. } : options.parser === "vue" ? {
  43174. parser: "__vue_expression"
  43175. } : {
  43176. parser: "__js_expression"
  43177. }), {
  43178. stripTrailingHardline: true
  43179. })])), node.parent.next && needsToBorrowPrevClosingTagEndMarker(node.parent.next) ? " " : line$e]);
  43180. }
  43181. break;
  43182. }
  43183. case "attribute":
  43184. {
  43185. if (!node.value) {
  43186. break;
  43187. } // lit-html: html`<my-element obj=${obj}></my-element>`
  43188. if (/^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
  43189. return concat$n([node.rawName, "=", node.value]);
  43190. } // lwc: html`<my-element data-for={value}></my-element>`
  43191. if (options.parser === "lwc") {
  43192. const interpolationRegex = /^{[\S\s]*}$/;
  43193. if (interpolationRegex.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
  43194. return concat$n([node.rawName, "=", node.value]);
  43195. }
  43196. }
  43197. const embeddedAttributeValueDoc = printEmbeddedAttributeValue(node, (code, opts) => // strictly prefer single quote to avoid unnecessary html entity escape
  43198. textToDoc(code, Object.assign({
  43199. __isInHtmlAttribute: true
  43200. }, opts), {
  43201. stripTrailingHardline: true
  43202. }), options);
  43203. if (embeddedAttributeValueDoc) {
  43204. return concat$n([node.rawName, '="', group$k(mapDoc$2(embeddedAttributeValueDoc, doc => typeof doc === "string" ? doc.replace(/"/g, "&quot;") : doc)), '"']);
  43205. }
  43206. break;
  43207. }
  43208. case "front-matter":
  43209. return printFrontMatter$2(node, textToDoc);
  43210. }
  43211. }
  43212. function genericPrint$5(path, options, print) {
  43213. const node = path.getValue();
  43214. switch (node.type) {
  43215. case "front-matter":
  43216. return concat$n(replaceEndOfLineWith$2(node.raw, literalline$5));
  43217. case "root":
  43218. if (options.__onHtmlRoot) {
  43219. options.__onHtmlRoot(node);
  43220. } // use original concat to not break stripTrailingHardline
  43221. return builders.concat([group$k(printChildren$2(path, options, print)), hardline$f]);
  43222. case "element":
  43223. case "ieConditionalComment":
  43224. {
  43225. if (shouldPreserveContent$1(node, options)) {
  43226. return concat$n([].concat(printOpeningTagPrefix(node, options), group$k(printOpeningTag(path, options, print)), replaceEndOfLineWith$2(getNodeContent(node, options), literalline$5), printClosingTag(node, options), printClosingTagSuffix(node, options)));
  43227. }
  43228. /**
  43229. * do not break:
  43230. *
  43231. * <div>{{
  43232. * ~
  43233. * interpolation
  43234. * }}</div>
  43235. * ~
  43236. *
  43237. * exception: break if the opening tag breaks
  43238. *
  43239. * <div
  43240. * long
  43241. * ~
  43242. * >{{
  43243. * interpolation
  43244. * }}</div
  43245. * ~
  43246. * >
  43247. */
  43248. const shouldHugContent = node.children.length === 1 && node.firstChild.type === "interpolation" && node.firstChild.isLeadingSpaceSensitive && !node.firstChild.hasLeadingSpaces && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces;
  43249. const attrGroupId = Symbol("element-attr-group-id");
  43250. return concat$n([group$k(concat$n([group$k(printOpeningTag(path, options, print), {
  43251. id: attrGroupId
  43252. }), node.children.length === 0 ? node.hasDanglingSpaces && node.isDanglingSpaceSensitive ? line$e : "" : concat$n([forceBreakContent$1(node) ? breakParent$7 : "", (childrenDoc => shouldHugContent ? ifBreak$a(indent$e(childrenDoc), childrenDoc, {
  43253. groupId: attrGroupId
  43254. }) : (isScriptLikeTag$1(node) || isVueCustomBlock$1(node, options)) && node.parent.type === "root" && options.parser === "vue" && !options.vueIndentScriptAndStyle ? childrenDoc : indent$e(childrenDoc))(concat$n([shouldHugContent ? ifBreak$a(softline$b, "", {
  43255. groupId: attrGroupId
  43256. }) : node.firstChild.hasLeadingSpaces && node.firstChild.isLeadingSpaceSensitive ? line$e : node.firstChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive ? dedentToRoot$2(softline$b) : softline$b, printChildren$2(path, options, print)])), (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? " " : "" : shouldHugContent ? ifBreak$a(softline$b, "", {
  43257. groupId: attrGroupId
  43258. }) : node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? line$e : (node.lastChild.type === "comment" || node.lastChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive) && new RegExp(`\\n[\\t ]{${options.tabWidth * countParents$1(path, n => n.parent && n.parent.type !== "root")}}$`).test(node.lastChild.value) ?
  43259. /**
  43260. * <div>
  43261. * <pre>
  43262. * something
  43263. * </pre>
  43264. * ~
  43265. * </div>
  43266. */
  43267. "" : softline$b])])), printClosingTag(node, options)]);
  43268. }
  43269. case "ieConditionalStartComment":
  43270. case "ieConditionalEndComment":
  43271. return concat$n([printOpeningTagStart(node), printClosingTagEnd(node)]);
  43272. case "interpolation":
  43273. return concat$n([printOpeningTagStart(node, options), concat$n(path.map(print, "children")), printClosingTagEnd(node, options)]);
  43274. case "text":
  43275. {
  43276. if (node.parent.type === "interpolation") {
  43277. // replace the trailing literalline with hardline for better readability
  43278. const trailingNewlineRegex = /\n[^\S\n]*?$/;
  43279. const hasTrailingNewline = trailingNewlineRegex.test(node.value);
  43280. const value = hasTrailingNewline ? node.value.replace(trailingNewlineRegex, "") : node.value;
  43281. return concat$n([concat$n(replaceEndOfLineWith$2(value, literalline$5)), hasTrailingNewline ? hardline$f : ""]);
  43282. }
  43283. return fill$6(normalizeParts$2([].concat(printOpeningTagPrefix(node, options), getTextValueParts(node), printClosingTagSuffix(node, options))));
  43284. }
  43285. case "docType":
  43286. return concat$n([group$k(concat$n([printOpeningTagStart(node, options), " ", node.value.replace(/^html\b/i, "html").replace(/\s+/g, " ")])), printClosingTagEnd(node, options)]);
  43287. case "comment":
  43288. {
  43289. return concat$n([printOpeningTagPrefix(node, options), concat$n(replaceEndOfLineWith$2(options.originalText.slice(options.locStart(node), options.locEnd(node)), literalline$5)), printClosingTagSuffix(node, options)]);
  43290. }
  43291. case "attribute":
  43292. {
  43293. if (node.value === null) {
  43294. return node.rawName;
  43295. }
  43296. const value = unescapeQuoteEntities$1(node.value);
  43297. const singleQuoteCount = countChars$1(value, "'");
  43298. const doubleQuoteCount = countChars$1(value, '"');
  43299. const quote = singleQuoteCount < doubleQuoteCount ? "'" : '"';
  43300. return concat$n([node.rawName, concat$n(["=", quote, concat$n(replaceEndOfLineWith$2(quote === '"' ? value.replace(/"/g, "&quot;") : value.replace(/'/g, "&apos;"), literalline$5)), quote])]);
  43301. }
  43302. default:
  43303. /* istanbul ignore next */
  43304. throw new Error(`Unexpected node type ${node.type}`);
  43305. }
  43306. }
  43307. function printChildren$2(path, options, print) {
  43308. const node = path.getValue();
  43309. if (forceBreakChildren$1(node)) {
  43310. return concat$n([breakParent$7, concat$n(path.map(childPath => {
  43311. const childNode = childPath.getValue();
  43312. const prevBetweenLine = !childNode.prev ? "" : printBetweenLine(childNode.prev, childNode);
  43313. return concat$n([!prevBetweenLine ? "" : concat$n([prevBetweenLine, forceNextEmptyLine$1(childNode.prev) ? hardline$f : ""]), printChild(childPath)]);
  43314. }, "children"))]);
  43315. }
  43316. const groupIds = node.children.map(() => Symbol(""));
  43317. return concat$n(path.map((childPath, childIndex) => {
  43318. const childNode = childPath.getValue();
  43319. if (isTextLikeNode$1(childNode)) {
  43320. if (childNode.prev && isTextLikeNode$1(childNode.prev)) {
  43321. const prevBetweenLine = printBetweenLine(childNode.prev, childNode);
  43322. if (prevBetweenLine) {
  43323. if (forceNextEmptyLine$1(childNode.prev)) {
  43324. return concat$n([hardline$f, hardline$f, printChild(childPath)]);
  43325. }
  43326. return concat$n([prevBetweenLine, printChild(childPath)]);
  43327. }
  43328. }
  43329. return printChild(childPath);
  43330. }
  43331. const prevParts = [];
  43332. const leadingParts = [];
  43333. const trailingParts = [];
  43334. const nextParts = [];
  43335. const prevBetweenLine = childNode.prev ? printBetweenLine(childNode.prev, childNode) : "";
  43336. const nextBetweenLine = childNode.next ? printBetweenLine(childNode, childNode.next) : "";
  43337. if (prevBetweenLine) {
  43338. if (forceNextEmptyLine$1(childNode.prev)) {
  43339. prevParts.push(hardline$f, hardline$f);
  43340. } else if (prevBetweenLine === hardline$f) {
  43341. prevParts.push(hardline$f);
  43342. } else {
  43343. if (isTextLikeNode$1(childNode.prev)) {
  43344. leadingParts.push(prevBetweenLine);
  43345. } else {
  43346. leadingParts.push(ifBreak$a("", softline$b, {
  43347. groupId: groupIds[childIndex - 1]
  43348. }));
  43349. }
  43350. }
  43351. }
  43352. if (nextBetweenLine) {
  43353. if (forceNextEmptyLine$1(childNode)) {
  43354. if (isTextLikeNode$1(childNode.next)) {
  43355. nextParts.push(hardline$f, hardline$f);
  43356. }
  43357. } else if (nextBetweenLine === hardline$f) {
  43358. if (isTextLikeNode$1(childNode.next)) {
  43359. nextParts.push(hardline$f);
  43360. }
  43361. } else {
  43362. trailingParts.push(nextBetweenLine);
  43363. }
  43364. }
  43365. return concat$n([].concat(prevParts, group$k(concat$n([concat$n(leadingParts), group$k(concat$n([printChild(childPath), concat$n(trailingParts)]), {
  43366. id: groupIds[childIndex]
  43367. })])), nextParts));
  43368. }, "children"));
  43369. function printChild(childPath) {
  43370. const child = childPath.getValue();
  43371. if (hasPrettierIgnore$6(child)) {
  43372. return concat$n([].concat(printOpeningTagPrefix(child, options), replaceEndOfLineWith$2(options.originalText.slice(options.locStart(child) + (child.prev && needsToBorrowNextOpeningTagStartMarker(child.prev) ? printOpeningTagStartMarker(child).length : 0), options.locEnd(child) - (child.next && needsToBorrowPrevClosingTagEndMarker(child.next) ? printClosingTagEndMarker(child, options).length : 0)), literalline$5), printClosingTagSuffix(child, options)));
  43373. }
  43374. return print(childPath);
  43375. }
  43376. function printBetweenLine(prevNode, nextNode) {
  43377. return isTextLikeNode$1(prevNode) && isTextLikeNode$1(nextNode) ? prevNode.isTrailingSpaceSensitive ? prevNode.hasTrailingSpaces ? preferHardlineAsLeadingSpaces$1(nextNode) ? hardline$f : line$e : "" : preferHardlineAsLeadingSpaces$1(nextNode) ? hardline$f : softline$b : needsToBorrowNextOpeningTagStartMarker(prevNode) && (hasPrettierIgnore$6(nextNode) ||
  43378. /**
  43379. * 123<a
  43380. * ~
  43381. * ><b>
  43382. */
  43383. nextNode.firstChild ||
  43384. /**
  43385. * 123<!--
  43386. * ~
  43387. * -->
  43388. */
  43389. nextNode.isSelfClosing ||
  43390. /**
  43391. * 123<span
  43392. * ~
  43393. * attr
  43394. */
  43395. nextNode.type === "element" && nextNode.attrs.length !== 0) ||
  43396. /**
  43397. * <img
  43398. * src="long"
  43399. * ~
  43400. * />123
  43401. */
  43402. prevNode.type === "element" && prevNode.isSelfClosing && needsToBorrowPrevClosingTagEndMarker(nextNode) ? "" : !nextNode.isLeadingSpaceSensitive || preferHardlineAsLeadingSpaces$1(nextNode) ||
  43403. /**
  43404. * Want to write us a letter? Use our<a
  43405. * ><b><a>mailing address</a></b></a
  43406. * ~
  43407. * >.
  43408. */
  43409. needsToBorrowPrevClosingTagEndMarker(nextNode) && prevNode.lastChild && needsToBorrowParentClosingTagStartMarker(prevNode.lastChild) && prevNode.lastChild.lastChild && needsToBorrowParentClosingTagStartMarker(prevNode.lastChild.lastChild) ? hardline$f : nextNode.hasLeadingSpaces ? line$e : softline$b;
  43410. }
  43411. }
  43412. function getNodeContent(node, options) {
  43413. let start = node.startSourceSpan.end.offset;
  43414. if (node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild)) {
  43415. start -= printOpeningTagEndMarker(node).length;
  43416. }
  43417. let end = node.endSourceSpan.start.offset;
  43418. if (node.lastChild && needsToBorrowParentClosingTagStartMarker(node.lastChild)) {
  43419. end += printClosingTagStartMarker(node, options).length;
  43420. } else if (needsToBorrowLastChildClosingTagEndMarker(node)) {
  43421. end -= printClosingTagEndMarker(node.lastChild, options).length;
  43422. }
  43423. return options.originalText.slice(start, end);
  43424. }
  43425. function printAttributes(path, options, print) {
  43426. const node = path.getValue();
  43427. if (!node.attrs || node.attrs.length === 0) {
  43428. return node.isSelfClosing ?
  43429. /**
  43430. * <br />
  43431. * ^
  43432. */
  43433. " " : "";
  43434. }
  43435. const ignoreAttributeData = node.prev && node.prev.type === "comment" && getPrettierIgnoreAttributeCommentData$1(node.prev.value);
  43436. const hasPrettierIgnoreAttribute = typeof ignoreAttributeData === "boolean" ? () => ignoreAttributeData : Array.isArray(ignoreAttributeData) ? attribute => ignoreAttributeData.includes(attribute.rawName) : () => false;
  43437. const printedAttributes = path.map(attributePath => {
  43438. const attribute = attributePath.getValue();
  43439. return hasPrettierIgnoreAttribute(attribute) ? concat$n(replaceEndOfLineWith$2(options.originalText.slice(options.locStart(attribute), options.locEnd(attribute)), literalline$5)) : print(attributePath);
  43440. }, "attrs");
  43441. const forceNotToBreakAttrContent = node.type === "element" && node.fullName === "script" && node.attrs.length === 1 && node.attrs[0].fullName === "src" && node.children.length === 0;
  43442. const parts = [indent$e(concat$n([forceNotToBreakAttrContent ? " " : line$e, join$d(line$e, printedAttributes)]))];
  43443. if (
  43444. /**
  43445. * 123<a
  43446. * attr
  43447. * ~
  43448. * >456
  43449. */
  43450. node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) ||
  43451. /**
  43452. * <span
  43453. * >123<meta
  43454. * ~
  43455. * /></span>
  43456. */
  43457. node.isSelfClosing && needsToBorrowLastChildClosingTagEndMarker(node.parent) || forceNotToBreakAttrContent) {
  43458. parts.push(node.isSelfClosing ? " " : "");
  43459. } else {
  43460. parts.push(node.isSelfClosing ? line$e : softline$b);
  43461. }
  43462. return concat$n(parts);
  43463. }
  43464. function printOpeningTag(path, options, print) {
  43465. const node = path.getValue();
  43466. return concat$n([printOpeningTagStart(node, options), printAttributes(path, options, print), node.isSelfClosing ? "" : printOpeningTagEnd(node)]);
  43467. }
  43468. function printOpeningTagStart(node, options) {
  43469. return node.prev && needsToBorrowNextOpeningTagStartMarker(node.prev) ? "" : concat$n([printOpeningTagPrefix(node, options), printOpeningTagStartMarker(node)]);
  43470. }
  43471. function printOpeningTagEnd(node) {
  43472. return node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) ? "" : printOpeningTagEndMarker(node);
  43473. }
  43474. function printClosingTag(node, options) {
  43475. return concat$n([node.isSelfClosing ? "" : printClosingTagStart(node, options), printClosingTagEnd(node, options)]);
  43476. }
  43477. function printClosingTagStart(node, options) {
  43478. return node.lastChild && needsToBorrowParentClosingTagStartMarker(node.lastChild) ? "" : concat$n([printClosingTagPrefix(node, options), printClosingTagStartMarker(node, options)]);
  43479. }
  43480. function printClosingTagEnd(node, options) {
  43481. return (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? "" : concat$n([printClosingTagEndMarker(node, options), printClosingTagSuffix(node, options)]);
  43482. }
  43483. function needsToBorrowNextOpeningTagStartMarker(node) {
  43484. /**
  43485. * 123<p
  43486. * ^^
  43487. * >
  43488. */
  43489. return node.next && !isTextLikeNode$1(node.next) && isTextLikeNode$1(node) && node.isTrailingSpaceSensitive && !node.hasTrailingSpaces;
  43490. }
  43491. function needsToBorrowParentOpeningTagEndMarker(node) {
  43492. /**
  43493. * <p
  43494. * >123
  43495. * ^
  43496. *
  43497. * <p
  43498. * ><a
  43499. * ^
  43500. */
  43501. return !node.prev && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces;
  43502. }
  43503. function needsToBorrowPrevClosingTagEndMarker(node) {
  43504. /**
  43505. * <p></p
  43506. * >123
  43507. * ^
  43508. *
  43509. * <p></p
  43510. * ><a
  43511. * ^
  43512. */
  43513. return node.prev && node.prev.type !== "docType" && !isTextLikeNode$1(node.prev) && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces;
  43514. }
  43515. function needsToBorrowLastChildClosingTagEndMarker(node) {
  43516. /**
  43517. * <p
  43518. * ><a></a
  43519. * ></p
  43520. * ^
  43521. * >
  43522. */
  43523. return node.lastChild && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces && !isTextLikeNode$1(getLastDescendant$1(node.lastChild)) && !isPreLikeNode$1(node);
  43524. }
  43525. function needsToBorrowParentClosingTagStartMarker(node) {
  43526. /**
  43527. * <p>
  43528. * 123</p
  43529. * ^^^
  43530. * >
  43531. *
  43532. * 123</b
  43533. * ></a
  43534. * ^^^
  43535. * >
  43536. */
  43537. return !node.next && !node.hasTrailingSpaces && node.isTrailingSpaceSensitive && isTextLikeNode$1(getLastDescendant$1(node));
  43538. }
  43539. function printOpeningTagPrefix(node, options) {
  43540. return needsToBorrowParentOpeningTagEndMarker(node) ? printOpeningTagEndMarker(node.parent) : needsToBorrowPrevClosingTagEndMarker(node) ? printClosingTagEndMarker(node.prev, options) : "";
  43541. }
  43542. function printClosingTagPrefix(node, options) {
  43543. return needsToBorrowLastChildClosingTagEndMarker(node) ? printClosingTagEndMarker(node.lastChild, options) : "";
  43544. }
  43545. function printClosingTagSuffix(node, options) {
  43546. return needsToBorrowParentClosingTagStartMarker(node) ? printClosingTagStartMarker(node.parent, options) : needsToBorrowNextOpeningTagStartMarker(node) ? printOpeningTagStartMarker(node.next) : "";
  43547. }
  43548. function printOpeningTagStartMarker(node) {
  43549. switch (node.type) {
  43550. case "ieConditionalComment":
  43551. case "ieConditionalStartComment":
  43552. return `<!--[if ${node.condition}`;
  43553. case "ieConditionalEndComment":
  43554. return "<!--<!";
  43555. case "interpolation":
  43556. return "{{";
  43557. case "docType":
  43558. return "<!DOCTYPE";
  43559. case "element":
  43560. if (node.condition) {
  43561. return `<!--[if ${node.condition}]><!--><${node.rawName}`;
  43562. }
  43563. // fall through
  43564. default:
  43565. return `<${node.rawName}`;
  43566. }
  43567. }
  43568. function printOpeningTagEndMarker(node) {
  43569. assert__default['default'](!node.isSelfClosing);
  43570. switch (node.type) {
  43571. case "ieConditionalComment":
  43572. return "]>";
  43573. case "element":
  43574. if (node.condition) {
  43575. return "><!--<![endif]-->";
  43576. }
  43577. // fall through
  43578. default:
  43579. return ">";
  43580. }
  43581. }
  43582. function printClosingTagStartMarker(node, options) {
  43583. assert__default['default'](!node.isSelfClosing);
  43584. /* istanbul ignore next */
  43585. if (shouldNotPrintClosingTag$1(node, options)) {
  43586. return "";
  43587. }
  43588. switch (node.type) {
  43589. case "ieConditionalComment":
  43590. return "<!";
  43591. case "element":
  43592. if (node.hasHtmComponentClosingTag) {
  43593. return "<//";
  43594. }
  43595. // fall through
  43596. default:
  43597. return `</${node.rawName}`;
  43598. }
  43599. }
  43600. function printClosingTagEndMarker(node, options) {
  43601. if (shouldNotPrintClosingTag$1(node, options)) {
  43602. return "";
  43603. }
  43604. switch (node.type) {
  43605. case "ieConditionalComment":
  43606. case "ieConditionalEndComment":
  43607. return "[endif]-->";
  43608. case "ieConditionalStartComment":
  43609. return "]><!-->";
  43610. case "interpolation":
  43611. return "}}";
  43612. case "element":
  43613. if (node.isSelfClosing) {
  43614. return "/>";
  43615. }
  43616. // fall through
  43617. default:
  43618. return ">";
  43619. }
  43620. }
  43621. function getTextValueParts(node, value = node.value) {
  43622. return node.parent.isWhitespaceSensitive ? node.parent.isIndentationSensitive ? replaceEndOfLineWith$2(value, literalline$5) : replaceEndOfLineWith$2(dedentString$1(htmlTrimPreserveIndentation$1(value)), hardline$f) : join$d(line$e, splitByHtmlWhitespace$1(value)).parts;
  43623. }
  43624. function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
  43625. const isKeyMatched = patterns => new RegExp(patterns.join("|")).test(node.fullName);
  43626. const getValue = () => unescapeQuoteEntities$1(node.value);
  43627. let shouldHug = false;
  43628. const __onHtmlBindingRoot = (root, options) => {
  43629. const rootNode = root.type === "NGRoot" ? root.node.type === "NGMicrosyntax" && root.node.body.length === 1 && root.node.body[0].type === "NGMicrosyntaxExpression" ? root.node.body[0].expression : root.node : root.type === "JsExpressionRoot" ? root.node : root;
  43630. if (rootNode && (rootNode.type === "ObjectExpression" || rootNode.type === "ArrayExpression" || options.parser === "__vue_expression" && (rootNode.type === "TemplateLiteral" || rootNode.type === "StringLiteral"))) {
  43631. shouldHug = true;
  43632. }
  43633. };
  43634. const printHug = doc => group$k(doc);
  43635. const printExpand = (doc, canHaveTrailingWhitespace = true) => group$k(concat$n([indent$e(concat$n([softline$b, doc])), canHaveTrailingWhitespace ? softline$b : ""]));
  43636. const printMaybeHug = doc => shouldHug ? printHug(doc) : printExpand(doc);
  43637. const textToDoc = (code, opts) => originalTextToDoc(code, Object.assign({
  43638. __onHtmlBindingRoot
  43639. }, opts), {
  43640. stripTrailingHardline: true
  43641. });
  43642. if (node.fullName === "srcset" && (node.parent.fullName === "img" || node.parent.fullName === "source")) {
  43643. return printExpand(printImgSrcset$1(getValue()));
  43644. }
  43645. if (node.fullName === "class" && !options.parentParser) {
  43646. const value = getValue();
  43647. if (!value.includes("{{")) {
  43648. return printClassNames$1(value);
  43649. }
  43650. }
  43651. if (node.fullName === "style" && !options.parentParser) {
  43652. const value = getValue();
  43653. if (!value.includes("{{")) {
  43654. return printExpand(textToDoc(value, {
  43655. parser: "css",
  43656. __isHTMLStyleAttribute: true
  43657. }));
  43658. }
  43659. }
  43660. if (options.parser === "vue") {
  43661. if (node.fullName === "v-for") {
  43662. return printVueFor$1(getValue(), textToDoc);
  43663. }
  43664. if (node.fullName === "slot-scope") {
  43665. return printVueSlotScope$1(getValue(), textToDoc);
  43666. }
  43667. /**
  43668. * @click="jsStatement"
  43669. * @click="jsExpression"
  43670. * v-on:click="jsStatement"
  43671. * v-on:click="jsExpression"
  43672. */
  43673. const vueEventBindingPatterns = ["^@", "^v-on:"];
  43674. /**
  43675. * :class="vueExpression"
  43676. * v-bind:id="vueExpression"
  43677. */
  43678. const vueExpressionBindingPatterns = ["^:", "^v-bind:"];
  43679. /**
  43680. * v-if="jsExpression"
  43681. */
  43682. const jsExpressionBindingPatterns = ["^v-", "^#"];
  43683. if (isKeyMatched(vueEventBindingPatterns)) {
  43684. const value = getValue();
  43685. return printMaybeHug(textToDoc(value, {
  43686. parser: isVueEventBindingExpression$3(value) ? "__js_expression" : "__vue_event_binding"
  43687. }));
  43688. }
  43689. if (isKeyMatched(vueExpressionBindingPatterns)) {
  43690. return printMaybeHug(textToDoc(getValue(), {
  43691. parser: "__vue_expression"
  43692. }));
  43693. }
  43694. if (isKeyMatched(jsExpressionBindingPatterns)) {
  43695. return printMaybeHug(textToDoc(getValue(), {
  43696. parser: "__js_expression"
  43697. }));
  43698. }
  43699. }
  43700. if (options.parser === "angular") {
  43701. const ngTextToDoc = (code, opts) => // angular does not allow trailing comma
  43702. textToDoc(code, Object.assign({}, opts, {
  43703. trailingComma: "none"
  43704. }));
  43705. /**
  43706. * *directive="angularDirective"
  43707. */
  43708. const ngDirectiveBindingPatterns = ["^\\*"];
  43709. /**
  43710. * (click)="angularStatement"
  43711. * on-click="angularStatement"
  43712. */
  43713. const ngStatementBindingPatterns = ["^\\(.+\\)$", "^on-"];
  43714. /**
  43715. * [target]="angularExpression"
  43716. * bind-target="angularExpression"
  43717. * [(target)]="angularExpression"
  43718. * bindon-target="angularExpression"
  43719. */
  43720. const ngExpressionBindingPatterns = ["^\\[.+\\]$", "^bind(on)?-", // Unofficial rudimentary support for some of the most used directives of AngularJS 1.x
  43721. "^ng-(if|show|hide|class|style)$"];
  43722. /**
  43723. * i18n="longDescription"
  43724. * i18n-attr="longDescription"
  43725. */
  43726. const ngI18nPatterns = ["^i18n(-.+)?$"];
  43727. if (isKeyMatched(ngStatementBindingPatterns)) {
  43728. return printMaybeHug(ngTextToDoc(getValue(), {
  43729. parser: "__ng_action"
  43730. }));
  43731. }
  43732. if (isKeyMatched(ngExpressionBindingPatterns)) {
  43733. return printMaybeHug(ngTextToDoc(getValue(), {
  43734. parser: "__ng_binding"
  43735. }));
  43736. }
  43737. if (isKeyMatched(ngI18nPatterns)) {
  43738. const value = getValue().trim();
  43739. return printExpand(fill$6(getTextValueParts(node, value)), !value.includes("@@"));
  43740. }
  43741. if (isKeyMatched(ngDirectiveBindingPatterns)) {
  43742. return printMaybeHug(ngTextToDoc(getValue(), {
  43743. parser: "__ng_directive"
  43744. }));
  43745. }
  43746. const interpolationRegex = /{{([\S\s]+?)}}/g;
  43747. const value = getValue();
  43748. if (interpolationRegex.test(value)) {
  43749. const parts = [];
  43750. value.split(interpolationRegex).forEach((part, index) => {
  43751. if (index % 2 === 0) {
  43752. parts.push(concat$n(replaceEndOfLineWith$2(part, literalline$5)));
  43753. } else {
  43754. try {
  43755. parts.push(group$k(concat$n(["{{", indent$e(concat$n([line$e, ngTextToDoc(part, {
  43756. parser: "__ng_interpolation",
  43757. __isInHtmlInterpolation: true // to avoid unexpected `}}`
  43758. })])), line$e, "}}"])));
  43759. } catch (e) {
  43760. parts.push("{{", concat$n(replaceEndOfLineWith$2(part, literalline$5)), "}}");
  43761. }
  43762. }
  43763. });
  43764. return group$k(concat$n(parts));
  43765. }
  43766. }
  43767. return null;
  43768. }
  43769. var printerHtml = {
  43770. preprocess: preprocess_1$2,
  43771. print: genericPrint$5,
  43772. insertPragma: insertPragma$7,
  43773. massageAstNode: clean$6,
  43774. embed: embed$4
  43775. };
  43776. const CATEGORY_HTML = "HTML"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  43777. var options$6 = {
  43778. htmlWhitespaceSensitivity: {
  43779. since: "1.15.0",
  43780. category: CATEGORY_HTML,
  43781. type: "choice",
  43782. default: "css",
  43783. description: "How to handle whitespaces in HTML.",
  43784. choices: [{
  43785. value: "css",
  43786. description: "Respect the default value of CSS display property."
  43787. }, {
  43788. value: "strict",
  43789. description: "Whitespaces are considered sensitive."
  43790. }, {
  43791. value: "ignore",
  43792. description: "Whitespaces are considered insensitive."
  43793. }]
  43794. },
  43795. vueIndentScriptAndStyle: {
  43796. since: "1.19.0",
  43797. category: CATEGORY_HTML,
  43798. type: "boolean",
  43799. default: false,
  43800. description: "Indent script and style tags in Vue files."
  43801. }
  43802. };
  43803. var name$g = "HTML";
  43804. var type$e = "markup";
  43805. var tmScope$e = "text.html.basic";
  43806. var aceMode$e = "html";
  43807. var codemirrorMode$b = "htmlmixed";
  43808. var codemirrorMimeType$b = "text/html";
  43809. var color$3 = "#e34c26";
  43810. var aliases$5 = [
  43811. "xhtml"
  43812. ];
  43813. var extensions$e = [
  43814. ".html",
  43815. ".htm",
  43816. ".html.hl",
  43817. ".inc",
  43818. ".st",
  43819. ".xht",
  43820. ".xhtml"
  43821. ];
  43822. var languageId$e = 146;
  43823. var HTML = {
  43824. name: name$g,
  43825. type: type$e,
  43826. tmScope: tmScope$e,
  43827. aceMode: aceMode$e,
  43828. codemirrorMode: codemirrorMode$b,
  43829. codemirrorMimeType: codemirrorMimeType$b,
  43830. color: color$3,
  43831. aliases: aliases$5,
  43832. extensions: extensions$e,
  43833. languageId: languageId$e
  43834. };
  43835. var HTML$1 = /*#__PURE__*/Object.freeze({
  43836. __proto__: null,
  43837. name: name$g,
  43838. type: type$e,
  43839. tmScope: tmScope$e,
  43840. aceMode: aceMode$e,
  43841. codemirrorMode: codemirrorMode$b,
  43842. codemirrorMimeType: codemirrorMimeType$b,
  43843. color: color$3,
  43844. aliases: aliases$5,
  43845. extensions: extensions$e,
  43846. languageId: languageId$e,
  43847. 'default': HTML
  43848. });
  43849. var name$h = "Vue";
  43850. var type$f = "markup";
  43851. var color$4 = "#2c3e50";
  43852. var extensions$f = [
  43853. ".vue"
  43854. ];
  43855. var tmScope$f = "text.html.vue";
  43856. var aceMode$f = "html";
  43857. var languageId$f = 391;
  43858. var Vue = {
  43859. name: name$h,
  43860. type: type$f,
  43861. color: color$4,
  43862. extensions: extensions$f,
  43863. tmScope: tmScope$f,
  43864. aceMode: aceMode$f,
  43865. languageId: languageId$f
  43866. };
  43867. var Vue$1 = /*#__PURE__*/Object.freeze({
  43868. __proto__: null,
  43869. name: name$h,
  43870. type: type$f,
  43871. color: color$4,
  43872. extensions: extensions$f,
  43873. tmScope: tmScope$f,
  43874. aceMode: aceMode$f,
  43875. languageId: languageId$f,
  43876. 'default': Vue
  43877. });
  43878. var require$$0$7 = getCjsExportFromNamespace(HTML$1);
  43879. var require$$1$2 = getCjsExportFromNamespace(Vue$1);
  43880. const languages$5 = [createLanguage(require$$0$7, () => ({
  43881. name: "Angular",
  43882. since: "1.15.0",
  43883. parsers: ["angular"],
  43884. vscodeLanguageIds: ["html"],
  43885. extensions: [".component.html"],
  43886. filenames: []
  43887. })), createLanguage(require$$0$7, data => ({
  43888. since: "1.15.0",
  43889. parsers: ["html"],
  43890. vscodeLanguageIds: ["html"],
  43891. extensions: data.extensions.concat([".mjml" // MJML is considered XML in Linguist but it should be formatted as HTML
  43892. ])
  43893. })), createLanguage(require$$0$7, () => ({
  43894. name: "Lightning Web Components",
  43895. since: "1.17.0",
  43896. parsers: ["lwc"],
  43897. vscodeLanguageIds: ["html"],
  43898. extensions: [],
  43899. filenames: []
  43900. })), createLanguage(require$$1$2, () => ({
  43901. since: "1.10.0",
  43902. parsers: ["vue"],
  43903. vscodeLanguageIds: ["vue"]
  43904. }))];
  43905. const printers$5 = {
  43906. html: printerHtml
  43907. };
  43908. const parsers$5 = {
  43909. // HTML
  43910. get html() {
  43911. return require("./parser-html").parsers.html;
  43912. },
  43913. // Vue
  43914. get vue() {
  43915. return require("./parser-html").parsers.vue;
  43916. },
  43917. // Angular
  43918. get angular() {
  43919. return require("./parser-html").parsers.angular;
  43920. },
  43921. // Lightning Web Components
  43922. get lwc() {
  43923. return require("./parser-html").parsers.lwc;
  43924. }
  43925. };
  43926. var languageHtml = {
  43927. languages: languages$5,
  43928. printers: printers$5,
  43929. options: options$6,
  43930. parsers: parsers$5
  43931. };
  43932. function isPragma(text) {
  43933. return /^\s*@(prettier|format)\s*$/.test(text);
  43934. }
  43935. function hasPragma$4(text) {
  43936. return /^\s*#[^\S\n]*@(prettier|format)\s*?(\n|$)/.test(text);
  43937. }
  43938. function insertPragma$8(text) {
  43939. return `# @format\n\n${text}`;
  43940. }
  43941. var pragma$5 = {
  43942. isPragma,
  43943. hasPragma: hasPragma$4,
  43944. insertPragma: insertPragma$8
  43945. };
  43946. const {
  43947. getLast: getLast$8
  43948. } = util;
  43949. function getAncestorCount(path, filter) {
  43950. let counter = 0;
  43951. const pathStackLength = path.stack.length - 1;
  43952. for (let i = 0; i < pathStackLength; i++) {
  43953. const value = path.stack[i];
  43954. if (isNode(value) && filter(value)) {
  43955. counter++;
  43956. }
  43957. }
  43958. return counter;
  43959. }
  43960. /**
  43961. * @param {any} value
  43962. * @param {string[]=} types
  43963. */
  43964. function isNode(value, types) {
  43965. return value && typeof value.type === "string" && (!types || types.includes(value.type));
  43966. }
  43967. function mapNode(node, callback, parent) {
  43968. return callback("children" in node ? Object.assign({}, node, {
  43969. children: node.children.map(childNode => mapNode(childNode, callback, node))
  43970. }) : node, parent);
  43971. }
  43972. function defineShortcut(x, key, getter) {
  43973. Object.defineProperty(x, key, {
  43974. get: getter,
  43975. enumerable: false
  43976. });
  43977. }
  43978. function isNextLineEmpty$7(node, text) {
  43979. let newlineCount = 0;
  43980. const textLength = text.length;
  43981. for (let i = node.position.end.offset - 1; i < textLength; i++) {
  43982. const char = text[i];
  43983. if (char === "\n") {
  43984. newlineCount++;
  43985. }
  43986. if (newlineCount === 1 && /\S/.test(char)) {
  43987. return false;
  43988. }
  43989. if (newlineCount === 2) {
  43990. return true;
  43991. }
  43992. }
  43993. return false;
  43994. }
  43995. function isLastDescendantNode(path) {
  43996. const node = path.getValue();
  43997. switch (node.type) {
  43998. case "tag":
  43999. case "anchor":
  44000. case "comment":
  44001. return false;
  44002. }
  44003. const pathStackLength = path.stack.length;
  44004. for (let i = 1; i < pathStackLength; i++) {
  44005. const item = path.stack[i];
  44006. const parentItem = path.stack[i - 1];
  44007. if (Array.isArray(parentItem) && typeof item === "number" && item !== parentItem.length - 1) {
  44008. return false;
  44009. }
  44010. }
  44011. return true;
  44012. }
  44013. function getLastDescendantNode$1(node) {
  44014. return "children" in node && node.children.length !== 0 ? getLastDescendantNode$1(getLast$8(node.children)) : node;
  44015. }
  44016. function isPrettierIgnore$2(comment) {
  44017. return comment.value.trim() === "prettier-ignore";
  44018. }
  44019. function hasPrettierIgnore$7(path) {
  44020. const node = path.getValue();
  44021. if (node.type === "documentBody") {
  44022. const document = path.getParentNode();
  44023. return hasEndComments(document.head) && isPrettierIgnore$2(getLast$8(document.head.endComments));
  44024. }
  44025. return hasLeadingComments(node) && isPrettierIgnore$2(getLast$8(node.leadingComments));
  44026. }
  44027. function isEmptyNode(node) {
  44028. return (!node.children || node.children.length === 0) && !hasComments(node);
  44029. }
  44030. function hasComments(node) {
  44031. return hasLeadingComments(node) || hasMiddleComments(node) || hasIndicatorComment(node) || hasTrailingComment$4(node) || hasEndComments(node);
  44032. }
  44033. function hasLeadingComments(node) {
  44034. return node && node.leadingComments && node.leadingComments.length !== 0;
  44035. }
  44036. function hasMiddleComments(node) {
  44037. return node && node.middleComments && node.middleComments.length !== 0;
  44038. }
  44039. function hasIndicatorComment(node) {
  44040. return node && node.indicatorComment;
  44041. }
  44042. function hasTrailingComment$4(node) {
  44043. return node && node.trailingComment;
  44044. }
  44045. function hasEndComments(node) {
  44046. return node && node.endComments && node.endComments.length !== 0;
  44047. }
  44048. /**
  44049. * " a b c d e f " -> [" a b", "c d", "e f "]
  44050. */
  44051. function splitWithSingleSpace(text) {
  44052. const parts = [];
  44053. let lastPart;
  44054. for (const part of text.split(/( +)/g)) {
  44055. /* istanbul ignore else */
  44056. if (part !== " ") {
  44057. if (lastPart === " ") {
  44058. parts.push(part);
  44059. } else {
  44060. parts.push((parts.pop() || "") + part);
  44061. }
  44062. } else if (lastPart === undefined) {
  44063. parts.unshift("");
  44064. }
  44065. lastPart = part;
  44066. }
  44067. /* istanbul ignore next */
  44068. if (lastPart === " ") {
  44069. parts.push((parts.pop() || "") + " ");
  44070. }
  44071. if (parts[0] === "") {
  44072. parts.shift();
  44073. parts.unshift(" " + (parts.shift() || ""));
  44074. }
  44075. return parts;
  44076. }
  44077. function getFlowScalarLineContents(nodeType, content, options) {
  44078. const rawLineContents = content.split("\n").map((lineContent, index, lineContents) => index === 0 && index === lineContents.length - 1 ? lineContent : index !== 0 && index !== lineContents.length - 1 ? lineContent.trim() : index === 0 ? lineContent.trimEnd() : lineContent.trimStart());
  44079. if (options.proseWrap === "preserve") {
  44080. return rawLineContents.map(lineContent => lineContent.length === 0 ? [] : [lineContent]);
  44081. }
  44082. return rawLineContents.map(lineContent => lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent)).reduce((reduced, lineContentWords, index) => index !== 0 && rawLineContents[index - 1].length !== 0 && lineContentWords.length !== 0 && !( // trailing backslash in quoteDouble should be preserved
  44083. nodeType === "quoteDouble" && getLast$8(getLast$8(reduced)).endsWith("\\")) ? reduced.concat([reduced.pop().concat(lineContentWords)]) : reduced.concat([lineContentWords]), []).map(lineContentWords => options.proseWrap === "never" ? [lineContentWords.join(" ")] : lineContentWords);
  44084. }
  44085. function getBlockValueLineContents(node, {
  44086. parentIndent,
  44087. isLastDescendant,
  44088. options
  44089. }) {
  44090. const content = node.position.start.line === node.position.end.line ? "" : options.originalText.slice(node.position.start.offset, node.position.end.offset) // exclude open line `>` or `|`
  44091. .match(/^[^\n]*?\n([\S\s]*)$/)[1];
  44092. const leadingSpaceCount = node.indent === null ? (match => match ? match[1].length : Infinity)(content.match(/^( *)\S/m)) : node.indent - 1 + parentIndent;
  44093. const rawLineContents = content.split("\n").map(lineContent => lineContent.slice(leadingSpaceCount));
  44094. if (options.proseWrap === "preserve" || node.type === "blockLiteral") {
  44095. return removeUnnecessaryTrailingNewlines(rawLineContents.map(lineContent => lineContent.length === 0 ? [] : [lineContent]));
  44096. }
  44097. return removeUnnecessaryTrailingNewlines(rawLineContents.map(lineContent => lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent)).reduce((reduced, lineContentWords, index) => index !== 0 && rawLineContents[index - 1].length !== 0 && lineContentWords.length !== 0 && !/^\s/.test(lineContentWords[0]) && !/^\s|\s$/.test(getLast$8(reduced)) ? reduced.concat([reduced.pop().concat(lineContentWords)]) : reduced.concat([lineContentWords]), []).map(lineContentWords => lineContentWords.reduce((reduced, word) => // disallow trailing spaces
  44098. reduced.length !== 0 && /\s$/.test(getLast$8(reduced)) ? reduced.concat(reduced.pop() + " " + word) : reduced.concat(word), [])).map(lineContentWords => options.proseWrap === "never" ? [lineContentWords.join(" ")] : lineContentWords));
  44099. function removeUnnecessaryTrailingNewlines(lineContents) {
  44100. if (node.chomping === "keep") {
  44101. return getLast$8(lineContents).length === 0 ? lineContents.slice(0, -1) : lineContents;
  44102. }
  44103. let trailingNewlineCount = 0;
  44104. for (let i = lineContents.length - 1; i >= 0; i--) {
  44105. if (lineContents[i].length === 0) {
  44106. trailingNewlineCount++;
  44107. } else {
  44108. break;
  44109. }
  44110. }
  44111. return trailingNewlineCount === 0 ? lineContents : trailingNewlineCount >= 2 && !isLastDescendant ? // next empty line
  44112. lineContents.slice(0, -(trailingNewlineCount - 1)) : lineContents.slice(0, -trailingNewlineCount);
  44113. }
  44114. }
  44115. var utils$b = {
  44116. getLast: getLast$8,
  44117. getAncestorCount,
  44118. isNode,
  44119. isEmptyNode,
  44120. mapNode,
  44121. defineShortcut,
  44122. isNextLineEmpty: isNextLineEmpty$7,
  44123. isLastDescendantNode,
  44124. getBlockValueLineContents,
  44125. getFlowScalarLineContents,
  44126. getLastDescendantNode: getLastDescendantNode$1,
  44127. hasPrettierIgnore: hasPrettierIgnore$7,
  44128. hasLeadingComments,
  44129. hasMiddleComments,
  44130. hasIndicatorComment,
  44131. hasTrailingComment: hasTrailingComment$4,
  44132. hasEndComments
  44133. };
  44134. const docBuilders$2 = document.builders;
  44135. const {
  44136. conditionalGroup: conditionalGroup$4,
  44137. breakParent: breakParent$8,
  44138. concat: concat$o,
  44139. dedent: dedent$3,
  44140. dedentToRoot: dedentToRoot$3,
  44141. fill: fill$7,
  44142. group: group$l,
  44143. hardline: hardline$g,
  44144. ifBreak: ifBreak$b,
  44145. join: join$e,
  44146. line: line$f,
  44147. lineSuffix: lineSuffix$2,
  44148. literalline: literalline$6,
  44149. markAsRoot: markAsRoot$4,
  44150. softline: softline$c
  44151. } = docBuilders$2;
  44152. const {
  44153. replaceEndOfLineWith: replaceEndOfLineWith$3,
  44154. isPreviousLineEmpty: isPreviousLineEmpty$3
  44155. } = util;
  44156. const {
  44157. insertPragma: insertPragma$9,
  44158. isPragma: isPragma$1
  44159. } = pragma$5;
  44160. const {
  44161. getAncestorCount: getAncestorCount$1,
  44162. getBlockValueLineContents: getBlockValueLineContents$1,
  44163. getFlowScalarLineContents: getFlowScalarLineContents$1,
  44164. getLast: getLast$9,
  44165. getLastDescendantNode: getLastDescendantNode$2,
  44166. hasLeadingComments: hasLeadingComments$1,
  44167. hasMiddleComments: hasMiddleComments$1,
  44168. hasIndicatorComment: hasIndicatorComment$1,
  44169. hasTrailingComment: hasTrailingComment$5,
  44170. hasEndComments: hasEndComments$1,
  44171. hasPrettierIgnore: hasPrettierIgnore$8,
  44172. isLastDescendantNode: isLastDescendantNode$1,
  44173. isNextLineEmpty: isNextLineEmpty$8,
  44174. isNode: isNode$1,
  44175. isEmptyNode: isEmptyNode$1,
  44176. defineShortcut: defineShortcut$1,
  44177. mapNode: mapNode$1
  44178. } = utils$b;
  44179. function preprocess$3(ast) {
  44180. return mapNode$1(ast, defineShortcuts);
  44181. }
  44182. function defineShortcuts(node) {
  44183. switch (node.type) {
  44184. case "document":
  44185. defineShortcut$1(node, "head", () => node.children[0]);
  44186. defineShortcut$1(node, "body", () => node.children[1]);
  44187. break;
  44188. case "documentBody":
  44189. case "sequenceItem":
  44190. case "flowSequenceItem":
  44191. case "mappingKey":
  44192. case "mappingValue":
  44193. defineShortcut$1(node, "content", () => node.children[0]);
  44194. break;
  44195. case "mappingItem":
  44196. case "flowMappingItem":
  44197. defineShortcut$1(node, "key", () => node.children[0]);
  44198. defineShortcut$1(node, "value", () => node.children[1]);
  44199. break;
  44200. }
  44201. return node;
  44202. }
  44203. function genericPrint$6(path, options, print) {
  44204. const node = path.getValue();
  44205. const parentNode = path.getParentNode();
  44206. const tag = !node.tag ? "" : path.call(print, "tag");
  44207. const anchor = !node.anchor ? "" : path.call(print, "anchor");
  44208. const nextEmptyLine = isNode$1(node, ["mapping", "sequence", "comment", "directive", "mappingItem", "sequenceItem"]) && !isLastDescendantNode$1(path) ? printNextEmptyLine(path, options.originalText) : "";
  44209. return concat$o([node.type !== "mappingValue" && hasLeadingComments$1(node) ? concat$o([join$e(hardline$g, path.map(print, "leadingComments")), hardline$g]) : "", tag, tag && anchor ? " " : "", anchor, tag || anchor ? isNode$1(node, ["sequence", "mapping"]) && !hasMiddleComments$1(node) ? hardline$g : " " : "", hasMiddleComments$1(node) ? concat$o([node.middleComments.length === 1 ? "" : hardline$g, join$e(hardline$g, path.map(print, "middleComments")), hardline$g]) : "", hasPrettierIgnore$8(path) ? concat$o(replaceEndOfLineWith$3(options.originalText.slice(node.position.start.offset, node.position.end.offset).trimEnd(), literalline$6)) : group$l(_print(node, parentNode, path, options, print)), hasTrailingComment$5(node) && !isNode$1(node, ["document", "documentHead"]) ? lineSuffix$2(concat$o([node.type === "mappingValue" && !node.content ? "" : " ", parentNode.type === "mappingKey" && path.getParentNode(2).type === "mapping" && isInlineNode(node) ? "" : breakParent$8, path.call(print, "trailingComment")])) : "", shouldPrintEndComments(node) ? align$4(node.type === "sequenceItem" ? 2 : 0, concat$o([hardline$g, join$e(hardline$g, path.map(path => concat$o([isPreviousLineEmpty$3(options.originalText, path.getValue(), options.locStart) ? hardline$g : "", print(path)]), "endComments"))])) : "", nextEmptyLine]);
  44210. }
  44211. function _print(node, parentNode, path, options, print) {
  44212. switch (node.type) {
  44213. case "root":
  44214. return concat$o([join$e(hardline$g, path.map((childPath, index) => {
  44215. const document = node.children[index];
  44216. const nextDocument = node.children[index + 1];
  44217. return concat$o([print(childPath), shouldPrintDocumentEndMarker(document, nextDocument) ? concat$o([hardline$g, "...", hasTrailingComment$5(document) ? concat$o([" ", path.call(print, "trailingComment")]) : ""]) : !nextDocument || hasTrailingComment$5(nextDocument.head) ? "" : concat$o([hardline$g, "---"])]);
  44218. }, "children")), node.children.length === 0 || (lastDescendantNode => isNode$1(lastDescendantNode, ["blockLiteral", "blockFolded"]) && lastDescendantNode.chomping === "keep")(getLastDescendantNode$2(node)) ? "" : hardline$g]);
  44219. case "document":
  44220. {
  44221. const nextDocument = parentNode.children[path.getName() + 1];
  44222. return join$e(hardline$g, [shouldPrintDocumentHeadEndMarker(node, nextDocument, parentNode, options) === "head" ? join$e(hardline$g, [node.head.children.length === 0 && node.head.endComments.length === 0 ? "" : path.call(print, "head"), concat$o(["---", hasTrailingComment$5(node.head) ? concat$o([" ", path.call(print, "head", "trailingComment")]) : ""])].filter(Boolean)) : "", shouldPrintDocumentBody(node) ? path.call(print, "body") : ""].filter(Boolean));
  44223. }
  44224. case "documentHead":
  44225. return join$e(hardline$g, [].concat(path.map(print, "children"), path.map(print, "endComments")));
  44226. case "documentBody":
  44227. {
  44228. const children = join$e(hardline$g, path.map(print, "children")).parts;
  44229. const endComments = join$e(hardline$g, path.map(print, "endComments")).parts;
  44230. const separator = children.length === 0 || endComments.length === 0 ? "" : (lastDescendantNode => isNode$1(lastDescendantNode, ["blockFolded", "blockLiteral"]) ? lastDescendantNode.chomping === "keep" ? // there's already a newline printed at the end of blockValue (chomping=keep, lastDescendant=true)
  44231. "" : // an extra newline for better readability
  44232. concat$o([hardline$g, hardline$g]) : hardline$g)(getLastDescendantNode$2(node));
  44233. return concat$o([].concat(children, separator, endComments));
  44234. }
  44235. case "directive":
  44236. return concat$o(["%", join$e(" ", [node.name].concat(node.parameters))]);
  44237. case "comment":
  44238. return concat$o(["#", node.value]);
  44239. case "alias":
  44240. return concat$o(["*", node.value]);
  44241. case "tag":
  44242. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  44243. case "anchor":
  44244. return concat$o(["&", node.value]);
  44245. case "plain":
  44246. return printFlowScalarContent(node.type, options.originalText.slice(node.position.start.offset, node.position.end.offset), options);
  44247. case "quoteDouble":
  44248. case "quoteSingle":
  44249. {
  44250. const singleQuote = "'";
  44251. const doubleQuote = '"';
  44252. const raw = options.originalText.slice(node.position.start.offset + 1, node.position.end.offset - 1);
  44253. if (node.type === "quoteSingle" && raw.includes("\\") || node.type === "quoteDouble" && /\\[^"]/.test(raw)) {
  44254. // only quoteDouble can use escape chars
  44255. // and quoteSingle do not need to escape backslashes
  44256. const originalQuote = node.type === "quoteDouble" ? doubleQuote : singleQuote;
  44257. return concat$o([originalQuote, printFlowScalarContent(node.type, raw, options), originalQuote]);
  44258. } else if (raw.includes(doubleQuote)) {
  44259. return concat$o([singleQuote, printFlowScalarContent(node.type, node.type === "quoteDouble" ? raw // double quote needs to be escaped by backslash in quoteDouble
  44260. .replace(/\\"/g, doubleQuote).replace(/'/g, singleQuote.repeat(2)) : raw, options), singleQuote]);
  44261. }
  44262. if (raw.includes(singleQuote)) {
  44263. return concat$o([doubleQuote, printFlowScalarContent(node.type, node.type === "quoteSingle" ? // single quote needs to be escaped by 2 single quotes in quoteSingle
  44264. raw.replace(/''/g, singleQuote) : raw, options), doubleQuote]);
  44265. }
  44266. const quote = options.singleQuote ? singleQuote : doubleQuote;
  44267. return concat$o([quote, printFlowScalarContent(node.type, raw, options), quote]);
  44268. }
  44269. case "blockFolded":
  44270. case "blockLiteral":
  44271. {
  44272. const parentIndent = getAncestorCount$1(path, ancestorNode => isNode$1(ancestorNode, ["sequence", "mapping"]));
  44273. const isLastDescendant = isLastDescendantNode$1(path);
  44274. return concat$o([node.type === "blockFolded" ? ">" : "|", node.indent === null ? "" : node.indent.toString(), node.chomping === "clip" ? "" : node.chomping === "keep" ? "+" : "-", hasIndicatorComment$1(node) ? concat$o([" ", path.call(print, "indicatorComment")]) : "", (node.indent === null ? dedent$3 : dedentToRoot$3)(align$4(node.indent === null ? options.tabWidth : node.indent - 1 + parentIndent, concat$o(getBlockValueLineContents$1(node, {
  44275. parentIndent,
  44276. isLastDescendant,
  44277. options
  44278. }).reduce((reduced, lineWords, index, lineContents) => reduced.concat(index === 0 ? hardline$g : "", fill$7(join$e(line$f, lineWords).parts), index !== lineContents.length - 1 ? lineWords.length === 0 ? hardline$g : markAsRoot$4(literalline$6) : node.chomping === "keep" && isLastDescendant ? lineWords.length === 0 ? dedentToRoot$3(hardline$g) : dedentToRoot$3(literalline$6) : ""), []))))]);
  44279. }
  44280. case "sequence":
  44281. return join$e(hardline$g, path.map(print, "children"));
  44282. case "sequenceItem":
  44283. return concat$o(["- ", align$4(2, !node.content ? "" : path.call(print, "content"))]);
  44284. case "mappingKey":
  44285. return !node.content ? "" : path.call(print, "content");
  44286. case "mappingValue":
  44287. return !node.content ? "" : path.call(print, "content");
  44288. case "mapping":
  44289. return join$e(hardline$g, path.map(print, "children"));
  44290. case "mappingItem":
  44291. case "flowMappingItem":
  44292. {
  44293. const isEmptyMappingKey = isEmptyNode$1(node.key);
  44294. const isEmptyMappingValue = isEmptyNode$1(node.value);
  44295. if (isEmptyMappingKey && isEmptyMappingValue) {
  44296. return concat$o([": "]);
  44297. }
  44298. const key = path.call(print, "key");
  44299. const value = path.call(print, "value");
  44300. if (isEmptyMappingValue) {
  44301. return node.type === "flowMappingItem" && parentNode.type === "flowMapping" ? key : node.type === "mappingItem" && isAbsolutelyPrintedAsSingleLineNode(node.key.content, options) && !hasTrailingComment$5(node.key.content) && (!parentNode.tag || parentNode.tag.value !== "tag:yaml.org,2002:set") ? concat$o([key, needsSpaceInFrontOfMappingValue(node) ? " " : "", ":"]) : concat$o(["? ", align$4(2, key)]);
  44302. }
  44303. if (isEmptyMappingKey) {
  44304. return concat$o([": ", align$4(2, value)]);
  44305. }
  44306. const groupId = Symbol("mappingKey");
  44307. const forceExplicitKey = hasLeadingComments$1(node.value) || !isInlineNode(node.key.content);
  44308. return forceExplicitKey ? concat$o(["? ", align$4(2, key), hardline$g, join$e("", path.map(print, "value", "leadingComments").map(comment => concat$o([comment, hardline$g]))), ": ", align$4(2, value)]) : // force singleline
  44309. isSingleLineNode(node.key.content) && !hasLeadingComments$1(node.key.content) && !hasMiddleComments$1(node.key.content) && !hasTrailingComment$5(node.key.content) && !hasEndComments$1(node.key) && !hasLeadingComments$1(node.value.content) && !hasMiddleComments$1(node.value.content) && !hasEndComments$1(node.value) && isAbsolutelyPrintedAsSingleLineNode(node.value.content, options) ? concat$o([key, needsSpaceInFrontOfMappingValue(node) ? " " : "", ": ", value]) : conditionalGroup$4([concat$o([group$l(concat$o([ifBreak$b("? "), group$l(align$4(2, key), {
  44310. id: groupId
  44311. })])), ifBreak$b(concat$o([hardline$g, ": ", align$4(2, value)]), indent(concat$o([needsSpaceInFrontOfMappingValue(node) ? " " : "", ":", hasLeadingComments$1(node.value.content) || hasEndComments$1(node.value) && node.value.content && !isNode$1(node.value.content, ["mapping", "sequence"]) || parentNode.type === "mapping" && hasTrailingComment$5(node.key.content) && isInlineNode(node.value.content) || isNode$1(node.value.content, ["mapping", "sequence"]) && node.value.content.tag === null && node.value.content.anchor === null ? hardline$g : !node.value.content ? "" : line$f, value])), {
  44312. groupId
  44313. })])]);
  44314. }
  44315. case "flowMapping":
  44316. case "flowSequence":
  44317. {
  44318. const openMarker = node.type === "flowMapping" ? "{" : "[";
  44319. const closeMarker = node.type === "flowMapping" ? "}" : "]";
  44320. const bracketSpacing = node.type === "flowMapping" && node.children.length !== 0 && options.bracketSpacing ? line$f : softline$c;
  44321. const isLastItemEmptyMappingItem = node.children.length !== 0 && (lastItem => lastItem.type === "flowMappingItem" && isEmptyNode$1(lastItem.key) && isEmptyNode$1(lastItem.value))(getLast$9(node.children));
  44322. return concat$o([openMarker, indent(concat$o([bracketSpacing, concat$o(path.map((childPath, index) => concat$o([print(childPath), index === node.children.length - 1 ? "" : concat$o([",", line$f, node.children[index].position.start.line !== node.children[index + 1].position.start.line ? printNextEmptyLine(childPath, options.originalText) : ""])]), "children")), ifBreak$b(",", "")])), isLastItemEmptyMappingItem ? "" : bracketSpacing, closeMarker]);
  44323. }
  44324. case "flowSequenceItem":
  44325. return path.call(print, "content");
  44326. // istanbul ignore next
  44327. default:
  44328. throw new Error(`Unexpected node type ${node.type}`);
  44329. }
  44330. function indent(doc) {
  44331. return docBuilders$2.align(" ".repeat(options.tabWidth), doc);
  44332. }
  44333. }
  44334. function align$4(n, doc) {
  44335. return typeof n === "number" && n > 0 ? docBuilders$2.align(" ".repeat(n), doc) : docBuilders$2.align(n, doc);
  44336. }
  44337. function isInlineNode(node) {
  44338. /* istanbul ignore next */
  44339. if (!node) {
  44340. return true;
  44341. }
  44342. switch (node.type) {
  44343. case "plain":
  44344. case "quoteDouble":
  44345. case "quoteSingle":
  44346. case "alias":
  44347. case "flowMapping":
  44348. case "flowSequence":
  44349. return true;
  44350. default:
  44351. return false;
  44352. }
  44353. }
  44354. function isSingleLineNode(node) {
  44355. /* istanbul ignore next */
  44356. if (!node) {
  44357. return true;
  44358. }
  44359. switch (node.type) {
  44360. case "plain":
  44361. case "quoteDouble":
  44362. case "quoteSingle":
  44363. return node.position.start.line === node.position.end.line;
  44364. case "alias":
  44365. return true;
  44366. default:
  44367. return false;
  44368. }
  44369. }
  44370. function shouldPrintDocumentBody(document) {
  44371. return document.body.children.length !== 0 || hasEndComments$1(document.body);
  44372. }
  44373. function shouldPrintDocumentEndMarker(document, nextDocument) {
  44374. return (
  44375. /**
  44376. *... # trailingComment
  44377. */
  44378. hasTrailingComment$5(document) || nextDocument && (
  44379. /**
  44380. * ...
  44381. * %DIRECTIVE
  44382. * ---
  44383. */
  44384. nextDocument.head.children.length !== 0 ||
  44385. /**
  44386. * ...
  44387. * # endComment
  44388. * ---
  44389. */
  44390. hasEndComments$1(nextDocument.head))
  44391. );
  44392. }
  44393. function shouldPrintDocumentHeadEndMarker(document, nextDocument, root, options) {
  44394. if (
  44395. /**
  44396. * ---
  44397. * preserve the first document head end marker
  44398. */
  44399. root.children[0] === document && /---(\s|$)/.test(options.originalText.slice(options.locStart(document), options.locStart(document) + 4)) ||
  44400. /**
  44401. * %DIRECTIVE
  44402. * ---
  44403. */
  44404. document.head.children.length !== 0 ||
  44405. /**
  44406. * # end comment
  44407. * ---
  44408. */
  44409. hasEndComments$1(document.head) ||
  44410. /**
  44411. * --- # trailing comment
  44412. */
  44413. hasTrailingComment$5(document.head)) {
  44414. return "head";
  44415. }
  44416. if (shouldPrintDocumentEndMarker(document, nextDocument)) {
  44417. return false;
  44418. }
  44419. return nextDocument ? "root" : false;
  44420. }
  44421. function isAbsolutelyPrintedAsSingleLineNode(node, options) {
  44422. if (!node) {
  44423. return true;
  44424. }
  44425. switch (node.type) {
  44426. case "plain":
  44427. case "quoteSingle":
  44428. case "quoteDouble":
  44429. break;
  44430. case "alias":
  44431. return true;
  44432. default:
  44433. return false;
  44434. }
  44435. if (options.proseWrap === "preserve") {
  44436. return node.position.start.line === node.position.end.line;
  44437. }
  44438. if ( // backslash-newline
  44439. /\\$/m.test(options.originalText.slice(node.position.start.offset, node.position.end.offset))) {
  44440. return false;
  44441. }
  44442. switch (options.proseWrap) {
  44443. case "never":
  44444. return !node.value.includes("\n");
  44445. case "always":
  44446. return !/[\n ]/.test(node.value);
  44447. // istanbul ignore next
  44448. default:
  44449. return false;
  44450. }
  44451. }
  44452. function needsSpaceInFrontOfMappingValue(node) {
  44453. return node.key.content && node.key.content.type === "alias";
  44454. }
  44455. function shouldPrintEndComments(node) {
  44456. return hasEndComments$1(node) && !isNode$1(node, ["documentHead", "documentBody"]);
  44457. }
  44458. function printNextEmptyLine(path, originalText) {
  44459. const node = path.getValue();
  44460. const root = path.stack[0];
  44461. root.isNextEmptyLinePrintedChecklist = root.isNextEmptyLinePrintedChecklist || [];
  44462. if (!root.isNextEmptyLinePrintedChecklist[node.position.end.line]) {
  44463. if (isNextLineEmpty$8(node, originalText)) {
  44464. root.isNextEmptyLinePrintedChecklist[node.position.end.line] = true;
  44465. if (!shouldPrintEndComments(path.getParentNode())) {
  44466. return softline$c;
  44467. }
  44468. }
  44469. }
  44470. return "";
  44471. }
  44472. function printFlowScalarContent(nodeType, content, options) {
  44473. const lineContents = getFlowScalarLineContents$1(nodeType, content, options);
  44474. return join$e(hardline$g, lineContents.map(lineContentWords => fill$7(join$e(line$f, lineContentWords).parts)));
  44475. }
  44476. function clean$7(node, newNode
  44477. /*, parent */
  44478. ) {
  44479. if (isNode$1(newNode)) {
  44480. delete newNode.position;
  44481. switch (newNode.type) {
  44482. case "comment":
  44483. // insert pragma
  44484. if (isPragma$1(newNode.value)) {
  44485. return null;
  44486. }
  44487. break;
  44488. case "quoteDouble":
  44489. case "quoteSingle":
  44490. newNode.type = "quote";
  44491. break;
  44492. }
  44493. }
  44494. }
  44495. var printerYaml = {
  44496. preprocess: preprocess$3,
  44497. print: genericPrint$6,
  44498. massageAstNode: clean$7,
  44499. insertPragma: insertPragma$9
  44500. };
  44501. var options$7 = {
  44502. bracketSpacing: commonOptions.bracketSpacing,
  44503. singleQuote: commonOptions.singleQuote,
  44504. proseWrap: commonOptions.proseWrap
  44505. };
  44506. var name$i = "YAML";
  44507. var type$g = "data";
  44508. var tmScope$g = "source.yaml";
  44509. var aliases$6 = [
  44510. "yml"
  44511. ];
  44512. var extensions$g = [
  44513. ".yml",
  44514. ".mir",
  44515. ".reek",
  44516. ".rviz",
  44517. ".sublime-syntax",
  44518. ".syntax",
  44519. ".yaml",
  44520. ".yaml-tmlanguage",
  44521. ".yaml.sed",
  44522. ".yml.mysql"
  44523. ];
  44524. var filenames$4 = [
  44525. ".clang-format",
  44526. ".clang-tidy",
  44527. ".gemrc",
  44528. "glide.lock",
  44529. "yarn.lock"
  44530. ];
  44531. var aceMode$g = "yaml";
  44532. var codemirrorMode$c = "yaml";
  44533. var codemirrorMimeType$c = "text/x-yaml";
  44534. var languageId$g = 407;
  44535. var YAML = {
  44536. name: name$i,
  44537. type: type$g,
  44538. tmScope: tmScope$g,
  44539. aliases: aliases$6,
  44540. extensions: extensions$g,
  44541. filenames: filenames$4,
  44542. aceMode: aceMode$g,
  44543. codemirrorMode: codemirrorMode$c,
  44544. codemirrorMimeType: codemirrorMimeType$c,
  44545. languageId: languageId$g
  44546. };
  44547. var YAML$1 = /*#__PURE__*/Object.freeze({
  44548. __proto__: null,
  44549. name: name$i,
  44550. type: type$g,
  44551. tmScope: tmScope$g,
  44552. aliases: aliases$6,
  44553. extensions: extensions$g,
  44554. filenames: filenames$4,
  44555. aceMode: aceMode$g,
  44556. codemirrorMode: codemirrorMode$c,
  44557. codemirrorMimeType: codemirrorMimeType$c,
  44558. languageId: languageId$g,
  44559. 'default': YAML
  44560. });
  44561. var require$$0$8 = getCjsExportFromNamespace(YAML$1);
  44562. const languages$6 = [createLanguage(require$$0$8, data => ({
  44563. since: "1.14.0",
  44564. parsers: ["yaml"],
  44565. vscodeLanguageIds: ["yaml", "ansible", "home-assistant"],
  44566. // yarn.lock is not YAML: https://github.com/yarnpkg/yarn/issues/5629
  44567. filenames: data.filenames.filter(filename => filename !== "yarn.lock")
  44568. }))];
  44569. const parsers$6 = {
  44570. get yaml() {
  44571. return require("./parser-yaml").parsers.yaml;
  44572. }
  44573. };
  44574. var languageYaml = {
  44575. languages: languages$6,
  44576. printers: {
  44577. yaml: printerYaml
  44578. },
  44579. options: options$7,
  44580. parsers: parsers$6
  44581. };
  44582. var languages$7 = [// JS
  44583. languageJs, // CSS
  44584. languageCss, // Handlebars
  44585. languageHandlebars, // GraphQL
  44586. languageGraphql, // Markdown
  44587. languageMarkdown, // HTML
  44588. languageHtml, // YAML
  44589. languageYaml];
  44590. const memoizedLoad = mem_1(load, {
  44591. cacheKey: JSON.stringify
  44592. });
  44593. const memoizedSearch = mem_1(findPluginsInNodeModules);
  44594. const clearCache$2 = () => {
  44595. mem_1.clear(memoizedLoad);
  44596. mem_1.clear(memoizedSearch);
  44597. };
  44598. function load(plugins, pluginSearchDirs) {
  44599. if (!plugins) {
  44600. plugins = [];
  44601. }
  44602. if (!pluginSearchDirs) {
  44603. pluginSearchDirs = [];
  44604. } // unless pluginSearchDirs are provided, auto-load plugins from node_modules that are parent to Prettier
  44605. if (!pluginSearchDirs.length) {
  44606. const autoLoadDir = thirdParty.findParentDir(__dirname, "node_modules");
  44607. if (autoLoadDir) {
  44608. pluginSearchDirs = [autoLoadDir];
  44609. }
  44610. }
  44611. const [externalPluginNames, externalPluginInstances] = partition_1(plugins, plugin => typeof plugin === "string");
  44612. const externalManualLoadPluginInfos = externalPluginNames.map(pluginName => {
  44613. let requirePath;
  44614. try {
  44615. // try local files
  44616. requirePath = resolve_1(path__default['default'].resolve(process.cwd(), pluginName));
  44617. } catch (_) {
  44618. // try node modules
  44619. requirePath = resolve_1(pluginName, {
  44620. paths: [process.cwd()]
  44621. });
  44622. }
  44623. return {
  44624. name: pluginName,
  44625. requirePath
  44626. };
  44627. });
  44628. const externalAutoLoadPluginInfos = pluginSearchDirs.map(pluginSearchDir => {
  44629. const resolvedPluginSearchDir = path__default['default'].resolve(process.cwd(), pluginSearchDir);
  44630. const nodeModulesDir = path__default['default'].resolve(resolvedPluginSearchDir, "node_modules"); // In some fringe cases (ex: files "mounted" as virtual directories), the
  44631. // isDirectory(resolvedPluginSearchDir) check might be false even though
  44632. // the node_modules actually exists.
  44633. if (!isDirectory$1(nodeModulesDir) && !isDirectory$1(resolvedPluginSearchDir)) {
  44634. throw new Error(`${pluginSearchDir} does not exist or is not a directory`);
  44635. }
  44636. return memoizedSearch(nodeModulesDir).map(pluginName => ({
  44637. name: pluginName,
  44638. requirePath: resolve_1(pluginName, {
  44639. paths: [resolvedPluginSearchDir]
  44640. })
  44641. }));
  44642. }).reduce((a, b) => a.concat(b), []);
  44643. const externalPlugins = uniqBy_1(externalManualLoadPluginInfos.concat(externalAutoLoadPluginInfos), "requirePath").map(externalPluginInfo => Object.assign({
  44644. name: externalPluginInfo.name
  44645. }, require(externalPluginInfo.requirePath))).concat(externalPluginInstances);
  44646. return languages$7.concat(externalPlugins);
  44647. }
  44648. function findPluginsInNodeModules(nodeModulesDir) {
  44649. const pluginPackageJsonPaths = globby$1.sync(["prettier-plugin-*/package.json", "@*/prettier-plugin-*/package.json", "@prettier/plugin-*/package.json"], {
  44650. cwd: nodeModulesDir,
  44651. expandDirectories: false
  44652. });
  44653. return pluginPackageJsonPaths.map(path__default['default'].dirname);
  44654. }
  44655. function isDirectory$1(dir) {
  44656. try {
  44657. return fs__default['default'].statSync(dir).isDirectory();
  44658. } catch (e) {
  44659. return false;
  44660. }
  44661. }
  44662. var loadPlugins = {
  44663. loadPlugins: memoizedLoad,
  44664. clearCache: clearCache$2
  44665. };
  44666. const {
  44667. version: version$2
  44668. } = require$$0;
  44669. const {
  44670. getSupportInfo: getSupportInfo$2
  44671. } = support;
  44672. function _withPlugins(fn, optsArgIdx = 1 // Usually `opts` is the 2nd argument
  44673. ) {
  44674. return (...args) => {
  44675. const opts = args[optsArgIdx] || {};
  44676. args[optsArgIdx] = Object.assign({}, opts, {
  44677. plugins: loadPlugins.loadPlugins(opts.plugins, opts.pluginSearchDirs)
  44678. });
  44679. return fn(...args);
  44680. };
  44681. }
  44682. function withPlugins(fn, optsArgIdx) {
  44683. const resultingFn = _withPlugins(fn, optsArgIdx);
  44684. if (fn.sync) {
  44685. // @ts-ignore
  44686. resultingFn.sync = _withPlugins(fn.sync, optsArgIdx);
  44687. }
  44688. return resultingFn;
  44689. }
  44690. const formatWithCursor = withPlugins(core.formatWithCursor);
  44691. var src$1 = {
  44692. formatWithCursor,
  44693. format(text, opts) {
  44694. return formatWithCursor(text, opts).formatted;
  44695. },
  44696. check(text, opts) {
  44697. const {
  44698. formatted
  44699. } = formatWithCursor(text, opts);
  44700. return formatted === text;
  44701. },
  44702. doc: document,
  44703. resolveConfig: resolveConfig_1.resolveConfig,
  44704. resolveConfigFile: resolveConfig_1.resolveConfigFile,
  44705. clearConfigCache() {
  44706. resolveConfig_1.clearCache();
  44707. loadPlugins.clearCache();
  44708. },
  44709. getFileInfo:
  44710. /** @type {typeof getFileInfo} */
  44711. withPlugins(getFileInfo_1),
  44712. getSupportInfo:
  44713. /** @type {typeof getSupportInfo} */
  44714. withPlugins(getSupportInfo$2, 0),
  44715. version: version$2,
  44716. util: utilShared,
  44717. // Internal shared
  44718. __internal: {
  44719. errors: errors,
  44720. coreOptions: coreOptions,
  44721. createIgnorer: createIgnorer_1,
  44722. optionsModule: options$1,
  44723. optionsNormalizer: optionsNormalizer,
  44724. utils: {
  44725. arrayify: arrayify
  44726. }
  44727. },
  44728. /* istanbul ignore next */
  44729. __debug: {
  44730. parse: withPlugins(core.parse),
  44731. formatAST: withPlugins(core.formatAST),
  44732. formatDoc: withPlugins(core.formatDoc),
  44733. printToDoc: withPlugins(core.printToDoc),
  44734. printDocToString: withPlugins(core.printDocToString)
  44735. }
  44736. };
  44737. var prettier = src$1;
  44738. module.exports = prettier;